@@ -3,12 +3,13 @@ import type { ChartDatasetCustomTypesPerDataset, ChartOptions } from "chart.js";
3
3
4
4
enum PrecipitationColor {
5
5
rain = '0, 145, 205' ,
6
- snowfall = '149, 214, 233' ,
6
+ mixed = '0, 0, 0' ,
7
+ snowfall = '255, 255, 255' ,
7
8
}
8
9
9
10
export function getPrecipitationChart ( forecast : Forecast ) : ChartDatasetCustomTypesPerDataset {
10
-
11
- const isSnow = forecast . hourly . map ( ( { rain, snowfall } ) => snowfall > rain )
11
+ const hasSnow = forecast . hourly . map ( ( { rain , snowfall } ) => snowfall > rain )
12
+ // const isMixed = forecast.hourly.map(({ rain, snowfall }) => snowfall !== 0 && rain !== 0 )
12
13
13
14
return {
14
15
type : 'bar' ,
@@ -18,7 +19,9 @@ export function getPrecipitationChart(forecast: Forecast): ChartDatasetCustomTyp
18
19
// Some tweaks to make precipitation bars more explicit.
19
20
// 1. shrink distribution from 0.1 to 1 (x/(100/0.8) + 0.2). This make low probability precipitation more visible.
20
21
// 2. +0.1 when x > 50 (x > 50 ? 0.1 : 0). This make high probability precipitation even more visible.
21
- backgroundColor : forecast . hourly . map ( ( { precipitationProbability } , i ) => `rgba(${ PrecipitationColor [ isSnow [ i ] ? 'snowfall' : 'rain' ] } , ${ precipitationProbability / ( 100 / 0.8 ) + 0.2 + ( precipitationProbability > 50 ? 0.1 : 0 ) } )` ) ,
22
+ backgroundColor : forecast . hourly . map ( ( { precipitationProbability } , i ) => `rgba(${ PrecipitationColor [ hasSnow [ i ] ? 'snowfall' : 'rain' ] } , ${ precipitationProbability / ( 100 / 0.8 ) + 0.2 + ( precipitationProbability > 50 ? 0.1 : 0 ) } )` ) ,
23
+ borderColor : forecast . hourly . map ( ( { precipitationProbability } , i ) => `rgba(0, 145, 205, ${ precipitationProbability / ( 100 / 0.8 ) + 0.2 + ( precipitationProbability > 50 ? 0.1 : 0 ) } )` ) ,
24
+ borderWidth : 1 ,
22
25
yAxisID : 'yp' ,
23
26
datalabels : {
24
27
display : false ,
0 commit comments