feat: add configurable wind units
This commit is contained in:
@@ -4,6 +4,8 @@ import { Bar, BarChart, Cell, ResponsiveContainer, Tooltip, XAxis, YAxis } from
|
||||
import type { SynopStation } from "@/types/imgw";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { useWeatherStore } from "@/lib/store";
|
||||
import { convertWindSpeed, getWindSpeedUnitLabel } from "@/lib/weather-utils";
|
||||
|
||||
const INITIAL_CHART_DIMENSION = { width: 1, height: 1 };
|
||||
const SNAPSHOT_COLORS = [
|
||||
@@ -14,9 +16,13 @@ const SNAPSHOT_COLORS = [
|
||||
|
||||
export function SnapshotChart({ station }: { station: SynopStation }) {
|
||||
const { t } = useI18n();
|
||||
const windSpeedUnit = useWeatherStore((state) => state.windSpeedUnit);
|
||||
const windDigits = windSpeedUnit === "ms" ? 1 : 0;
|
||||
const windSpeed = station.windSpeed === null ? null : Number(convertWindSpeed(station.windSpeed, windSpeedUnit).toFixed(windDigits));
|
||||
const windMax = windSpeedUnit === "ms" ? 20 : windSpeedUnit === "kmh" ? 72 : 45;
|
||||
const rows = [
|
||||
{ name: t("weather.humidity"), value: station.humidity, unit: "%", max: 100, color: SNAPSHOT_COLORS[0] },
|
||||
{ name: t("weather.wind"), value: station.windSpeed, unit: "m/s", max: 20, color: SNAPSHOT_COLORS[1] },
|
||||
{ name: t("weather.wind"), value: windSpeed, unit: getWindSpeedUnitLabel(windSpeedUnit), max: windMax, color: SNAPSHOT_COLORS[1] },
|
||||
{ name: t("weather.rainfall"), value: station.rainfall, unit: "mm", max: 30, color: SNAPSHOT_COLORS[2] },
|
||||
].filter((row) => row.value !== null).map((row) => ({ ...row, normalized: Math.min(100, ((row.value ?? 0) / row.max) * 100) }));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user