From 50983c8524faaaec1a27357b25f34ae2aa9d65f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 18 Oct 2017 12:39:38 +0200 Subject: [PATCH] Fix initial size of temperature graph Plot area was wrongly sized due to (invisible) X axis tick labels. We now initialize an empty plot to min/max timestamps of "now" to circumvent this. Additionally plot was not properly initialized on initial load of page due to onAfterTabChange not firing for the first tab. Also added a bit for tick labels. --- src/octoprint/static/js/app/main.js | 7 ++++++- .../static/js/app/viewmodels/temperature.js | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index f7541d56..bf1f1cf7 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -497,6 +497,10 @@ $(function() { callViewModels(allViewModels, "onTabChange", [current, previous]); }; + var onAfterTabChange = function(current, previous) { + callViewModels(allViewModels, "onAfterTabChange", [current, previous]); + }; + var tabs = $('#tabs a[data-toggle="tab"]'); tabs.on('show', function (e) { var current = e.target.hash; @@ -507,10 +511,11 @@ $(function() { tabs.on('shown', function (e) { var current = e.target.hash; var previous = e.relatedTarget.hash; - callViewModels(allViewModels, "onAfterTabChange", [current, previous]); + onAfterTabChange(current, previous); }); onTabChange(OCTOPRINT_INITIAL_TAB); + onAfterTabChange(OCTOPRINT_INITIAL_TAB, undefined); // Fix input element click problems on dropdowns $(".dropdown input, .dropdown label").click(function(e) { diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 6e70610b..55c8cc50 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -330,10 +330,14 @@ $(function() { // convert to minutes var diffInMins = Math.round(diff / (60 * 1000)); - if (diffInMins === 0) + if (diffInMins === 0) { return gettext("just now"); - else + } else if (diffInMins < 0) { + // we can't look into the future + return ""; + } else { return "- " + diffInMins + " " + gettext("min"); + } } }, legend: { @@ -357,6 +361,7 @@ $(function() { if (!heaterOptions) return undefined; var maxTemps = [310/1.1]; + var now = Date.now(); var showFahrenheit = self._shallShowFahrenheit(); @@ -379,12 +384,12 @@ $(function() { data.push({ label: gettext("Actual") + " " + heaterOptions[type].name + ": " + actualTemp, color: heaterOptions[type].color, - data: actuals + data: actuals.length ? actuals : [[now, undefined]] }); data.push({ label: gettext("Target") + " " + heaterOptions[type].name + ": " + targetTemp, color: pusher.color(heaterOptions[type].color).tint(0.5).html(), - data: targets + data: targets.length ? targets : [[now, undefined]] }); maxTemps.push(self.getMaxTemp(actuals, targets)); @@ -450,7 +455,6 @@ $(function() { }; self.getMaxTemp = function(actuals, targets) { - var pair; var maxTemp = 0; actuals.forEach(function(pair) { if (pair[1] > maxTemp){