{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "aurora-area-chart",
  "title": "Aurora Area Chart",
  "description": "A calm multi-series area chart with monotone curves and soft fills, source toggles that show live values, a hover readout and keyboard point inspection.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "registry/new-york/aurora-area-chart/aurora-area-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\n\nexport interface AuroraSeries {\n  label: string;\n  values: number[];\n  /** Leave it out to use the chart's own palette. */\n  color?: string;\n}\n\nexport interface AuroraAreaChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  title?: string;\n  subtitle?: string;\n  theme?: \"dark\" | \"light\";\n  labels?: string[];\n  series?: AuroraSeries[];\n  /** Height of the plot, in px. */\n  height?: number;\n  formatValue?: (value: number) => string;\n}\n\nconst PALETTES = {\n  dark: {\n    bg: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    tip: \"#161718\",\n    tipShadow: \"0 4px 24px rgba(0,0,0,0.4)\",\n    series: [\"#5E6AD2\", \"#4EA7FC\", \"#8A8F98\"],\n    fill: 0.2,\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    tip: \"#FFFFFF\",\n    tipShadow: \"0 3px 12px rgba(8,9,10,0.09)\",\n    series: [\"#5E6AD2\", \"#4EA7FC\", \"#8A8F98\"],\n    fill: 0.14,\n  },\n};\n\nconst LABELS = [\n  \"Jan\",\n  \"Feb\",\n  \"Mar\",\n  \"Apr\",\n  \"May\",\n  \"Jun\",\n  \"Jul\",\n  \"Aug\",\n  \"Sep\",\n  \"Oct\",\n  \"Nov\",\n  \"Dec\",\n];\n\nconst SERIES: AuroraSeries[] = [\n  {\n    label: \"Organic\",\n    values: [24, 38, 32, 54, 48, 65, 58, 78, 70, 88, 81, 104],\n  },\n  {\n    label: \"Referral\",\n    values: [14, 19, 30, 22, 38, 31, 46, 39, 56, 48, 63, 72],\n  },\n  { label: \"Direct\", values: [8, 15, 12, 24, 18, 33, 26, 42, 35, 49, 44, 58] },\n];\n\nconst FORMAT = (n: number) => `${n.toLocaleString(\"en-US\")}k`;\n\nconst LEFT = 44;\nconst RIGHT = 12;\nconst TOP = 12;\nconst BOTTOM = 26;\n\n// Monotone cubic interpolation preserves local extrema and never overshoots the data.\nfunction curve(points: [number, number][]) {\n  if (!points.length) return \"\";\n  if (points.length === 1) return `M${points[0].join(\",\")}`;\n  const slopes = points\n    .slice(1)\n    .map((p, i) => (p[1] - points[i][1]) / (p[0] - points[i][0]));\n  const tangents = points.map((_, i) =>\n    i === 0\n      ? slopes[0]\n      : i === points.length - 1\n        ? slopes[i - 1]\n        : slopes[i - 1] * slopes[i] <= 0\n          ? 0\n          : (slopes[i - 1] + slopes[i]) / 2,\n  );\n  return (\n    `M${points[0].join(\",\")}` +\n    points\n      .slice(1)\n      .map((p, i) => {\n        const prev = points[i];\n        const dx = (p[0] - prev[0]) / 3;\n        return `C${prev[0] + dx},${prev[1] + dx * tangents[i]} ${p[0] - dx},${p[1] - dx * tangents[i + 1]} ${p.join(\",\")}`;\n      })\n      .join(\"\")\n  );\n}\n\nexport function AuroraAreaChart({\n  title = \"Traffic by source\",\n  subtitle = \"A year of momentum, one source at a time.\",\n  theme = \"dark\",\n  labels = LABELS,\n  series = SERIES,\n  height = 280,\n  formatValue = FORMAT,\n  className,\n  style,\n  ...props\n}: AuroraAreaChartProps) {\n  const pal = PALETTES[theme];\n  const id = React.useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const reduced = useReducedMotion();\n  const plotRef = React.useRef<HTMLDivElement>(null);\n  const [width, setWidth] = React.useState(700);\n  const [active, setActive] = React.useState<number | null>(null);\n  const [hidden, setHidden] = React.useState<string[]>([]);\n\n  // Drawn at the real width, so the axis text stays the same size on a phone.\n  React.useEffect(() => {\n    const el = plotRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) =>\n      setWidth(Math.max(240, Math.round(entry.contentRect.width))),\n    );\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const valid = series.filter(\n    (s) =>\n      s.values.length === labels.length &&\n      s.values.every((v) => Number.isFinite(v) && v >= 0),\n  );\n  const colorOf = (s: AuroraSeries) =>\n    s.color ?? pal.series[valid.indexOf(s) % pal.series.length];\n  const visible = valid.filter((s) => !hidden.includes(s.label));\n  const max = Math.max(1, ...visible.flatMap((s) => s.values)) * 1.15;\n  const span = width - LEFT - RIGHT;\n  const base = height - BOTTOM;\n  const x = (i: number) =>\n    LEFT + (labels.length <= 1 ? span / 2 : (i / (labels.length - 1)) * span);\n  const y = (v: number) => base - (v / max) * (base - TOP);\n  const index =\n    active === null ? labels.length - 1 : Math.min(active, labels.length - 1);\n  const total = visible.reduce((n, s) => n + (s.values[index] ?? 0), 0);\n  const every = Math.max(1, Math.ceil(labels.length / Math.floor(width / 72)));\n\n  return (\n    <section\n      className={`w-full rounded-2xl p-5 sm:p-7 ${className ?? \"\"}`}\n      style={{\n        background: pal.bg,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily:\n          '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif',\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-4\">\n        <div>\n          <h3 className=\"m-0 text-[20px] leading-[1.33] font-[590] tracking-[-0.012em]\">\n            {title}\n          </h3>\n          <p\n            className=\"m-0 mt-1 text-[13px] tracking-[-0.011em]\"\n            style={{ color: pal.sub }}\n          >\n            {subtitle}\n          </p>\n        </div>\n        <div className=\"text-left sm:text-right\">\n          <p className=\"m-0 text-[32px] leading-none font-[510] tracking-[-0.022em] tabular-nums\">\n            {formatValue(total)}\n          </p>\n          <p className=\"m-0 mt-1.5 text-[13px]\" style={{ color: pal.sub }}>\n            {labels[index] ?? \"No data\"}, total visits\n          </p>\n        </div>\n      </div>\n\n      <div\n        className=\"mt-5 flex flex-wrap gap-1.5\"\n        role=\"group\"\n        aria-label=\"Toggle traffic sources\"\n      >\n        {valid.map((s) => {\n          const off = hidden.includes(s.label);\n          return (\n            <button\n              key={s.label}\n              type=\"button\"\n              aria-pressed={!off}\n              onClick={() =>\n                setHidden((h) =>\n                  off ? h.filter((v) => v !== s.label) : [...h, s.label],\n                )\n              }\n              className=\"flex h-7 cursor-pointer items-center gap-2 rounded-full px-3 text-[13px] font-[510] tracking-[-0.011em] transition-opacity outline-none focus-visible:ring-2\"\n              style={{\n                background: pal.chip,\n                opacity: off ? 0.45 : 1,\n              }}\n            >\n              <span\n                className=\"size-2 rounded-full\"\n                style={{ background: colorOf(s) }}\n              />\n              {s.label}\n              <span className=\"tabular-nums\" style={{ color: pal.sub }}>\n                {formatValue(s.values[index] ?? 0)}\n              </span>\n            </button>\n          );\n        })}\n      </div>\n\n      {!labels.length || !valid.length ? (\n        <p className=\"py-16 text-center text-sm\" style={{ color: pal.sub }}>\n          No traffic data available.\n        </p>\n      ) : (\n        <div\n          ref={plotRef}\n          className=\"relative mt-4 rounded-lg outline-none focus-visible:ring-2\"\n          tabIndex={0}\n          role=\"group\"\n          aria-label=\"Traffic chart. Use left and right arrow keys to inspect months.\"\n          onBlur={() => setActive(null)}\n          onKeyDown={(e) => {\n            if (\n              [\"ArrowLeft\", \"ArrowRight\", \"Home\", \"End\", \"Escape\"].includes(\n                e.key,\n              )\n            ) {\n              e.preventDefault();\n              setActive(\n                e.key === \"Escape\"\n                  ? null\n                  : e.key === \"Home\"\n                    ? 0\n                    : e.key === \"End\"\n                      ? labels.length - 1\n                      : Math.max(\n                          0,\n                          Math.min(\n                            labels.length - 1,\n                            (active ?? 0) + (e.key === \"ArrowRight\" ? 1 : -1),\n                          ),\n                        ),\n              );\n            }\n          }}\n        >\n          <svg\n            viewBox={`0 0 ${width} ${height}`}\n            className=\"block w-full\"\n            style={{ height }}\n            role=\"img\"\n            aria-label={`${labels[index]}: ${visible.map((s) => `${s.label} ${formatValue(s.values[index] ?? 0)}`).join(\", \")}`}\n            onPointerLeave={() => setActive(null)}\n            onPointerMove={(e) => {\n              const r = e.currentTarget.getBoundingClientRect();\n              setActive(\n                Math.max(\n                  0,\n                  Math.min(\n                    labels.length - 1,\n                    Math.round(\n                      ((e.clientX - r.left - LEFT) / span) *\n                        (labels.length - 1),\n                    ),\n                  ),\n                ),\n              );\n            }}\n          >\n            <defs>\n              {valid.map((s, i) => (\n                <linearGradient\n                  key={s.label}\n                  id={`${id}-fill-${i}`}\n                  x1=\"0\"\n                  y1=\"0\"\n                  x2=\"0\"\n                  y2=\"1\"\n                >\n                  <stop stopColor={colorOf(s)} stopOpacity={pal.fill} />\n                  <stop offset=\"1\" stopColor={colorOf(s)} stopOpacity=\"0\" />\n                </linearGradient>\n              ))}\n            </defs>\n            {[0, 1, 2, 3, 4].map((i) => (\n              <g key={i}>\n                <line\n                  x1={LEFT}\n                  x2={width - RIGHT}\n                  y1={y((max * i) / 4)}\n                  y2={y((max * i) / 4)}\n                  stroke={pal.grid}\n                />\n                <text\n                  x={LEFT - 10}\n                  y={y((max * i) / 4) + 4}\n                  textAnchor=\"end\"\n                  fill={pal.faint}\n                  fontSize=\"11\"\n                >\n                  {formatValue(Math.round((max * i) / 4))}\n                </text>\n              </g>\n            ))}\n            {visible.map((s) => {\n              const i = valid.indexOf(s);\n              const line = curve(\n                s.values.map((v, j) => [x(j), y(v)] as [number, number]),\n              );\n              return (\n                <g key={s.label}>\n                  <motion.path\n                    d={`${line}L${x(labels.length - 1)},${base}L${x(0)},${base}Z`}\n                    fill={`url(#${id}-fill-${i})`}\n                    initial={{ opacity: reduced ? 1 : 0 }}\n                    whileInView={{ opacity: 1 }}\n                    viewport={{ once: true }}\n                    transition={{ duration: 0.8 }}\n                  />\n                  <motion.path\n                    d={line}\n                    fill=\"none\"\n                    stroke={colorOf(s)}\n                    strokeWidth=\"1.75\"\n                    strokeLinecap=\"round\"\n                    initial={{ pathLength: reduced ? 1 : 0 }}\n                    whileInView={{ pathLength: 1 }}\n                    viewport={{ once: true }}\n                    transition={{ duration: 1, ease: \"easeOut\" }}\n                  />\n                </g>\n              );\n            })}\n            {labels.map(\n              (label, i) =>\n                i % every === 0 && (\n                  <text\n                    key={label}\n                    x={x(i)}\n                    y={height - 6}\n                    textAnchor={i === 0 ? \"start\" : \"middle\"}\n                    fontSize=\"11\"\n                    fill={pal.faint}\n                  >\n                    {label}\n                  </text>\n                ),\n            )}\n            {active !== null && (\n              <g>\n                <line\n                  x1={x(index)}\n                  x2={x(index)}\n                  y1={TOP}\n                  y2={base}\n                  stroke={pal.border}\n                />\n                {visible.map((s) => (\n                  <circle\n                    key={s.label}\n                    cx={x(index)}\n                    cy={y(s.values[index] ?? 0)}\n                    r=\"3.5\"\n                    fill={colorOf(s)}\n                    stroke={pal.bg}\n                    strokeWidth=\"2\"\n                  />\n                ))}\n              </g>\n            )}\n          </svg>\n\n          {active !== null && visible.length > 0 && (\n            <div\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute top-2 w-[148px] rounded-lg p-2.5 text-[12px] tracking-[-0.011em]\"\n              style={{\n                left: x(index),\n                transform: `translateX(${x(index) > width * 0.6 ? \"calc(-100% - 12px)\" : \"12px\"})`,\n                background: pal.tip,\n                boxShadow: `inset 0 0 0 1px ${pal.border}, ${pal.tipShadow}`,\n              }}\n            >\n              <p className=\"m-0 mb-1.5 font-[510]\">{labels[index]}</p>\n              {visible.map((s) => (\n                <p\n                  key={s.label}\n                  className=\"m-0 flex items-center gap-2 leading-[20px]\"\n                  style={{ color: pal.sub }}\n                >\n                  <span\n                    className=\"size-1.5 rounded-full\"\n                    style={{ background: colorOf(s) }}\n                  />\n                  {s.label}\n                  <span\n                    className=\"ml-auto tabular-nums\"\n                    style={{ color: pal.text }}\n                  >\n                    {formatValue(s.values[index] ?? 0)}\n                  </span>\n                </p>\n              ))}\n            </div>\n          )}\n        </div>\n      )}\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}