Skip to content

Commit

Permalink
Merge pull request #4331 from rosco54/Issue_4323_rebased
Browse files Browse the repository at this point in the history
Multiple-yaxis-scales, 3 series with 2 scales demo was broken by 3.47.0
  • Loading branch information
junedchhipa committed Mar 19, 2024
2 parents 119fabc + 686266c commit 733b080
Show file tree
Hide file tree
Showing 29 changed files with 619 additions and 500 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
2 changes: 0 additions & 2 deletions samples/react/mixed/multiple-yaxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
},
yaxis: [
{
min: 0,
seriesName: 'Income',
axisTicks: {
show: true,
Expand All @@ -139,7 +138,6 @@
}
},
{
min: 0,
seriesName: 'Cashflow',
opposite: true,
axisTicks: {
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
2 changes: 0 additions & 2 deletions samples/source/mixed/multiple-yaxes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ xaxis: {
},
yaxis: [
{
min: 0,
seriesName: 'Income',
axisTicks: {
show: true,
Expand All @@ -63,7 +62,6 @@ yaxis: [
}
},
{
min: 0,
seriesName: 'Cashflow',
opposite: true,
axisTicks: {
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
2 changes: 0 additions & 2 deletions samples/vanilla-js/mixed/multiple-yaxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
},
yaxis: [
{
min: 0,
seriesName: 'Income',
axisTicks: {
show: true,
Expand All @@ -122,7 +121,6 @@
}
},
{
min: 0,
seriesName: 'Cashflow',
opposite: true,
axisTicks: {
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
2 changes: 0 additions & 2 deletions samples/vue/mixed/multiple-yaxes.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
},
yaxis: [
{
min: 0,
seriesName: 'Income',
axisTicks: {
show: true,
Expand All @@ -142,7 +141,6 @@
}
},
{
min: 0,
seriesName: 'Cashflow',
opposite: true,
axisTicks: {
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
Loading

0 comments on commit 733b080

Please sign in to comment.