Skip to content

Commit 30f2b30

Browse files
committed
Multiple-yaxis-scales, 3 series with 2 scales demo was broken
by 3.47.0 after the introduction of the new yaxis:seriesName as an array feature. Refactored some of that code. Fixes relating to yaxis.seriesName array feature added to 3.47.0. Anything that indexes into minYArr[], maxYArr[], baseLineY[], xyRatios.yRatio[], etc, that doesn't derive from realIndex needed to map the index through w.globals.seriesYAxisMap[seriesIndex]. Fix historical issue with goals and annotations being drawn when the axis is hidden or drawn outside the grid area when zoomed or panned, or where rect area annotation should be clipped. apexcharts#3073 apexcharts#3553 apexcharts#2757 Fix historical baseLineY not being scaled correctly for logarithmic yaxis. Miscellaneous: 1) Remove yaxis.min: 0 from the bar axes in sample as not required. 2) Fix sample syntax not parsed by e2e test harness. 3) Fix several calls to CoreUtils.getLogVal(b,d,seriesIndex) that were missing the 'b' (base) argument. 4) in getYLogValue(): return zero if 'd' <= 0 (was 'd' == 0). This may fix apexcharts#4241. 5) wrong point annotation x position in sparkline chart fix apexcharts#4081.
2 parents a818970 + 7b79778 commit 30f2b30

25 files changed

+589
-507
lines changed

samples/react/column/stacked-column-with-line-new.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@
290290
labels: {
291291
showDuplicates: false,
292292
formatter: function(value) {
293-
return value?.toFixed(0) // Value is undefined if all series are collapsed
293+
// Value is undefined if all series are collapsed
294+
return value !== undefined ? value.toFixed(0) : ''
294295
}
295296
}
296297
},

samples/react/column/stacked-column-with-line.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@
290290
labels: {
291291
showDuplicates: false,
292292
formatter: function(value) {
293-
return value?.toFixed(0) // Value is undefined if all series are collapsed
293+
// Value is undefined if all series are collapsed
294+
return value !== undefined ? value.toFixed(0) : ''
294295
}
295296
}
296297
},

samples/source/column/stacked-column-with-line-new.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ xaxis: {
7171
labels: {
7272
showDuplicates: false,
7373
formatter: function(value) {
74-
return value?.toFixed(0) // Value is undefined if all series are collapsed
74+
// Value is undefined if all series are collapsed
75+
return value !== undefined ? value.toFixed(0) : ''
7576
}
7677
}
7778
},

samples/source/column/stacked-column-with-line.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ xaxis: {
7171
labels: {
7272
showDuplicates: false,
7373
formatter: function(value) {
74-
return value?.toFixed(0) // Value is undefined if all series are collapsed
74+
// Value is undefined if all series are collapsed
75+
return value !== undefined ? value.toFixed(0) : ''
7576
}
7677
}
7778
},

samples/vanilla-js/column/stacked-column-with-line-new.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@
273273
labels: {
274274
showDuplicates: false,
275275
formatter: function(value) {
276-
return value?.toFixed(0) // Value is undefined if all series are collapsed
276+
// Value is undefined if all series are collapsed
277+
return value !== undefined ? value.toFixed(0) : ''
277278
}
278279
}
279280
},

samples/vanilla-js/column/stacked-column-with-line.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@
273273
labels: {
274274
showDuplicates: false,
275275
formatter: function(value) {
276-
return value?.toFixed(0) // Value is undefined if all series are collapsed
276+
// Value is undefined if all series are collapsed
277+
return value !== undefined ? value.toFixed(0) : ''
277278
}
278279
}
279280
},

samples/vue/column/stacked-column-with-line-new.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@
293293
labels: {
294294
showDuplicates: false,
295295
formatter: function(value) {
296-
return value?.toFixed(0) // Value is undefined if all series are collapsed
296+
// Value is undefined if all series are collapsed
297+
return value !== undefined ? value.toFixed(0) : ''
297298
}
298299
}
299300
},

samples/vue/column/stacked-column-with-line.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@
293293
labels: {
294294
showDuplicates: false,
295295
formatter: function(value) {
296-
return value?.toFixed(0) // Value is undefined if all series are collapsed
296+
// Value is undefined if all series are collapsed
297+
return value !== undefined ? value.toFixed(0) : ''
297298
}
298299
}
299300
},

src/charts/Bar.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Bar {
4242
this.baseLineInvertedY = xyRatios.baseLineInvertedY
4343
}
4444
this.yaxisIndex = 0
45+
this.translationsIndex = 0
4546
this.seriesLen = 0
4647
this.pathArr = []
4748

@@ -126,8 +127,10 @@ class Bar {
126127
let barWidth = 0
127128

128129
if (this.yRatio.length > 1) {
129-
this.yaxisIndex = realIndex
130+
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex]
131+
this.translationsIndex = realIndex
130132
}
133+
let translationsIndex = this.translationsIndex
131134

132135
this.isReversed =
133136
w.config.yaxis[this.yaxisIndex] &&
@@ -182,6 +185,7 @@ class Bar {
182185
i,
183186
j,
184187
realIndex,
188+
translationsIndex,
185189
bc,
186190
},
187191
x,
@@ -204,7 +208,7 @@ class Bar {
204208
barWidth,
205209
zeroH,
206210
})
207-
barHeight = this.series[i][j] / this.yRatio[this.yaxisIndex]
211+
barHeight = this.series[i][j] / this.yRatio[translationsIndex]
208212
}
209213

210214
let pathFill = this.barHelpers.getPathFillColor(series, i, j, realIndex)
@@ -511,6 +515,7 @@ class Bar {
511515
let w = this.w
512516

513517
let realIndex = indexes.realIndex
518+
let translationsIndex = indexes.translationsIndex
514519
let i = indexes.i
515520
let j = indexes.j
516521
let bc = indexes.bc
@@ -540,7 +545,7 @@ class Bar {
540545
}
541546
}
542547

543-
y = this.barHelpers.getYForValue(this.series[i][j], zeroH)
548+
y = this.barHelpers.getYForValue(this.series[i][j], zeroH, translationsIndex)
544549

545550
const paths = this.barHelpers.getColumnPaths({
546551
barXPosition,
@@ -549,7 +554,7 @@ class Bar {
549554
y2: y,
550555
strokeWidth,
551556
series: this.series,
552-
realIndex: indexes.realIndex,
557+
realIndex: realIndex,
553558
i,
554559
j,
555560
w,
@@ -573,7 +578,7 @@ class Bar {
573578
pathFrom: paths.pathFrom,
574579
x,
575580
y,
576-
goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j),
581+
goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
577582
barXPosition,
578583
barWidth,
579584
}

src/charts/BarStacked.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ class BarStacked extends Bar {
6161

6262
let realIndex = w.globals.comboCharts ? seriesIndex[i] : i
6363

64+
let translationsIndex = 0
6465
if (this.yRatio.length > 1) {
65-
this.yaxisIndex = realIndex
66+
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0]
67+
translationsIndex = realIndex
6668
}
6769

6870
this.isReversed =
@@ -97,7 +99,8 @@ class BarStacked extends Bar {
9799
xDivision,
98100
yDivision,
99101
zeroH,
100-
zeroW
102+
zeroW,
103+
translationsIndex
101104
)
102105
y = initPositions.y
103106
barHeight = initPositions.barHeight
@@ -126,7 +129,7 @@ class BarStacked extends Bar {
126129
for (let j = 0; j < w.globals.dataPoints; j++) {
127130
const strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex)
128131
const commonPathOpts = {
129-
indexes: { i, j, realIndex, bc },
132+
indexes: { i, j, realIndex, translationsIndex, bc },
130133
strokeWidth,
131134
x,
132135
y,
@@ -150,7 +153,7 @@ class BarStacked extends Bar {
150153
barWidth,
151154
zeroH,
152155
})
153-
barHeight = this.series[i][j] / this.yRatio[this.yaxisIndex]
156+
barHeight = this.series[i][j] / this.yRatio[translationsIndex]
154157
}
155158

156159
const barGoalLine = this.barHelpers.drawGoalLine({
@@ -214,7 +217,7 @@ class BarStacked extends Bar {
214217
return ret
215218
}
216219

217-
initialPositions(x, y, xDivision, yDivision, zeroH, zeroW) {
220+
initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex) {
218221
let w = this.w
219222

220223
let barHeight, barWidth
@@ -257,9 +260,9 @@ class BarStacked extends Bar {
257260
}
258261
zeroH =
259262
w.globals.gridHeight -
260-
this.baseLineY[this.yaxisIndex] -
263+
this.baseLineY[translationsIndex] -
261264
(this.isReversed ? w.globals.gridHeight : 0) +
262-
(this.isReversed ? this.baseLineY[this.yaxisIndex] * 2 : 0)
265+
(this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0)
263266

264267
// initial x position is one third of barWidth
265268
x = w.globals.padHorizontal + (xDivision - barWidth) / 2
@@ -297,6 +300,7 @@ class BarStacked extends Bar {
297300
let barXPosition
298301
let i = indexes.i
299302
let j = indexes.j
303+
let translationsIndex = indexes.translationsIndex
300304

301305
let prevBarW = 0
302306
for (let k = 0; k < this.groupCtx.prevXF.length; k++) {
@@ -369,7 +373,7 @@ class BarStacked extends Bar {
369373
return {
370374
pathTo: paths.pathTo,
371375
pathFrom: paths.pathFrom,
372-
goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j),
376+
goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j, translationsIndex),
373377
barYPosition,
374378
x,
375379
y,
@@ -391,6 +395,7 @@ class BarStacked extends Bar {
391395
let i = indexes.i
392396
let j = indexes.j
393397
let bc = indexes.bc
398+
let translationsIndex = indexes.translationsIndex
394399

395400
if (w.globals.isXNumeric) {
396401
let seriesVal = w.globals.seriesX[i][j]
@@ -485,9 +490,9 @@ class BarStacked extends Bar {
485490
if (this.series[i][j]) {
486491
y =
487492
barYPosition -
488-
this.series[i][j] / this.yRatio[this.yaxisIndex] +
493+
this.series[i][j] / this.yRatio[translationsIndex] +
489494
(this.isReversed
490-
? this.series[i][j] / this.yRatio[this.yaxisIndex]
495+
? this.series[i][j] / this.yRatio[translationsIndex]
491496
: 0) *
492497
2
493498
} else {
@@ -500,7 +505,7 @@ class BarStacked extends Bar {
500505
barWidth,
501506
y1: barYPosition,
502507
y2: y,
503-
yRatio: this.yRatio[this.yaxisIndex],
508+
yRatio: this.yRatio[translationsIndex],
504509
strokeWidth: this.strokeWidth,
505510
series: this.series,
506511
seriesGroup,

src/charts/BoxCandleStick.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ class BoxCandleStick extends Bar {
6666
let barHeight = 0
6767
let barWidth = 0
6868

69+
let translationsIndex = 0
6970
if (this.yRatio.length > 1) {
70-
this.yaxisIndex = realIndex
71+
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0]
72+
translationsIndex = realIndex
7173
}
7274

7375
let initPositions = this.barHelpers.initialPositions()
@@ -98,7 +100,8 @@ class BoxCandleStick extends Bar {
98100
indexes: {
99101
i,
100102
j,
101-
realIndex
103+
realIndex,
104+
translationsIndex
102105
},
103106
x,
104107
y,
@@ -201,7 +204,7 @@ class BoxCandleStick extends Bar {
201204
color = [this.boxOptions.colors.lower, this.boxOptions.colors.upper]
202205
}
203206

204-
const yRatio = this.yRatio[this.yaxisIndex]
207+
const yRatio = this.yRatio[indexes.translationsIndex]
205208
let realIndex = indexes.realIndex
206209

207210
const ohlc = this.getOHLCValue(realIndex, j)

src/charts/Line.js

+14-6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class Line {
6262
series = this.lineHelpers.sameValueSeriesFix(i, series)
6363

6464
let realIndex = w.globals.comboCharts ? seriesIndex[i] : i
65+
let translationsIndex = this.yRatio.length > 1 ? realIndex: 0
66+
6567

6668
this._initSerieVariables(series, i, realIndex)
6769

@@ -97,6 +99,7 @@ class Line {
9799
series,
98100
prevY,
99101
lineYPosition,
102+
translationsIndex
100103
})
101104
prevY = firstPrevY.prevY
102105
if (w.config.stroke.curve === 'monotonCubic' && series[i][0] === null) {
@@ -116,6 +119,7 @@ class Line {
116119
series: seriesRangeEnd,
117120
prevY: prevY2,
118121
lineYPosition,
122+
translationsIndex
119123
})
120124
prevY2 = firstPrevY2.prevY
121125
pY2 = prevY2
@@ -136,6 +140,7 @@ class Line {
136140
type,
137141
series,
138142
realIndex,
143+
translationsIndex,
139144
i,
140145
x,
141146
y,
@@ -221,8 +226,10 @@ class Line {
221226
? w.config.stroke.width[realIndex]
222227
: w.config.stroke.width
223228

229+
let translationsIndex = 0
224230
if (this.yRatio.length > 1) {
225-
this.yaxisIndex = realIndex
231+
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex]
232+
translationsIndex = realIndex
226233
}
227234

228235
this.isReversed =
@@ -232,9 +239,9 @@ class Line {
232239
// zeroY is the 0 value in y series which can be used in negative charts
233240
this.zeroY =
234241
w.globals.gridHeight -
235-
this.baseLineY[this.yaxisIndex] -
242+
this.baseLineY[translationsIndex] -
236243
(this.isReversed ? w.globals.gridHeight : 0) +
237-
(this.isReversed ? this.baseLineY[this.yaxisIndex] * 2 : 0)
244+
(this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0)
238245

239246
this.areaBottomY = this.zeroY
240247
if (
@@ -288,7 +295,7 @@ class Line {
288295
for (let s = 0; s < series[i].length; s++) {
289296
if (series[i][s] !== null) {
290297
prevX = this.xDivision * s
291-
prevY = this.zeroY - series[i][s] / this.yRatio[this.yaxisIndex]
298+
prevY = this.zeroY - series[i][s] / this.yRatio[realIndex]
292299
linePath = graphics.move(prevX, prevY)
293300
areaPath = graphics.move(prevX, this.areaBottomY)
294301
break
@@ -478,6 +485,7 @@ class Line {
478485
series,
479486
iterations,
480487
realIndex,
488+
translationsIndex,
481489
i,
482490
x,
483491
y,
@@ -513,8 +521,8 @@ class Line {
513521
const getY = (_y, lineYPos) => {
514522
return (
515523
lineYPos -
516-
_y / yRatio[this.yaxisIndex] +
517-
(this.isReversed ? _y / yRatio[this.yaxisIndex] : 0) * 2
524+
_y / yRatio[translationsIndex] +
525+
(this.isReversed ? _y / yRatio[translationsIndex] : 0) * 2
518526
)
519527
}
520528

0 commit comments

Comments
 (0)