{
  "name": "bar-chart",
  "type": "ui:component",
  "title": "BarChart",
  "description": "Zero-dependency responsive SVG bar chart with hover callouts and gridlines.",
  "dependencies": [],
  "registryDependencies": [
    "theme"
  ],
  "files": [
    {
      "path": "src/ui/bar-chart.tsx",
      "target": "src/ui/bar-chart.tsx",
      "sha256": "89a2f248fe5158cb2d6bbfba3a33c452820297c2e7a514472691f25a8ac31013",
      "content": "import './theme.css';\nimport { scope, type Ctx } from '@fierst/aster';\n\nconst bcScope = scope`\n  :scope {\n    display: grid;\n    gap: 0.5rem;\n    font-family: var(--aster-font-sans);\n    min-width: 0;\n  }\n  .bc-meta { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.8rem; color: var(--aster-on-surface-muted); min-height: 1.25rem; }\n  .bc-val { font-family: var(--aster-font-mono); font-weight: 600; color: var(--aster-on-surface); }\n  svg { width: 100%; height: auto; display: block; overflow: visible; }\n  .grid-line { stroke: var(--aster-border); stroke-dasharray: 3 3; }\n  .bar-rect { fill: var(--aster-primary); transition: opacity var(--aster-dur-fast); cursor: pointer; }\n  .bar-rect.is-dim { opacity: 0.45; }\n  .axis-lbl { fill: var(--aster-on-surface-subtle); font-size: 11px; font-family: var(--aster-font-sans); }\n`;\n\nexport interface ChartDatum {\n  label: string;\n  value: number;\n}\n\nexport function* BarChart(\n  props: {\n    data: readonly ChartDatum[];\n    height?: number;\n    unit?: string;\n    label?: string;\n    class?: string;\n  },\n  ctx: Ctx,\n) {\n  let hoveredIdx = -1;\n\n  for (props of ctx) {\n    const h = props.height ?? 190;\n    const w = 420;\n    const padB = 24;\n    const padT = 12;\n    const plotH = h - padB - padT;\n    const maxVal = props.data.reduce((max, d) => Math.max(max, d.value), 0);\n    const minVal = props.data.reduce((min, d) => Math.min(min, d.value), 0);\n    const scale = plotH / (maxVal - minVal || 1);\n    const baseline = padT + maxVal * scale;\n    const n = Math.max(1, props.data.length);\n    const slotW = w / n;\n    const barW = Math.min(38, slotW * 0.62);\n    const active = hoveredIdx >= 0 ? props.data[hoveredIdx] : null;\n\n    yield (\n      <div class={[bcScope, props.class].filter(Boolean).join(' ')}>\n        <div class=\"bc-meta\">\n          <span>{active ? active.label : (props.label ?? 'Overview')}</span>\n          <span class=\"bc-val\">\n            {active\n              ? `${active.value.toLocaleString()}${props.unit ?? ''}`\n              : `Max: ${maxVal.toLocaleString()}${props.unit ?? ''}`}\n          </span>\n        </div>\n        <svg\n          viewBox={`0 0 ${w} ${h}`}\n          role=\"img\"\n          aria-label={props.label ?? 'Bar chart'}\n          on:pointerleave={() => (hoveredIdx = -1)}\n        >\n          <desc>\n            {props.data.map((d) => d.label + ': ' + d.value + (props.unit ?? '')).join(', ')}\n          </desc>\n          {[0.25, 0.5, 0.75, 1].map((t) => {\n            const y = padT + plotH * (1 - t);\n            return <line key={t} class=\"grid-line\" x1=\"0\" y1={y} x2={w} y2={y} />;\n          })}\n          {props.data.map((d, idx) => {\n            const bh = Math.abs(d.value) * scale;\n            const x = idx * slotW + (slotW - barW) / 2;\n            const y = d.value > 0 ? baseline - bh : baseline;\n            return (\n              <g key={d.label} on:pointerenter={() => (hoveredIdx = idx)}>\n                <rect\n                  x={x}\n                  y={y}\n                  width={barW}\n                  height={bh}\n                  rx=\"4\"\n                  class=\"bar-rect\"\n                  class:is-dim={hoveredIdx >= 0 && hoveredIdx !== idx}\n                />\n                <text x={x + barW / 2} y={h - 6} text-anchor=\"middle\" class=\"axis-lbl\">\n                  {d.label}\n                </text>\n              </g>\n            );\n          })}\n        </svg>\n      </div>\n    );\n  }\n}\n"
    }
  ]
}
