Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Add snowfall to weather chart
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Dec 9, 2023
1 parent 34d4ec0 commit 88f399f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/api/queries/weather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const useWeather = (
const cloudCover = `Cloud_Cover_${location.latitude},${location.longitude}`
const windSpeed = `Wind_Speed_${location.latitude},${location.longitude}`
const rain = `Rain_${location.latitude},${location.longitude}`
const snowfall = `Snowfall_${location.latitude},${location.longitude}`

const { isSuccess, data } = useQueries({
queries: [
Expand All @@ -41,6 +42,11 @@ export const useWeather = (
queryKey: ['predictions', rain, startTime, endTime],
queryFn: () => predictions(rain, startTime, endTime),
enabled
},
{
queryKey: ['predictions', snowfall, startTime, endTime],
queryFn: () => predictions(snowfall, startTime, endTime),
enabled
}
],
combine: (results) => {
Expand Down Expand Up @@ -69,6 +75,12 @@ export const useWeather = (
average: 0,
values: []
},
snowfall: {
minimum: 0,
maximum: 0,
average: 0,
values: []
},
cloudCover: 0,
windSpeed: 0
}
Expand All @@ -89,6 +101,12 @@ export const useWeather = (
average: Math.avg(data[rain].value.slice(0, 24)), // FIXME: API returns 48 values
values: data[rain].value.slice(0, 24) // FIXME: API returns 48 values
},
snowfall: {
minimum: Math.min(...data[snowfall].value.slice(0, 24)), // FIXME: API returns 48 values
maximum: Math.max(...data[snowfall].value.slice(0, 24)), // FIXME: API returns 48 values
average: Math.avg(data[snowfall].value.slice(0, 24)), // FIXME: API returns 48 values
values: data[snowfall].value.slice(0, 24) // FIXME: API returns 48 values
},
cloudCover: Math.avg(data[cloudCover].value.slice(0, 24)), // FIXME: API returns 48 values
windSpeed: Math.avg(data[windSpeed].value.slice(0, 24)) // FIXME: API returns 48 values
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/cards/weather.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ function WeatherDetail(props: {
name: 'Rain',
type: 'column',
data: forecast.rain.values
},
{
name: 'Snowfall',
type: 'column',
data: forecast.snowfall.values
}
]}
/>
Expand Down
12 changes: 11 additions & 1 deletion src/components/charts/temperature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function Temperature(props: TemperatureProps): ReactElement {
chart: {
id: 'temperature',
type: 'line',
stacked: true,
background: 'transparent',
zoom: {
enabled: false
Expand All @@ -36,7 +37,7 @@ export default function Temperature(props: TemperatureProps): ReactElement {
enabled: false
}
},
colors: ['#0369A1', '#BAE6FD'],
colors: ['#0369A1', '#BAE6FD', '#F1F5F9'],
stroke: {
curve: 'straight',
width: 2
Expand Down Expand Up @@ -68,6 +69,15 @@ export default function Temperature(props: TemperatureProps): ReactElement {
title: {
text: 'Rain'
}
},
{
opposite: true,
labels: {
formatter: (value) => `${Math.round(value)} mm`
},
title: {
text: 'Snowfall'
}
}
],
series: props.series,
Expand Down
6 changes: 6 additions & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export interface Forecast {
average: number
values: number[]
}
snowfall: {
minimum: number
maximum: number
average: number
values: number[]
}
cloudCover: number
windSpeed: number
}
Expand Down

0 comments on commit 88f399f

Please sign in to comment.