interface BarValue { color: string; value: number; } interface BarData { label: string; values: BarValue[]; } interface Props { data: BarData[]; height?: number; } export default function BarChart({ data, height = 200 }: Props) { const maxTotal = Math.max(...data.map((d) => d.values.reduce((sum, v) => sum + v.value, 0)), 1); return (
{data.map((bar, i) => { const total = bar.values.reduce((sum, v) => sum + v.value, 0); const ratio = total / maxTotal; return (
`${v.color}: ${v.value}`).join(', ')} > {bar.values .filter((v) => v.value > 0) .map((v, j) => { const segmentRatio = total > 0 ? (v.value / total) * 100 : 0; return (
); })}
); })}
{data.map((bar, i) => (

{bar.label}

))}
); } function colorToClass(color: string): string { const map: Record = { green: 'bg-green-500', red: 'bg-red-500', gray: 'bg-gray-400', blue: 'bg-blue-500', yellow: 'bg-yellow-500', orange: 'bg-orange-500', indigo: 'bg-indigo-500', }; return map[color] ?? color; }