1
0
mirror of https://github.com/beestat/app.git synced 2025-07-09 03:04:07 -04:00

Fixed #124 - Temperature Profiles chart axis gets skewed if you reload a previously loaded profile (only in °C)

I was performing the same mutation on an object multiple times because I did not clone it or store the data separately.
This commit is contained in:
Jon Ziebell 2019-06-04 22:23:45 -04:00
parent 729022e85a
commit 98905d6181
2 changed files with 18 additions and 11 deletions

10
js/beestat/clone.js Normal file
View File

@ -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));
};

View File

@ -44,7 +44,10 @@ beestat.component.card.temperature_profiles.prototype.decorate_contents_ = funct
var y_min = Infinity; var y_min = Infinity;
var y_max = -Infinity; var y_max = -Infinity;
for (var type in beestat.cache.data.comparison_temperature_profile) { 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) { if (profile !== null) {
// Convert the data to Celsius if necessary // 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)); var absolute_y_max = Math.max(Math.abs(y_min), Math.abs(y_max));
y_min = absolute_y_max * -1; y_min = absolute_y_max * -1;
y_max = absolute_y_max; 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 // Chart
this.chart_.options.exporting.chartOptions.title.text = this.get_title_(); this.chart_.options.exporting.chartOptions.title.text = this.get_title_();
this.chart_.options.exporting.chartOptions.subtitle.text = this.get_subtitle_(); 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.legend = {'enabled': false};
this.chart_.options.xAxis = { this.chart_.options.xAxis = {
// 'categories': x_categories,
// 'min': x_min,
// 'max': x_max,
'lineWidth': 0, 'lineWidth': 0,
'tickLength': 0, 'tickLength': 0,
'tickInterval': 5, 'tickInterval': 5,