import { AreaChart as RechartsAreaChart, Area, XAxis, YAxis, CartesianGrid, Tooltip, Legend, } from 'recharts' import { ChartContainer, ChartTooltipContent, type Series, getSeriesColor } from './chart_container' interface GradientConfig { from: string; to: string } interface AreaChartProps { data: Record[] xKey: string yKey?: string series?: Series[] stacked?: boolean gradient?: GradientConfig | boolean showGrid?: boolean showLegend?: boolean height?: number | string className?: string xAxisFormatter?: (value: unknown) => string yAxisFormatter?: (value: unknown) => string valueFormatter?: (value: number) => string } function AreaChartComponent({ data, xKey, yKey, series, stacked = false, gradient = true, showGrid = true, showLegend = false, height = 300, className, xAxisFormatter, yAxisFormatter, valueFormatter = (v) => v.toLocaleString(), }: AreaChartProps) { const areas = series ? series.map((s, i) => ({ dataKey: s.key, name: s.name, color: getSeriesColor(i, s.color) })) : yKey ? [{ dataKey: yKey, name: yKey, color: getSeriesColor(0) }] : [] const gradientConfig: GradientConfig | null = gradient ? typeof gradient === 'object' ? gradient : { from: '', to: 'transparent' } : null return ( {areas.map((area) => ( ))} {showGrid && } } cursor={{ stroke: 'hsl(var(--muted-foreground))', strokeDasharray: '3 3' }} /> {showLegend && } {areas.map((area) => ( ))} ) } export const AreaChart = AreaChartComponent export type { AreaChartProps, GradientConfig }