import { fmtValue, unitLabel } from '@/lib/format'; export interface CompareBarDatum { label: string; value: number | null; // null = no figure (rendered as "โ€”", never as zero) note?: string | null; // e.g. "2024 ยท observed" or "registry level: Lung cancer" href?: string; muted?: boolean; } /** * Compact horizontal bar list for the compare page (one small chart per metric). Bars are plain * divs so the block stays responsive on narrow screens; the number always accompanies the bar and * missing values are shown as a dash, never as an empty bar of length zero. */ export function CompareBars({ title, unit, data, caption }: { title: string; unit?: string | null; data: CompareBarDatum[]; caption?: React.ReactNode }) { const values = data.map((d) => d.value).filter((v): v is number => v != null && Number.isFinite(v)); const max = Math.max(...values, Number.EPSILON); return (
{title} {unit ? {unitLabel(unit)} : null}
    {data.map((d, i) => { const has = d.value != null && Number.isFinite(d.value); const pct = has ? Math.max(1, (Math.abs(d.value!) / max) * 100) : 0; return (
  1. {d.href ? ( {d.label} ) : ( d.label )} {has ? fmtValue(d.value, unit) : 'โ€”'}
    {has ?
    : null}
    {d.note ?
    {d.note}
    : null}
  2. ); })}
{caption ?

{caption}

: null}
); }