import Dn from '../Dn' import type { WeeklyActivity } from '../../lib/database.types' interface Props { data: WeeklyActivity[] // Which metric to visualize as the bar: 'cups' or 'co2_kg'. metric?: 'cups' | 'co2_kg' } // E-Ink horizontal bar chart. No external libs, no animations. // Each row is one week. Bar width scales to the real max in the dataset // (falls back to 1 only when every value is zero, to avoid divide-by-zero). export default function WeeklyChart({ data, metric = 'cups' }: Props) { const values = data.map((d) => (metric === 'cups' ? d.cups : d.co2_kg)) const realMax = Math.max(...values, 0) const max = realMax > 0 ? realMax : 1 return (
{data.map((row) => { const value = metric === 'cups' ? row.cups : row.co2_kg const pct = (value / max) * 100 const isZero = value === 0 return (
{/* Week label */}

{formatWeekLabel(row.week_start)}

{/* Bar track — borderless dash for zero, framed track for values */}
{isZero ? (
) : ( <>
)}
{/* Value */}

{metric === 'cups' ? value : {value.toFixed(2)}}

{row.active_citizens > 0 && (

시민 {row.active_citizens}

)}
) })}
) } // "04-13" style label (MM-DD of Monday). function formatWeekLabel(iso: string): string { const [, m, d] = iso.split('-') return `${m}/${d}` }