Skip to content

Commit

Permalink
Fix getMinYMaxY() handling of multiple Y values per X value that was
Browse files Browse the repository at this point in the history
broken sometime after revision 3.45.2 following changes to handle
chart y axis autoscaling directly within this function.
  • Loading branch information
rosco54 committed Jul 19, 2024
1 parent 260567f commit b28d322
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions src/modules/Range.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,6 @@ class Range {
if (endingSeriesIndex === null) {
endingSeriesIndex = startingSeriesIndex + 1
}

let firstXIndex = 0
let lastXIndex = 0
let seriesX = undefined
if (gl.seriesX.length >= endingSeriesIndex) {
seriesX = [...new Set([].concat(...gl.seriesX.slice(startingSeriesIndex, endingSeriesIndex)))]
firstXIndex = 0
lastXIndex = seriesX.length - 1
// Eventually brushSource will be set if the current chart is a target.
// That is, after the appropriate event causes us to update.
let brush = gl.brushSource?.w.config.chart.brush
if ((cnf.chart.zoom.enabled && cnf.chart.zoom.autoScaleYaxis)
|| (brush?.enabled && brush?.autoScaleYaxis)
) {
// Scale the Y axis to the min..max within the zoomed X axis domain.
if (cnf.xaxis.min) {
for (
firstXIndex = 0;
firstXIndex < lastXIndex && seriesX[firstXIndex] < cnf.xaxis.min;
firstXIndex++
) {}
}
if (cnf.xaxis.max) {
for (
;
lastXIndex > firstXIndex && seriesX[lastXIndex] > cnf.xaxis.max;
lastXIndex--
) {}
}
}
}

let series = gl.series
let seriesMin = series
Expand All @@ -82,6 +51,17 @@ class Range {
seriesMin = gl.seriesRangeStart
seriesMax = gl.seriesRangeEnd
}
let autoScaleYaxis = false
if (gl.seriesX.length >= endingSeriesIndex) {
// Eventually brushSource will be set if the current chart is a target.
// That is, after the appropriate event causes us to update.
let brush = gl.brushSource?.w.config.chart.brush
if ((cnf.chart.zoom.enabled && cnf.chart.zoom.autoScaleYaxis)
|| (brush?.enabled && brush?.autoScaleYaxis)
) {
autoScaleYaxis = true
}
}

for (let i = startingSeriesIndex; i < endingSeriesIndex; i++) {
gl.dataPoints = Math.max(gl.dataPoints, series[i].length)
Expand All @@ -102,9 +82,24 @@ class Range {
// the condition cnf.xaxis.type !== 'datetime' fixes #3897 and #3905
gl.dataPoints = Math.max(gl.dataPoints, gl.labels.length)
}
if (!seriesX) {
firstXIndex = 0
lastXIndex = gl.series[i].length
let firstXIndex = 0
let lastXIndex = series[i].length - 1
if (autoScaleYaxis) {
// Scale the Y axis to the min..max within the possibly zoomed X axis domain.
if (cnf.xaxis.min) {
for (
;
firstXIndex < lastXIndex && gl.seriesX[i][firstXIndex] < cnf.xaxis.min;
firstXIndex++
) {}
}
if (cnf.xaxis.max) {
for (
;
lastXIndex > firstXIndex && gl.seriesX[i][lastXIndex] > cnf.xaxis.max;
lastXIndex--
) {}
}
}
for (let j = firstXIndex; j <= lastXIndex && j < gl.series[i].length; j++) {
let val = series[i][j]
Expand Down

0 comments on commit b28d322

Please sign in to comment.