mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 21:00:57 +00:00
Changed roundTemp implementation to a cleaner one
This commit is contained in:
@@ -182,13 +182,9 @@ Module.register("currentweather",{
|
|||||||
weatherIcon.className = "wi weathericon " + this.weatherType;
|
weatherIcon.className = "wi weathericon " + this.weatherType;
|
||||||
large.appendChild(weatherIcon);
|
large.appendChild(weatherIcon);
|
||||||
|
|
||||||
var temp = this.temperature;
|
|
||||||
if (this.config.roundTemp) {
|
|
||||||
temp = Math.round(temp);
|
|
||||||
}
|
|
||||||
var temperature = document.createElement("span");
|
var temperature = document.createElement("span");
|
||||||
temperature.className = "bright";
|
temperature.className = "bright";
|
||||||
temperature.innerHTML = " " + temp + "°";
|
temperature.innerHTML = " " + this.temperature + "°";
|
||||||
large.appendChild(temperature);
|
large.appendChild(temperature);
|
||||||
|
|
||||||
wrapper.appendChild(large);
|
wrapper.appendChild(large);
|
||||||
@@ -436,6 +432,7 @@ Module.register("currentweather",{
|
|||||||
|
|
||||||
|
|
||||||
roundValue: function(temperature) {
|
roundValue: function(temperature) {
|
||||||
return parseFloat(temperature).toFixed(1);
|
var decimals = this.config.roundTemp ? 0 : 1;
|
||||||
|
return parseFloat(temperature).toFixed(decimals);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@@ -135,20 +135,13 @@ Module.register("weatherforecast",{
|
|||||||
icon.className = "wi weathericon " + forecast.icon;
|
icon.className = "wi weathericon " + forecast.icon;
|
||||||
iconCell.appendChild(icon);
|
iconCell.appendChild(icon);
|
||||||
|
|
||||||
var maxTemp = forecast.maxTemp;
|
|
||||||
var minTemp = forecast.minTemp;
|
|
||||||
if (this.config.roundTemp) {
|
|
||||||
maxTemp = Math.round(maxTemp);
|
|
||||||
minTemp = Math.round(minTemp);
|
|
||||||
}
|
|
||||||
|
|
||||||
var maxTempCell = document.createElement("td");
|
var maxTempCell = document.createElement("td");
|
||||||
maxTempCell.innerHTML = maxTemp;
|
maxTempCell.innerHTML = forecast.maxTemp;
|
||||||
maxTempCell.className = "align-right bright max-temp";
|
maxTempCell.className = "align-right bright max-temp";
|
||||||
row.appendChild(maxTempCell);
|
row.appendChild(maxTempCell);
|
||||||
|
|
||||||
var minTempCell = document.createElement("td");
|
var minTempCell = document.createElement("td");
|
||||||
minTempCell.innerHTML = minTemp;
|
minTempCell.innerHTML = forecast.minTemp;
|
||||||
minTempCell.className = "align-right min-temp";
|
minTempCell.className = "align-right min-temp";
|
||||||
row.appendChild(minTempCell);
|
row.appendChild(minTempCell);
|
||||||
|
|
||||||
@@ -351,14 +344,15 @@ Module.register("weatherforecast",{
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* function(temperature)
|
/* function(temperature)
|
||||||
* Rounds a temperature to 1 decimal.
|
* Rounds a temperature to 1 decimal or integer (depending on config.roundTemp).
|
||||||
*
|
*
|
||||||
* argument temperature number - Temperature.
|
* argument temperature number - Temperature.
|
||||||
*
|
*
|
||||||
* return number - Rounded Temperature.
|
* return number - Rounded Temperature.
|
||||||
*/
|
*/
|
||||||
roundValue: function(temperature) {
|
roundValue: function(temperature) {
|
||||||
return parseFloat(temperature).toFixed(1);
|
var decimals = this.config.roundTemp ? 0 : 1;
|
||||||
|
return parseFloat(temperature).toFixed(decimals);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user