import type { EnumFeatureStats } from '../../types'; interface StackedEnumChartProps { components: { label: string; stats: EnumFeatureStats }[]; valueOrder: string[]; valueColors: string[]; } /** Strip common suffixes to produce short row labels */ function shortenLabel(name: string): string { return name.replace(/ risk$/, ''); } export default function StackedEnumChart({ components, valueOrder, valueColors, }: StackedEnumChartProps) { const visibleRows = components.filter(({ stats }) => { const total = Object.values(stats.counts).reduce((a, b) => a + b, 0); if (total === 0) return false; const lowCount = stats.counts[valueOrder[0]] ?? 0; return total - lowCount > 0; }); if (visibleRows.length === 0) { return
All low
; } return (
{visibleRows.map(({ label, stats }) => { const total = Object.values(stats.counts).reduce((a, b) => a + b, 0); return (
{shortenLabel(label)}
{valueOrder.map((value, i) => { const count = stats.counts[value] ?? 0; const pct = (count / total) * 100; if (pct < 0.5) return null; return (
); })}
); })} {/* Legend */}
{valueOrder.map((value, i) => (
{value}
))}
); }