Skip to content

Commit c453970

Browse files
committed
fix: Improve contrast of snow
1 parent 209afcc commit c453970

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/components/ForecastViews/precipitationChart.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import type { ChartDatasetCustomTypesPerDataset, ChartOptions } from "chart.js";
33

44
enum PrecipitationColor {
55
rain = '0, 145, 205',
6-
snowfall = '149, 214, 233',
6+
mixed = '0, 0, 0',
7+
snowfall = '255, 255, 255',
78
}
89

910
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)
1213

1314
return {
1415
type: 'bar',
@@ -18,7 +19,9 @@ export function getPrecipitationChart(forecast: Forecast): ChartDatasetCustomTyp
1819
// Some tweaks to make precipitation bars more explicit.
1920
// 1. shrink distribution from 0.1 to 1 (x/(100/0.8) + 0.2). This make low probability precipitation more visible.
2021
// 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,
2225
yAxisID: 'yp',
2326
datalabels: {
2427
display: false,

0 commit comments

Comments
 (0)