{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "line-chart",
  "type": "registry:component",
  "title": "Line chart",
  "description": "Borderless SVG line chart with area fills, hover tooltip, range tabs and legend. Based on the MCP Apps for Claude kit.",
  "registryDependencies": [
    "https://mcpblocks.dev/r/host-tokens.json"
  ],
  "files": [
    {
      "path": "registry/mcpblocks/components/line-chart.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport type LineChartSeries = {\n  name: string\n  /** One value per label. */\n  values: number[]\n  /** Line color. Defaults cycle through the kit's chart palette. */\n  color?: string\n}\n\nexport type LineChartProps = {\n  title?: string\n  /** X-axis labels, one per data point. */\n  labels: string[]\n  series: LineChartSeries[]\n  /** Which labels to print under the axis (every Nth). Default: about 4 ticks. */\n  labelEvery?: number\n  /** Range tabs, e.g. [\"1D\",\"1W\",\"1M\",\"1Y\"]. */\n  ranges?: string[]\n  range?: string\n  onRangeChange?: (range: string) => void\n  /** Chart plot height in px. */\n  height?: number\n  formatValue?: (v: number) => string\n  className?: string\n}\n\nconst PALETTE = [\"#E0574F\", \"#6366E9\", \"#2C84DB\", \"#D1A041\"]\nconst W = 640\n\nfunction smoothPath(points: [number, number][]) {\n  if (points.length < 2) return \"\"\n  // Monotone cubic interpolation (Fritsch–Carlson) so lines never overshoot.\n  const n = points.length\n  const dx: number[] = []\n  const m: number[] = []\n  for (let i = 0; i < n - 1; i++) {\n    dx.push(points[i + 1][0] - points[i][0])\n    m.push((points[i + 1][1] - points[i][1]) / dx[i])\n  }\n  const t: number[] = [m[0]]\n  for (let i = 1; i < n - 1; i++) t.push(m[i - 1] * m[i] <= 0 ? 0 : (m[i - 1] + m[i]) / 2)\n  t.push(m[n - 2])\n  let d = `M${points[0][0]},${points[0][1]}`\n  for (let i = 0; i < n - 1; i++) {\n    const c1x = points[i][0] + dx[i] / 3\n    const c1y = points[i][1] + (t[i] * dx[i]) / 3\n    const c2x = points[i + 1][0] - dx[i] / 3\n    const c2y = points[i + 1][1] - (t[i + 1] * dx[i]) / 3\n    d += ` C${c1x},${c1y} ${c2x},${c2y} ${points[i + 1][0]},${points[i + 1][1]}`\n  }\n  return d\n}\n\nfunction niceTicks(max: number, target = 5) {\n  const raw = max / target\n  const mag = Math.pow(10, Math.floor(Math.log10(raw || 1)))\n  const step = [1, 2, 2.5, 5, 10].map((s) => s * mag).find((s) => s >= raw) ?? raw\n  const count = Math.max(1, Math.ceil(max / step))\n  return Array.from({ length: count + 1 }, (_, i) => i * step)\n}\n\n/**\n * Borderless line chart with area fills, hover tooltip, range tabs and legend.\n * Matches the \"Borderless card\" data pattern in the MCP Apps for Claude kit.\n * Register the resource with `_meta.ui.prefersBorder: false`.\n */\nexport function LineChart({\n  title,\n  labels,\n  series,\n  labelEvery,\n  ranges,\n  range,\n  onRangeChange,\n  height = 200,\n  formatValue = (v) => v.toLocaleString(),\n  className,\n}: LineChartProps) {\n  const id = React.useId()\n  const [hover, setHover] = React.useState<number | null>(null)\n  const [activeRange, setActiveRange] = React.useState(range ?? ranges?.[0])\n  const current = range ?? activeRange\n\n  const max = Math.max(1, ...series.flatMap((s) => s.values))\n  const ticks = niceTicks(max)\n  const top = ticks[ticks.length - 1]\n  const H = height\n  const x = (i: number) => (labels.length <= 1 ? 0 : (i / (labels.length - 1)) * W)\n  const y = (v: number) => H - (v / top) * (H - 8) - 4\n  const every = labelEvery ?? Math.max(1, Math.round(labels.length / 4))\n\n  function onMove(e: React.PointerEvent<SVGSVGElement>) {\n    const rect = e.currentTarget.getBoundingClientRect()\n    const rel = ((e.clientX - rect.left) / rect.width) * W\n    setHover(Math.max(0, Math.min(labels.length - 1, Math.round((rel / W) * (labels.length - 1)))))\n  }\n\n  return (\n    <div\n      data-slot=\"line-chart\"\n      className={cn(\"flex w-full flex-col gap-3 p-4 text-host-fg font-[family-name:var(--font-sans)]\", className)}\n    >\n      {title ? <p className=\"text-sm leading-[1.4]\">{title}</p> : null}\n\n      <div className=\"flex gap-3 pt-3 pb-2\">\n        <div\n          aria-hidden=\"true\"\n          className=\"flex flex-col-reverse justify-between text-right text-xs leading-[1.4] text-host-fg-tertiary tabular-nums\"\n          style={{ height: H }}\n        >\n          {ticks.map((t) => (\n            <span key={t}>{formatValue(t)}</span>\n          ))}\n        </div>\n\n        <div className=\"relative min-w-0 flex-1\">\n          <svg\n            viewBox={`0 0 ${W} ${H}`}\n            preserveAspectRatio=\"none\"\n            className=\"block w-full touch-none overflow-visible\"\n            style={{ height: H }}\n            role=\"img\"\n            aria-label={`${title ?? \"Line chart\"}: ${series.map((s) => s.name).join(\", \")}`}\n            onPointerMove={onMove}\n            onPointerLeave={() => setHover(null)}\n          >\n            <defs>\n              {series.map((s, si) => (\n                <linearGradient key={si} id={`${id}-g${si}`} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n                  <stop offset=\"0%\" stopColor={s.color ?? PALETTE[si % PALETTE.length]} stopOpacity=\"0.12\" />\n                  <stop offset=\"100%\" stopColor={s.color ?? PALETTE[si % PALETTE.length]} stopOpacity=\"0\" />\n                </linearGradient>\n              ))}\n            </defs>\n            {ticks.map((t) => (\n              <line\n                key={t}\n                x1=\"0\"\n                x2={W}\n                y1={y(t)}\n                y2={y(t)}\n                stroke=\"var(--color-border-tertiary)\"\n                strokeDasharray=\"4 4\"\n                vectorEffect=\"non-scaling-stroke\"\n              />\n            ))}\n            {labels.map((_, i) =>\n              i % every === 0 ? (\n                <line key={i} x1={x(i)} x2={x(i)} y1=\"0\" y2={H} stroke=\"var(--color-border-tertiary)\" vectorEffect=\"non-scaling-stroke\" />\n              ) : null\n            )}\n            {series.map((s, si) => {\n              const pts = s.values.map((v, i) => [x(i), y(v)] as [number, number])\n              const line = smoothPath(pts)\n              const color = s.color ?? PALETTE[si % PALETTE.length]\n              return (\n                <g key={s.name}>\n                  <path d={`${line} L${W},${H} L0,${H} Z`} fill={`url(#${id}-g${si})`} />\n                  <path d={line} fill=\"none\" stroke={color} strokeWidth=\"2\" vectorEffect=\"non-scaling-stroke\" />\n                </g>\n              )\n            })}\n            {hover !== null ? (\n              <line x1={x(hover)} x2={x(hover)} y1=\"0\" y2={H} stroke=\"var(--color-border-primary)\" strokeWidth=\"1.5\" vectorEffect=\"non-scaling-stroke\" />\n            ) : null}\n          </svg>\n\n          {hover !== null\n            ? series.map((s, si) => (\n                <span\n                  key={s.name}\n                  aria-hidden=\"true\"\n                  className=\"pointer-events-none absolute size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full\"\n                  style={{\n                    left: `${(x(hover) / W) * 100}%`,\n                    top: y(s.values[hover] ?? 0),\n                    backgroundColor: s.color ?? PALETTE[si % PALETTE.length],\n                  }}\n                />\n              ))\n            : null}\n\n          {hover !== null ? (\n            <div\n              role=\"status\"\n              className=\"pointer-events-none absolute top-1/2 flex w-[120px] flex-col gap-[7px] rounded-host-md border-[length:var(--border-width-regular,0.5px)] border-host-border-tertiary bg-host-bg/90 p-2 backdrop-blur-[2px]\"\n              style={\n                x(hover) / W > 0.7\n                  ? { right: `calc(${100 - (x(hover) / W) * 100}% + 10px)` }\n                  : { left: `calc(${(x(hover) / W) * 100}% + 10px)` }\n              }\n            >\n              {series.map((s, si) => (\n                <span key={s.name} className=\"flex items-center gap-[7px] text-sm leading-[1.4] font-medium\">\n                  <span aria-hidden=\"true\" className=\"h-[3px] w-3 rounded-full\" style={{ backgroundColor: s.color ?? PALETTE[si % PALETTE.length] }} />\n                  {formatValue(s.values[hover] ?? 0)}\n                </span>\n              ))}\n              <span className=\"text-xs leading-[1.4] text-host-fg-tertiary\">{labels[hover]}</span>\n            </div>\n          ) : null}\n\n          <div aria-hidden=\"true\" className=\"relative mt-2 h-[17px] text-xs leading-[1.4] text-host-fg-tertiary\">\n            {labels.map((l, i) =>\n              i % every === 0 && i > 0 && i < labels.length - 1 ? (\n                <span key={i} className=\"absolute -translate-x-1/2 whitespace-nowrap\" style={{ left: `${(x(i) / W) * 100}%` }}>\n                  {l}\n                </span>\n              ) : null\n            )}\n          </div>\n        </div>\n      </div>\n\n      <div className=\"flex flex-wrap items-center justify-between gap-3\">\n        {ranges?.length ? (\n          <div role=\"tablist\" aria-label=\"Range\" className=\"flex items-center gap-2 rounded-3xl bg-host-bg-secondary p-1\">\n            {ranges.map((r) => (\n              <button\n                key={r}\n                type=\"button\"\n                role=\"tab\"\n                aria-selected={r === current}\n                onClick={() => {\n                  setActiveRange(r)\n                  onRangeChange?.(r)\n                }}\n                className={cn(\n                  \"inline-flex min-h-11 min-w-11 items-center justify-center rounded-full px-3 text-xs leading-[1.4]\",\n                  r === current ? \"bg-host-bg text-host-fg-secondary\" : \"text-host-fg-tertiary hover:text-host-fg\"\n                )}\n              >\n                {r}\n              </button>\n            ))}\n          </div>\n        ) : (\n          <span />\n        )}\n        <div className=\"flex items-center gap-4\">\n          {series.map((s, si) => (\n            <span key={s.name} className=\"flex items-center gap-1.5 text-[10px] leading-[1.4] text-host-fg-secondary\">\n              <span aria-hidden=\"true\" className=\"h-[3px] w-2 rounded-full\" style={{ backgroundColor: s.color ?? PALETTE[si % PALETTE.length] }} />\n              {s.name}\n            </span>\n          ))}\n        </div>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ]
}