Skip to content

Commit

Permalink
Multiple-yaxis-scales, 3 series with 2 scales demo was broken
Browse files Browse the repository at this point in the history
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. #3073 #3553 #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 #4241.
5) wrong point annotation x position in sparkline chart fix #4081.
  • Loading branch information
rosco54 committed Mar 19, 2024
2 parents a818970 + 7b79778 commit 686266c
Show file tree
Hide file tree
Showing 25 changed files with 608 additions and 516 deletions.
3 changes: 2 additions & 1 deletion samples/react/column/stacked-column-with-line-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/react/column/stacked-column-with-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/source/column/stacked-column-with-line-new.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ xaxis: {
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/source/column/stacked-column-with-line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ xaxis: {
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/vanilla-js/column/stacked-column-with-line-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/vanilla-js/column/stacked-column-with-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/vue/column/stacked-column-with-line-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion samples/vue/column/stacked-column-with-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@
labels: {
showDuplicates: false,
formatter: function(value) {
return value?.toFixed(0) // Value is undefined if all series are collapsed
// Value is undefined if all series are collapsed
return value !== undefined ? value.toFixed(0) : ''
}
}
},
Expand Down
15 changes: 10 additions & 5 deletions src/charts/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Bar {
this.baseLineInvertedY = xyRatios.baseLineInvertedY
}
this.yaxisIndex = 0
this.translationsIndex = 0
this.seriesLen = 0
this.pathArr = []

Expand Down Expand Up @@ -126,8 +127,10 @@ class Bar {
let barWidth = 0

if (this.yRatio.length > 1) {
this.yaxisIndex = realIndex
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex]
this.translationsIndex = realIndex
}
let translationsIndex = this.translationsIndex

this.isReversed =
w.config.yaxis[this.yaxisIndex] &&
Expand Down Expand Up @@ -182,6 +185,7 @@ class Bar {
i,
j,
realIndex,
translationsIndex,
bc,
},
x,
Expand All @@ -204,7 +208,7 @@ class Bar {
barWidth,
zeroH,
})
barHeight = this.series[i][j] / this.yRatio[this.yaxisIndex]
barHeight = this.series[i][j] / this.yRatio[translationsIndex]
}

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

let realIndex = indexes.realIndex
let translationsIndex = indexes.translationsIndex
let i = indexes.i
let j = indexes.j
let bc = indexes.bc
Expand Down Expand Up @@ -540,7 +545,7 @@ class Bar {
}
}

y = this.barHelpers.getYForValue(this.series[i][j], zeroH)
y = this.barHelpers.getYForValue(this.series[i][j], zeroH, translationsIndex)

const paths = this.barHelpers.getColumnPaths({
barXPosition,
Expand All @@ -549,7 +554,7 @@ class Bar {
y2: y,
strokeWidth,
series: this.series,
realIndex: indexes.realIndex,
realIndex: realIndex,
i,
j,
w,
Expand All @@ -573,7 +578,7 @@ class Bar {
pathFrom: paths.pathFrom,
x,
y,
goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j),
goalY: this.barHelpers.getGoalValues('y', null, zeroH, i, j, translationsIndex),
barXPosition,
barWidth,
}
Expand Down
27 changes: 16 additions & 11 deletions src/charts/BarStacked.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ class BarStacked extends Bar {

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

let translationsIndex = 0
if (this.yRatio.length > 1) {
this.yaxisIndex = realIndex
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0]
translationsIndex = realIndex
}

this.isReversed =
Expand Down Expand Up @@ -97,7 +99,8 @@ class BarStacked extends Bar {
xDivision,
yDivision,
zeroH,
zeroW
zeroW,
translationsIndex
)
y = initPositions.y
barHeight = initPositions.barHeight
Expand Down Expand Up @@ -126,7 +129,7 @@ class BarStacked extends Bar {
for (let j = 0; j < w.globals.dataPoints; j++) {
const strokeWidth = this.barHelpers.getStrokeWidth(i, j, realIndex)
const commonPathOpts = {
indexes: { i, j, realIndex, bc },
indexes: { i, j, realIndex, translationsIndex, bc },
strokeWidth,
x,
y,
Expand All @@ -150,7 +153,7 @@ class BarStacked extends Bar {
barWidth,
zeroH,
})
barHeight = this.series[i][j] / this.yRatio[this.yaxisIndex]
barHeight = this.series[i][j] / this.yRatio[translationsIndex]
}

const barGoalLine = this.barHelpers.drawGoalLine({
Expand Down Expand Up @@ -214,7 +217,7 @@ class BarStacked extends Bar {
return ret
}

initialPositions(x, y, xDivision, yDivision, zeroH, zeroW) {
initialPositions(x, y, xDivision, yDivision, zeroH, zeroW, translationsIndex) {
let w = this.w

let barHeight, barWidth
Expand Down Expand Up @@ -257,9 +260,9 @@ class BarStacked extends Bar {
}
zeroH =
w.globals.gridHeight -
this.baseLineY[this.yaxisIndex] -
this.baseLineY[translationsIndex] -
(this.isReversed ? w.globals.gridHeight : 0) +
(this.isReversed ? this.baseLineY[this.yaxisIndex] * 2 : 0)
(this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0)

// initial x position is one third of barWidth
x = w.globals.padHorizontal + (xDivision - barWidth) / 2
Expand Down Expand Up @@ -297,6 +300,7 @@ class BarStacked extends Bar {
let barXPosition
let i = indexes.i
let j = indexes.j
let translationsIndex = indexes.translationsIndex

let prevBarW = 0
for (let k = 0; k < this.groupCtx.prevXF.length; k++) {
Expand Down Expand Up @@ -369,7 +373,7 @@ class BarStacked extends Bar {
return {
pathTo: paths.pathTo,
pathFrom: paths.pathFrom,
goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j),
goalX: this.barHelpers.getGoalValues('x', zeroW, null, i, j, translationsIndex),
barYPosition,
x,
y,
Expand All @@ -391,6 +395,7 @@ class BarStacked extends Bar {
let i = indexes.i
let j = indexes.j
let bc = indexes.bc
let translationsIndex = indexes.translationsIndex

if (w.globals.isXNumeric) {
let seriesVal = w.globals.seriesX[i][j]
Expand Down Expand Up @@ -485,9 +490,9 @@ class BarStacked extends Bar {
if (this.series[i][j]) {
y =
barYPosition -
this.series[i][j] / this.yRatio[this.yaxisIndex] +
this.series[i][j] / this.yRatio[translationsIndex] +
(this.isReversed
? this.series[i][j] / this.yRatio[this.yaxisIndex]
? this.series[i][j] / this.yRatio[translationsIndex]
: 0) *
2
} else {
Expand All @@ -500,7 +505,7 @@ class BarStacked extends Bar {
barWidth,
y1: barYPosition,
y2: y,
yRatio: this.yRatio[this.yaxisIndex],
yRatio: this.yRatio[translationsIndex],
strokeWidth: this.strokeWidth,
series: this.series,
seriesGroup,
Expand Down
9 changes: 6 additions & 3 deletions src/charts/BoxCandleStick.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ class BoxCandleStick extends Bar {
let barHeight = 0
let barWidth = 0

let translationsIndex = 0
if (this.yRatio.length > 1) {
this.yaxisIndex = realIndex
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex][0]
translationsIndex = realIndex
}

let initPositions = this.barHelpers.initialPositions()
Expand Down Expand Up @@ -98,7 +100,8 @@ class BoxCandleStick extends Bar {
indexes: {
i,
j,
realIndex
realIndex,
translationsIndex
},
x,
y,
Expand Down Expand Up @@ -201,7 +204,7 @@ class BoxCandleStick extends Bar {
color = [this.boxOptions.colors.lower, this.boxOptions.colors.upper]
}

const yRatio = this.yRatio[this.yaxisIndex]
const yRatio = this.yRatio[indexes.translationsIndex]
let realIndex = indexes.realIndex

const ohlc = this.getOHLCValue(realIndex, j)
Expand Down
20 changes: 14 additions & 6 deletions src/charts/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class Line {
series = this.lineHelpers.sameValueSeriesFix(i, series)

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


this._initSerieVariables(series, i, realIndex)

Expand Down Expand Up @@ -97,6 +99,7 @@ class Line {
series,
prevY,
lineYPosition,
translationsIndex
})
prevY = firstPrevY.prevY
if (w.config.stroke.curve === 'monotonCubic' && series[i][0] === null) {
Expand All @@ -116,6 +119,7 @@ class Line {
series: seriesRangeEnd,
prevY: prevY2,
lineYPosition,
translationsIndex
})
prevY2 = firstPrevY2.prevY
pY2 = prevY2
Expand All @@ -136,6 +140,7 @@ class Line {
type,
series,
realIndex,
translationsIndex,
i,
x,
y,
Expand Down Expand Up @@ -221,8 +226,10 @@ class Line {
? w.config.stroke.width[realIndex]
: w.config.stroke.width

let translationsIndex = 0
if (this.yRatio.length > 1) {
this.yaxisIndex = realIndex
this.yaxisIndex = w.globals.seriesYAxisReverseMap[realIndex]
translationsIndex = realIndex
}

this.isReversed =
Expand All @@ -232,9 +239,9 @@ class Line {
// zeroY is the 0 value in y series which can be used in negative charts
this.zeroY =
w.globals.gridHeight -
this.baseLineY[this.yaxisIndex] -
this.baseLineY[translationsIndex] -
(this.isReversed ? w.globals.gridHeight : 0) +
(this.isReversed ? this.baseLineY[this.yaxisIndex] * 2 : 0)
(this.isReversed ? this.baseLineY[translationsIndex] * 2 : 0)

this.areaBottomY = this.zeroY
if (
Expand Down Expand Up @@ -288,7 +295,7 @@ class Line {
for (let s = 0; s < series[i].length; s++) {
if (series[i][s] !== null) {
prevX = this.xDivision * s
prevY = this.zeroY - series[i][s] / this.yRatio[this.yaxisIndex]
prevY = this.zeroY - series[i][s] / this.yRatio[realIndex]
linePath = graphics.move(prevX, prevY)
areaPath = graphics.move(prevX, this.areaBottomY)
break
Expand Down Expand Up @@ -478,6 +485,7 @@ class Line {
series,
iterations,
realIndex,
translationsIndex,
i,
x,
y,
Expand Down Expand Up @@ -513,8 +521,8 @@ class Line {
const getY = (_y, lineYPos) => {
return (
lineYPos -
_y / yRatio[this.yaxisIndex] +
(this.isReversed ? _y / yRatio[this.yaxisIndex] : 0) * 2
_y / yRatio[translationsIndex] +
(this.isReversed ? _y / yRatio[translationsIndex] : 0) * 2
)
}

Expand Down

0 comments on commit 686266c

Please sign in to comment.