Skip to content

Commit

Permalink
Fix edge case in weather widget graph
Browse files Browse the repository at this point in the history
  • Loading branch information
svilenmarkov committed Dec 11, 2024
1 parent 804cf99 commit 949fde1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/feed/openmeteo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 949fde1

Please sign in to comment.