import { Area, AreaChart, Line, LineChart as RechartsLineChart, ResponsiveContainer, } from 'recharts'; interface LineChartProps { data: number[]; color?: string; fillColor?: string; height?: number; showDots?: boolean; smooth?: boolean; } interface LineAreaChartProps { data: number[]; color?: string; fillOpacity?: number; height?: number; } interface MultiLineChartDataset { data: number[]; color: string; fillOpacity?: number; } interface MultiLineChartProps { datasets: MultiLineChartDataset[]; height?: number; } interface LineMetricChartProps { data: number[]; color?: string; fillOpacity?: number; height?: number; showArea?: boolean; } interface DualLineChartProps { data1: number[]; data2: number[]; height?: number; color1?: string; color2?: string; fillOpacity1?: number; fillOpacity2?: number; } interface BarChartProps { data: number[]; color?: string; height?: number; gap?: number; } function toLineData(data: number[]) { return data.map((value, index) => ({ index, value })); } function gradientId(prefix: string, color: string, index = 0) { return `${prefix}-${color.replace(/[^a-zA-Z0-9]/g, '') || 'chart'}-${index}`; } export function LineChart({ data, color = '#ff7043', fillColor = 'transparent', height = 76, showDots = true, smooth = true, }: LineChartProps) { const chartData = toLineData(data); return (
); } export function LineAreaChart({ data, color = '#e8316a', fillOpacity = 0.15, height = 130, }: LineAreaChartProps) { const chartData = toLineData(data); const id = gradientId('gradient', color); return (
); } export function MultiLineChart({ datasets, height = 58, }: MultiLineChartProps) { const maxLength = Math.max(...datasets.map((dataset) => dataset.data.length)); const chartData = Array.from({ length: maxLength }, (_, index) => { const point: Record = { index }; datasets.forEach((dataset, datasetIndex) => { point[`value${datasetIndex}`] = dataset.data[index] ?? 0; }); return point; }); return (
{datasets.map((dataset, index) => { const id = gradientId('gradient-multi', dataset.color, index); return ( ); })} {datasets.map((dataset, index) => { const id = gradientId('gradient-multi', dataset.color, index); return ( ); })}
); } export function LineMetricChart({ data, color = '#ff7043', fillOpacity = 0.15, height = 76, showArea = false, }: LineMetricChartProps) { if (showArea) { return ( ); } return ; } export function DualLineChart({ data1, data2, height = 58, color1 = '#6c8ef0', color2 = '#9c7ef0', fillOpacity1 = 0.15, fillOpacity2 = 0.15, }: DualLineChartProps) { return ( ); } export function BarChart({ data, color = '#3dd68c', height = 128, gap = 4, }: BarChartProps) { return (
{data.map((value, index) => (
))}
); }