{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radar-chart",
  "type": "registry:component",
  "title": "Profile comparison",
  "description": "Compare the shape of multiple measures across categories.",
  "categories": [
    "charts"
  ],
  "dependencies": [
    "recharts-analytics@npm:recharts@3.10.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/radar-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/radar-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  PolarAngleAxis,\n  PolarGrid,\n  PolarRadiusAxis,\n  Radar,\n  RadarChart as RechartsRadarChart,\n} from \"recharts-analytics\";\n\nimport { cn } from \"@/lib/utils\";\nimport { formatNumber } from \"./metric-format\";\nimport {\n  ChartContainer,\n  ChartLegend,\n  ChartTooltip,\n  type ChartConfig,\n} from \"./analytics-chart\";\n\nexport interface RadarSeries {\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 RadarChartProps extends Omit<\n  React.ComponentProps<typeof ChartContainer>,\n  \"config\" | \"children\"\n> {\n  data: Record<string, unknown>[];\n  /** Key of the category label in each row, one per spoke. */\n  angleKey: string;\n  series: RadarSeries[];\n  /** \"filled\" shades the area, \"line\" draws only the outline, \"dots\" adds a dot at every vertex. */\n  variant?: \"filled\" | \"line\" | \"dots\";\n  /** Shape of the background grid rings. */\n  grid?: \"polygon\" | \"circle\" | \"none\";\n  /** Show the category label at the end of each spoke. */\n  showAngleLabels?: boolean;\n  /** Show value ticks along the vertical spoke. */\n  showRadiusAxis?: boolean;\n  showLegend?: boolean;\n  showTooltip?: boolean;\n  /** Recharts domain for the value axis, e.g. [0, 100]. Defaults to [0, \"auto\"]. */\n  domain?: React.ComponentProps<typeof PolarRadiusAxis>[\"domain\"];\n  valueFormatter?: (value: number) => string;\n  /** Animate polygons after hydration and when data changes. Respects reduced motion. */\n  animate?: boolean;\n  animationDuration?: number;\n}\n\nconst EASE = \"cubic-bezier(0.22,1,0.36,1)\";\nconst GRID = \"color-mix(in oklab, var(--color-foreground) 8%, 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\ninterface RadarPoint {\n  x: number;\n  y: number;\n  cx: number;\n  cy: number;\n  radius: number;\n}\n\nfunction round(n: number) {\n  return Math.round(n * 100) / 100;\n}\n\n/** Recharts passes `[name]` through, so a key is safe to use in an SVG id. */\nfunction idSafe(key: string) {\n  return key.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n}\n\ninterface ResolvedSeries {\n  key: string;\n  label: string;\n  color: string;\n}\n\nfunction RadarTooltipContent({\n  active,\n  payload,\n  label,\n  series,\n  valueFormatter,\n}: {\n  active?: boolean;\n  payload?: ReadonlyArray<{ dataKey?: unknown; value?: unknown }>;\n  label?: unknown;\n  series: ResolvedSeries[];\n  valueFormatter: (value: number) => string;\n}) {\n  if (!active || !payload?.length) return null;\n  const values = new Map(\n    payload.map((item) => [String(item.dataKey), item.value]),\n  );\n  return (\n    <div className=\"grid min-w-40 gap-1.5 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      {label != null && label !== \"\" ? (\n        <p className=\"m-0 font-medium text-foreground\">{String(label)}</p>\n      ) : null}\n      <div className=\"grid gap-1\">\n        {series\n          .filter((s) => values.has(s.key))\n          .map((s) => (\n            <div key={s.key} className=\"flex items-center gap-2\">\n              <span\n                aria-hidden=\"true\"\n                className=\"h-2.5 w-[3px] shrink-0 rounded-full\"\n                style={{ backgroundColor: s.color }}\n              />\n              <span className=\"text-muted-foreground\">{s.label}</span>\n              <span className=\"ml-auto pl-4 font-medium text-foreground tabular-nums\">\n                {valueFormatter(Number(values.get(s.key)))}\n              </span>\n            </div>\n          ))}\n      </div>\n    </div>\n  );\n}\n\n/** A radar chart on shadcn's chart primitives: filled, outlined, or dotted, with one polygon per series. */\nfunction RadarChart({\n  data,\n  angleKey,\n  series,\n  variant = \"filled\",\n  grid = \"polygon\",\n  showAngleLabels = true,\n  showRadiusAxis = false,\n  showLegend = false,\n  showTooltip = true,\n  domain,\n  valueFormatter = (value) => formatNumber(value, { format: \"compact\" }),\n  animate = true,\n  animationDuration = 700,\n  className,\n  ...props\n}: RadarChartProps) {\n  const reducedMotion = React.useSyncExternalStore(\n    subscribeToReducedMotion,\n    getReducedMotionSnapshot,\n    getReducedMotionServerSnapshot,\n  );\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [activeLabel, setActiveLabel] = React.useState<string | null>(null);\n  const [focusKey, setFocusKey] = React.useState<string | null>(null);\n\n  const resolved: ResolvedSeries[] = series.map((s, index) => ({\n    key: s.key,\n    label: s.label,\n    color: s.color ?? `var(--color-chart-${(index % 5) + 1})`,\n  }));\n  const config = Object.fromEntries(\n    resolved.map((s) => [s.key, { label: s.label, color: s.color }]),\n  ) satisfies ChartConfig;\n  const motion = animate && !reducedMotion;\n\n  const renderShape = (s: ResolvedSeries) =>\n    function RadarShape(shapeProps: { points?: RadarPoint[] }) {\n      const points = shapeProps.points ?? [];\n      if (!points.length) return <g />;\n      const { cx, cy } = points[0]!;\n      const reach = Math.max(1, ...points.map((p) => p.radius));\n      const d = `${points\n        .map((p, i) => `${i ? \"L\" : \"M\"}${round(p.x)},${round(p.y)}`)\n        .join(\" \")} Z`;\n      const color = `var(--color-${s.key})`;\n      const gradientId = `${uid}-radar-${idSafe(s.key)}`;\n      const dimmed = focusKey !== null && focusKey !== s.key;\n      return (\n        <g\n          data-slot=\"radar-chart-series\"\n          data-series={s.key}\n          className=\"transition-opacity duration-150 motion-reduce:transition-none\"\n          style={{ opacity: dimmed ? 0.25 : 1 }}\n        >\n          {variant === \"filled\" ? (\n            <>\n              <defs>\n                <radialGradient\n                  id={gradientId}\n                  gradientUnits=\"userSpaceOnUse\"\n                  cx={round(cx)}\n                  cy={round(cy)}\n                  r={round(reach)}\n                >\n                  <stop offset=\"0%\" stopColor={color} stopOpacity={0.04} />\n                  <stop offset=\"100%\" stopColor={color} stopOpacity={0.3} />\n                </radialGradient>\n              </defs>\n              <path d={d} fill={`url(#${gradientId})`} stroke=\"none\" />\n            </>\n          ) : null}\n          <path\n            d={d}\n            fill=\"none\"\n            stroke={color}\n            strokeWidth={2}\n            strokeLinejoin=\"round\"\n            strokeLinecap=\"round\"\n            className=\"dark:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,var(--radar-glow)_50%,transparent))]\"\n            style={{ [\"--radar-glow\" as string]: color }}\n          />\n        </g>\n      );\n    };\n\n  const renderDot = (s: ResolvedSeries) =>\n    function RadarDot(dotProps: { cx?: number; cy?: number }) {\n      const { cx, cy } = dotProps;\n      if (cx == null || cy == null) return <g />;\n      const color = `var(--color-${s.key})`;\n      const dimmed = focusKey !== null && focusKey !== s.key;\n      return (\n        <g\n          className=\"transition-opacity duration-150 motion-reduce:transition-none\"\n          style={{ opacity: dimmed ? 0.25 : 1 }}\n        >\n          <circle cx={cx} cy={cy} r={6} fill={color} fillOpacity={0.18} />\n          <circle\n            cx={cx}\n            cy={cy}\n            r={3}\n            fill={color}\n            stroke=\"var(--color-card)\"\n            strokeWidth={1.5}\n          />\n        </g>\n      );\n    };\n\n  const renderActiveDot = (s: ResolvedSeries) =>\n    function RadarActiveDot(dotProps: { cx?: number; cy?: number }) {\n      const { cx, cy } = dotProps;\n      if (cx == null || cy == null) return <g />;\n      const color = `var(--color-${s.key})`;\n      return (\n        <g data-slot=\"radar-chart-active-dot\" pointerEvents=\"none\">\n          <circle cx={cx} cy={cy} r={9} fill={color} fillOpacity={0.16} />\n          <circle\n            cx={cx}\n            cy={cy}\n            r={4}\n            fill={color}\n            stroke=\"var(--color-card)\"\n            strokeWidth={2}\n          />\n        </g>\n      );\n    };\n\n  return (\n    <ChartContainer\n      data-slot=\"radar-chart\"\n      data-variant={variant}\n      config={config}\n      className={cn(\"aspect-auto h-64 w-full\", className)}\n      {...props}\n    >\n      <RechartsRadarChart\n        data={data}\n        margin={{ top: 12, right: 28, bottom: 12, left: 28 }}\n        onMouseMove={(state) =>\n          setActiveLabel(\n            state?.isTooltipActive && state.activeLabel != null\n              ? String(state.activeLabel)\n              : null,\n          )\n        }\n        onMouseLeave={() => setActiveLabel(null)}\n      >\n        {grid !== \"none\" ? (\n          <PolarGrid\n            gridType={grid}\n            stroke={GRID}\n            fill=\"color-mix(in oklab, var(--color-foreground) 2%, transparent)\"\n          />\n        ) : null}\n        <PolarAngleAxis\n          dataKey={angleKey}\n          tickLine={false}\n          axisLine={false}\n          tick={\n            showAngleLabels\n              ? (tickProps: {\n                  x: number | string;\n                  y: number | string;\n                  textAnchor?: string;\n                  verticalAnchor?: string;\n                  payload?: { value?: unknown };\n                }) => {\n                  const value = String(tickProps.payload?.value ?? \"\");\n                  const isActive = activeLabel === value;\n                  const dy =\n                    tickProps.verticalAnchor === \"end\"\n                      ? -2\n                      : tickProps.verticalAnchor === \"start\"\n                        ? 9\n                        : 3.5;\n                  return (\n                    <text\n                      x={tickProps.x}\n                      y={tickProps.y}\n                      dy={dy}\n                      textAnchor={\n                        tickProps.textAnchor as \"start\" | \"middle\" | \"end\"\n                      }\n                      data-active={isActive || undefined}\n                      className={cn(\n                        \"fill-muted-foreground text-[11px] transition-[fill] duration-150 motion-reduce:transition-none\",\n                        isActive && \"fill-foreground font-medium\",\n                      )}\n                    >\n                      {value}\n                    </text>\n                  );\n                }\n              : false\n          }\n        />\n        <PolarRadiusAxis\n          // Run the value ticks between the first two spokes so they never sit on a line.\n          angle={data.length > 2 ? 90 - 180 / data.length : 90}\n          domain={domain}\n          axisLine={false}\n          tick={\n            showRadiusAxis\n              ? (tickProps: {\n                  x: number | string;\n                  y: number | string;\n                  payload?: { value?: unknown };\n                }) => {\n                  const value = Number(tickProps.payload?.value);\n                  if (!Number.isFinite(value) || value === 0) return <g />;\n                  return (\n                    <text\n                      x={tickProps.x}\n                      y={tickProps.y}\n                      dx={3}\n                      dy={3.5}\n                      textAnchor=\"start\"\n                      stroke=\"var(--color-card)\"\n                      strokeWidth={3}\n                      paintOrder=\"stroke\"\n                      className=\"fill-muted-foreground text-[10px] tabular-nums\"\n                    >\n                      {valueFormatter(value)}\n                    </text>\n                  );\n                }\n              : false\n          }\n        />\n        {showTooltip ? (\n          <ChartTooltip\n            cursor={{\n              stroke:\n                \"color-mix(in oklab, var(--color-foreground) 25%, transparent)\",\n              strokeWidth: 1,\n            }}\n            isAnimationActive={false}\n            content={(tooltipProps) => (\n              <RadarTooltipContent\n                active={tooltipProps.active}\n                payload={\n                  tooltipProps.payload as ReadonlyArray<{\n                    dataKey?: unknown;\n                    value?: unknown;\n                  }>\n                }\n                label={tooltipProps.label}\n                series={resolved}\n                valueFormatter={valueFormatter}\n              />\n            )}\n          />\n        ) : null}\n        {showLegend ? (\n          <ChartLegend\n            content={() => (\n              <div\n                data-slot=\"radar-chart-legend\"\n                className=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-1 pt-4\"\n                onPointerLeave={() => setFocusKey(null)}\n              >\n                {resolved.map((s) => (\n                  <span\n                    key={s.key}\n                    onPointerEnter={() => setFocusKey(s.key)}\n                    className={cn(\n                      \"flex cursor-default items-center gap-1.5 text-xs text-muted-foreground transition-[color,opacity] duration-150 motion-reduce:transition-none\",\n                      focusKey === s.key && \"text-foreground\",\n                      focusKey !== null && focusKey !== s.key && \"opacity-50\",\n                    )}\n                  >\n                    <svg\n                      aria-hidden=\"true\"\n                      width=\"14\"\n                      height=\"8\"\n                      viewBox=\"0 0 14 8\"\n                    >\n                      <line\n                        x1=\"1\"\n                        x2=\"13\"\n                        y1=\"4\"\n                        y2=\"4\"\n                        stroke={s.color}\n                        strokeWidth=\"2\"\n                        strokeLinecap=\"round\"\n                      />\n                      <circle cx=\"7\" cy=\"4\" r=\"2.5\" fill={s.color} />\n                    </svg>\n                    {s.label}\n                  </span>\n                ))}\n              </div>\n            )}\n          />\n        ) : null}\n        {resolved.map((s) => {\n          const color = `var(--color-${s.key})`;\n          return (\n            <Radar\n              key={s.key}\n              dataKey={s.key}\n              name={s.key}\n              stroke={color}\n              strokeWidth={2}\n              fill={color}\n              fillOpacity={variant === \"filled\" ? 0.25 : 0}\n              shape={renderShape(s)}\n              dot={variant === \"dots\" ? renderDot(s) : false}\n              activeDot={renderActiveDot(s)}\n              isAnimationActive={motion}\n              animationDuration={animationDuration}\n              animationEasing={EASE}\n            />\n          );\n        })}\n      </RechartsRadarChart>\n    </ChartContainer>\n  );\n}\n\nexport { RadarChart };\n"
    },
    {
      "path": "src/registry/overtrue/metric-format.tsx",
      "type": "registry:component",
      "target": "components/overtrue/metric-format.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 */\nexport type NumberFormat = \"number\" | \"compact\" | \"currency\" | \"percent\";\n\nexport interface FormatNumberOptions {\n  format?: NumberFormat;\n  /** ISO 4217 code, used when format is \"currency\". Defaults to USD. */\n  currency?: string;\n  locale?: string;\n  maximumFractionDigits?: number;\n  /** Abbreviate large values, e.g. \"$158K\" instead of \"$158,143\". */\n  compact?: boolean;\n}\n\nconst formatterCache = new Map<string, Intl.NumberFormat>();\n\nfunction getFormatter(locale: string, options: Intl.NumberFormatOptions) {\n  const key = locale + JSON.stringify(options);\n  let formatter = formatterCache.get(key);\n  if (!formatter) {\n    formatter = new Intl.NumberFormat(locale, options);\n    formatterCache.set(key, formatter);\n  }\n  return formatter;\n}\n\n/**\n * Format a metric value for display.\n *\n * formatNumber(1234567)                          -> \"1,234,567\"\n * formatNumber(1234567, { format: \"compact\" })   -> \"1.2M\"\n * formatNumber(48.2, { format: \"currency\" })     -> \"$48.20\"\n * formatNumber(158143, { format: \"currency\", compact: true }) -> \"$158K\"\n * formatNumber(0.124, { format: \"percent\" })     -> \"12.4%\"\n */\nexport function formatNumber(\n  value: number,\n  {\n    format = \"number\",\n    currency = \"USD\",\n    locale = \"en-US\",\n    maximumFractionDigits,\n    compact = false,\n  }: FormatNumberOptions = {},\n): string {\n  if (!Number.isFinite(value)) return \"—\";\n\n  // Compact values keep three significant digits: $158K, $1.23M, 41.2K.\n  const compactOptions: Intl.NumberFormatOptions = compact\n    ? maximumFractionDigits === undefined\n      ? { notation: \"compact\", maximumSignificantDigits: 3 }\n      : { notation: \"compact\", maximumFractionDigits }\n    : {};\n  switch (format) {\n    case \"compact\":\n      return getFormatter(locale, {\n        notation: \"compact\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value);\n    case \"currency\":\n      return getFormatter(locale, {\n        style: \"currency\",\n        currency,\n        maximumFractionDigits: maximumFractionDigits ?? 2,\n        ...compactOptions,\n      }).format(value);\n    case \"percent\":\n      return getFormatter(locale, {\n        style: \"percent\",\n        maximumFractionDigits: maximumFractionDigits ?? 1,\n      }).format(value);\n    default:\n      return getFormatter(locale, {\n        maximumFractionDigits: maximumFractionDigits ?? 0,\n        ...compactOptions,\n      }).format(value);\n  }\n}\n\n/**\n * Format a fractional change as a signed percentage.\n *\n * formatDelta(0.124)  -> \"+12.4%\"\n * formatDelta(-0.03)  -> \"-3.0%\"\n * formatDelta(0)      -> \"0.0%\"\n */\nexport function formatDelta(delta: number, locale = \"en-US\"): string {\n  if (!Number.isFinite(delta)) return \"—\";\n  return getFormatter(locale, {\n    style: \"percent\",\n    signDisplay: \"exceptZero\",\n    maximumFractionDigits: 1,\n    minimumFractionDigits: 1,\n  }).format(delta);\n}\n\n/**\n * Fractional change between two values. Returns 0 when there is no baseline.\n */\nexport function computeDelta(current: number, previous: number): number {\n  if (!previous) return 0;\n  return (current - previous) / Math.abs(previous);\n}\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/radar-chart. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
