Skip to content

Commit

Permalink
Merge pull request #4576 from rosco54/Issue_4560
Browse files Browse the repository at this point in the history
Fix for issue 4560
  • Loading branch information
junedchhipa authored Jul 20, 2024
2 parents b075c08 + b28d322 commit 34b3a67
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 34b3a67

Please sign in to comment.