{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radial-gauge",
  "type": "registry:component",
  "title": "Radial gauge",
  "description": "Use a compact dial to summarize a target, utilization level, or service measure.",
  "categories": [
    "metrics"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/radial-gauge.tsx",
      "type": "registry:component",
      "target": "components/overtrue/radial-gauge.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\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface RadialGaugeZone {\n  from: number;\n  to: number;\n  /** Any CSS color. Defaults to chart-1 through chart-5 in order. */\n  color?: string;\n  label?: string;\n}\n\nexport interface RadialGaugeProps extends React.ComponentProps<\"div\"> {\n  value: number;\n  min?: number;\n  max?: number;\n  /** Diameter in pixels. */\n  size?: number;\n  /** Stroke width in pixels. */\n  thickness?: number;\n  /** Number of arc segments. 0 draws a continuous arc. */\n  segments?: number;\n  /** Gap between segments in degrees. */\n  gap?: number;\n  /** Angle where the arc starts, in degrees clockwise from 12 o'clock. */\n  startAngle?: number;\n  /** Total sweep of the arc in degrees. 180 is a semicircle, 360 a ring. */\n  sweep?: number;\n  /** Any CSS color. Defaults to chart-1, or to the zone that holds the value. */\n  color?: string;\n  /** Defaults to a soft tint of the arc color. */\n  trackColor?: string;\n  /** Reveal filled segments in sequence when the gauge mounts. */\n  animate?: boolean;\n  /** Total reveal time in milliseconds. */\n  animationDuration?: number;\n  /** Threshold bands drawn as a thin ring just outside the arc. */\n  zones?: RadialGaugeZone[];\n  /** Fade the arc in from its start so the leading edge reads brightest. */\n  gradient?: boolean;\n  /** Content rendered in the middle of the gauge. */\n  children?: React.ReactNode;\n}\n\nconst defaultColors = [\n  \"var(--color-chart-1)\",\n  \"var(--color-chart-2)\",\n  \"var(--color-chart-3)\",\n  \"var(--color-chart-4)\",\n  \"var(--color-chart-5)\",\n];\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\nconst UPDATE_MS = 450;\n\n// Round so server and client render identical path strings.\nconst round = (n: number) => Math.round(n * 1000) / 1000;\n\nfunction polar(cx: number, cy: number, r: number, angleDeg: number) {\n  const rad = ((angleDeg - 90) * Math.PI) / 180;\n  return { x: round(cx + r * Math.cos(rad)), y: round(cy + r * Math.sin(rad)) };\n}\n\nfunction arcPath(cx: number, cy: number, r: number, from: number, to: number) {\n  const start = polar(cx, cy, r, from);\n  // A single SVG arc with coincident endpoints is empty, not a full circle.\n  if (to - from >= 360) {\n    const middle = polar(cx, cy, r, from + 180);\n    return `M ${start.x} ${start.y} A ${r} ${r} 0 1 1 ${middle.x} ${middle.y} A ${r} ${r} 0 1 1 ${start.x} ${start.y}`;\n  }\n  const end = polar(cx, cy, r, to);\n  const largeArc = to - from > 180 ? 1 : 0;\n  return `M ${start.x} ${start.y} A ${r} ${r} 0 ${largeArc} 1 ${end.x} ${end.y}`;\n}\n\nconst REDUCED_QUERY = \"(prefers-reduced-motion: reduce)\";\nfunction subscribeReducedMotion(callback: () => void) {\n  const query = window.matchMedia(REDUCED_QUERY);\n  query.addEventListener(\"change\", callback);\n  return () => query.removeEventListener(\"change\", callback);\n}\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    subscribeReducedMotion,\n    () => window.matchMedia(REDUCED_QUERY).matches,\n    () => false,\n  );\n}\n\n/** A dial for a single measure: a luminous arc over a soft track, with optional threshold zones. */\nfunction RadialGauge({\n  value,\n  min = 0,\n  max = 100,\n  size = 160,\n  thickness = 10,\n  segments = 0,\n  gap = 2,\n  startAngle,\n  sweep = 180,\n  color: colorProp,\n  trackColor: trackProp,\n  animate = false,\n  animationDuration = 700,\n  zones,\n  gradient = true,\n  className,\n  style,\n  children,\n  ...props\n}: RadialGaugeProps) {\n  const range = max - min || 1;\n  const safe = Number.isFinite(value) ? value : min;\n  const fraction = Math.min(1, Math.max(0, (safe - min) / range));\n  const start = startAngle ?? (sweep >= 360 ? 0 : -sweep / 2);\n  const angleOf = (v: number) =>\n    start + sweep * Math.min(1, Math.max(0, (v - min) / range));\n\n  const bands = (zones ?? []).filter(\n    (zone) =>\n      Number.isFinite(zone.from) &&\n      Number.isFinite(zone.to) &&\n      zone.to > zone.from,\n  );\n  const activeZone = bands.findIndex(\n    (zone, i) =>\n      safe >= zone.from &&\n      (safe < zone.to || (i === bands.length - 1 && safe <= zone.to)),\n  );\n  const color =\n    colorProp ??\n    (activeZone >= 0\n      ? (bands[activeZone].color ??\n        defaultColors[activeZone % defaultColors.length])\n      : \"var(--color-chart-1)\");\n  const trackColor =\n    trackProp ??\n    \"color-mix(in oklab, var(--gauge-color) 14%, color-mix(in oklab, var(--color-foreground) 4%, transparent))\";\n\n  const zoneWidth = bands.length ? Math.max(2, Math.round(thickness * 0.3)) : 0;\n  const zoneGap = bands.length ? Math.max(3, Math.round(thickness * 0.35)) : 0;\n  const cx = size / 2;\n  const cy = size / 2;\n  const r = size / 2 - thickness / 2 - (bands.length ? zoneWidth + zoneGap : 0);\n  const zoneRadius = size / 2 - zoneWidth / 2;\n  // Trim the box to the arc's vertical extent so a semicircle does not\n  // reserve a full circle of space.\n  const angles = Array.from({ length: 64 }, (_, i) => start + (sweep * i) / 63);\n  const ys = angles.map((a) => polar(cx, cy, r, a).y);\n  const outset = thickness / 2 + (bands.length ? zoneWidth + zoneGap : 0);\n  const top = Math.max(0, Math.min(...ys) - outset);\n  const bottom = Math.min(size, Math.max(...ys) + thickness / 2);\n  const height = bottom - top;\n\n  const reduced = useReducedMotion();\n  const fillRef = React.useRef<SVGPathElement>(null);\n  const ghostRef = React.useRef<SVGPathElement>(null);\n  const settled = React.useRef(animate ? 0 : fraction);\n  const mounted = React.useRef(false);\n  const [ghost, setGhost] = React.useState<{ from: number; to: number } | null>(\n    null,\n  );\n\n  // The fill path always has its final geometry, so it can be measured at once.\n  // Growth is revealed with a dash; a shrink leaves a ghost arc that retracts.\n  React.useLayoutEffect(() => {\n    const previous = settled.current;\n    const first = !mounted.current;\n    mounted.current = true;\n    settled.current = fraction;\n    if (segments > 0 || reduced || previous === fraction) return;\n    const duration = first ? animationDuration : UPDATE_MS;\n    if (fraction > previous) {\n      setGhost(null);\n      fillRef.current?.animate(\n        [\n          { strokeDasharray: `${round(previous / fraction)} 2` },\n          { strokeDasharray: \"1 2\" },\n        ],\n        { duration, easing: EASE },\n      );\n    } else {\n      setGhost({ from: fraction, to: previous });\n    }\n  }, [fraction, segments, reduced, animationDuration]);\n\n  React.useLayoutEffect(() => {\n    const path = ghostRef.current;\n    if (!ghost || !path) return;\n    const animation = path.animate(\n      [{ strokeDasharray: \"1 2\" }, { strokeDasharray: \"0 2\" }],\n      { duration: UPDATE_MS, easing: EASE, fill: \"forwards\" },\n    );\n    animation.onfinish = () => setGhost(null);\n    return () => animation.cancel();\n  }, [ghost]);\n\n  const filledDeg = sweep * fraction;\n  const capDeg = ((thickness / 2 / Math.max(r, 1)) * 180) / Math.PI;\n  const center = `${round((cx / size) * 100)}% ${round(((cy - top) / height) * 100)}%`;\n  const fade =\n    gradient &&\n    segments === 0 &&\n    fraction > 0 &&\n    filledDeg + capDeg * 2 + 6 < 360\n      ? `conic-gradient(from ${round(start - capDeg - 2)}deg at ${center}, rgb(0 0 0 / 0.4) 0deg, #000 ${round(filledDeg + capDeg + 2)}deg, #000 360deg)`\n      : undefined;\n  const headSize = Math.round(thickness * 0.42);\n  const showHead = segments === 0 && fraction > 0 && thickness >= 8;\n  const motion = reduced ? \"none\" : undefined;\n\n  const arcs: { from: number; to: number; filled: boolean }[] = [];\n  if (segments > 0) {\n    const step = sweep / segments;\n    for (let i = 0; i < segments; i++) {\n      const from = start + i * step + gap / 2;\n      const to = start + (i + 1) * step - gap / 2;\n      const mid = (i + 0.5) / segments;\n      arcs.push({ from, to, filled: mid <= fraction });\n    }\n  }\n  const filledCount = arcs.filter((arc) => arc.filled).length;\n\n  return (\n    <div\n      data-slot=\"radial-gauge\"\n      role=\"meter\"\n      aria-valuemin={min}\n      aria-valuemax={max}\n      aria-valuenow={value}\n      className={cn(\"relative inline-flex shrink-0\", className)}\n      style={\n        {\n          ...style,\n          width: size,\n          height,\n          \"--gauge-color\": color,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <svg\n        width={size}\n        height={height}\n        viewBox={`0 ${top} ${size} ${height}`}\n        className=\"absolute inset-0 overflow-visible\"\n        aria-hidden=\"true\"\n        data-slot=\"radial-gauge-track\"\n      >\n        {segments > 0 ? (\n          arcs.map((arc, index) => (\n            <path\n              key={index}\n              d={arcPath(cx, cy, r, arc.from, arc.to)}\n              fill=\"none\"\n              stroke={trackColor}\n              strokeWidth={thickness}\n              strokeLinecap=\"butt\"\n            />\n          ))\n        ) : (\n          <path\n            d={arcPath(cx, cy, r, start, start + sweep)}\n            fill=\"none\"\n            stroke={trackColor}\n            strokeWidth={thickness}\n            strokeLinecap={sweep >= 360 ? \"butt\" : \"round\"}\n          />\n        )}\n      </svg>\n      <div\n        aria-hidden=\"true\"\n        data-slot=\"radial-gauge-fill\"\n        className=\"pointer-events-none absolute inset-0 dark:drop-shadow-[0_0_7px_color-mix(in_oklab,var(--gauge-color)_55%,transparent)]\"\n      >\n        <svg\n          width={size}\n          height={height}\n          viewBox={`0 ${top} ${size} ${height}`}\n          className=\"absolute inset-0 overflow-visible\"\n          style={fade ? { maskImage: fade, WebkitMaskImage: fade } : undefined}\n        >\n          {segments > 0\n            ? arcs.map((arc, index) =>\n                arc.filled ? (\n                  <path\n                    key={index}\n                    d={arcPath(cx, cy, r, arc.from, arc.to)}\n                    fill=\"none\"\n                    stroke=\"var(--gauge-color)\"\n                    strokeWidth={thickness}\n                    strokeLinecap=\"butt\"\n                    // Segments brighten toward the leading edge.\n                    strokeOpacity={\n                      gradient\n                        ? round(0.4 + 0.6 * ((index + 1) / filledCount) ** 1.3)\n                        : 1\n                    }\n                    className={cn(\n                      \"transition-[stroke-opacity] duration-300\",\n                      animate &&\n                        \"starting:[stroke-opacity:0] motion-reduce:transition-none\",\n                    )}\n                    style={\n                      animate\n                        ? {\n                            transitionDelay: `${(index / Math.max(1, filledCount)) * animationDuration * 0.8}ms`,\n                          }\n                        : undefined\n                    }\n                  />\n                ) : null,\n              )\n            : fraction > 0 && (\n                <path\n                  ref={fillRef}\n                  d={arcPath(cx, cy, r, start, start + filledDeg)}\n                  fill=\"none\"\n                  stroke=\"var(--gauge-color)\"\n                  strokeWidth={thickness}\n                  strokeLinecap=\"round\"\n                  pathLength={1}\n                />\n              )}\n          {ghost && segments === 0 ? (\n            <path\n              ref={ghostRef}\n              d={arcPath(\n                cx,\n                cy,\n                r,\n                start + sweep * ghost.from,\n                start + sweep * ghost.to,\n              )}\n              fill=\"none\"\n              stroke=\"var(--gauge-color)\"\n              strokeWidth={thickness}\n              strokeLinecap=\"round\"\n              pathLength={1}\n            />\n          ) : null}\n        </svg>\n      </div>\n      {bands.length ? (\n        <svg\n          width={size}\n          height={height}\n          viewBox={`0 ${top} ${size} ${height}`}\n          className=\"pointer-events-none absolute inset-0 overflow-visible\"\n          aria-hidden=\"true\"\n          data-slot=\"radial-gauge-zones\"\n        >\n          {bands.map((zone, index) => {\n            const inset =\n              ((zoneWidth / 2 + 1.5) / zoneRadius) * (180 / Math.PI);\n            const from = angleOf(zone.from) + inset;\n            const to = angleOf(zone.to) - inset;\n            if (to <= from) return null;\n            return (\n              <path\n                key={index}\n                d={arcPath(cx, cy, zoneRadius, from, to)}\n                fill=\"none\"\n                stroke={\n                  zone.color ?? defaultColors[index % defaultColors.length]\n                }\n                strokeWidth={zoneWidth}\n                strokeLinecap=\"round\"\n                strokeOpacity={index === activeZone ? 1 : 0.35}\n                className=\"transition-[stroke-opacity] duration-300\"\n              >\n                {zone.label ? <title>{zone.label}</title> : null}\n              </path>\n            );\n          })}\n        </svg>\n      ) : null}\n      {showHead ? (\n        // Rotates about the center, so the head glides along the arc in both directions.\n        <div\n          aria-hidden=\"true\"\n          data-slot=\"radial-gauge-head\"\n          className=\"pointer-events-none absolute size-0\"\n          style={{\n            left: cx,\n            top: cy - top,\n            rotate: `${round(start + filledDeg)}deg`,\n            transition: motion ?? `rotate ${UPDATE_MS}ms ${EASE}`,\n          }}\n        >\n          <span\n            className={cn(\n              \"absolute rounded-full bg-card shadow-[0_0_0_1px_color-mix(in_oklab,var(--gauge-color)_30%,transparent)] transition-opacity duration-300 dark:bg-[color-mix(in_oklab,var(--color-foreground)_90%,var(--gauge-color))] dark:shadow-[0_0_8px_1px_color-mix(in_oklab,var(--gauge-color)_80%,transparent)]\",\n              animate && !reduced && \"starting:opacity-0\",\n            )}\n            style={{\n              width: headSize,\n              height: headSize,\n              left: -headSize / 2,\n              top: -r - headSize / 2,\n              transitionDelay: animate\n                ? `${animationDuration * 0.7}ms`\n                : undefined,\n            }}\n          />\n        </div>\n      ) : null}\n      {children ? (\n        <div\n          data-slot=\"radial-gauge-content\"\n          className={cn(\n            \"absolute inset-x-0 flex flex-col items-center justify-center text-center\",\n            sweep > 200 ? \"top-0\" : \"bottom-0\",\n          )}\n          style={sweep > 200 ? { height: (cy - top) * 2 } : undefined}\n        >\n          {children}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport { RadialGauge };\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/radial-gauge. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
