Beta 3 of the Weather App is up. Now after the current weather you get a
5-day forecast with the day name, weather icon and max/min temperature
for each day!!!(kinda usefull i know), plus a small chart below showing the max (red) and min
(blue) temperatures across the week. The chart is drawn on a canvas
with vanilla JS, no Chart.js or any library, just moveto/lineTo/arc.
The tricky part was the forecast API. It returns a data point every 3
hours, so I had to filter and group them by day, taking the actual max
and min of all the 3-hour readings inside each day. Otherwise the “max”
was just the temperature at a random hour, not the real daily high.
I also had to redefine my existing mostrarClima function to also trigger
the forecast fetch - I kept the old function in a variable and called it
inside the new one, so the GIF background logic I had before still
runs. Took me a while to figure that pattern out.
Next version will probably be the last: geolocation + favorites +
installable PWA. But i don`t really know if geolocation is a good idea
Update:Hit a nasty bug in this version: every search returned “city not found”
even for Madrid, (which definitely works). Turns out the pattern I used to
extend mostrarClima (saving the old function and redefining it) caused an
infinite recursion because of JavaScript hoisting -function declarations
get hoisted to the top, so when I saved “the old function” I was actually
saving the new one, which then called itself forever. Changed function
mostrarClima() to mostrarClima = function() (function expression instead
of declaration) and it fixed it. Took me way too long to figure out.