From 98905d61819696af7b1a6882afc8ba8a1aff7360 Mon Sep 17 00:00:00 2001 From: Jon Ziebell Date: Tue, 4 Jun 2019 22:23:45 -0400 Subject: [PATCH] =?UTF-8?q?Fixed=20#124=20-=20Temperature=20Profiles=20cha?= =?UTF-8?q?rt=20axis=20gets=20skewed=20if=20you=20reload=20a=20previously?= =?UTF-8?q?=20loaded=20profile=20(only=20in=20=C2=B0C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I was performing the same mutation on an object multiple times because I did not clone it or store the data separately. --- js/beestat/clone.js | 10 ++++++++++ js/component/card/temperature_profiles.js | 19 ++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 js/beestat/clone.js diff --git a/js/beestat/clone.js b/js/beestat/clone.js new file mode 100644 index 0000000..8960392 --- /dev/null +++ b/js/beestat/clone.js @@ -0,0 +1,10 @@ +/** + * Performs a deep clone of a simple object. + * + * @param {Object} object The object to clone. + * + * @return {Object} The cloned object. + */ +beestat.clone = function(object) { + return JSON.parse(JSON.stringify(object)); +}; diff --git a/js/component/card/temperature_profiles.js b/js/component/card/temperature_profiles.js index c435bc0..b49ecdc 100644 --- a/js/component/card/temperature_profiles.js +++ b/js/component/card/temperature_profiles.js @@ -44,7 +44,10 @@ beestat.component.card.temperature_profiles.prototype.decorate_contents_ = funct var y_min = Infinity; var y_max = -Infinity; for (var type in beestat.cache.data.comparison_temperature_profile) { - var profile = beestat.cache.data.comparison_temperature_profile[type]; + // Cloned because I mutate this data for temperature conversions. + var profile = beestat.clone( + beestat.cache.data.comparison_temperature_profile[type] + ); if (profile !== null) { // Convert the data to Celsius if necessary @@ -117,17 +120,14 @@ beestat.component.card.temperature_profiles.prototype.decorate_contents_ = funct } } - // Set y_min and y_max to be equal but opposite so the graph is always - // centered. + /* + * Set y_min and y_max to be equal but opposite so the graph is always + * centered. + */ var absolute_y_max = Math.max(Math.abs(y_min), Math.abs(y_max)); y_min = absolute_y_max * -1; y_max = absolute_y_max; - // y_min = -5; - // y_max = 5; - // x_min = Math.min(x_min, 0); - // x_max = Math.max(x_max, 100); - // Chart this.chart_.options.exporting.chartOptions.title.text = this.get_title_(); this.chart_.options.exporting.chartOptions.subtitle.text = this.get_subtitle_(); @@ -139,9 +139,6 @@ beestat.component.card.temperature_profiles.prototype.decorate_contents_ = funct this.chart_.options.legend = {'enabled': false}; this.chart_.options.xAxis = { - // 'categories': x_categories, - // 'min': x_min, - // 'max': x_max, 'lineWidth': 0, 'tickLength': 0, 'tickInterval': 5,