Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow stack bar only #3891

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/charts/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ class Line {
}

let y2 = y

let stackSeries =
w.config.chart.stacked &&
(!this.w.config.chart.stackOnlyBar ||
(this.w.config.series[realIndex] &&
this.w.config.series[realIndex].type &&
(this.w.config.series[realIndex].type === 'bar' ||
this.w.config.series[realIndex].type === '')))

for (let j = 0; j < iterations; j++) {
const isNull =
typeof series[i][j + 1] === 'undefined' || series[i][j + 1] === null
Expand All @@ -505,7 +514,7 @@ class Line {
x = x + this.xDivision
}

if (w.config.chart.stacked) {
if (stackSeries) {
if (
i > 0 &&
w.globals.collapsedSeries.length < w.config.series.length - 1
Expand Down
6 changes: 4 additions & 2 deletions src/charts/common/line/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ export default class Helpers {

determineFirstPrevY({ i, series, prevY, lineYPosition }) {
let w = this.w
let stackSeries = w.config.chart.stacked && (!w.config.chart.stackOnlyBar || (series[i] && series[i].type && series[i].type === 'bar'));

if (typeof series[i]?.[0] !== 'undefined') {
if (w.config.chart.stacked) {
if (stackSeries) {
if (i > 0) {
// 1st y value of previous series
lineYPosition = this.lineCtx.prevSeriesY[i - 1][0]
Expand All @@ -126,7 +128,7 @@ export default class Helpers {
} else {
// the first value in the current series is null
if (
w.config.chart.stacked &&
stackSeries &&
i > 0 &&
typeof series[i][0] === 'undefined'
) {
Expand Down
16 changes: 11 additions & 5 deletions src/modules/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,12 +549,18 @@ class Range {
stackedPoss[group][j] = 0
stackedNegs[group][j] = 0
}

if (gl.series[i][j] !== null && Utils.isNumber(gl.series[i][j])) {
gl.series[i][j] > 0
? (stackedPoss[group][j] += parseFloat(gl.series[i][j]) + 0.0001)
: (stackedNegs[group][j] += parseFloat(gl.series[i][j]))
let stackSeries =
!this.w.config.chart.stackOnlyBar ||
(gl.series[i] && gl.series[i].type && gl.series[i].type === 'bar')

if (stackSeries) {
if (gl.series[i][j] !== null && Utils.isNumber(gl.series[i][j])) {
gl.series[i][j] > 0
? (stackedPoss[group][j] += parseFloat(gl.series[i][j]) + 0.0001)
: (stackedNegs[group][j] += parseFloat(gl.series[i][j]))
}
}

}
})
})
Expand Down
2 changes: 2 additions & 0 deletions src/modules/settings/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export default class Options {
target: undefined,
},
stacked: false,
stackOnlyBar: true, // mixed chart with stacked bars and line series - incorrect line draw #907
stackType: 'normal',
toolbar: {
show: true,
Expand Down Expand Up @@ -921,6 +922,7 @@ export default class Options {
enabled: true,
enabledOnSeries: undefined,
shared: true,
hideEmptyShared: true,
followCursor: false, // when disabled, the tooltip will show on top of the series instead of mouse position
intersect: false, // when enabled, tooltip will only show when user directly hovers over point
inverseOrder: false,
Expand Down
11 changes: 11 additions & 0 deletions src/modules/tooltip/Labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,17 @@ export default class Labels {

if (shared && ttItemsChildren[0]) {
// hide when no Val or series collapsed
if (w.config.tooltip.hideEmptyShared) {
let ttItemMarker = ttItems[t].querySelector('.apexcharts-tooltip-marker');
let ttItemText = ttItems[t].querySelector('.apexcharts-tooltip-text');
if (parseFloat(val) == 0) {
ttItemMarker.style.display = 'none';
ttItemText.style.display = 'none';
} else {
ttItemMarker.style.display = 'block';
ttItemText.style.display = 'block';
}
}
if (
typeof val === 'undefined' ||
val === null ||
Expand Down