calculate isZoomed state before mutating graph data, fixes #193

This commit is contained in:
Nick Krecklow 2020-06-24 15:14:31 -05:00
parent 1b2a3de3f7
commit b7492b3a3b
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94

@ -28,6 +28,11 @@ export class GraphDisplayManager {
// and the application has received updates prior to the initial state
return
}
// Calculate isZoomed before mutating graphData otherwise the indexed values
// are out of date and will always fail when compared to plotScaleX.min/max
const plotScaleX = this._plotInstance.scales.x
const isZoomed = plotScaleX.min > this._graphTimestamps[0] || plotScaleX.max < this._graphTimestamps[this._graphTimestamps.length - 1]
this._graphTimestamps.push(timestamp)
@ -49,12 +54,6 @@ export class GraphDisplayManager {
}
}
// Dedrive plotTimestamps from the uPlot instance's data since this._graphTimestamps has been mutated
const plotTimestamps = this._plotInstance.data[0]
const plotScaleX = this._plotInstance.scales.x
const isZoomed = plotScaleX.min > plotTimestamps[0] || plotScaleX.max < plotTimestamps[plotTimestamps.length - 1]
// Avoid redrawing the plot when zoomed
this._plotInstance.setData(this.getGraphData(), !isZoomed)
}