Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 4560 #4576

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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