Skip to content

Commit a6cefdc

Browse files
committed
fixes #4790; fixes #4791; fix marker bug when null values were present
1 parent afe2d86 commit a6cefdc

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed

src/charts/Line.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,17 @@ class Line {
299299

300300
if (w.globals.hasNullValues) {
301301
// fixes https://github.com/apexcharts/apexcharts.js/issues/3641
302-
const firstPoint = this.markers.plotChartMarkers(
303-
{
302+
const firstPoint = this.markers.plotChartMarkers({
303+
pointsPos: {
304304
x: [w.globals.minX - 100],
305305
y: [w.globals.minY - 100],
306306
},
307-
i,
308-
0,
309-
0.1,
310-
true
311-
)
307+
seriesIndex: i,
308+
j: 0,
309+
pSize: 0.1,
310+
alwaysDrawMarker: true,
311+
isVirtualPoint: true,
312+
})
312313

313314
if (firstPoint !== null) {
314315
// firstPoint is rendered for cases where there are null values and when dynamic markers are required
@@ -764,11 +765,11 @@ class Line {
764765
this.elPointsMain.node.classList.add('apexcharts-element-hidden')
765766
}
766767

767-
let elPointsWrap = this.markers.plotChartMarkers(
768+
let elPointsWrap = this.markers.plotChartMarkers({
768769
pointsPos,
769-
realIndex,
770-
j + 1
771-
)
770+
seriesIndex: realIndex,
771+
j: j + 1,
772+
})
772773
if (elPointsWrap !== null) {
773774
this.elPointsMain.add(elPointsWrap)
774775
}
@@ -1150,14 +1151,15 @@ class Line {
11501151
if (!(pSize > 0)) {
11511152
pSize = 0
11521153
}
1154+
11531155
// fixes apexcharts.js#1282, #1252
1154-
let elPointsWrap = this.markers.plotChartMarkers(
1156+
let elPointsWrap = this.markers.plotChartMarkers({
11551157
pointsPos,
1156-
realIndex,
1157-
j + 1,
1158+
seriesIndex: realIndex,
1159+
j: j + 1,
11581160
pSize,
1159-
true
1160-
)
1161+
alwaysDrawMarker: true,
1162+
})
11611163
if (elPointsWrap !== null) {
11621164
this.elPointsMain.add(elPointsWrap)
11631165
}

src/charts/common/line/Helpers.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,41 +34,35 @@ export default class Helpers {
3434
let ptX = []
3535
let ptY = []
3636

37-
if (j === 0) {
38-
let xPT1st =
39-
this.lineCtx.categoryAxisCorrection + w.config.markers.offsetX
40-
// the first point for line series
41-
// we need to check whether it's not a time series, because a time series may
42-
// start from the middle of the x axis
43-
if (w.globals.isXNumeric) {
44-
xPT1st =
45-
(w.globals.seriesX[realIndex][0] - w.globals.minX) /
46-
this.lineCtx.xRatio +
47-
w.config.markers.offsetX
48-
}
37+
let xPT1st = this.lineCtx.categoryAxisCorrection + w.config.markers.offsetX
38+
39+
// the first point for line series
40+
// we need to check whether it's not a time series, because a time series may
41+
// start from the middle of the x axis
42+
if (w.globals.isXNumeric) {
43+
xPT1st =
44+
(w.globals.seriesX[realIndex][0] - w.globals.minX) /
45+
this.lineCtx.xRatio +
46+
w.config.markers.offsetX
47+
}
4948

50-
// push 2 points for the first data values
49+
// push 2 points for the first data values
50+
if (j === 0) {
5151
ptX.push(xPT1st)
5252
ptY.push(
5353
Utils.isNumber(series[i][0]) ? prevY + w.config.markers.offsetY : null
5454
)
55-
ptX.push(x + w.config.markers.offsetX)
56-
ptY.push(
57-
Utils.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null
58-
)
59-
} else {
60-
ptX.push(x + w.config.markers.offsetX)
61-
ptY.push(
62-
Utils.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null
63-
)
6455
}
6556

66-
let pointsPos = {
57+
ptX.push(x + w.config.markers.offsetX)
58+
ptY.push(
59+
Utils.isNumber(series[i][j + 1]) ? y + w.config.markers.offsetY : null
60+
)
61+
62+
return {
6763
x: ptX,
6864
y: ptY,
6965
}
70-
71-
return pointsPos
7266
}
7367

7468
checkPreviousPaths({ pathFromLine, pathFromArea, realIndex }) {

src/modules/Markers.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ export default class Markers {
3434
}
3535
}
3636

37-
plotChartMarkers(pointsPos, seriesIndex, j, pSize, alwaysDrawMarker = false) {
37+
plotChartMarkers({
38+
pointsPos,
39+
seriesIndex,
40+
j,
41+
pSize,
42+
alwaysDrawMarker = false,
43+
isVirtualPoint = false,
44+
}) {
3845
let w = this.w
3946

4047
let i = seriesIndex
@@ -51,7 +58,11 @@ export default class Markers {
5158
let markerElement
5259

5360
let dataPointIndex = j
54-
const invalidMarker = !Utils.isNumber(p.y[q])
61+
let invalidMarker = !Utils.isNumber(p.y[q])
62+
63+
if (w.globals.series[i][j + 1] !== null && !isVirtualPoint) {
64+
invalidMarker = true
65+
}
5566

5667
// a small hack as we have 2 points for the first val to connect it
5768
if (j === 1 && q === 0) dataPointIndex = 0

0 commit comments

Comments
 (0)