Fix edge case in weather widget
If the temperature for the entire day is the same the range is 0, divide by 0 no bueno
This commit is contained in:
parent
4420d1df2c
commit
8a8aaa752e
1 changed files with 8 additions and 1 deletions
|
@ -189,12 +189,19 @@ func FetchWeatherForPlace(place *PlaceJson, units string) (*Weather, error) {
|
|||
minT := slices.Min(temperatures)
|
||||
maxT := slices.Max(temperatures)
|
||||
|
||||
temperaturesRange := float64(maxT - minT)
|
||||
|
||||
for i := 0; i < 12; i++ {
|
||||
bars = append(bars, weatherColumn{
|
||||
Temperature: temperatures[i],
|
||||
Scale: float64(temperatures[i]-minT) / float64(maxT-minT),
|
||||
HasPrecipitation: precipitations[i],
|
||||
})
|
||||
|
||||
if temperaturesRange > 0 {
|
||||
bars[i].Scale = float64(temperatures[i]-minT) / temperaturesRange
|
||||
} else {
|
||||
bars[i].Scale = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue