From bf7d4173cd96c1443b8f4446f33ad0ec0a7f7b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 27 Oct 2017 14:22:03 +0200 Subject: [PATCH] Fix auto-adjust of temperature y axis Thanks @Salandora for the heads-up --- .../static/js/app/viewmodels/temperature.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 719825db..49394835 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -296,19 +296,25 @@ $(function() { var plotInfo = self._getPlotInfo(); if (plotInfo === undefined) return; - // update the data - self.plot.setData(plotInfo.data); - self.plot.getAxes().yaxis.max = Math.max(Math.max.apply(null, plotInfo.max) * 1.1, 310); - self.updateLegend(self._replaceLegendLabel); - self.plot.draw(); + var newMax = Math.max(Math.max.apply(null, plotInfo.max) * 1.1, 310); + if (newMax !== self.plot.getAxes().yaxis.max) { + // re-init (because flot apparently has NO way to change the max value of an axes :/) + self._initializePlot(true, plotInfo); + } else { + // update the data + self.plot.setData(plotInfo.data); + self.plot.setupGrid(); + self.updateLegend(self._replaceLegendLabel); + self.plot.draw(); + } }; - self._initializePlot = function(force) { + self._initializePlot = function(force, plotInfo) { var graph = $("#temperature-graph"); if (!graph.length) return; // no graph if (self.plot && !force) return; // already initialized - var plotInfo = self._getPlotInfo(); + plotInfo = plotInfo || self._getPlotInfo(); if (plotInfo === undefined) return; // we don't have a plot yet, we need to set stuff up