{
  "name": "line-chart",
  "type": "ui:component",
  "title": "LineChart & AreaChart",
  "description": "Zero-dependency responsive SVG line and area charts with interactive data points.",
  "dependencies": [],
  "registryDependencies": [
    "theme"
  ],
  "files": [
    {
      "path": "src/ui/line-chart.tsx",
      "target": "src/ui/line-chart.tsx",
      "sha256": "6986104b5adcea743875674a54ee09432cf5fa942f1667ebc708d0624f196397",
      "content": "import './theme.css';\nimport { scope, type Ctx } from '@fierst/aster';\n\nconst lcScope = scope`\n  :scope { display: grid; gap: 0.5rem; font-family: var(--aster-font-sans); min-width: 0; }\n  .lc-meta { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--aster-on-surface-muted); }\n  .lc-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  .line-path { fill: none; stroke: var(--aster-primary); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }\n  .area-path { fill: var(--aster-primary); opacity: 0.12; }\n  .pt { fill: var(--aster-surface); stroke: var(--aster-primary); stroke-width: 2; cursor: pointer; }\n  .pt.is-active { fill: var(--aster-primary); }\n  .axis-lbl { fill: var(--aster-on-surface-subtle); font-size: 11px; }\n`;\n\nexport function* LineChart(\n  props: {\n    data: readonly { label: string; value: number }[];\n    area?: boolean;\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 padX = 16;\n    const padT = 12;\n    const padB = 24;\n    const plotW = w - padX * 2;\n    const plotH = h - padT - padB;\n    const maxVal = Math.max(...props.data.map((d) => d.value), 1);\n    const minVal = Math.min(...props.data.map((d) => d.value), 0);\n    const span = Math.max(1, maxVal - minVal);\n    const n = Math.max(2, props.data.length);\n\n    const pts = props.data.map((d, i) => ({\n      ...d,\n      x: padX + (i / (n - 1)) * plotW,\n      y: padT + plotH - ((d.value - minVal) / span) * plotH,\n    }));\n\n    const lineD = pts\n      .map((p, i) => `${i === 0 ? 'M' : 'L'}${p.x.toFixed(1)},${p.y.toFixed(1)}`)\n      .join(' ');\n    const areaD =\n      pts.length > 0\n        ? `${lineD} L${pts[pts.length - 1].x.toFixed(1)},${(padT + plotH).toFixed(1)} L${pts[0].x.toFixed(1)},${(padT + plotH).toFixed(1)} Z`\n        : '';\n    const active = hoveredIdx >= 0 ? pts[hoveredIdx] : pts[pts.length - 1];\n\n    yield (\n      <div class={[lcScope, props.class].filter(Boolean).join(' ')}>\n        <div class=\"lc-meta\">\n          <span>{active ? active.label : (props.label ?? 'Trend')}</span>\n          <span class=\"lc-val\">\n            {active ? `${active.value.toLocaleString()}${props.unit ?? ''}` : ''}\n          </span>\n        </div>\n        <svg\n          viewBox={`0 0 ${w} ${h}`}\n          role=\"img\"\n          aria-label={props.label ?? 'Line chart'}\n          on:pointerleave={() => (hoveredIdx = -1)}\n        >\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={padX} y1={y} x2={w - padX} y2={y} />;\n          })}\n          {props.area && areaD ? <path d={areaD} class=\"area-path\" /> : null}\n          {lineD ? <path d={lineD} class=\"line-path\" /> : null}\n          {pts.map((p, idx) => (\n            <g key={p.label} on:pointerenter={() => (hoveredIdx = idx)}>\n              <circle\n                cx={p.x}\n                cy={p.y}\n                r={hoveredIdx === idx ? 5 : 3.5}\n                class=\"pt\"\n                class:is-active={hoveredIdx === idx}\n              />\n              <text x={p.x} y={h - 6} text-anchor=\"middle\" class=\"axis-lbl\">\n                {p.label}\n              </text>\n            </g>\n          ))}\n        </svg>\n      </div>\n    );\n  }\n}\n\nexport function AreaChart(props: {\n  data: readonly { label: string; value: number }[];\n  height?: number;\n  unit?: string;\n  label?: string;\n  class?: string;\n}) {\n  return <LineChart {...props} area />;\n}\n"
    }
  ]
}
