'use client'; import { Bar, BarChart, CartesianGrid, Cell, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts'; import type { TodayChartBucket } from '@/types/today'; import { TODAY_CHART_AXIS_COLOR, TODAY_CHART_COLORS, TODAY_CHART_GRID_COLOR, TODAY_CHART_TOOLTIP_BG, TODAY_CHART_TOOLTIP_BORDER, } from '@/components/today/chart-theme'; interface TodayBarChartProps { data: TodayChartBucket[]; colorForCode?: (code: string, index: number) => string; } export function TodayBarChart({ data, colorForCode }: TodayBarChartProps) { const chartData = data.map((item) => ({ ...item, shortLabel: truncateLabel(item.label), })); return ( { const { x, y, payload } = props as { x: number; y: number; payload: { value: string }; }; const index = chartData.findIndex((row) => row.shortLabel === payload.value); const entry = chartData[index]; const fill = entry != null ? colorForCode(entry.code, index >= 0 ? index : 0) : TODAY_CHART_AXIS_COLOR; return ( {payload.value} ); } : { fill: TODAY_CHART_AXIS_COLOR, fontSize: 11 } } axisLine={{ stroke: TODAY_CHART_GRID_COLOR }} tickLine={false} interval={0} /> { const row = payload?.[0]?.payload as TodayChartBucket | undefined; return row?.label ?? ''; }} /> {chartData.map((entry, index) => ( ))} ); } function truncateLabel(label: string, max = 12): string { if (label.length <= max) return label; return `${label.slice(0, max - 1)}…`; }