From b7492b3a3b136ba577c5f4687585c4e6306f2c15 Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Wed, 24 Jun 2020 15:14:31 -0500 Subject: [PATCH] calculate isZoomed state before mutating graph data, fixes #193 --- assets/js/graph.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index 5cb3f72..2153f32 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -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) }