Skip to content

Commit 3b70cbd

Browse files
chore: improve precipitation display for zero values
- Display "—" (em-dash) for days with no rain/snow when at least one other day has precipitation - Prevents confusion between "no data" and "no precipitation" - Improves table readability and consistency - Applies to both layout modes (rows and columns) When no days have precipitation, cells remain empty as before.
1 parent 31eabe3 commit 3b70cbd

2 files changed

Lines changed: 47 additions & 27 deletions

File tree

MMM-OneCallWeather.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ Module.register('MMM-OneCallWeather', {
328328
const forecastTable = document.createElement('table')
329329
forecastTable.className = 'forecast-table small'
330330

331+
// Check if any day has precipitation
332+
const hasAnyRain = this.forecast.days.slice(0, this.config.maxDailiesToShow).some(day => day.rain > 0)
333+
const hasAnySnow = this.forecast.days.slice(0, this.config.maxDailiesToShow).some(day => day.snow > 0)
334+
331335
for (let i = 0; i < this.config.maxDailiesToShow; i += 1) {
332336
dailyForecast = this.forecast.days[i]
333337

@@ -377,6 +381,9 @@ Module.register('MMM-OneCallWeather', {
377381
? `${parseFloat(dailyForecast.rain).toFixed(2)} <span class="precip-unit">in</span>`
378382
: `${parseFloat(dailyForecast.rain).toFixed(1)} <span class="precip-unit">mm</span>`
379383
}
384+
else if (hasAnyRain) {
385+
rainCell.innerHTML = '—'
386+
}
380387
rainCell.className = 'align-right bright rain precip-rain'
381388
row.appendChild(rainCell)
382389
}
@@ -389,6 +396,9 @@ Module.register('MMM-OneCallWeather', {
389396
? `${parseFloat(formatted.value).toFixed(2)} <span class="precip-unit">${formatted.unit}</span>`
390397
: `${parseFloat(formatted.value).toFixed(1)} <span class="precip-unit">${formatted.unit}</span>`
391398
}
399+
else if (hasAnySnow) {
400+
snowCell.innerHTML = '—'
401+
}
392402
snowCell.className = 'align-right bright snow precip-snow'
393403
row.appendChild(snowCell)
394404
}
@@ -445,6 +455,10 @@ Module.register('MMM-OneCallWeather', {
445455
? document.createElement('tr')
446456
: null
447457

458+
// Check if any day has precipitation
459+
const hasAnyRain = this.forecast.days.slice(0, this.config.maxDailiesToShow).some(day => day.rain > 0)
460+
const hasAnySnow = this.forecast.days.slice(0, this.config.maxDailiesToShow).some(day => day.snow > 0)
461+
448462
for (let j = 0; j < this.config.maxDailiesToShow; j += 1) {
449463
dailyForecast = this.forecast.days[j]
450464

@@ -521,6 +535,9 @@ Module.register('MMM-OneCallWeather', {
521535
? `${parseFloat(dailyForecast.rain).toFixed(2)} <span class="precip-unit">in</span>`
522536
: `${parseFloat(dailyForecast.rain).toFixed(1)} <span class="precip-unit">mm</span>`
523537
}
538+
else if (hasAnyRain) {
539+
rainCell.innerHTML = '—'
540+
}
524541
rainCell.className = 'align-right bright rain precip-rain'
525542
if (this.config.colored) {
526543
rainCell.className += ' colored'
@@ -537,6 +554,9 @@ Module.register('MMM-OneCallWeather', {
537554
? `${parseFloat(formatted.value).toFixed(2)} <span class="precip-unit">${formatted.unit}</span>`
538555
: `${parseFloat(formatted.value).toFixed(1)} <span class="precip-unit">${formatted.unit}</span>`
539556
}
557+
else if (hasAnySnow) {
558+
snowCell.innerHTML = '—'
559+
}
540560
snowCell.className = 'align-right bright snow precip-snow'
541561
if (this.config.colored) {
542562
snowCell.className += ' colored'

0 commit comments

Comments
 (0)