fix: improve chart tooltips
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Bar, CartesianGrid, ComposedChart, Legend, Line, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { ChartTooltip } from "@/components/charts/chart-tooltip";
|
||||
import { CHART_COLORS } from "@/lib/chart-theme";
|
||||
import { useI18n } from "@/lib/i18n";
|
||||
import { formatForecastRainfall, formatForecastTemperature } from "@/lib/forecast-utils";
|
||||
@@ -56,17 +57,16 @@ export function DayForecastCharts({ hours }: { hours: HourlyForecast[] }) {
|
||||
unit={temperatureUnitLabel}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
borderRadius: 14,
|
||||
border: `1px solid ${CHART_COLORS.tooltipBorder}`,
|
||||
background: CHART_COLORS.tooltipBackground,
|
||||
color: CHART_COLORS.tooltipText,
|
||||
}}
|
||||
formatter={(value) => [
|
||||
typeof value === "number"
|
||||
? formatTemperatureValue(value, language, temperatureUnit)
|
||||
: formatForecastTemperature(null, language, temperatureUnit),
|
||||
]}
|
||||
cursor={{ stroke: CHART_COLORS.grid, strokeDasharray: "4 4" }}
|
||||
content={
|
||||
<ChartTooltip
|
||||
valueFormatter={(entry) =>
|
||||
typeof entry.value === "number"
|
||||
? formatTemperatureValue(entry.value, language, temperatureUnit)
|
||||
: formatForecastTemperature(null, language, temperatureUnit)
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Legend wrapperStyle={{ fontSize: "0.72rem" }} />
|
||||
<Line
|
||||
@@ -130,18 +130,16 @@ export function DayForecastCharts({ hours }: { hours: HourlyForecast[] }) {
|
||||
unit="%"
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={{
|
||||
borderRadius: 14,
|
||||
border: `1px solid ${CHART_COLORS.tooltipBorder}`,
|
||||
background: CHART_COLORS.tooltipBackground,
|
||||
color: CHART_COLORS.tooltipText,
|
||||
}}
|
||||
formatter={(value, name) => [
|
||||
name === t("forecast.precipitation")
|
||||
? formatForecastRainfall(typeof value === "number" ? value : null, language)
|
||||
: `${typeof value === "number" ? value : "—"}%`,
|
||||
name,
|
||||
]}
|
||||
cursor={{ fill: "hsl(var(--border) / 0.18)" }}
|
||||
content={
|
||||
<ChartTooltip
|
||||
valueFormatter={(entry) =>
|
||||
entry.dataKey === "precipitation"
|
||||
? formatForecastRainfall(typeof entry.value === "number" ? entry.value : null, language)
|
||||
: `${typeof entry.value === "number" ? entry.value : "—"}%`
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Legend wrapperStyle={{ fontSize: "0.72rem" }} />
|
||||
<Bar
|
||||
|
||||
Reference in New Issue
Block a user