{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "score-gauge-card",
  "title": "Score Gauge Card",
  "description": "A score card with a headline word, a radial gauge around the score, and a breakdown list of labelled bars.",
  "registryDependencies": [
    "card",
    "tooltip"
  ],
  "files": [
    {
      "path": "registry/dashboardcn/blocks/score-gauge-card.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  Card,\n  CardAction,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport { RadialGauge } from \"@/registry/dashboardcn/ui/radial-gauge\"\nimport { TickBar } from \"@/registry/dashboardcn/ui/tick-bar\"\nimport { MetricValue } from \"@/registry/dashboardcn/ui/metric-value\"\n\nexport interface ScoreGaugeItem {\n  label: string\n  /** Text after the label, e.g. \"7h 50m\" renders \"Duration: 7h 50m\". */\n  detail?: string\n  value: number\n  max: number\n  /** Any CSS color for the bar. Defaults to the card color. */\n  color?: string\n}\n\nexport interface ScoreGaugeStatus {\n  /** Lowest score that earns this label. */\n  min: number\n  label: string\n}\n\n/** Applied to the score as a share of max when neither status nor statuses is given. */\nconst defaultStatuses: ScoreGaugeStatus[] = [\n  { min: 0, label: \"Poor\" },\n  { min: 50, label: \"Fair\" },\n  { min: 70, label: \"Good\" },\n  { min: 85, label: \"Excellent\" },\n]\n\nexport interface ScoreGaugeCardProps extends React.ComponentProps<typeof Card> {\n  title: string\n  /** Headline word, e.g. \"Excellent\". Derived from statuses when omitted. */\n  status?: string\n  /** Score thresholds used to derive the headline word, e.g. [{ min: 85, label: \"Excellent\" }]. */\n  statuses?: ScoreGaugeStatus[]\n  /** Period text under the headline, e.g. \"29 Jun - 5 Jul\". */\n  caption?: string\n  score: number\n  max?: number\n  /** Any CSS color for the gauge and bars. Defaults to chart-1. */\n  color?: string\n  /** Gauge diameter in pixels. */\n  gaugeSize?: number\n  /** Gauge stroke width in pixels. */\n  thickness?: number\n  /** Number of gauge segments. 0 draws a continuous arc. */\n  segments?: number\n  /** Gap between gauge segments in degrees. */\n  segmentGap?: number\n  /** Gauge sweep in degrees. 360 draws a ring, 180 a semicircle. */\n  sweep?: number\n  /** Ticks in each breakdown bar. 0 draws a solid bar. */\n  barSegments?: number\n  /** Breakdown rows, each with a bar filled to value/max. */\n  items: ScoreGaugeItem[]\n  /** Slot in the top-right corner, e.g. a menu button. */\n  action?: React.ReactNode\n}\n\nfunction deriveStatus(score: number, statuses: ScoreGaugeStatus[]) {\n  let match: ScoreGaugeStatus | undefined\n  for (const status of statuses) {\n    if (score >= status.min && (!match || status.min >= match.min)) match = status\n  }\n  return match?.label\n}\n\n/** A score card with a headline word, a radial gauge around the score, and a breakdown list of labelled bars. */\nfunction ScoreGaugeCard({\n  title,\n  status,\n  statuses,\n  caption,\n  score,\n  max = 100,\n  color = \"var(--chart-1)\",\n  gaugeSize = 160,\n  thickness = 12,\n  segments = 0,\n  segmentGap = 2,\n  sweep = 360,\n  barSegments = 0,\n  items,\n  action,\n  className,\n  ...props\n}: ScoreGaugeCardProps) {\n  const headline =\n    status ??\n    (statuses\n      ? deriveStatus(score, statuses)\n      : deriveStatus((score / (max || 1)) * 100, defaultStatuses))\n\n  return (\n    <Card\n      data-slot=\"score-gauge-card\"\n      className={cn(\"@container/card gap-4\", className)}\n      {...props}\n    >\n      <CardHeader>\n        <CardDescription>{title}</CardDescription>\n        {headline ? (\n          <CardTitle className=\"text-2xl font-semibold tracking-tight\">{headline}</CardTitle>\n        ) : null}\n        {caption ? (\n          <div className=\"text-muted-foreground text-sm tabular-nums\">{caption}</div>\n        ) : null}\n        {action ? <CardAction>{action}</CardAction> : null}\n      </CardHeader>\n      <CardContent>\n        <div className=\"flex flex-col items-center gap-6 @sm/card:flex-row @sm/card:items-center @sm/card:gap-8\">\n          <RadialGauge\n            value={score}\n            max={max}\n            size={gaugeSize}\n            thickness={thickness}\n            segments={segments}\n            gap={segmentGap}\n            sweep={sweep}\n            color={color}\n            aria-label={`${title}: ${score} of ${max}`}\n            className=\"shrink-0\"\n          >\n            <MetricValue\n              value={score}\n              className=\"text-4xl font-semibold tracking-tight\"\n            />\n          </RadialGauge>\n          <ul className=\"flex w-full min-w-0 flex-1 flex-col gap-4\">\n            {items.map((item) => {\n              const fraction = Math.min(1, Math.max(0, item.value / (item.max || 1)))\n              const barColor = item.color ?? color\n              return (\n                <li key={item.label} className=\"flex flex-col gap-1.5\">\n                  <div className=\"flex items-baseline justify-between gap-3 text-sm\">\n                    <span className=\"min-w-0 truncate\">\n                      <span className=\"font-medium\">{item.label}</span>\n                      {item.detail ? (\n                        <span className=\"text-muted-foreground\">: {item.detail}</span>\n                      ) : null}\n                    </span>\n                    <span className=\"text-muted-foreground shrink-0 tabular-nums\">\n                      <MetricValue value={item.value} className=\"text-foreground font-medium\" />\n                      /\n                      <MetricValue value={item.max} />\n                    </span>\n                  </div>\n                  {barSegments > 0 ? (\n                    <TickBar\n                      value={item.value}\n                      max={item.max}\n                      segments={barSegments}\n                      shape=\"pill\"\n                      color={barColor}\n                      className=\"h-2\"\n                    />\n                  ) : (\n                    <div\n                      role=\"progressbar\"\n                      aria-label={item.label}\n                      aria-valuemin={0}\n                      aria-valuemax={item.max}\n                      aria-valuenow={item.value}\n                      className=\"bg-muted h-2 w-full overflow-hidden rounded-full\"\n                    >\n                      <div\n                        className=\"h-full rounded-full transition-[width] duration-500\"\n                        style={{\n                          width: `${Math.round(fraction * 1000) / 10}%`,\n                          backgroundColor: barColor,\n                        }}\n                      />\n                    </div>\n                  )}\n                </li>\n              )\n            })}\n          </ul>\n        </div>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { ScoreGaugeCard }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/dashboardcn/ui/radial-gauge.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\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. */\n  color?: string\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  /** Content rendered in the middle of the gauge. */\n  children?: React.ReactNode\n}\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  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\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 = \"var(--chart-1)\",\n  trackColor = \"var(--muted)\",\n  animate = false,\n  animationDuration = 700,\n  className,\n  children,\n  ...props\n}: RadialGaugeProps) {\n  const fraction = Math.min(1, Math.max(0, (value - min) / (max - min || 1)))\n  const start = startAngle ?? (sweep >= 360 ? 0 : -sweep / 2)\n  const r = size / 2 - thickness / 2\n  const cx = size / 2\n  const cy = size / 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 top = Math.max(0, Math.min(...ys) - thickness / 2)\n  const bottom = Math.min(size, Math.max(...ys) + thickness / 2)\n  const height = bottom - top\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\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={{ width: size, height }}\n      {...props}\n    >\n      <svg\n        width={size}\n        height={height}\n        viewBox={`0 ${top} ${size} ${height}`}\n        className=\"absolute inset-0\"\n        aria-hidden=\"true\"\n      >\n        {segments > 0 ? (\n          arcs.map((arc, index) => {\n            const path = arcPath(cx, cy, r, arc.from, arc.to)\n            const filledCount = Math.max(1, Math.round(fraction * segments))\n            const delay = (index / filledCount) * animationDuration * 0.8\n\n            return (\n              <g key={index}>\n                <path\n                  d={path}\n                  fill=\"none\"\n                  stroke={trackColor}\n                  strokeWidth={thickness}\n                  strokeLinecap=\"butt\"\n                />\n                {arc.filled ? (\n                  <path\n                    d={path}\n                    fill=\"none\"\n                    stroke={color}\n                    strokeWidth={thickness}\n                    strokeLinecap=\"butt\"\n                    className={cn(\n                      animate && \"motion-safe:animate-in motion-safe:fade-in\"\n                    )}\n                    style={\n                      animate\n                        ? {\n                            animationDelay: `${delay}ms`,\n                            animationDuration: `${Math.max(120, animationDuration * 0.25)}ms`,\n                            animationFillMode: \"both\",\n                          }\n                        : undefined\n                    }\n                  />\n                ) : null}\n              </g>\n            )\n          })\n        ) : (\n          <>\n            <path\n              d={arcPath(cx, cy, r, start, start + sweep - (sweep >= 360 ? 0.01 : 0))}\n              fill=\"none\"\n              stroke={trackColor}\n              strokeWidth={thickness}\n              strokeLinecap={sweep >= 360 ? \"butt\" : \"round\"}\n            />\n            {fraction > 0 ? (\n              <path\n                d={arcPath(cx, cy, r, start, start + sweep * fraction)}\n                fill=\"none\"\n                stroke={color}\n                strokeWidth={thickness}\n                strokeLinecap=\"round\"\n                className={cn(\n                  \"transition-[d] duration-500\",\n                  animate && \"motion-safe:animate-in motion-safe:fade-in\"\n                )}\n                style={\n                  animate\n                    ? { animationDuration: `${animationDuration}ms` }\n                    : undefined\n                }\n              />\n            ) : null}\n          </>\n        )}\n      </svg>\n      {children ? (\n        <div\n          className={cn(\n            \"absolute inset-x-0 flex flex-col items-center justify-center text-center\",\n            sweep > 200 ? \"inset-y-0\" : \"bottom-0\"\n          )}\n        >\n          {children}\n        </div>\n      ) : null}\n    </div>\n  )\n}\n\nexport { RadialGauge }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/tick-bar.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface TickBarProps extends React.ComponentProps<\"div\"> {\n  /** Current value, from 0 to max. */\n  value: number\n  max?: number\n  /** Number of ticks. */\n  segments?: number\n  /** Any CSS color for the filled ticks. Defaults to chart-1. */\n  color?: string\n  /** Any CSS color for the unfilled ticks. Defaults to muted. */\n  trackColor?: string\n  /** \"tick\" draws thin bars; \"pill\" draws wide rounded ones. */\n  shape?: \"tick\" | \"pill\"\n  /** Reveal filled ticks in sequence when the bar mounts. */\n  animate?: boolean\n  /** Total reveal time in milliseconds. */\n  animationDuration?: number\n}\n\n/** A progress bar drawn as a row of ticks, lit up to the current value. */\nfunction TickBar({\n  value,\n  max = 100,\n  segments = 40,\n  color = \"var(--chart-1)\",\n  trackColor,\n  shape = \"tick\",\n  animate = false,\n  animationDuration = 700,\n  className,\n  ...props\n}: TickBarProps) {\n  const fraction = Math.min(1, Math.max(0, value / (max || 1)))\n  // Any non-zero value lights at least one tick so small values still register.\n  const filled = fraction === 0 ? 0 : Math.max(1, Math.round(fraction * segments))\n\n  return (\n    <div\n      data-slot=\"tick-bar\"\n      data-shape={shape}\n      role=\"progressbar\"\n      aria-valuemin={0}\n      aria-valuemax={max}\n      aria-valuenow={value}\n      className={cn(\n        \"flex w-full\",\n        shape === \"tick\" ? \"h-6 gap-[3px]\" : \"h-4 gap-1.5\",\n        className\n      )}\n      {...props}\n    >\n      {Array.from({ length: segments }, (_, index) => {\n        const lit = index < filled\n        return (\n          <span\n            key={index}\n            data-filled={lit}\n            className={cn(\n              \"bg-muted relative h-full min-w-0 flex-1 overflow-hidden transition-colors\",\n              shape === \"tick\" ? \"rounded-[1.5px]\" : \"rounded-full\"\n            )}\n            style={{ backgroundColor: trackColor }}\n          >\n            {lit ? (\n              <span\n                className={cn(\n                  \"absolute inset-0\",\n                  shape === \"tick\" ? \"rounded-[1.5px]\" : \"rounded-full\",\n                  animate && \"motion-safe:animate-in motion-safe:fade-in\"\n                )}\n                style={{\n                  backgroundColor: color,\n                  ...(animate\n                    ? {\n                        animationDelay: `${(index / Math.max(1, filled)) * animationDuration * 0.8}ms`,\n                        animationDuration: `${Math.max(120, animationDuration * 0.25)}ms`,\n                        animationFillMode: \"both\",\n                      }\n                    : null),\n                }}\n              />\n            ) : null}\n          </span>\n        )\n      })}\n    </div>\n  )\n}\n\nexport { TickBar }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/ui/metric-value.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { formatNumber, type NumberFormat } from \"@/registry/dashboardcn/lib/format\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n/** Values at or above this are abbreviated by default. */\nexport const DEFAULT_COMPACT_FROM = 100_000\n\nexport interface MetricValueProps extends Omit<React.ComponentProps<\"span\">, \"children\"> {\n  /** Strings render as-is. */\n  value: number | string\n  format?: NumberFormat\n  currency?: string\n  maximumFractionDigits?: number\n  /** Values at or above this are abbreviated (e.g. $158K) with the full value in a tooltip. Set to Infinity to always show the full value. */\n  compactFrom?: number\n  /** Text after the number, e.g. a unit. */\n  suffix?: React.ReactNode\n}\n\n/** A formatted number. Large values are abbreviated and reveal the full value on hover. */\nfunction MetricValue({\n  value,\n  format,\n  currency,\n  maximumFractionDigits,\n  compactFrom = DEFAULT_COMPACT_FROM,\n  suffix,\n  className,\n  ...props\n}: MetricValueProps) {\n  const classes = cn(\"tabular-nums\", className)\n\n  if (typeof value !== \"number\") {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {value}\n        {suffix}\n      </span>\n    )\n  }\n\n  const full = formatNumber(value, { format, currency, maximumFractionDigits })\n  const abbreviate = format !== \"percent\" && Math.abs(value) >= compactFrom\n  if (!abbreviate) {\n    return (\n      <span data-slot=\"metric-value\" className={classes} {...props}>\n        {full}\n        {suffix}\n      </span>\n    )\n  }\n\n  return (\n    <TooltipProvider>\n      <Tooltip>\n        <TooltipTrigger asChild>\n          <span\n            data-slot=\"metric-value\"\n            data-compact=\"\"\n            className={cn(classes, \"cursor-default\")}\n            {...props}\n          >\n            {formatNumber(value, { format, currency, compact: true })}\n            {suffix}\n          </span>\n        </TooltipTrigger>\n        <TooltipContent className=\"tabular-nums\">\n          {full}\n          {suffix}\n        </TooltipContent>\n      </Tooltip>\n    </TooltipProvider>\n  )\n}\n\nexport { MetricValue }\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/dashboardcn/lib/format.ts",
      "content": "export 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",
      "type": "registry:lib"
    }
  ],
  "categories": [
    "dashboard",
    "charts"
  ],
  "type": "registry:block"
}