import type React from 'react' interface StackedBarsProps { days: { tools: Record }[] toolColor: (tool: string) => string w?: number h?: number } export function StackedBars({ days, toolColor, w = 600, h = 130 }: StackedBarsProps): React.JSX.Element { const n = days.length if (n === 0) { return ( ) } // Find the maximum total across all days for scaling. const totals = days.map(d => Object.values(d.tools).reduce((a, b) => a + b, 0)) const maxTotal = Math.max(...totals, 1) const barW = Math.max(1, (w / n) - 2) return ( {/* Y axis grid lines */} {[0, 0.25, 0.5, 0.75, 1].map(frac => { const y = h - frac * h return ( ) })} {days.map((day, i) => { const x = i * (w / n) + 1 const tools = Object.entries(day.tools).sort((a, b) => a[0].localeCompare(b[0])) let yBottom = h return ( {tools.map(([tool, count]) => { if (count <= 0) return null const barH = (count / maxTotal) * h yBottom -= barH return ( ) })} ) })} ) }