Skip to content

Commit

Permalink
hidden property added to series; fix #468
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Aug 13, 2024
1 parent ce68600 commit e0ed1cf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 46 deletions.
19 changes: 14 additions & 5 deletions src/apexcharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,23 @@ export default class ApexCharts {
return null
}

const combo = CoreUtils.checkComboSeries(ser, w.config.chart.type)
let series = ser
ser.forEach((s, realIndex) => {
if (s.hidden) {
series = this.legend.legendHelpers.collapseHiddenSeries({
realIndex,
})
}
})

const combo = CoreUtils.checkComboSeries(series, w.config.chart.type)
gl.comboCharts = combo.comboCharts
gl.comboBarCount = combo.comboBarCount

const allSeriesAreEmpty = ser.every((s) => s.data && s.data.length === 0)
const allSeriesAreEmpty = series.every((s) => s.data && s.data.length === 0)

if (
ser.length === 0 ||
series.length === 0 ||
(allSeriesAreEmpty && gl.collapsedSeries.length < 1)
) {
this.series.handleNoData()
Expand All @@ -170,7 +179,7 @@ export default class ApexCharts {
this.events.setupEventHandlers()

// Handle the data inputted by user and set some of the global variables (for eg, if data is datetime / numeric / category). Don't calculate the range / min / max at this time
this.data.parseData(ser)
this.data.parseData(series)

// this is a good time to set theme colors first
this.theme.init()
Expand Down Expand Up @@ -222,7 +231,7 @@ export default class ApexCharts {

this.grid.createGridMask()

const elGraph = this.core.plotChartType(ser, xyRatios)
const elGraph = this.core.plotChartType(series, xyRatios)

const dataLabels = new DataLabels(this)
dataLabels.bringForward()
Expand Down
37 changes: 18 additions & 19 deletions src/charts/BoxCandleStick.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BoxCandleStick extends Bar {
this.barHelpers.initVariables(series)

let ret = graphics.group({
class: `apexcharts-${type}-series apexcharts-plot-series`
class: `apexcharts-${type}-series apexcharts-plot-series`,
})

for (let i = 0; i < series.length; i++) {
Expand All @@ -49,15 +49,14 @@ class BoxCandleStick extends Bar {

let realIndex = w.globals.comboCharts ? seriesIndex[i] : i
// As BoxCandleStick derives from Bar, we need this to render.
let {columnGroupIndex} =
this.barHelpers.getGroupIndex(realIndex)
let { columnGroupIndex } = this.barHelpers.getGroupIndex(realIndex)

// el to which series will be drawn
let elSeries = graphics.group({
class: `apexcharts-series`,
seriesName: Utils.escapeString(w.globals.seriesNames[realIndex]),
rel: i + 1,
'data:realIndex': realIndex
'data:realIndex': realIndex,
})

this.ctx.series.addCollapsedClassToSeries(elSeries, realIndex)
Expand Down Expand Up @@ -92,7 +91,7 @@ class BoxCandleStick extends Bar {
// eldatalabels
let elDataLabelsWrap = graphics.group({
class: 'apexcharts-datalabels',
'data:realIndex': realIndex
'data:realIndex': realIndex,
})

for (let j = 0; j < w.globals.dataPoints; j++) {
Expand All @@ -104,27 +103,27 @@ class BoxCandleStick extends Bar {
i,
j,
realIndex,
translationsIndex
translationsIndex,
},
x,
y,
strokeWidth,
elSeries
elSeries,
}

if (this.isHorizontal) {
paths = this.drawHorizontalBoxPaths({
...pathsParams,
yDivision,
barHeight,
zeroW
zeroW,
})
} else {
paths = this.drawVerticalBoxPaths({
...pathsParams,
xDivision,
barWidth,
zeroH
zeroH,
})
}

Expand All @@ -148,7 +147,7 @@ class BoxCandleStick extends Bar {
seriesNumber: realIndex,
dataPointIndex: j,
color: paths.color[pi],
value: series[i][j]
value: series[i][j],
})

this.renderSeries({
Expand All @@ -169,7 +168,7 @@ class BoxCandleStick extends Bar {
barWidth,
elDataLabelsWrap,
visibleSeries: this.visibleI,
type: w.config.chart.type
type: w.config.chart.type,
})
})
}
Expand All @@ -191,7 +190,7 @@ class BoxCandleStick extends Bar {
xDivision,
barWidth,
zeroH,
strokeWidth
strokeWidth,
}) {
let w = this.w
let graphics = new Graphics(this.ctx)
Expand Down Expand Up @@ -275,7 +274,7 @@ class BoxCandleStick extends Bar {
graphics.line(barXPosition + barWidth / 2, y2) +
graphics.line(barXPosition, y2) +
graphics.line(barXPosition, m) +
'z'
'z',
]
} else {
// candlestick
Expand All @@ -290,7 +289,7 @@ class BoxCandleStick extends Bar {
graphics.line(barXPosition + barWidth / 2, l2) +
graphics.line(barXPosition + barWidth / 2, y1) +
graphics.line(barXPosition, y1) +
graphics.line(barXPosition, y2 - strokeWidth / 2)
graphics.line(barXPosition, y2 - strokeWidth / 2),
]
}

Expand All @@ -306,7 +305,7 @@ class BoxCandleStick extends Bar {
x,
y: y2,
barXPosition,
color: this.isBoxPlot ? color : isPositive ? [colorPos] : [colorNeg]
color: this.isBoxPlot ? color : isPositive ? [colorPos] : [colorNeg],
}
}

Expand All @@ -317,7 +316,7 @@ class BoxCandleStick extends Bar {
yDivision,
barHeight,
zeroW,
strokeWidth
strokeWidth,
}) {
let w = this.w
let graphics = new Graphics(this.ctx)
Expand Down Expand Up @@ -394,7 +393,7 @@ class BoxCandleStick extends Bar {
graphics.line(x2, barYPosition + barHeight / 2) +
graphics.line(x2, barYPosition) +
graphics.line(m, barYPosition) +
'z'
'z',
]

pathFrom = pathFrom + graphics.move(x1, barYPosition)
Expand All @@ -409,7 +408,7 @@ class BoxCandleStick extends Bar {
x: x2,
y,
barYPosition,
color
color,
}
}
getOHLCValue(i, j) {
Expand All @@ -428,7 +427,7 @@ class BoxCandleStick extends Bar {
: w.globals.seriesCandleL[i][j],
c: this.isBoxPlot
? w.globals.seriesCandleL[i][j]
: w.globals.seriesCandleC[i][j]
: w.globals.seriesCandleC[i][j],
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/helpers/UpdateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default class UpdateHelpers {
color: s.color ? s.color : ser?.color,
type: s.type ? s.type : ser?.type,
group: s.group ? s.group : ser?.group,
hidden: typeof s.hidden !== 'undefined' ? s.hidden : ser?.hidden,
data: s.data ? s.data : ser?.data,
zIndex: typeof s.zIndex !== 'undefined' ? s.zIndex : i,
}
Expand Down
48 changes: 26 additions & 22 deletions src/modules/legend/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class Helpers {
}
}

hideSeries({ seriesEl, realIndex }) {
getSeriesAfterCollapsing({ realIndex }) {
const w = this.w
const gl = w.globals

Expand All @@ -168,22 +168,19 @@ export default class Helpers {
if (gl.axisCharts) {
let yaxis = w.config.yaxis[gl.seriesYAxisReverseMap[realIndex]]

const collapseData = {
index: realIndex,
data: series[realIndex].data.slice(),
type: series[realIndex].type || w.config.chart.type,
}
if (yaxis && yaxis.show && yaxis.showAlways) {
if (gl.ancillaryCollapsedSeriesIndices.indexOf(realIndex) < 0) {
gl.ancillaryCollapsedSeries.push({
index: realIndex,
data: series[realIndex].data.slice(),
type: seriesEl.parentNode.className.baseVal.split('-')[1],
})
gl.ancillaryCollapsedSeries.push(collapseData)
gl.ancillaryCollapsedSeriesIndices.push(realIndex)
}
} else {
if (gl.collapsedSeriesIndices.indexOf(realIndex) < 0) {
gl.collapsedSeries.push({
index: realIndex,
data: series[realIndex].data.slice(),
type: seriesEl.parentNode.className.baseVal.split('-')[1],
})
gl.collapsedSeries.push(collapseData)
gl.collapsedSeriesIndices.push(realIndex)

let removeIndexOfRising = gl.risingSeries.indexOf(realIndex)
Expand All @@ -198,6 +195,20 @@ export default class Helpers {
gl.collapsedSeriesIndices.push(realIndex)
}

gl.allSeriesCollapsed =
gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length ===
w.config.series.length

return this._getSeriesBasedOnCollapsedState(series)
}

hideSeries({ seriesEl, realIndex }) {
const w = this.w

let series = this.getSeriesAfterCollapsing({
realIndex,
})

let seriesChildren = seriesEl.childNodes
for (let sc = 0; sc < seriesChildren.length; sc++) {
if (
Expand All @@ -211,11 +222,6 @@ export default class Helpers {
}
}

gl.allSeriesCollapsed =
gl.collapsedSeries.length + gl.ancillaryCollapsedSeries.length ===
w.config.series.length

series = this._getSeriesBasedOnCollapsedState(series)
this.lgCtx.ctx.updateHelpers._updateSeries(
series,
w.config.chart.animations.dynamicAnimation.enabled
Expand All @@ -231,15 +237,13 @@ export default class Helpers {
if (collapsedSeries[c].index === realIndex) {
if (w.globals.axisCharts) {
series[realIndex].data = collapsedSeries[c].data.slice()
collapsedSeries.splice(c, 1)
seriesIndices.splice(c, 1)
w.globals.risingSeries.push(realIndex)
} else {
series[realIndex] = collapsedSeries[c].data
collapsedSeries.splice(c, 1)
seriesIndices.splice(c, 1)
w.globals.risingSeries.push(realIndex)
}
series[realIndex].hidden = false
collapsedSeries.splice(c, 1)
seriesIndices.splice(c, 1)
w.globals.risingSeries.push(realIndex)
}
}

Expand Down
1 change: 1 addition & 0 deletions types/apexcharts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ type ApexAxisChartSeries = {
type?: string
color?: string
group?: string
hidden?: boolean
zIndex?: number
data:
| (number | null)[]
Expand Down

0 comments on commit e0ed1cf

Please sign in to comment.