{
  "schemaVersion": 1,
  "target": "react",
  "name": "chart",
  "version": "0.1.1",
  "category": "data",
  "title": "Chart",
  "description": "Line, area, and grouped bar charts in plain SVG with axes, gridlines, a hover crosshair and tooltip, a toggleable legend, and a draw-in entrance.",
  "tags": [
    "chart",
    "graph",
    "data",
    "svg",
    "line",
    "area",
    "bar"
  ],
  "requires": {
    "projectTypes": [
      "next",
      "vite-react"
    ],
    "styling": "tailwind-v4"
  },
  "npmDependencies": {},
  "registryDependencies": [],
  "docsPath": "/components/chart",
  "props": [
    {
      "name": "type",
      "type": "\"line\" | \"area\" | \"bar\"",
      "default": "\"line\"",
      "description": "Chart kind. Bars group side by side per index."
    },
    {
      "name": "data",
      "type": "Row[]",
      "description": "One object per x position."
    },
    {
      "name": "index",
      "type": "keyof Row",
      "description": "The field holding the x-axis label."
    },
    {
      "name": "series",
      "type": "{ key, label, tone?, dashed? }[]",
      "description": "Series to plot. tone is ink, sky, amber, emerald, violet, red, or muted; dashed suits forecasts and previous periods."
    },
    {
      "name": "label",
      "type": "string",
      "description": "Accessible name for the chart."
    },
    {
      "name": "height",
      "type": "number",
      "default": "240",
      "description": "Plot height in pixels; width follows the container."
    },
    {
      "name": "curve",
      "type": "\"smooth\" | \"linear\"",
      "default": "\"smooth\"",
      "description": "Monotone smoothing that never overshoots, or straight segments."
    },
    {
      "name": "grid",
      "type": "boolean",
      "default": "true",
      "description": "Dotted gridlines at each y tick."
    },
    {
      "name": "legend",
      "type": "boolean",
      "description": "Legend whose entries toggle series. On by default for two or more series."
    },
    {
      "name": "yTicks",
      "type": "number",
      "default": "4",
      "description": "About how many y steps to draw."
    },
    {
      "name": "valueFormatter / axisFormatter",
      "type": "(value: number) => string",
      "description": "Tooltip and y-axis number formatting. The axis defaults to compact notation."
    },
    {
      "name": "loading",
      "type": "boolean",
      "default": "false",
      "description": "Shows the frame with a loading note instead of marks."
    }
  ],
  "accessibility": [
    "The plot is focusable with a descriptive name; Left and Right arrows step through points, Home and End jump to the ends, Escape clears, and each step is announced in a polite live region.",
    "A visually hidden table carries every value, so the data is available without the picture.",
    "Legend entries are toggle buttons with aria-pressed; the last visible series cannot be hidden.",
    "Lines draw in and bars grow once on mount; under reduced motion the marks appear without motion.",
    "Series differ by color and, where needed, by dashing, and the tooltip names every series in text."
  ],
  "states": [
    "line",
    "area",
    "bar",
    "hover",
    "keyboard focus",
    "loading",
    "empty"
  ],
  "files": [
    {
      "path": "ui/chart.tsx",
      "content": "\"use client\";\n\nimport { type FocusEvent, type KeyboardEvent, type PointerEvent, useEffect, useId, useMemo, useRef, useState } from \"react\";\n\nfunction cx(...classes: (string | false | null | undefined)[]) {\n  return classes.filter(Boolean).join(\" \");\n}\n\n// Series colors: ink first, then a few restrained hues. Each is a text color so SVG marks,\n// legend swatches, and tooltip keys can all use `currentColor`.\nconst tones = {\n  ink: \"text-zinc-950 dark:text-white\",\n  sky: \"text-sky-500\",\n  amber: \"text-amber-500\",\n  emerald: \"text-emerald-500\",\n  violet: \"text-violet-500\",\n  red: \"text-red-500\",\n  muted: \"text-zinc-400 dark:text-zinc-500\",\n} as const;\n\nexport type ChartTone = keyof typeof tones;\nconst toneOrder: ChartTone[] = [\"ink\", \"sky\", \"amber\", \"emerald\", \"violet\", \"muted\"];\n\nexport interface ChartSeries {\n  /** The row field that holds this series' numbers. */\n  key: string;\n  label: string;\n  /** Color. Defaults to the next in the series order: ink, sky, amber, emerald, violet, muted. */\n  tone?: ChartTone;\n  /** Draws the line dashed, for a forecast or a previous period. Line and area charts only. */\n  dashed?: boolean;\n}\n\nexport interface ChartProps<Row extends Record<string, unknown>> {\n  type?: \"line\" | \"area\" | \"bar\";\n  data: Row[];\n  /** The row field holding the x-axis label, for example `\"month\"`. */\n  index: keyof Row & string;\n  series: ChartSeries[];\n  /** Accessible name, for example \"Requests per day, last 14 days\". */\n  label: string;\n  /** Plot height in pixels. Width follows the container. */\n  height?: number;\n  /** Line shape. `smooth` uses a monotone curve that never overshoots the data. */\n  curve?: \"smooth\" | \"linear\";\n  /** Horizontal gridlines at each y tick. */\n  grid?: boolean;\n  /** Shows the legend. Each entry toggles its series. Defaults to on for two or more series. */\n  legend?: boolean;\n  /** About how many y-axis steps to draw. */\n  yTicks?: number;\n  /** Formats values in the tooltip and screen reader output. */\n  valueFormatter?: (value: number) => string;\n  /** Formats y-axis labels. Defaults to compact notation (12K). */\n  axisFormatter?: (value: number) => string;\n  /** Shows empty gridlines and a loading note instead of data. */\n  loading?: boolean;\n  className?: string;\n}\n\nconst compact = new Intl.NumberFormat(undefined, { notation: \"compact\", maximumFractionDigits: 1 });\nconst standard = new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 });\n\nfunction niceStep(range: number, count: number) {\n  const raw = range / Math.max(1, count);\n  const magnitude = 10 ** Math.floor(Math.log10(raw));\n  const normalized = raw / magnitude;\n  const nice = normalized <= 1 ? 1 : normalized <= 2 ? 2 : normalized <= 2.5 ? 2.5 : normalized <= 5 ? 5 : 10;\n  return nice * magnitude;\n}\n\ntype Point = { x: number; y: number };\n\n/** Monotone cubic interpolation (Fritsch and Carlson): smooth, and never overshoots a data point. */\nfunction smoothPath(points: Point[]) {\n  const n = points.length;\n  if (n === 0) return \"\";\n  const first = points[0]!;\n  if (n === 1) return `M${first.x},${first.y}`;\n  if (n === 2) return `M${first.x},${first.y}L${points[1]!.x},${points[1]!.y}`;\n  const slopes: number[] = [];\n  for (let i = 0; i < n - 1; i++) slopes.push((points[i + 1]!.y - points[i]!.y) / (points[i + 1]!.x - points[i]!.x));\n  const tangents = points.map((_, i) => {\n    if (i === 0) return slopes[0]!;\n    if (i === n - 1) return slopes[n - 2]!;\n    const a = slopes[i - 1]!;\n    const b = slopes[i]!;\n    return a * b <= 0 ? 0 : (a + b) / 2;\n  });\n  for (let i = 0; i < n - 1; i++) {\n    const slope = slopes[i]!;\n    if (slope === 0) {\n      tangents[i] = 0;\n      tangents[i + 1] = 0;\n      continue;\n    }\n    const a = tangents[i]! / slope;\n    const b = tangents[i + 1]! / slope;\n    const s = a * a + b * b;\n    if (s > 9) {\n      const t = 3 / Math.sqrt(s);\n      tangents[i] = t * a * slope;\n      tangents[i + 1] = t * b * slope;\n    }\n  }\n  let d = `M${first.x},${first.y}`;\n  for (let i = 0; i < n - 1; i++) {\n    const p0 = points[i]!;\n    const p1 = points[i + 1]!;\n    const dx = (p1.x - p0.x) / 3;\n    d += `C${p0.x + dx},${p0.y + tangents[i]! * dx},${p1.x - dx},${p1.y - tangents[i + 1]! * dx},${p1.x},${p1.y}`;\n  }\n  return d;\n}\n\nfunction linearPath(points: Point[]) {\n  return points.map((point, i) => `${i ? \"L\" : \"M\"}${point.x},${point.y}`).join(\"\");\n}\n\n/** A bar with its two far corners rounded, growing up from (or down from) the baseline. */\nfunction barPath(x: number, y: number, width: number, height: number, up: boolean) {\n  const r = Math.min(3, width / 2, Math.abs(height));\n  if (height === 0) return \"\";\n  if (up) return `M${x},${y + height}V${y + r}Q${x},${y} ${x + r},${y}H${x + width - r}Q${x + width},${y} ${x + width},${y + r}V${y + height}Z`;\n  return `M${x},${y}V${y + height - r}Q${x},${y + height} ${x + r},${y + height}H${x + width - r}Q${x + width},${y + height} ${x + width},${y + height - r}V${y}Z`;\n}\n\n/**\n * Line, area, and grouped bar charts drawn in SVG with no chart library. Width follows the\n * container; a crosshair and tooltip follow the pointer, and arrow keys step through points\n * when the plot has focus. Lines draw in and bars grow on first render, except under reduced motion.\n */\nexport function Chart<Row extends Record<string, unknown>>({\n  type = \"line\",\n  data,\n  index,\n  series,\n  label,\n  height = 240,\n  curve = \"smooth\",\n  grid = true,\n  legend = series.length > 1,\n  yTicks = 4,\n  valueFormatter = (value) => standard.format(value),\n  axisFormatter = (value) => compact.format(value),\n  loading = false,\n  className,\n}: ChartProps<Row>) {\n  const id = useId();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const [width, setWidth] = useState(0);\n  const [hidden, setHidden] = useState<Set<string>>(() => new Set());\n  const [active, setActive] = useState<number | null>(null);\n  const [announcement, setAnnouncement] = useState(\"\");\n  // Bars stagger their entrance; once settled, hover dimming should answer without that delay.\n  const [settled, setSettled] = useState(false);\n\n  useEffect(() => {\n    const node = wrapRef.current;\n    if (!node) return;\n    const observer = new ResizeObserver(([entry]) => entry && setWidth(Math.round(entry.contentRect.width)));\n    observer.observe(node);\n    setWidth(Math.round(node.getBoundingClientRect().width));\n    return () => observer.disconnect();\n  }, []);\n\n  const toned = series.map((item, i) => ({ ...item, tone: item.tone ?? toneOrder[i % toneOrder.length]! }));\n  const visible = toned.filter((item) => !hidden.has(item.key));\n  const value = (row: Row | undefined, key: string) => {\n    const raw = row?.[key];\n    return typeof raw === \"number\" && Number.isFinite(raw) ? raw : null;\n  };\n  const labels = data.map((row) => String(row[index] ?? \"\"));\n\n  // Y domain over the visible series, always including zero, rounded out to nice steps.\n  const scale = useMemo(() => {\n    let min = 0;\n    let max = 0;\n    for (const row of data)\n      for (const item of visible) {\n        const v = value(row, item.key);\n        if (v === null) continue;\n        min = Math.min(min, v);\n        max = Math.max(max, v);\n      }\n    if (max === min) max = min + 1;\n    const step = niceStep(max - min, yTicks);\n    const lo = Math.floor(min / step) * step;\n    const hi = Math.ceil(max / step) * step;\n    const ticks: number[] = [];\n    for (let tick = lo; tick <= hi + step / 2; tick += step) ticks.push(Number(tick.toPrecision(12)));\n    return { lo, hi, ticks };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [data, visible.map((item) => item.key).join(), yTicks]);\n\n  const tickLabels = scale.ticks.map(axisFormatter);\n  const longest = Math.max(...tickLabels.map((text) => text.length), 1);\n  const pad = { top: 10, right: 12, bottom: 28, left: Math.ceil(longest * 6.6) + 14 };\n  const innerW = Math.max(0, width - pad.left - pad.right);\n  const innerH = Math.max(0, height - pad.top - pad.bottom);\n  const n = data.length;\n  const y = (v: number) => pad.top + innerH - ((v - scale.lo) / (scale.hi - scale.lo)) * innerH;\n  const baseline = y(Math.max(scale.lo, Math.min(0, scale.hi)));\n  const band = type === \"bar\" ? innerW / Math.max(1, n) : 0;\n  const xAt = (i: number) => (type === \"bar\" ? pad.left + band * i + band / 2 : n === 1 ? pad.left + innerW / 2 : pad.left + (i * innerW) / (n - 1));\n\n  const labelEvery = Math.max(1, Math.ceil(n / Math.max(1, Math.floor(innerW / 64))));\n\n  function indexFromPointer(event: PointerEvent<SVGRectElement>) {\n    const rect = event.currentTarget.getBoundingClientRect();\n    const px = event.clientX - rect.left;\n    if (n === 0) return null;\n    if (type === \"bar\") return Math.max(0, Math.min(n - 1, Math.floor(px / band)));\n    if (n === 1) return 0;\n    return Math.max(0, Math.min(n - 1, Math.round((px / innerW) * (n - 1))));\n  }\n\n  function describe(i: number) {\n    const row = data[i];\n    const parts = visible.map((item) => {\n      const v = value(row, item.key);\n      return `${item.label} ${v === null ? \"no data\" : valueFormatter(v)}`;\n    });\n    return `${labels[i]}: ${parts.join(\", \")}`;\n  }\n\n  function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {\n    if (n === 0) return;\n    let next: number | null = active;\n    if (event.key === \"ArrowRight\") next = active === null ? 0 : Math.min(n - 1, active + 1);\n    else if (event.key === \"ArrowLeft\") next = active === null ? n - 1 : Math.max(0, active - 1);\n    else if (event.key === \"Home\") next = 0;\n    else if (event.key === \"End\") next = n - 1;\n    else if (event.key === \"Escape\") next = null;\n    else return;\n    event.preventDefault();\n    setActive(next);\n    setAnnouncement(next === null ? \"\" : describe(next));\n  }\n\n  function onFocus(event: FocusEvent<HTMLDivElement>) {\n    if (active === null && n > 0 && event.currentTarget.matches(\":focus-visible\")) {\n      setActive(n - 1);\n      setAnnouncement(describe(n - 1));\n    }\n  }\n\n  function toggle(key: string) {\n    setHidden((current) => {\n      const next = new Set(current);\n      if (next.has(key)) next.delete(key);\n      else if (toned.length - next.size > 1) next.add(key);\n      return next;\n    });\n  }\n\n  const ready = width > 0;\n  useEffect(() => {\n    if (!ready || settled) return;\n    const timer = setTimeout(() => setSettled(true), 900);\n    return () => clearTimeout(timer);\n  }, [ready, settled]);\n  const empty = !loading && n === 0;\n  const activeRow = active !== null ? data[active] : undefined;\n  const activeX = active !== null ? xAt(active) : 0;\n  const tooltipLeft = activeX > width / 2;\n  const groupW = Math.min(band * 0.72, visible.length * 28 + (visible.length - 1) * 3);\n  const barW = visible.length ? (groupW - (visible.length - 1) * 3) / visible.length : 0;\n\n  return (\n    <figure data-slot=\"chart\" data-type={type} className={cx(\"m-0 grid min-w-0 gap-3\", className)}>\n      {legend ? (\n        <div role=\"group\" aria-label=\"Series\" className=\"flex flex-wrap items-center gap-x-1 gap-y-1\">\n          {toned.map((item) => {\n            const on = !hidden.has(item.key);\n            return (\n              <button\n                key={item.key}\n                type=\"button\"\n                aria-pressed={on}\n                onClick={() => toggle(item.key)}\n                className={cx(\n                  \"inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs\",\n                  \"transition-[background-color,color,opacity] duration-150 ease-out motion-reduce:transition-none\",\n                  \"hover:bg-zinc-950/[0.04] dark:hover:bg-white/[0.06]\",\n                  \"focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-0 focus-visible:outline-sky-500\",\n                  on ? \"text-zinc-600 dark:text-zinc-400\" : \"text-zinc-400 opacity-60 dark:text-zinc-600\",\n                )}\n              >\n                <span aria-hidden=\"true\" className={cx(\"flex\", tones[item.tone])}>\n                  {type === \"bar\" ? (\n                    <span className=\"size-2.5 rounded-[3px] bg-current\" />\n                  ) : item.dashed ? (\n                    <svg viewBox=\"0 0 14 4\" className=\"h-1 w-3.5\">\n                      <path d=\"M1 2h12\" stroke=\"currentColor\" strokeWidth=\"2\" strokeDasharray=\"3 2\" strokeLinecap=\"round\" />\n                    </svg>\n                  ) : (\n                    <span className=\"h-0.5 w-3.5 rounded-full bg-current\" />\n                  )}\n                </span>\n                {item.label}\n              </button>\n            );\n          })}\n        </div>\n      ) : null}\n\n      <div\n        ref={wrapRef}\n        role=\"img\"\n        aria-label={`${label}. Focus and use the arrow keys to read each point.`}\n        aria-busy={loading || undefined}\n        tabIndex={empty || loading ? undefined : 0}\n        onKeyDown={onKeyDown}\n        onFocus={onFocus}\n        onBlur={() => setActive(null)}\n        style={{ height }}\n        className=\"relative w-full rounded-lg outline-none select-none focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-4 focus-visible:outline-sky-500\"\n      >\n        {ready ? (\n          <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} aria-hidden=\"true\" className=\"block overflow-visible\">\n            {/* Gridlines and y labels */}\n            {scale.ticks.map((tick, i) => (\n              <g key={tick}>\n                {grid || tick === 0 ? (\n                  <line\n                    x1={pad.left}\n                    x2={width - pad.right}\n                    y1={Math.round(y(tick)) + 0.5}\n                    y2={Math.round(y(tick)) + 0.5}\n                    className={tick === 0 ? \"stroke-zinc-950/15 dark:stroke-white/20\" : \"stroke-zinc-950/[0.07] dark:stroke-white/[0.08]\"}\n                    strokeDasharray={tick === 0 ? undefined : \"2 3\"}\n                  />\n                ) : null}\n                <text x={pad.left - 10} y={y(tick)} dy=\"0.32em\" textAnchor=\"end\" className=\"fill-zinc-500 text-[11px] tabular-nums\">\n                  {loading ? \"\" : tickLabels[i]}\n                </text>\n              </g>\n            ))}\n\n            {/* X labels */}\n            {labels.map((text, i) =>\n              i % labelEvery === 0 || (type !== \"bar\" && i === n - 1 && (n - 1) % labelEvery > labelEvery / 2) ? (\n                <text\n                  key={i}\n                  x={xAt(i)}\n                  y={height - 8}\n                  textAnchor={type === \"bar\" || n === 1 ? \"middle\" : i === 0 ? \"start\" : i === n - 1 ? \"end\" : \"middle\"}\n                  className={cx(\n                    \"text-[11px] tabular-nums transition-[fill] duration-150 motion-reduce:transition-none\",\n                    active === i ? \"fill-zinc-950 dark:fill-white\" : \"fill-zinc-500\",\n                  )}\n                >\n                  {text}\n                </text>\n              ) : null,\n            )}\n\n            {/* Hover band behind bars */}\n            {type === \"bar\" && active !== null ? (\n              <rect\n                x={pad.left + band * active + 1}\n                y={pad.top}\n                width={Math.max(0, band - 2)}\n                height={innerH}\n                rx={6}\n                className=\"fill-zinc-950/[0.035] dark:fill-white/[0.05]\"\n              />\n            ) : null}\n\n            {/* Marks */}\n            {!loading\n              ? visible.map((item, s) => {\n                  if (type === \"bar\") {\n                    return (\n                      <g key={item.key} className={tones[item.tone]}>\n                        {data.map((row, i) => {\n                          const v = value(row, item.key);\n                          if (v === null) return null;\n                          const x = pad.left + band * i + (band - groupW) / 2 + s * (barW + 3);\n                          const top = Math.min(y(v), baseline);\n                          const h = Math.abs(y(v) - baseline);\n                          return (\n                            <path\n                              key={i}\n                              d={barPath(x, top, barW, h, v >= 0)}\n                              style={settled ? undefined : { transitionDelay: `${Math.min(i * 28, 320)}ms` }}\n                              className={cx(\n                                \"fill-current [transform-box:fill-box]\",\n                                v >= 0 ? \"origin-bottom\" : \"origin-top\",\n                                \"transition-[scale,opacity] duration-500 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                                \"motion-safe:starting:scale-y-0\",\n                                active !== null && active !== i ? \"opacity-55\" : \"opacity-100\",\n                              )}\n                            />\n                          );\n                        })}\n                      </g>\n                    );\n                  }\n                  // Lines break at missing values instead of dropping to zero.\n                  const segments: Point[][] = [[]];\n                  data.forEach((row, i) => {\n                    const v = value(row, item.key);\n                    if (v === null) segments.push([]);\n                    else segments[segments.length - 1]!.push({ x: xAt(i), y: y(v) });\n                  });\n                  const paths = segments.filter((segment) => segment.length > 0);\n                  const draw = curve === \"smooth\" ? smoothPath : linearPath;\n                  const gradientId = `${id}-${item.key}-fill`;\n                  return (\n                    <g key={item.key} className={tones[item.tone]}>\n                      {type === \"area\" ? (\n                        <>\n                          <defs>\n                            <linearGradient id={gradientId} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n                              <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity={visible.length > 1 ? 0.14 : 0.2} />\n                              <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity={0} />\n                            </linearGradient>\n                          </defs>\n                          {paths.map((segment, k) => (\n                            <path\n                              key={`area-${k}`}\n                              d={`${draw(segment)}L${segment[segment.length - 1]!.x},${baseline}L${segment[0]!.x},${baseline}Z`}\n                              fill={`url(#${gradientId})`}\n                              className=\"transition-opacity delay-150 duration-700 ease-out motion-reduce:transition-none motion-safe:starting:opacity-0\"\n                            />\n                          ))}\n                        </>\n                      ) : null}\n                      {paths.map((segment, k) => (\n                        <path\n                          key={`line-${k}`}\n                          d={draw(segment)}\n                          fill=\"none\"\n                          stroke=\"currentColor\"\n                          strokeWidth={1.75}\n                          strokeLinecap=\"round\"\n                          strokeLinejoin=\"round\"\n                          pathLength={item.dashed ? undefined : 1}\n                          strokeDasharray={item.dashed ? \"4 4\" : \"1\"}\n                          className={cx(\n                            item.dashed\n                              ? \"transition-opacity duration-500 ease-out motion-reduce:transition-none motion-safe:starting:opacity-0\"\n                              : \"[stroke-dashoffset:0] transition-[stroke-dashoffset] duration-[900ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none motion-safe:starting:[stroke-dashoffset:1]\",\n                          )}\n                        />\n                      ))}\n                    </g>\n                  );\n                })\n              : null}\n\n            {/* Crosshair and active points */}\n            {type !== \"bar\" && active !== null && !loading ? (\n              <g>\n                <line\n                  x1={Math.round(activeX) + 0.5}\n                  x2={Math.round(activeX) + 0.5}\n                  y1={pad.top}\n                  y2={pad.top + innerH}\n                  className=\"stroke-zinc-950/25 dark:stroke-white/30\"\n                />\n                {visible.map((item) => {\n                  const v = value(activeRow, item.key);\n                  return v === null ? null : (\n                    <circle\n                      key={item.key}\n                      cx={activeX}\n                      cy={y(v)}\n                      r={3.75}\n                      strokeWidth={2}\n                      className={cx(\"fill-current stroke-white dark:stroke-black\", tones[item.tone])}\n                    />\n                  );\n                })}\n              </g>\n            ) : null}\n\n            {/* Pointer target over the plot */}\n            {!loading && n > 0 ? (\n              <rect\n                x={pad.left}\n                y={pad.top}\n                width={innerW}\n                height={innerH}\n                fill=\"transparent\"\n                className=\"touch-pan-y\"\n                onPointerMove={(event) => setActive(indexFromPointer(event))}\n                onPointerDown={(event) => setActive(indexFromPointer(event))}\n                onPointerLeave={(event) => event.pointerType === \"mouse\" && setActive(null)}\n              />\n            ) : null}\n          </svg>\n        ) : null}\n\n        {loading || empty ? (\n          <p className=\"absolute inset-0 flex items-center justify-center pb-6 text-xs text-zinc-500\">\n            {loading ? \"Loading data\" : \"No data in this range\"}\n          </p>\n        ) : null}\n\n        {ready && active !== null && activeRow && !loading ? (\n          <div\n            aria-hidden=\"true\"\n            style={{\n              left: activeX,\n              top: pad.top,\n              transform: tooltipLeft ? \"translateX(calc(-100% - 14px))\" : \"translateX(14px)\",\n            }}\n            className={cx(\n              \"pointer-events-none absolute z-10 grid min-w-36 gap-1.5 rounded-lg border px-3 py-2 text-xs\",\n              \"border-zinc-950/10 bg-white shadow-[0_12px_32px_-8px_rgb(0_0_0/0.18)]\",\n              \"dark:border-white/15 dark:bg-black dark:shadow-[0_16px_48px_-12px_rgb(0_0_0/1),inset_0_1px_0_rgb(255_255_255/0.08)]\",\n              \"transition-opacity duration-150 ease-out motion-reduce:transition-none starting:opacity-0\",\n            )}\n          >\n            <p className=\"font-medium text-zinc-950 dark:text-white\">{labels[active]}</p>\n            {visible.map((item) => {\n              const v = value(activeRow, item.key);\n              return (\n                <div key={item.key} className=\"flex items-center gap-2\">\n                  <span aria-hidden=\"true\" className={cx(\"size-2 shrink-0 rounded-[3px] bg-current\", tones[item.tone])} />\n                  <span className=\"text-zinc-600 dark:text-zinc-400\">{item.label}</span>\n                  <span className=\"ms-auto ps-3 font-medium text-zinc-950 tabular-nums dark:text-white\">{v === null ? \"None\" : valueFormatter(v)}</span>\n                </div>\n              );\n            })}\n          </div>\n        ) : null}\n      </div>\n\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {announcement}\n      </p>\n\n      {/* The numbers behind the picture, for screen readers. */}\n      <table className=\"sr-only\">\n        <caption>{label}</caption>\n        <thead>\n          <tr>\n            <th scope=\"col\">{String(index)}</th>\n            {toned.map((item) => (\n              <th key={item.key} scope=\"col\">\n                {item.label}\n              </th>\n            ))}\n          </tr>\n        </thead>\n        <tbody>\n          {data.map((row, i) => (\n            <tr key={i}>\n              <th scope=\"row\">{labels[i]}</th>\n              {toned.map((item) => {\n                const v = value(row, item.key);\n                return <td key={item.key}>{v === null ? \"No data\" : valueFormatter(v)}</td>;\n              })}\n            </tr>\n          ))}\n        </tbody>\n      </table>\n    </figure>\n  );\n}\n"
    }
  ],
  "example": {
    "content": "import { Chart } from \"@/components/shaken/ui/chart\";\n\nconst days = [\"Nov 1\", \"Nov 2\", \"Nov 3\", \"Nov 4\", \"Nov 5\", \"Nov 6\", \"Nov 7\", \"Nov 8\", \"Nov 9\", \"Nov 10\", \"Nov 11\", \"Nov 12\", \"Nov 13\", \"Nov 14\"];\nconst current = [18_400, 21_050, 19_870, 24_310, 26_920, 15_480, 13_960, 22_740, 25_160, 27_830, 26_410, 30_220, 31_870, 29_640];\nconst previous = [16_900, 18_200, 18_950, 20_400, 22_100, 14_300, 12_800, 19_600, 21_300, 22_900, 23_400, 24_100, 25_800, 24_900];\n\nconst data = days.map((day, i) => ({ day, requests: current[i]!, previous: previous[i]! }));\nconst total = current.reduce((sum, value) => sum + value, 0);\n\nexport default function ChartExample() {\n  return (\n    <section className=\"grid w-full max-w-2xl gap-4 rounded-xl border border-zinc-950/10 bg-white p-5 shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:border-white/10 dark:bg-black dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]\">\n      <header className=\"grid gap-1\">\n        <h3 className=\"text-sm font-medium text-zinc-600 dark:text-zinc-400\">API requests</h3>\n        <p className=\"flex items-baseline gap-2\">\n          <span className=\"text-2xl font-semibold tracking-tight text-zinc-950 tabular-nums dark:text-white\">{total.toLocaleString(\"en-US\")}</span>\n          <span className=\"text-xs font-medium text-emerald-700 tabular-nums dark:text-emerald-400\">+14.2% vs previous 14 days</span>\n        </p>\n      </header>\n      <Chart\n        type=\"area\"\n        label=\"API requests per day, November 1 to 14, compared with the previous 14 days\"\n        data={data}\n        index=\"day\"\n        series={[\n          { key: \"requests\", label: \"This period\" },\n          { key: \"previous\", label: \"Previous period\", tone: \"muted\", dashed: true },\n        ]}\n        height={220}\n      />\n    </section>\n  );\n}\n"
  }
}
