Skip to content

Commit

Permalink
Merge pull request #6 from Sti2nd/master
Browse files Browse the repository at this point in the history
Show celcius sign on temp values
  • Loading branch information
fmandal authored Feb 3, 2020
2 parents e8e2331 + 765c790 commit f332160
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
38 changes: 27 additions & 11 deletions MMM-YrThen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Module.register('MMM-YrThen', {
roundTemp: true,
roundPrec: false,
title: 'Værmelding for Skrubblivegen',
header: false
header: false,
size: "small"
},

getTranslations: function() {
Expand Down Expand Up @@ -65,7 +66,7 @@ Module.register('MMM-YrThen', {
var wrapper = document.createElement('div');
if(!this.loaded){
wrapper.innerHTML = this.translate('loading');
wrapper.className = "dimmed light small";
wrapper.className = "dimmed light " + this.config.size;
return wrapper;
}

Expand All @@ -75,10 +76,17 @@ Module.register('MMM-YrThen', {
header.className = 'align-left';
wrapper.appendChild(header);
}
wrapper.classList.add = "dimmed light small";
wrapper.classList.add = "dimmed light " + this.config.size;

var table = document.createElement('table');
table.className = "xsmall yrthen-table";

// Find the size one smaller than size
var possibleSizes = ["xsmall", "small", "medium", "large", "xlarge"]
var oneSmallerSize = possibleSizes.indexOf(this.config.size) - 1;
if (oneSmallerSize < 0) {
oneSmallerSize = 0;
}
table.className = possibleSizes[oneSmallerSize] + " yrthen-table";

// SHOWING DETAILED FORECAST
if(this.config.showAll == true){
Expand All @@ -87,9 +95,17 @@ Module.register('MMM-YrThen', {
var first = true;
var timeRow = document.createElement('tr');
table.appendChild(timeRow);

// Find the size one smaller than size
var possibleSizes = ["xsmall", "small", "medium", "large", "xlarge"]
var oneSmallerSize = possibleSizes.indexOf(this.config.size) - 1;
if (oneSmallerSize < 0) {
oneSmallerSize = 0;
}

for(var i = 0; i < 5; i++){
var newCell = document.createElement('td');
newCell.className = 'align-left bright xsmall yrthen-header';
newCell.className = 'align-left bright ' + oneSmallerSize + ' yrthen-header';
if(i == 0) newCell.innerHTML = '&nbsp;';
if(i == 1) newCell.innerHTML = this.translate("night");
if(i == 2) newCell.innerHTML = this.translate("morning");
Expand Down Expand Up @@ -157,20 +173,20 @@ Module.register('MMM-YrThen', {
}
if(this.config.showMaxMin){
if(newData.temperature.min && newData.temperature.max){
forecastCell.innerHTML += '<span class="bright small">' + minValue + this.config.maxMinSeparator + maxValue + '</span><br>';
forecastCell.innerHTML += '<span class="bright ' + this.config.size + '">' + minValue + '°' + this.config.maxMinSeparator + maxValue + '°</span><br>';
}
else forecastCell.innerHTML += ' <span class="bright small">' + tempValue + '</span><br>';
else forecastCell.innerHTML += ' <span class="bright ' + this.config.size + '">' + tempValue + '°</span><br>';
}
else{
forecastCell.innerHTML += ' <span class="bright small">' + tempValue + '</span>';
forecastCell.innerHTML += ' <span class="bright ' + this.config.size + '">' + tempValue + '°</span>';
if(this.config.showMaxMin){
forecastCell.innerHTML += '<br>';
}
if(newData.temperature.min && newData.temperature.max && this.config.showMaxMin){
forecastCell.innerHTML += '<span class="dimmed">(' + minValue + '/' + maxValue + ')</span><br>';
forecastCell.innerHTML += '<span class="dimmed">(' + minValue + '°/' + maxValue + '°)</span><br>';
}
else if(!newData.temperature.min && !newData.temperature.max && this.config.showMaxMin){
forecastCell.innerHTML += '<span class="dimmed">(' + tempValue + '/' + tempValue + ')</span><br>';
forecastCell.innerHTML += '<span class="dimmed">(' + tempValue + '°/' + tempValue + '°)</span><br>';
}
}
if(this.config.showPrecipitation){
Expand Down Expand Up @@ -236,7 +252,7 @@ Module.register('MMM-YrThen', {
var maxTempCell = document.createElement("td");
if(this.config.roundTemp) maxTempCell.innerHTML = this.round(newData.temperature.value, 0);
else maxTempCell.innerHTML = this.round(newData.temperature.value, 1);
maxTempCell.className = "align-right bright yrthen-temp small";
maxTempCell.className = "align-right bright yrthen-temp " + this.config.size;
row.appendChild(maxTempCell);

var minTempCell = document.createElement("td");
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ Find your location using the search form at <a href="https://www.yr.no/nb/liste/
<td>Show header or not. Contents of header is title.</td>
<td>false</td>
</tr>
<tr>
<td>size</td>
<td>The size of the text. One of the CSS classes defined in main.css of MagicMirror2: "xsmall", "small", "medium", "large", "xlarge"</td>
<td>"small"</td>
</tr>
</table>

0 comments on commit f332160

Please sign in to comment.