From 481faf8da11aa83615c53695f92a7dfb2e131638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Nov 2017 16:47:16 +0100 Subject: [PATCH] Fix graph initialization We only want to initialize it when the graph is actually visible. For this we hook into tab changes, user changes and StartupComplete. That will hopefully ensure that once it DOES become visible it will get initialized, but not before. --- .../static/js/app/viewmodels/temperature.js | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 4f061e182..6ec55eb27 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -148,6 +148,7 @@ $(function() { } self.updatePlot(); }; + self.settingsViewModel.printerProfiles.currentProfileData.subscribe(function() { self._printerProfileUpdated(); self.settingsViewModel.printerProfiles.currentProfileData().extruder.count.subscribe(self._printerProfileUpdated); @@ -155,30 +156,6 @@ $(function() { self.settingsViewModel.printerProfiles.currentProfileData().heatedBed.subscribe(self._printerProfileUpdated); }); - self.onUserLoggedIn = function () { - self._initializePlot(true); - - self.loginStateSubscription = self.loginState.hasPermissionKo(self.access.permissions.STATUS).subscribe(function(value) { - var graph = $("#temp, #temp_link"); - if (graph.length) { - if (value) { - graph.removeAttr("style"); - } - else { - graph.hide(); - } - } - self.updatePlot(); - }); - }; - - self.onUserLoggedOut = function (){ - if (self.loginStateSubscription !== undefined) { - self.loginStateSubscription.dispose(); - self.loginStateSubscription = undefined; - } - }; - self.temperatures = []; self.plot = undefined; @@ -756,8 +733,9 @@ $(function() { } }; - self.onAfterTabChange = function(current, previous) { - if (current !== "#temp") { + self.initOrUpdate = function() { + if (OctoPrint.coreui.selectedTab !== "#temp" || !$("#temp").is(":visible")) { + // do not try to initialize the graph when it's not visible or its sizing will be off return; } @@ -768,6 +746,10 @@ $(function() { } }; + self.onAfterTabChange = function() { + self.initOrUpdate(); + }; + self.onStartup = function() { var graph = $("#temperature-graph"); if (graph.length && !OctoPrint.coreui.browser.mobile) { @@ -785,9 +767,18 @@ $(function() { }; self.onStartupComplete = function() { + self.initOrUpdate(); self._printerProfileUpdated(); }; + self.onUserLoggedIn = function() { + self.initOrUpdate(); + }; + + self.onUserLoggedOut = function() { + self.initOrUpdate(); + }; + } OCTOPRINT_VIEWMODELS.push([