{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "metric-chart",
  "type": "registry:component",
  "title": "Metric chart",
  "description": "An area chart with period comparison, value formatting, and an accessible summary.",
  "categories": [
    "charts"
  ],
  "dependencies": [
    "recharts@^2.15.1"
  ],
  "registryDependencies": [
    "card"
  ],
  "files": [
    {
      "path": "src/registry/overtrue/metric-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/metric-chart.tsx",
      "content": "\"use client\";\nimport { useId, useSyncExternalStore, type ReactNode } from \"react\";\nimport { ChartLegend } from \"./chart-legend\";\nimport {\n  Area,\n  AreaChart,\n  CartesianGrid,\n  ResponsiveContainer,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from \"recharts\";\nimport { Card, CardContent, CardHeader, CardTitle } from \"@/components/ui/card\";\nexport interface MetricPoint {\n  label: string;\n  value: number;\n  previous?: number;\n}\n\nconst reducedMotionQuery = \"(prefers-reduced-motion: reduce)\";\nfunction subscribeToReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(reducedMotionQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n}\nfunction getReducedMotionSnapshot() {\n  return window.matchMedia(reducedMotionQuery).matches;\n}\n/** The server snapshot disables motion so hydration starts from identical markup. */\nfunction getReducedMotionServerSnapshot() {\n  return true;\n}\n\nconst PRIMARY = \"var(--color-primary)\";\nconst COMPARISON = \"var(--color-muted-foreground)\";\nconst GRID = \"color-mix(in oklab, var(--color-foreground) 7%, transparent)\";\nconst CROSSHAIR =\n  \"color-mix(in oklab, var(--color-foreground) 25%, transparent)\";\nconst TICK = { fontSize: 11, fill: \"var(--color-muted-foreground)\" };\n/** react-smooth accepts any cubic-bezier() string; the Recharts type lists only keywords. */\nconst EASE = \"cubic-bezier(0.22,1,0.36,1)\" as \"ease-out\";\n\nfunction HaloDot({\n  cx,\n  cy,\n  color,\n}: {\n  cx?: number;\n  cy?: number;\n  color: string;\n}) {\n  if (cx == null || cy == null) return <g />;\n  return (\n    <g pointerEvents=\"none\">\n      <circle cx={cx} cy={cy} r={8} fill={color} fillOpacity={0.18} />\n      <circle\n        cx={cx}\n        cy={cy}\n        r={3.5}\n        fill={color}\n        stroke=\"var(--color-card)\"\n        strokeWidth={1.5}\n      />\n    </g>\n  );\n}\n\nexport function MetricChart({\n  title = \"Revenue overview\",\n  data,\n  height = 240,\n  seriesLabel = \"Revenue\",\n  comparisonLabel = \"Previous period\",\n  valueFormatter = (value: number) => value.toLocaleString(\"en-US\"),\n  axisFormatter = (value: number) =>\n    value.toLocaleString(\"en-US\", {\n      notation: \"compact\",\n      maximumFractionDigits: 1,\n    }),\n  description,\n  actions,\n}: {\n  title?: string;\n  data: MetricPoint[];\n  height?: number;\n  seriesLabel?: string;\n  comparisonLabel?: string;\n  valueFormatter?: (value: number) => string;\n  axisFormatter?: (value: number) => string;\n  description?: string;\n  actions?: ReactNode;\n}) {\n  const gradient = useId().replace(/:/g, \"\");\n  const reducedMotion = useSyncExternalStore(\n    subscribeToReducedMotion,\n    getReducedMotionSnapshot,\n    getReducedMotionServerSnapshot,\n  );\n  const points = data\n    .filter((point) => Number.isFinite(point.value))\n    .map((point) => ({\n      ...point,\n      previous: Number.isFinite(point.previous) ? point.previous : undefined,\n    }));\n  const hasComparison = points.some((point) => point.previous !== undefined);\n  const chartHeight = Number.isFinite(height) ? Math.max(120, height) : 240;\n  const last = points.length - 1;\n  return (\n    <Card\n      data-slot=\"metric-chart\"\n      className=\"min-w-0 gap-0 rounded-2xl border border-border/70 bg-card py-0 text-card-foreground shadow-[0_1px_2px_rgb(0_0_0/0.04),0_8px_24px_-12px_rgb(0_0_0/0.10)] dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_1px_2px_rgb(0_0_0/0.5)]\"\n    >\n      <CardHeader className=\"flex flex-row flex-wrap items-center justify-between gap-3 border-b border-border/60 px-5 py-4 [.border-b]:pb-4\">\n        <div className=\"min-w-0\">\n          <CardTitle className=\"text-sm font-semibold tracking-tight\">\n            {title}\n          </CardTitle>\n          {description && (\n            <p className=\"mt-1 text-xs leading-5 text-muted-foreground\">\n              {description}\n            </p>\n          )}\n        </div>\n        {actions}\n        <ChartLegend\n          layout=\"horizontal\"\n          items={[\n            { label: seriesLabel, color: PRIMARY },\n            ...(hasComparison\n              ? [\n                  {\n                    label: comparisonLabel,\n                    color: COMPARISON,\n                    dashed: true,\n                  },\n                ]\n              : []),\n          ]}\n        />\n      </CardHeader>\n      <CardContent className=\"p-5 pb-3\">\n        {!points.length ? (\n          <div\n            className=\"flex items-center justify-center text-sm text-muted-foreground\"\n            style={{ height: chartHeight }}\n          >\n            No data for this period.\n          </div>\n        ) : (\n          <div\n            role=\"img\"\n            aria-label={`${title}: ${points.map((point) => `${point.label}: ${seriesLabel} ${valueFormatter(point.value)}${point.previous !== undefined ? `, ${comparisonLabel} ${valueFormatter(point.previous)}` : \"\"}`).join(\"; \")}`}\n            data-slot=\"metric-chart-plot\"\n            className=\"tabular-nums dark:[&_.recharts-area-curve]:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,currentColor_50%,transparent))]\"\n            style={{ height: chartHeight }}\n          >\n            <ResponsiveContainer width=\"100%\" height=\"100%\">\n              <AreaChart\n                data={points}\n                margin={{ top: 10, right: 10, left: 0, bottom: 0 }}\n              >\n                <defs>\n                  <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n                    <stop offset=\"0%\" stopColor={PRIMARY} stopOpacity={0.32} />\n                    <stop\n                      offset=\"55%\"\n                      stopColor={PRIMARY}\n                      stopOpacity={0.11}\n                    />\n                    <stop offset=\"100%\" stopColor={PRIMARY} stopOpacity={0} />\n                  </linearGradient>\n                </defs>\n                <CartesianGrid vertical={false} stroke={GRID} />\n                <XAxis\n                  dataKey=\"label\"\n                  tickLine={false}\n                  axisLine={false}\n                  tick={TICK}\n                  minTickGap={24}\n                  dy={8}\n                />\n                <YAxis\n                  width={48}\n                  tickFormatter={axisFormatter}\n                  tickLine={false}\n                  axisLine={false}\n                  tick={TICK}\n                />\n                <Tooltip\n                  isAnimationActive={false}\n                  cursor={{ stroke: CROSSHAIR, strokeWidth: 1 }}\n                  content={({ active, payload, label }) => {\n                    const row = payload?.[0]?.payload as\n                      | (MetricPoint & { previous?: number })\n                      | undefined;\n                    if (!active || !row) return null;\n                    const change =\n                      row.previous !== undefined && row.previous !== 0\n                        ? (row.value - row.previous) / Math.abs(row.previous)\n                        : null;\n                    return (\n                      <div\n                        data-slot=\"metric-chart-tooltip\"\n                        className=\"min-w-44 rounded-xl border border-border/70 bg-popover/90 px-3 py-2.5 text-xs text-popover-foreground shadow-xl backdrop-blur-md\"\n                      >\n                        <p className=\"mb-1.5 font-medium text-foreground\">\n                          {label}\n                        </p>\n                        <div className=\"grid gap-1\">\n                          <div className=\"flex items-center gap-2\">\n                            <span\n                              aria-hidden=\"true\"\n                              className=\"size-2 shrink-0 rounded-full\"\n                              style={{ backgroundColor: PRIMARY }}\n                            />\n                            <span className=\"text-muted-foreground\">\n                              {seriesLabel}\n                            </span>\n                            <span className=\"ml-auto pl-4 font-medium text-foreground tabular-nums\">\n                              {valueFormatter(row.value)}\n                            </span>\n                          </div>\n                          {row.previous !== undefined && (\n                            <div className=\"flex items-center gap-2\">\n                              <span\n                                aria-hidden=\"true\"\n                                className=\"w-2 shrink-0 border-t-2 border-dashed\"\n                                style={{ borderColor: COMPARISON }}\n                              />\n                              <span className=\"text-muted-foreground\">\n                                {comparisonLabel}\n                              </span>\n                              <span className=\"ml-auto pl-4 font-medium text-foreground tabular-nums\">\n                                {valueFormatter(row.previous)}\n                              </span>\n                            </div>\n                          )}\n                        </div>\n                        {change !== null && Number.isFinite(change) && (\n                          <p className=\"mt-1.5 border-t border-border/60 pt-1.5 text-muted-foreground tabular-nums\">\n                            <span className=\"font-medium text-foreground\">\n                              {change > 0 ? \"+\" : change < 0 ? \"−\" : \"\"}\n                              {Math.abs(change * 100).toFixed(1)}%\n                            </span>{\" \"}\n                            vs. {comparisonLabel.toLowerCase()}\n                          </p>\n                        )}\n                      </div>\n                    );\n                  }}\n                />\n                {hasComparison && (\n                  <Area\n                    type=\"monotone\"\n                    dataKey=\"previous\"\n                    name={comparisonLabel}\n                    stroke={COMPARISON}\n                    strokeOpacity={0.7}\n                    strokeWidth={1.5}\n                    strokeDasharray=\"4 4\"\n                    fill=\"none\"\n                    activeDot={(props: { cx?: number; cy?: number }) => (\n                      <circle\n                        cx={props.cx}\n                        cy={props.cy}\n                        r={3}\n                        fill=\"var(--color-card)\"\n                        stroke={COMPARISON}\n                        strokeWidth={1.5}\n                      />\n                    )}\n                    isAnimationActive={!reducedMotion}\n                    animationDuration={700}\n                    animationEasing={EASE}\n                  />\n                )}\n                <Area\n                  type=\"monotone\"\n                  dataKey=\"value\"\n                  name={seriesLabel}\n                  stroke={PRIMARY}\n                  color={PRIMARY}\n                  strokeWidth={2}\n                  strokeLinecap=\"round\"\n                  strokeLinejoin=\"round\"\n                  fill={`url(#${gradient})`}\n                  dot={(props: { cx?: number; cy?: number; index?: number }) =>\n                    props.index === last ? (\n                      <HaloDot\n                        key=\"metric-chart-latest\"\n                        cx={props.cx}\n                        cy={props.cy}\n                        color={PRIMARY}\n                      />\n                    ) : (\n                      <g key={`metric-chart-dot-${props.index}`} />\n                    )\n                  }\n                  activeDot={(props: { cx?: number; cy?: number }) => (\n                    <HaloDot cx={props.cx} cy={props.cy} color={PRIMARY} />\n                  )}\n                  isAnimationActive={!reducedMotion}\n                  animationDuration={700}\n                  animationEasing={EASE}\n                />\n              </AreaChart>\n            </ResponsiveContainer>\n          </div>\n        )}\n      </CardContent>\n    </Card>\n  );\n}\n"
    },
    {
      "path": "src/registry/overtrue/chart-legend.tsx",
      "type": "registry:component",
      "target": "components/overtrue/chart-legend.tsx",
      "content": "import type { ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ChartLegendItem {\n  label: string;\n  color: string;\n  value?: ReactNode;\n  dashed?: boolean;\n}\nexport function ChartLegend({\n  items,\n  label = \"Chart legend\",\n  layout = \"vertical\",\n  className,\n}: {\n  items: readonly ChartLegendItem[];\n  label?: string;\n  layout?: \"horizontal\" | \"vertical\";\n  className?: string;\n}) {\n  return (\n    <ul\n      data-slot=\"chart-legend\"\n      data-layout={layout}\n      aria-label={label}\n      className={cn(\n        \"m-0 list-none p-0 text-xs\",\n        layout === \"horizontal\"\n          ? \"flex flex-wrap items-center gap-x-4 gap-y-2\"\n          : \"grid gap-3\",\n        className,\n      )}\n    >\n      {items.map((item) => (\n        <li\n          key={item.label}\n          data-slot=\"chart-legend-item\"\n          className=\"flex min-w-0 items-center gap-2\"\n        >\n          {item.dashed ? (\n            <svg\n              aria-hidden=\"true\"\n              data-slot=\"chart-legend-swatch\"\n              viewBox=\"0 0 14 2\"\n              className=\"h-0.5 w-3.5 shrink-0 overflow-visible\"\n            >\n              <line\n                x1=\"1\"\n                y1=\"1\"\n                x2=\"13\"\n                y2=\"1\"\n                stroke={item.color}\n                strokeWidth=\"2\"\n                strokeLinecap=\"round\"\n                strokeDasharray=\"2 4\"\n              />\n            </svg>\n          ) : (\n            <span\n              aria-hidden=\"true\"\n              data-slot=\"chart-legend-swatch\"\n              className=\"size-2 shrink-0 rounded-full\"\n              style={{\n                backgroundColor: item.color,\n                boxShadow: `0 0 0 2px color-mix(in oklab, ${item.color} 16%, transparent)`,\n              }}\n            />\n          )}\n          <span className=\"min-w-0 break-words text-muted-foreground\">\n            {item.label}\n          </span>\n          {item.value != null && (\n            <span className=\"ms-auto ps-3 font-medium text-foreground tabular-nums\">\n              {item.value}\n            </span>\n          )}\n        </li>\n      ))}\n    </ul>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/metric-chart. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
