Yevgenium / weather-chart-card

Custom weather card with charts
MIT License
275 stars 81 forks source link

Zero values get ignored when populating data (e.g. 0 precipitation) #65

Closed greendog99 closed 2 years ago

greendog99 commented 3 years ago

Noticed that precipitation always appears on the first day of the forecast, even if rain isn't expected until later in the week. Here's the cause:

https://github.com/Yevgenium/weather-chart-card/blob/0c16ee74a90c8b0902d4a989d883f9d2207331c7/src/main.js#L145-L153

if (d.temperature) resolves to false for zero values (e.g. 0 degrees, 0 precipitation), causing these days to be skipped in the chart data. Need to use something like if (typeof d.temperature !== 'undefined').

Also, it may be best to insert a dummy value in these cases, so that if d.datetime and d.temperature are defined, but d.templow is not defined, the various arrays all keep the same length. Without doing that, the array that's missing a value will have all of its remaining data offset by one day.

Yevgenium commented 3 years ago

Yes, I already noticed that. Will be fixed in the next version. Thanks!

greendog99 commented 3 years ago

I modified my version in the interim, and came across another edge case: the Dark Sky weather integration returns null when precipitation is 0 (instead of returning a float). That was causing the graph to not show up for me (after my changes). I had to add a check for null and instead push a 0 into the array :-(

ss-20210823-161711
Yevgenium commented 3 years ago

Fixed in v1.0.2. Could you check?

greendog99 commented 3 years ago

Tested OK with both 0 and null values. Looks good to me!