{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "trend-chart",
  "type": "registry:component",
  "title": "Trend chart",
  "description": "Compare changes over time with the chart style that fits the question.",
  "categories": [
    "charts"
  ],
  "dependencies": [
    "recharts-analytics@npm:recharts@3.10.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/trend-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/trend-chart.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\n\"use client\";\n\nimport * as React from \"react\";\nimport {\n  Area,\n  AreaChart,\n  AreaRevealShape,\n  Bar,\n  BarChart,\n  CartesianGrid,\n  Line,\n  LineChart,\n  Rectangle,\n  ReferenceLine,\n  XAxis,\n  YAxis,\n  useActiveTooltipDataPoints,\n  type ActiveDotProps,\n  type AreaRevealShapeProps,\n  type BarProps,\n  type BarShapeProps,\n} from \"recharts-analytics\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartTooltip,\n  type ChartConfig,\n} from \"./analytics-chart\";\n\nexport interface TrendSeries {\n  /** Key in each data row. */\n  key: string;\n  label: string;\n  /** Any CSS color. Defaults to chart-1 through chart-5 in order. */\n  color?: string;\n}\n\nexport interface TrendChartProps extends Omit<\n  React.ComponentProps<typeof ChartContainer>,\n  \"config\" | \"children\"\n> {\n  data: Record<string, unknown>[];\n  /** Key of the x-axis value in each row. */\n  xKey: string;\n  series: TrendSeries[];\n  type?: \"area\" | \"line\" | \"bar\";\n  /** Area fill: a plain gradient, or a dot grid that fades out toward the line. */\n  fill?: \"gradient\" | \"dots\";\n  /** Bars only: \"horizontal\" runs bars left to right with categories down the side. */\n  layout?: \"vertical\" | \"horizontal\";\n  /** Bars only: corner radius in px, or \"full\" for pill-shaped bars. */\n  barRadius?: number | \"full\";\n  /** Bars only: thickness of each bar in px. Defaults to a share of the category width. */\n  barSize?: number;\n  stacked?: boolean;\n  showLegend?: boolean;\n  legendPosition?: \"top\" | \"bottom\";\n  legendAlign?: \"left\" | \"center\" | \"right\";\n  showGrid?: boolean;\n  /** Show the value axis. In the horizontal layout this is the axis along the bottom. */\n  showYAxis?: boolean;\n  /** Recharts domain for the value axis, e.g. [\"dataMin\", \"dataMax\"] or [\"auto\", \"auto\"]. Defaults to [0, \"auto\"]. */\n  yDomain?: React.ComponentProps<typeof YAxis>[\"domain\"];\n  xFormatter?: (value: unknown) => string;\n  yFormatter?: (value: number) => string;\n  /** Animate series after hydration and when data changes. Respects reduced motion. */\n  animate?: boolean;\n  animationDuration?: number;\n}\n\n/** Keyboard focus on the plot gets the shared primary ring. */\nconst FOCUS =\n  \"[&_.recharts-surface:focus-visible]:rounded-lg [&_.recharts-surface:focus-visible]:shadow-[0_0_0_2px_color-mix(in_oklab,var(--color-primary)_30%,transparent)]\";\n\nconst reducedMotionQuery = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribeToReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(reducedMotionQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n}\n\nfunction getReducedMotionSnapshot() {\n  return window.matchMedia(reducedMotionQuery).matches;\n}\n\nfunction getReducedMotionServerSnapshot() {\n  return true;\n}\n\nfunction defaultXFormatter(value: unknown) {\n  if (typeof value === \"string\" && /^\\d{4}-\\d{2}-\\d{2}/.test(value)) {\n    const [y, m, d] = value.split(\"-\").map(Number);\n    return new Date(y!, m! - 1, d).toLocaleDateString(\"en-US\", {\n      month: \"short\",\n      day: \"numeric\",\n    });\n  }\n  return String(value);\n}\n\n/* ------------------------------------------------------------ visual tokens */\n\n/** Entrance and update curve, also used by the hand-driven bar tween below. */\nconst EASE = \"cubic-bezier(0.22,1,0.36,1)\" as const;\n/** cubic-bezier(0.22, 1, 0.36, 1) is the ease-out-quint curve. */\nconst easeOut = (t: number) => 1 - Math.pow(1 - t, 5);\nconst clamp01 = (t: number) => Math.min(1, Math.max(0, t));\nconst mix = (from: number, to: number, t: number) => from + (to - from) * t;\n\nconst GRID = \"color-mix(in oklab, var(--color-foreground) 7%, transparent)\";\nconst CROSSHAIR =\n  \"color-mix(in oklab, var(--color-foreground) 25%, transparent)\";\n/** Lines glow in their own color in dark mode; `color` on each series feeds currentColor. */\nconst GLOW =\n  \"dark:[&_.recharts-area-curve]:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,currentColor_50%,transparent))] dark:[&_.recharts-line-curve]:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,currentColor_50%,transparent))]\";\nconst TICK = { fontSize: 11, fill: \"var(--color-muted-foreground)\" };\n/** Gap between stacked segments, in px. */\nconst STACK_GAP = 1.5;\n\n/** Area shape that masks the fill to a dot grid while keeping the stroke solid. */\nfunction DotGridAreaShape({\n  maskId,\n  ...props\n}: AreaRevealShapeProps & { maskId: string }) {\n  return (\n    <>\n      <g mask={`url(#${maskId})`}>\n        <AreaRevealShape {...props} stroke=\"none\" />\n      </g>\n      <AreaRevealShape {...props} id={undefined} fill=\"none\" />\n    </>\n  );\n}\n\n/** Areas rise from the baseline on entrance; later updates tween in place. */\nfunction RisingAreaShape({\n  maskId,\n  ...props\n}: AreaRevealShapeProps & { maskId?: string }) {\n  const { isEntrance, animationElapsedTime = 1, baseLine } = props;\n  const shape = { ...props, isEntrance: false, vectorEffect: \"non-scaling-stroke\" };\n  const content = maskId ? (\n    <DotGridAreaShape {...shape} maskId={maskId} />\n  ) : (\n    <AreaRevealShape {...shape} />\n  );\n  if (!isEntrance || animationElapsedTime >= 1) return content;\n  const base =\n    typeof baseLine === \"number\"\n      ? baseLine\n      : Math.max(0, ...(baseLine ?? []).map((point) => point.y ?? 0));\n  const t = Math.max(animationElapsedTime, 0.001);\n  return (\n    <g\n      transform={`translate(0 ${base * (1 - t)}) scale(1 ${t})`}\n      opacity={Math.min(1, t * 4)}\n    >\n      {content}\n    </g>\n  );\n}\n\n/** A solid point with a soft halo, used for the hovered value on lines and areas. */\nfunction HaloDot({ cx, cy, color }: { cx?: number; cy?: number; color: string }) {\n  if (cx == null || cy == null) return null;\n  return (\n    <g data-slot=\"trend-chart-active-dot\" 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\ntype BarInterpolate = NonNullable<BarProps[\"animationInterpolateFn\"]>;\n\n/**\n * Bars rise from their base one after another on entrance and glide on updates.\n * Recharts runs the clock linearly; each bar applies its own delay and easing.\n */\nfunction barTween(count: number, duration: number, delay: number) {\n  const step = count > 1 ? Math.min(32, 320 / (count - 1)) : 0;\n  const total = duration + delay + step * Math.max(count - 1, 0);\n  const interpolate: BarInterpolate = (items, elapsed, layout) => {\n    if (items == null) return [];\n    const entering = items.every((item) => item.status === \"added\");\n    return items.flatMap((item, index) => {\n      const t =\n        elapsed >= 1\n          ? 1\n          : easeOut(\n              clamp01(\n                (elapsed * total - delay - (entering ? index * step : 0)) /\n                  duration,\n              ),\n            );\n      if (item.status === \"removed\") {\n        if (t >= 1) return [];\n        const prev = item.prev;\n        return layout === \"horizontal\"\n          ? [\n              {\n                ...prev,\n                height: mix(prev.height, 0, t),\n                y: mix(prev.y, prev.y + prev.height, t),\n              },\n            ]\n          : [{ ...prev, width: mix(prev.width, 0, t) }];\n      }\n      if (item.status === \"matched\") {\n        const { prev, next } = item;\n        return [\n          {\n            ...next,\n            x: mix(prev.x, next.x, t),\n            y: mix(prev.y, next.y, t),\n            width: mix(prev.width, next.width, t),\n            height: mix(prev.height, next.height, t),\n          },\n        ];\n      }\n      const next = item.next;\n      return layout === \"horizontal\"\n        ? [\n            {\n              ...next,\n              height: mix(0, next.height, t),\n              y: mix(next.stackedBarStart, next.y, t),\n            },\n          ]\n        : [\n            {\n              ...next,\n              width: mix(0, next.width, t),\n              x: mix(next.stackedBarStart, next.x, t),\n            },\n          ];\n    });\n  };\n  return { interpolate, total };\n}\n\n/** A gradient bar that dims while another category is hovered or focused. */\nfunction TrendBarShape({\n  gradient,\n  inset,\n  horizontal,\n  ...props\n}: BarShapeProps & {\n  gradient: string;\n  /** Pull the base end in to leave a hairline gap between stacked segments. */\n  inset: boolean;\n  horizontal: boolean;\n}) {\n  const active = useActiveTooltipDataPoints();\n  const dimmed =\n    active != null && active.length > 0 && !active.includes(props.payload);\n  let { x, y, width, height } = props;\n  if (inset) {\n    if (horizontal && Math.abs(width) > STACK_GAP * 2) {\n      x += STACK_GAP;\n      width -= STACK_GAP;\n    } else if (!horizontal && Math.abs(height) > STACK_GAP * 2) {\n      height -= STACK_GAP;\n    }\n  }\n  return (\n    <Rectangle\n      {...props}\n      x={x}\n      y={y}\n      width={width}\n      height={height}\n      fill={`url(#${gradient})`}\n      className=\"transition-opacity duration-150 ease-out motion-reduce:transition-none\"\n      style={{ opacity: dimmed ? 0.4 : 1 }}\n    />\n  );\n}\n\n/** Recharts clamps corner radii to half the bar, so an oversized radius draws a pill. */\nconst PILL = 9999;\n\ntype Radius = number | [number, number, number, number];\n\n/** Round only the outer corners of a stack; mixed-sign stacks stay square. */\nfunction barCorners(\n  radius: number | \"full\",\n  stacked: boolean,\n  hasNegative: boolean,\n  horizontal: boolean,\n  index: number,\n  count: number,\n): Radius {\n  const r = radius === \"full\" ? PILL : radius;\n  if (!stacked || count === 1) return r;\n  if (hasNegative) return 0;\n  // Corners run [top-left, top-right, bottom-right, bottom-left].\n  if (index === count - 1) return horizontal ? [0, r, r, 0] : [r, r, 0, 0];\n  if (index === 0) return horizontal ? [r, 0, 0, r] : [0, 0, r, r];\n  return 0;\n}\n\ninterface TooltipRow {\n  key: string;\n  label: React.ReactNode;\n  color: string;\n  value: string;\n}\n\nfunction TrendTooltip({\n  label,\n  rows,\n  total,\n}: {\n  label: React.ReactNode;\n  rows: TooltipRow[];\n  total?: string;\n}) {\n  return (\n    <div\n      data-slot=\"trend-chart-tooltip\"\n      className=\"min-w-40 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\">{label}</p>\n      <div className=\"grid gap-1\">\n        {rows.map((row) => (\n          <div key={row.key} className=\"flex items-center gap-2\">\n            <span\n              aria-hidden=\"true\"\n              className=\"size-2 shrink-0 rounded-full\"\n              style={{ backgroundColor: row.color }}\n            />\n            <span className=\"text-muted-foreground\">{row.label}</span>\n            <span className=\"ml-auto pl-4 font-medium text-foreground tabular-nums\">\n              {row.value}\n            </span>\n          </div>\n        ))}\n      </div>\n      {total != null ? (\n        <div className=\"mt-1.5 flex items-center gap-2 border-t border-border/60 pt-1.5\">\n          <span className=\"text-muted-foreground\">Total</span>\n          <span className=\"ml-auto pl-4 font-semibold text-foreground tabular-nums\">\n            {total}\n          </span>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nfunction TrendLegend({\n  items,\n  position,\n  align,\n}: {\n  items: { key: string; label: React.ReactNode; color: string }[];\n  position: \"top\" | \"bottom\";\n  align: \"left\" | \"center\" | \"right\";\n}) {\n  return (\n    <div\n      data-slot=\"trend-chart-legend\"\n      className={cn(\n        \"flex flex-wrap items-center gap-x-4 gap-y-1.5 text-xs text-muted-foreground\",\n        position === \"top\" ? \"pb-4\" : \"pt-4\",\n        align === \"right\"\n          ? \"justify-end\"\n          : align === \"left\"\n            ? \"justify-start\"\n            : \"justify-center\",\n      )}\n    >\n      {items.map((item) => (\n        <span key={item.key} className=\"inline-flex items-center gap-1.5\">\n          <span\n            aria-hidden=\"true\"\n            className=\"size-2 shrink-0 rounded-full\"\n            style={{ backgroundColor: item.color }}\n          />\n          {item.label}\n        </span>\n      ))}\n    </div>\n  );\n}\n\nfunction TrendChart({\n  data,\n  xKey,\n  series,\n  type = \"area\",\n  fill = \"gradient\",\n  layout = \"vertical\",\n  barRadius = 4,\n  barSize,\n  stacked = false,\n  showLegend = false,\n  legendPosition = \"bottom\",\n  legendAlign = \"center\",\n  showGrid = true,\n  showYAxis = false,\n  yDomain,\n  xFormatter = defaultXFormatter,\n  yFormatter,\n  animate = true,\n  animationDuration = 500,\n  className,\n  ...props\n}: TrendChartProps) {\n  const id = React.useId().replace(/:/g, \"\");\n  const reducedMotion = React.useSyncExternalStore(\n    subscribeToReducedMotion,\n    getReducedMotionSnapshot,\n    getReducedMotionServerSnapshot,\n  );\n  const motion = animate && !reducedMotion;\n  const dots = type === \"area\" && fill === \"dots\";\n  const horizontal = type === \"bar\" && layout === \"horizontal\";\n  const hasNegative = React.useMemo(\n    () =>\n      data.some((row) =>\n        series.some((s) => {\n          const v = row[s.key];\n          return typeof v === \"number\" && v < 0;\n        }),\n      ),\n    [data, series],\n  );\n  const colors = series.map(\n    (s, index) => s.color ?? `var(--color-chart-${(index % 5) + 1})`,\n  );\n  const config = Object.fromEntries(\n    series.map((s, index) => [s.key, { label: s.label, color: colors[index] }]),\n  ) satisfies ChartConfig;\n  const format = (value: number) =>\n    yFormatter ? yFormatter(value) : value.toLocaleString();\n  // Overlapping areas each get a lighter wash so the layers stay luminous, not muddy.\n  const layered = type === \"area\" && !stacked && series.length > 1;\n  const areaTop = dots ? 0.08 : layered ? 0.24 : 0.32;\n\n  const axes = (\n    <>\n      {showGrid ? (\n        <CartesianGrid\n          vertical={horizontal}\n          horizontal={!horizontal}\n          stroke={GRID}\n        />\n      ) : null}\n      {horizontal ? (\n        <>\n          <XAxis\n            type=\"number\"\n            hide={!showYAxis}\n            tickLine={false}\n            axisLine={false}\n            tickMargin={10}\n            tick={TICK}\n            domain={yDomain}\n            tickFormatter={yFormatter}\n          />\n          <YAxis\n            type=\"category\"\n            dataKey={xKey}\n            tickLine={false}\n            axisLine={false}\n            tickMargin={10}\n            tick={{ ...TICK, fontSize: 12 }}\n            width=\"auto\"\n            tickFormatter={xFormatter}\n          />\n        </>\n      ) : (\n        <>\n          <XAxis\n            dataKey={xKey}\n            tickLine={false}\n            axisLine={false}\n            tickMargin={10}\n            tick={TICK}\n            minTickGap={32}\n            tickFormatter={xFormatter}\n          />\n          {showYAxis ? (\n            <YAxis\n              tickLine={false}\n              axisLine={false}\n              tickMargin={10}\n              tick={TICK}\n              width=\"auto\"\n              domain={yDomain}\n              tickFormatter={yFormatter}\n            />\n          ) : yDomain ? (\n            <YAxis hide domain={yDomain} />\n          ) : null}\n        </>\n      )}\n      {hasNegative ? (\n        <ReferenceLine\n          {...(horizontal ? { x: 0 } : { y: 0 })}\n          stroke=\"color-mix(in oklab, var(--color-foreground) 22%, transparent)\"\n          strokeWidth={1}\n        />\n      ) : null}\n      <ChartTooltip\n        isAnimationActive={false}\n        cursor={\n          type === \"bar\"\n            ? false\n            : {\n                stroke: CROSSHAIR,\n                strokeWidth: 1,\n                style: { stroke: CROSSHAIR },\n              }\n        }\n        content={({ active, payload, label }) => {\n          if (!active || !payload?.length) return null;\n          const shown = payload.filter(\n            (item) => item.type !== \"none\" && item.value != null,\n          );\n          if (!shown.length) return null;\n          const ordered = type === \"bar\" && stacked ? [...shown].reverse() : shown;\n          const rows = ordered.map((item) => {\n            const key = String(item.dataKey);\n            const index = series.findIndex((s) => s.key === key);\n            return {\n              key,\n              label: series[index]?.label ?? key,\n              color: colors[index] ?? String(item.color),\n              value: format(Number(item.value)),\n            };\n          });\n          const total =\n            stacked && shown.length > 1\n              ? format(shown.reduce((sum, item) => sum + Number(item.value), 0))\n              : undefined;\n          return (\n            <TrendTooltip label={xFormatter(label)} rows={rows} total={total} />\n          );\n        }}\n      />\n      {showLegend ? (\n        <ChartLegend\n          verticalAlign={legendPosition}\n          align={legendAlign}\n          content={() => (\n            <TrendLegend\n              position={legendPosition}\n              align={legendAlign}\n              items={series.map((s, index) => ({\n                key: s.key,\n                label: s.label,\n                color: colors[index]!,\n              }))}\n            />\n          )}\n        />\n      ) : null}\n    </>\n  );\n\n  const margin = {\n    top: 10,\n    right: 10,\n    bottom: 0,\n    left: showYAxis || horizontal ? 0 : 10,\n  };\n\n  return (\n    <ChartContainer\n      data-slot=\"trend-chart\"\n      data-type={type}\n      config={config}\n      className={cn(\"aspect-auto h-64 w-full tabular-nums\", GLOW, FOCUS, className)}\n      {...props}\n    >\n      {type === \"bar\" ? (\n        <BarChart\n          data={data}\n          layout={horizontal ? \"vertical\" : \"horizontal\"}\n          margin={margin}\n          stackOffset={stacked ? \"sign\" : \"none\"}\n          barCategoryGap={horizontal ? \"24%\" : \"28%\"}\n          barGap={4}\n        >\n          <defs>\n            {series.map((s, index) => (\n              <linearGradient\n                key={s.key}\n                id={`${id}-bar-${index}`}\n                x1=\"0\"\n                y1=\"0\"\n                x2={horizontal ? \"1\" : \"0\"}\n                y2={horizontal ? \"0\" : \"1\"}\n              >\n                <stop\n                  offset=\"0%\"\n                  stopColor={colors[index]}\n                  stopOpacity={horizontal ? 0.72 : 1}\n                />\n                <stop\n                  offset=\"100%\"\n                  stopColor={colors[index]}\n                  stopOpacity={horizontal ? 1 : 0.72}\n                />\n              </linearGradient>\n            ))}\n          </defs>\n          {axes}\n          {series.map((s, index) => {\n            const tween = barTween(data.length, animationDuration, index * 40);\n            return (\n              <Bar\n                key={s.key}\n                dataKey={s.key}\n                fill={colors[index]}\n                barSize={barSize}\n                radius={barCorners(\n                  barRadius,\n                  stacked,\n                  hasNegative,\n                  horizontal,\n                  index,\n                  series.length,\n                )}\n                stackId={stacked ? \"stack\" : undefined}\n                isAnimationActive={motion}\n                animationDuration={tween.total}\n                animationEasing=\"linear\"\n                animationInterpolateFn={tween.interpolate}\n                shape={(shape: BarShapeProps) => (\n                  <TrendBarShape\n                    {...shape}\n                    gradient={`${id}-bar-${index}`}\n                    horizontal={horizontal}\n                    inset={stacked && !hasNegative && index > 0}\n                  />\n                )}\n              />\n            );\n          })}\n        </BarChart>\n      ) : type === \"line\" ? (\n        <LineChart data={data} margin={margin}>\n          {axes}\n          {series.map((s, index) => (\n            <Line\n              key={s.key}\n              isAnimationActive={motion}\n              animationDuration={animationDuration + 200}\n              animationBegin={index * 80}\n              animationEasing={EASE}\n              type=\"monotone\"\n              dataKey={s.key}\n              stroke={colors[index]}\n              color={colors[index]}\n              strokeWidth={2}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              dot={false}\n              activeDot={(dot: ActiveDotProps) => (\n                <HaloDot\n                  key={`${s.key}-${dot.index}`}\n                  cx={dot.cx}\n                  cy={dot.cy}\n                  color={colors[index]!}\n                />\n              )}\n            />\n          ))}\n        </LineChart>\n      ) : (\n        <AreaChart\n          data={data}\n          margin={margin}\n          stackOffset={stacked ? \"sign\" : \"none\"}\n        >\n          <defs>\n            {series.map((s, index) => (\n              <linearGradient\n                key={s.key}\n                id={`${id}-area-${index}`}\n                x1=\"0\"\n                y1=\"0\"\n                x2=\"0\"\n                y2=\"1\"\n              >\n                <stop\n                  offset=\"0%\"\n                  stopColor={colors[index]}\n                  stopOpacity={areaTop}\n                />\n                <stop\n                  offset=\"55%\"\n                  stopColor={colors[index]}\n                  stopOpacity={dots ? 0.45 : areaTop * 0.35}\n                />\n                <stop\n                  offset=\"100%\"\n                  stopColor={colors[index]}\n                  stopOpacity={dots ? 0.9 : 0}\n                />\n              </linearGradient>\n            ))}\n            {dots ? (\n              <>\n                <pattern\n                  id={`${id}-dots`}\n                  patternUnits=\"userSpaceOnUse\"\n                  width={5}\n                  height={5}\n                >\n                  <circle cx={2.5} cy={2.5} r={1} fill=\"#fff\" />\n                </pattern>\n                <mask\n                  id={`${id}-mask`}\n                  maskUnits=\"userSpaceOnUse\"\n                  x={0}\n                  y={0}\n                  width=\"100%\"\n                  height=\"100%\"\n                >\n                  <rect width=\"100%\" height=\"100%\" fill={`url(#${id}-dots)`} />\n                </mask>\n              </>\n            ) : null}\n          </defs>\n          {axes}\n          {series.map((s, index) => (\n            <Area\n              key={s.key}\n              isAnimationActive={motion}\n              animationDuration={animationDuration + 200}\n              animationBegin={index * 60}\n              animationEasing={EASE}\n              type=\"monotone\"\n              dataKey={s.key}\n              stroke={colors[index]}\n              color={colors[index]}\n              fill={`url(#${id}-area-${index})`}\n              fillOpacity={1}\n              strokeWidth={2}\n              strokeLinecap=\"round\"\n              strokeLinejoin=\"round\"\n              stackId={stacked ? \"stack\" : undefined}\n              activeDot={(dot: ActiveDotProps) => (\n                <HaloDot\n                  key={`${s.key}-${dot.index}`}\n                  cx={dot.cx}\n                  cy={dot.cy}\n                  color={colors[index]!}\n                />\n              )}\n              shape={(shape: AreaRevealShapeProps) => (\n                <RisingAreaShape\n                  {...shape}\n                  maskId={dots ? `${id}-mask` : undefined}\n                />\n              )}\n            />\n          ))}\n        </AreaChart>\n      )}\n    </ChartContainer>\n  );\n}\n\nexport { TrendChart };\n"
    },
    {
      "path": "src/registry/overtrue/analytics-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/analytics-chart.tsx",
      "content": "/** Adapted from dashboardcn (MIT), copyright 2026 dashboardcn contributors.\n * Source: https://github.com/NoahGdev/dashboardcn/tree/b1ffacbca0f7a0be60135c8665b9e8c267205c48\n *\n * MIT License\n *\n * Copyright (c) 2026 dashboardcn contributors\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n *\n * ---\n *\n * Portions of this project are derived from shadcn/ui and shadcn/registry-template\n * (https://github.com/shadcn-ui/ui), Copyright (c) 2023 shadcn, licensed under the\n * MIT License. The notice above applies to those portions as well.\n */\n\"use client\";\n\nimport * as React from \"react\";\nimport * as RechartsPrimitive from \"recharts-analytics\";\nimport type { TooltipValueType } from \"recharts-analytics\";\n\nimport { cn } from \"@/lib/utils\";\n\n// Format: { THEME_NAME: CSS_SELECTOR }\nconst THEMES = { light: \"\", dark: \".dark\" } as const;\n\nconst INITIAL_DIMENSION = { width: 320, height: 200 } as const;\ntype TooltipNameType = number | string;\n\nexport type ChartConfig = Record<\n  string,\n  {\n    label?: React.ReactNode;\n    icon?: React.ComponentType;\n  } & (\n    | { color?: string; theme?: never }\n    | { color?: never; theme: Record<keyof typeof THEMES, string> }\n  )\n>;\n\ntype ChartContextProps = {\n  config: ChartConfig;\n};\n\nconst ChartContext = React.createContext<ChartContextProps | null>(null);\n\nfunction useChart() {\n  const context = React.useContext(ChartContext);\n\n  if (!context) {\n    throw new Error(\"useChart must be used within a <ChartContainer />\");\n  }\n\n  return context;\n}\n\nfunction ChartContainer({\n  id,\n  className,\n  children,\n  config,\n  initialDimension = INITIAL_DIMENSION,\n  ...props\n}: React.ComponentProps<\"div\"> & {\n  config: ChartConfig;\n  children: React.ComponentProps<\n    typeof RechartsPrimitive.ResponsiveContainer\n  >[\"children\"];\n  initialDimension?: {\n    width: number;\n    height: number;\n  };\n}) {\n  const uniqueId = React.useId();\n  const chartId = `chart-${id ?? uniqueId.replace(/:/g, \"\")}`;\n\n  return (\n    <ChartContext.Provider value={{ config }}>\n      <div\n        data-slot=\"chart\"\n        data-chart={chartId}\n        className={cn(\n          \"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden\",\n          className,\n        )}\n        {...props}\n      >\n        <ChartStyle id={chartId} config={config} />\n        <RechartsPrimitive.ResponsiveContainer\n          initialDimension={initialDimension}\n        >\n          {children}\n        </RechartsPrimitive.ResponsiveContainer>\n      </div>\n    </ChartContext.Provider>\n  );\n}\n\nconst ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {\n  const colorConfig = Object.entries(config).filter(\n    ([, config]) => config.theme ?? config.color,\n  );\n\n  if (!colorConfig.length) {\n    return null;\n  }\n\n  return (\n    <style\n      dangerouslySetInnerHTML={{\n        __html: Object.entries(THEMES)\n          .map(\n            ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n  .map(([key, itemConfig]) => {\n    const color =\n      itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??\n      itemConfig.color;\n    return color ? `  --color-${key}: ${color};` : null;\n  })\n  .join(\"\\n\")}\n}\n`,\n          )\n          .join(\"\\n\"),\n      }}\n    />\n  );\n};\n\nconst ChartTooltip = RechartsPrimitive.Tooltip;\n\nfunction ChartTooltipContent({\n  active,\n  payload,\n  className,\n  indicator = \"dot\",\n  hideLabel = false,\n  hideIndicator = false,\n  label,\n  labelFormatter,\n  labelClassName,\n  formatter,\n  color,\n  nameKey,\n  labelKey,\n}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &\n  React.ComponentProps<\"div\"> & {\n    hideLabel?: boolean;\n    hideIndicator?: boolean;\n    indicator?: \"line\" | \"dot\" | \"dashed\";\n    nameKey?: string;\n    labelKey?: string;\n  } & Omit<\n    RechartsPrimitive.DefaultTooltipContentProps<\n      TooltipValueType,\n      TooltipNameType\n    >,\n    \"accessibilityLayer\"\n  >) {\n  const { config } = useChart();\n\n  const tooltipLabel = React.useMemo(() => {\n    if (hideLabel || !payload?.length) {\n      return null;\n    }\n\n    const [item] = payload;\n    const key = `${labelKey ?? item?.dataKey ?? item?.name ?? \"value\"}`;\n    const itemConfig = getPayloadConfigFromPayload(config, item, key);\n    const value =\n      !labelKey && typeof label === \"string\"\n        ? (config[label]?.label ?? label)\n        : itemConfig?.label;\n\n    if (labelFormatter) {\n      return (\n        <div className={cn(\"font-medium\", labelClassName)}>\n          {labelFormatter(value, payload)}\n        </div>\n      );\n    }\n\n    if (!value) {\n      return null;\n    }\n\n    return <div className={cn(\"font-medium\", labelClassName)}>{value}</div>;\n  }, [\n    label,\n    labelFormatter,\n    payload,\n    hideLabel,\n    labelClassName,\n    config,\n    labelKey,\n  ]);\n\n  if (!active || !payload?.length) {\n    return null;\n  }\n\n  const nestLabel = payload.length === 1 && indicator !== \"dot\";\n\n  return (\n    <div\n      className={cn(\n        \"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl\",\n        className,\n      )}\n    >\n      {!nestLabel ? tooltipLabel : null}\n      <div className=\"grid gap-1.5\">\n        {payload\n          .filter((item) => item.type !== \"none\")\n          .map((item, index) => {\n            const key = `${nameKey ?? item.name ?? item.dataKey ?? \"value\"}`;\n            const itemConfig = getPayloadConfigFromPayload(config, item, key);\n            const indicatorColor = color ?? item.payload?.fill ?? item.color;\n\n            return (\n              <div\n                key={index}\n                className={cn(\n                  \"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground\",\n                  indicator === \"dot\" && \"items-center\",\n                )}\n              >\n                {formatter && item?.value !== undefined && item.name ? (\n                  formatter(item.value, item.name, item, index, item.payload)\n                ) : (\n                  <>\n                    {itemConfig?.icon ? (\n                      <itemConfig.icon />\n                    ) : (\n                      !hideIndicator && (\n                        <div\n                          className={cn(\n                            \"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)\",\n                            {\n                              \"h-2.5 w-2.5\": indicator === \"dot\",\n                              \"w-1\": indicator === \"line\",\n                              \"w-0 border-[1.5px] border-dashed bg-transparent\":\n                                indicator === \"dashed\",\n                              \"my-0.5\": nestLabel && indicator === \"dashed\",\n                            },\n                          )}\n                          style={\n                            {\n                              \"--color-bg\": indicatorColor,\n                              \"--color-border\": indicatorColor,\n                            } as React.CSSProperties\n                          }\n                        />\n                      )\n                    )}\n                    <div\n                      className={cn(\n                        \"flex flex-1 justify-between leading-none\",\n                        nestLabel ? \"items-end\" : \"items-center\",\n                      )}\n                    >\n                      <div className=\"grid gap-1.5\">\n                        {nestLabel ? tooltipLabel : null}\n                        <span className=\"text-muted-foreground\">\n                          {itemConfig?.label ?? item.name}\n                        </span>\n                      </div>\n                      {item.value != null && (\n                        <span className=\"font-mono font-medium text-foreground tabular-nums\">\n                          {typeof item.value === \"number\"\n                            ? item.value.toLocaleString()\n                            : String(item.value)}\n                        </span>\n                      )}\n                    </div>\n                  </>\n                )}\n              </div>\n            );\n          })}\n      </div>\n    </div>\n  );\n}\n\nconst ChartLegend = RechartsPrimitive.Legend;\n\nfunction ChartLegendContent({\n  className,\n  hideIcon = false,\n  payload,\n  verticalAlign = \"bottom\",\n  nameKey,\n}: React.ComponentProps<\"div\"> & {\n  hideIcon?: boolean;\n  nameKey?: string;\n} & RechartsPrimitive.DefaultLegendContentProps) {\n  const { config } = useChart();\n\n  if (!payload?.length) {\n    return null;\n  }\n\n  return (\n    <div\n      className={cn(\n        \"flex items-center justify-center gap-4\",\n        verticalAlign === \"top\" ? \"pb-3\" : \"pt-3\",\n        className,\n      )}\n    >\n      {payload\n        .filter((item) => item.type !== \"none\")\n        .map((item, index) => {\n          const key = `${nameKey ?? item.dataKey ?? \"value\"}`;\n          const itemConfig = getPayloadConfigFromPayload(config, item, key);\n\n          return (\n            <div\n              key={index}\n              className={cn(\n                \"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground\",\n              )}\n            >\n              {itemConfig?.icon && !hideIcon ? (\n                <itemConfig.icon />\n              ) : (\n                <div\n                  className=\"h-2 w-2 shrink-0 rounded-[2px]\"\n                  style={{\n                    backgroundColor: item.color,\n                  }}\n                />\n              )}\n              {itemConfig?.label}\n            </div>\n          );\n        })}\n    </div>\n  );\n}\n\n// Helper to extract item config from a payload.\nfunction getPayloadConfigFromPayload(\n  config: ChartConfig,\n  payload: unknown,\n  key: string,\n) {\n  if (typeof payload !== \"object\" || payload === null) {\n    return undefined;\n  }\n\n  const payloadPayload =\n    \"payload\" in payload &&\n    typeof payload.payload === \"object\" &&\n    payload.payload !== null\n      ? payload.payload\n      : undefined;\n\n  let configLabelKey: string = key;\n\n  if (\n    key in payload &&\n    typeof payload[key as keyof typeof payload] === \"string\"\n  ) {\n    configLabelKey = payload[key as keyof typeof payload] as string;\n  } else if (\n    payloadPayload &&\n    key in payloadPayload &&\n    typeof payloadPayload[key as keyof typeof payloadPayload] === \"string\"\n  ) {\n    configLabelKey = payloadPayload[\n      key as keyof typeof payloadPayload\n    ] as string;\n  }\n\n  return configLabelKey in config ? config[configLabelKey] : config[key];\n}\n\nexport {\n  ChartContainer,\n  ChartTooltip,\n  ChartTooltipContent,\n  ChartLegend,\n  ChartLegendContent,\n  ChartStyle,\n};\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/trend-chart. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
