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([