{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "heatmap-chart",
  "type": "registry:component",
  "title": "Heatmap matrix",
  "description": "Find busy periods and uneven coverage across two dimensions.",
  "categories": [
    "charts"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/heatmap-chart.tsx",
      "type": "registry:component",
      "target": "components/overtrue/heatmap-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\";\n\nimport { cn } from \"@/lib/utils\";\nimport { formatNumber } from \"./metric-format\";\n\nexport interface HeatmapRow {\n  label: string;\n  /** One value per column, in column order. Missing entries read as 0. */\n  values: number[];\n}\n\n/** A cell's position by row and column index. */\nexport interface HeatmapCell {\n  row: number;\n  column: number;\n}\n\nexport interface HeatmapDatum extends HeatmapCell {\n  rowLabel: string;\n  columnLabel: string;\n  value: number;\n}\n\nexport interface HeatmapChartProps extends React.ComponentProps<\"div\"> {\n  /** One row per line of the matrix, top to bottom. */\n  rows: HeatmapRow[];\n  /** Column labels, left to right. Sets the number of columns. */\n  columns: string[];\n  /** Any CSS color. Cells mix this into the card surface by value. Defaults to chart-1. */\n  color?: string;\n  /** Value drawn fully saturated. Defaults to the largest value. */\n  max?: number;\n  /** How values map to color. `sqrt` spreads out small values. */\n  scale?: \"linear\" | \"sqrt\";\n  /** Quantize the fill into this many steps instead of a continuous ramp. */\n  levels?: number;\n  /** Gap between cells in px. Cells themselves stretch to fill the container. */\n  gap?: number;\n  /** Cells stay square until they reach this height in px, then widen to fill the row. */\n  maxCellHeight?: number;\n  valueFormatter?: (value: number) => string;\n  /** Label for the value in the tooltip, e.g. \"sessions\". */\n  unit?: string;\n  showLegend?: boolean;\n  showRowLabels?: boolean;\n  showColumnLabels?: boolean;\n  /** Show every nth column label. Defaults to whatever keeps about 12 labels. */\n  columnLabelEvery?: number;\n  /** Replace the tooltip body. Return `null` to hide it for that cell. */\n  renderTooltip?: (datum: HeatmapDatum) => React.ReactNode;\n  onCellClick?: (datum: HeatmapDatum) => void;\n  /** The hovered cell, to control it from outside. */\n  activeCell?: HeatmapCell | null;\n  /** Called when the hovered cell changes, with null when the pointer leaves. */\n  onActiveCellChange?: (cell: HeatmapCell | null) => void;\n}\n\nconst EMPTY_FILL = \"color-mix(in oklab, var(--color-muted) 72%, transparent)\";\n\nconst useIsomorphicLayoutEffect =\n  typeof window === \"undefined\" ? React.useEffect : React.useLayoutEffect;\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (onChange) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", onChange);\n      return () => query.removeEventListener(\"change\", onChange);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** Where a value sits between the empty track (0) and the accent (1). */\nfunction fractionFor(\n  value: number,\n  max: number,\n  scale: \"linear\" | \"sqrt\",\n  levels?: number,\n) {\n  if (value <= 0 || max <= 0) return 0;\n  let t = Math.min(1, value / max);\n  if (scale === \"sqrt\") t = Math.sqrt(t);\n  if (levels && levels > 1) {\n    t = Math.max(1, Math.ceil(t * (levels - 1))) / (levels - 1);\n  }\n  return t;\n}\n\n/**\n * A sequential ramp mixed in OKLab from the card surface to the accent, so equal\n * steps in value read as equal steps in lightness in light and dark themes alike.\n */\nfunction fillFor(color: string, fraction: number) {\n  if (fraction <= 0) return EMPTY_FILL;\n  // Floor the mix so the smallest non-zero values still read against the surface.\n  const pct = Math.round(12 + fraction * 88);\n  return `color-mix(in oklab, ${color} ${pct}%, var(--color-card))`;\n}\n\nfunction percentOf(value: number, max: number) {\n  if (!(max > 0)) return \"0%\";\n  const pct = (value / max) * 100;\n  if (pct > 0 && pct < 1) return \"<1%\";\n  return `${Math.round(pct)}%`;\n}\n\n/**\n * A matrix heatmap with a row per line and a column per label, e.g. weekday by hour.\n * Cells stretch to the container width. Hovering or focusing a cell outlines it,\n * lights up its row and column as a crosshair, and shows a readout; arrow keys move\n * between cells.\n */\nfunction HeatmapChart({\n  rows,\n  columns,\n  color = \"var(--color-chart-1)\",\n  max,\n  scale = \"linear\",\n  levels,\n  gap = 4,\n  maxCellHeight = 32,\n  valueFormatter = (value) => formatNumber(value),\n  unit,\n  showLegend = true,\n  showRowLabels = true,\n  showColumnLabels = true,\n  columnLabelEvery,\n  renderTooltip,\n  onCellClick,\n  activeCell,\n  onActiveCellChange,\n  className,\n  ...props\n}: HeatmapChartProps) {\n  const reduced = useReducedMotion();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const gridRef = React.useRef<HTMLDivElement>(null);\n  const tipRef = React.useRef<HTMLDivElement>(null);\n  const [internal, setInternal] = React.useState<HeatmapCell | null>(null);\n  const [tabStop, setTabStop] = React.useState<HeatmapCell>({\n    row: 0,\n    column: 0,\n  });\n  const [anchor, setAnchor] = React.useState<{\n    x: number;\n    top: number;\n    bottom: number;\n  } | null>(null);\n  const active = activeCell === undefined ? internal : activeCell;\n  const setActive = (cell: HeatmapCell | null) => {\n    if (cell?.row === active?.row && cell?.column === active?.column) return;\n    setInternal(cell);\n    onActiveCellChange?.(cell);\n  };\n\n  const { top, peak } = React.useMemo(() => {\n    let best: HeatmapCell | null = null;\n    let bestValue = 0;\n    rows.forEach((row, r) =>\n      row.values.forEach((value, c) => {\n        if (c < columns.length && value > bestValue) {\n          bestValue = value;\n          best = { row: r, column: c };\n        }\n      }),\n    );\n    return {\n      top: max ?? bestValue,\n      peak: best as HeatmapCell | null,\n    };\n  }, [rows, columns.length, max]);\n\n  const every = columnLabelEvery ?? Math.max(1, Math.ceil(columns.length / 12));\n  const steps = levels && levels > 1 ? levels : 0;\n\n  const withUnit = (value: number) =>\n    unit ? `${valueFormatter(value)} ${unit}` : valueFormatter(value);\n\n  const datumAt = (cell: HeatmapCell): HeatmapDatum | null => {\n    const row = rows[cell.row];\n    const column = columns[cell.column];\n    if (!row || column === undefined) return null;\n    return {\n      row: cell.row,\n      column: cell.column,\n      rowLabel: row.label,\n      columnLabel: column,\n      value: row.values[cell.column] ?? 0,\n    };\n  };\n\n  const activeDatum = active ? datumAt(active) : null;\n  const activeFraction = activeDatum\n    ? fractionFor(activeDatum.value, top, scale, levels)\n    : null;\n\n  // Which edges have more columns hidden behind them, so they can fade out.\n  const scrollRef = React.useRef<HTMLDivElement>(null);\n  const [edges, setEdges] = React.useState({ start: false, end: false });\n  const updateEdges = React.useCallback(() => {\n    const node = scrollRef.current;\n    if (!node) return;\n    const start = node.scrollLeft > 1;\n    const end = node.scrollLeft < node.scrollWidth - node.clientWidth - 1;\n    setEdges((current) =>\n      current.start === start && current.end === end ? current : { start, end },\n    );\n  }, []);\n  useIsomorphicLayoutEffect(() => {\n    const node = scrollRef.current;\n    if (!node) return;\n    updateEdges();\n    const observer = new ResizeObserver(updateEdges);\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [updateEdges, columns.length]);\n\n  // Measure the active cell so the readout can float above it, outside the scroll area.\n  const measure = React.useCallback(() => {\n    const root = rootRef.current;\n    if (!root || !active) {\n      setAnchor(null);\n      return;\n    }\n    const cell = gridRef.current?.querySelector<HTMLElement>(\n      `[data-row=\"${active.row}\"][data-column=\"${active.column}\"]`,\n    );\n    if (!cell) {\n      setAnchor(null);\n      return;\n    }\n    const box = root.getBoundingClientRect();\n    const rect = cell.getBoundingClientRect();\n    setAnchor({\n      x: rect.left + rect.width / 2 - box.left,\n      top: rect.top - box.top,\n      bottom: rect.bottom - box.top,\n    });\n  }, [active]);\n\n  useIsomorphicLayoutEffect(measure, [measure, rows, columns]);\n\n  // Keep the readout inside the chart's width and flip it below the cell near the top edge.\n  useIsomorphicLayoutEffect(() => {\n    const tip = tipRef.current;\n    const root = rootRef.current;\n    if (!tip || !root || !anchor) return;\n    const width = tip.offsetWidth;\n    const height = tip.offsetHeight;\n    const limit = root.clientWidth;\n    const left = Math.min(\n      Math.max(anchor.x - width / 2, 0),\n      Math.max(0, limit - width),\n    );\n    const below = anchor.top - height - 10 < -4;\n    const y = below ? anchor.bottom + 10 : anchor.top - height - 10;\n    tip.style.transform = `translate3d(${Math.round(left)}px, ${Math.round(y)}px, 0)`;\n    tip.dataset.side = below ? \"bottom\" : \"top\";\n  });\n\n  const focusCell = (cell: HeatmapCell) => {\n    const row = Math.min(Math.max(cell.row, 0), rows.length - 1);\n    const column = Math.min(Math.max(cell.column, 0), columns.length - 1);\n    setTabStop({ row, column });\n    gridRef.current\n      ?.querySelector<HTMLElement>(\n        `[data-row=\"${row}\"][data-column=\"${column}\"]`,\n      )\n      ?.focus();\n  };\n\n  const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    const target = event.target as HTMLElement;\n    if (target.dataset.slot !== \"heatmap-chart-cell\") return;\n    const row = Number(target.dataset.row);\n    const column = Number(target.dataset.column);\n    const next: Record<string, HeatmapCell | undefined> = {\n      ArrowRight: { row, column: column + 1 },\n      ArrowLeft: { row, column: column - 1 },\n      ArrowDown: { row: row + 1, column },\n      ArrowUp: { row: row - 1, column },\n      Home: { row, column: 0 },\n      End: { row, column: columns.length - 1 },\n    };\n    const cell = next[event.key];\n    if (!cell) return;\n    event.preventDefault();\n    focusCell(cell);\n  };\n\n  const stop = {\n    row: Math.min(tabStop.row, Math.max(0, rows.length - 1)),\n    column: Math.min(tabStop.column, Math.max(0, columns.length - 1)),\n  };\n\n  const tooltipBody = activeDatum ? (\n    renderTooltip ? (\n      renderTooltip(activeDatum)\n    ) : (\n      <div className=\"grid min-w-36 gap-1\">\n        <div className=\"flex items-center gap-2\">\n          <span\n            aria-hidden=\"true\"\n            className=\"size-2.5 shrink-0 rounded-[3px] inset-ring inset-ring-foreground/10\"\n            style={{\n              backgroundColor: fillFor(color, activeFraction ?? 0),\n            }}\n          />\n          <span className=\"font-medium text-foreground\">\n            {activeDatum.rowLabel}\n            <span className=\"px-1 text-muted-foreground\">·</span>\n            {activeDatum.columnLabel}\n          </span>\n          <span className=\"ml-auto pl-4 font-semibold text-foreground tabular-nums\">\n            {valueFormatter(activeDatum.value)}\n            {unit ? (\n              <span className=\"ml-1 font-normal text-muted-foreground\">\n                {unit}\n              </span>\n            ) : null}\n          </span>\n        </div>\n        <div className=\"pl-[18px] text-[11px] text-muted-foreground tabular-nums\">\n          {peak &&\n          peak.row === activeDatum.row &&\n          peak.column === activeDatum.column\n            ? \"Peak value\"\n            : `${percentOf(activeDatum.value, top)} of peak`}\n        </div>\n      </div>\n    )\n  ) : null;\n\n  const peakDatum = peak ? datumAt(peak) : null;\n  const legendGradient = steps\n    ? null\n    : `linear-gradient(to right, ${[0.02, 0.25, 0.5, 0.75, 1]\n        .map((t) => fillFor(color, t))\n        .join(\", \")})`;\n\n  return (\n    <div\n      ref={rootRef}\n      data-slot=\"heatmap-chart\"\n      data-active={active ? \"\" : undefined}\n      className={cn(\"relative flex min-w-0 flex-col gap-3 text-xs\", className)}\n      {...props}\n    >\n      <style href=\"overtrue-heatmap-chart\" precedence=\"default\">\n        {`@keyframes heatmap-cell-in{from{opacity:0;transform:scale(.55)}}`}\n      </style>\n      <div\n        ref={scrollRef}\n        // The padding keeps the active outline clear of the scroll clip; the margin cancels it out.\n        className=\"-m-2 overflow-x-auto overscroll-x-contain p-2 [scrollbar-color:color-mix(in_oklab,var(--color-foreground)_18%,transparent)_transparent] [scrollbar-width:thin]\"\n        tabIndex={0}\n        role=\"region\"\n        aria-label=\"Heatmap, scroll to see all columns\"\n        onScroll={() => {\n          measure();\n          updateEdges();\n        }}\n        style={{\n          maskImage:\n            edges.start || edges.end\n              ? `linear-gradient(to right, ${edges.start ? \"transparent, #000 24px\" : \"#000\"}, ${edges.end ? \"#000 calc(100% - 24px), transparent\" : \"#000\"})`\n              : undefined,\n        }}\n      >\n        <div\n          ref={gridRef}\n          role=\"group\"\n          aria-label=\"Heatmap\"\n          className=\"grid min-w-0 items-center\"\n          style={{\n            gap,\n            gridTemplateColumns: `${showRowLabels ? \"auto \" : \"\"}repeat(${columns.length}, minmax(${showColumnLabels ? \"1.125rem\" : \"1rem\"}, 1fr))`,\n          }}\n          onPointerLeave={() => setActive(null)}\n          onKeyDown={onKeyDown}\n          onBlur={(event) => {\n            // Keep the highlight while focus moves between cells so the readout does not flash.\n            if (!event.currentTarget.contains(event.relatedTarget as Node))\n              setActive(null);\n          }}\n        >\n          {rows.map((row, r) => (\n            <React.Fragment key={r}>\n              {showRowLabels ? (\n                <div\n                  data-slot=\"heatmap-chart-row-label\"\n                  data-active={active?.row === r}\n                  onPointerEnter={() => setActive(null)}\n                  className=\"flex items-center gap-1.5 pr-2 leading-none whitespace-nowrap text-muted-foreground transition-colors duration-150 data-[active=true]:font-medium data-[active=true]:text-foreground motion-reduce:transition-none\"\n                >\n                  {row.label}\n                </div>\n              ) : null}\n              {columns.map((column, c) => {\n                const value = row.values[c] ?? 0;\n                const datum: HeatmapDatum = {\n                  row: r,\n                  column: c,\n                  rowLabel: row.label,\n                  columnLabel: column,\n                  value,\n                };\n                const isActive = active?.row === r && active?.column === c;\n                const inCrosshair =\n                  active != null && (active.row === r || active.column === c);\n                const fraction = fractionFor(value, top, scale, levels);\n\n                return (\n                  <button\n                    key={c}\n                    type=\"button\"\n                    aria-label={`${withUnit(value)}, ${row.label} ${column}`}\n                    data-slot=\"heatmap-chart-cell\"\n                    data-row={r}\n                    data-column={c}\n                    data-active={isActive}\n                    data-empty={fraction === 0 || undefined}\n                    tabIndex={stop.row === r && stop.column === c ? 0 : -1}\n                    onPointerEnter={() => setActive({ row: r, column: c })}\n                    onFocus={() => {\n                      setTabStop({ row: r, column: c });\n                      setActive({ row: r, column: c });\n                    }}\n                    onClick={onCellClick ? () => onCellClick(datum) : undefined}\n                    className={cn(\n                      \"relative aspect-square w-full rounded-[4px] inset-ring inset-ring-foreground/6 outline-0 outline-offset-1 outline-transparent\",\n                      // In dark mode the strongest cells give off a little light of their own.\n                      \"dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.05),0_0_14px_-3px_var(--heatmap-glow)]\",\n                      \"transition-[background-color,opacity,outline-color] [transition-duration:450ms,150ms,150ms] [transition-timing-function:cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                      \"data-[active=true]:z-10 data-[active=true]:outline-2 data-[active=true]:outline-foreground/85\",\n                      \"focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-ring\",\n                      active != null && !inCrosshair && \"opacity-45\",\n                      !reduced &&\n                        \"motion-safe:animate-[heatmap-cell-in_640ms_cubic-bezier(0.22,1,0.36,1)_backwards]\",\n                      onCellClick ? \"cursor-pointer\" : \"cursor-default\",\n                    )}\n                    style={{\n                      maxHeight: maxCellHeight,\n                      backgroundColor: fillFor(color, fraction),\n                      [\"--heatmap-glow\" as string]:\n                        fraction > 0.55\n                          ? `color-mix(in oklab, ${color} ${Math.round((fraction - 0.55) * 110)}%, transparent)`\n                          : \"transparent\",\n                      animationDelay: reduced\n                        ? undefined\n                        : `${Math.round((r + c) * Math.min(28, 520 / Math.max(1, rows.length + columns.length)))}ms`,\n                    }}\n                  />\n                );\n              })}\n            </React.Fragment>\n          ))}\n\n          {showColumnLabels ? (\n            <>\n              {showRowLabels ? <div aria-hidden /> : null}\n              {columns.map((column, c) => {\n                const isActive = active?.column === c;\n                return (\n                  <div\n                    key={c}\n                    data-slot=\"heatmap-chart-column-label\"\n                    data-active={isActive}\n                    onPointerEnter={() => setActive(null)}\n                    className=\"min-w-0 pt-0.5 text-center text-[11px] leading-none whitespace-nowrap text-muted-foreground tabular-nums transition-colors duration-150 data-[active=true]:font-medium data-[active=true]:text-foreground motion-reduce:transition-none\"\n                  >\n                    {c % every === 0 || isActive ? column : \"\"}\n                  </div>\n                );\n              })}\n            </>\n          ) : null}\n        </div>\n      </div>\n\n      {anchor && tooltipBody !== null && tooltipBody !== undefined ? (\n        <div\n          ref={tipRef}\n          aria-hidden=\"true\"\n          data-slot=\"heatmap-chart-tooltip\"\n          className={cn(\n            \"pointer-events-none absolute top-0 left-0 z-20 w-max max-w-64 rounded-xl border border-border/70 bg-popover/90 px-3 py-2 text-xs text-popover-foreground shadow-xl backdrop-blur-md\",\n            !reduced &&\n              \"transition-transform duration-150 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n          )}\n        >\n          {tooltipBody}\n        </div>\n      ) : null}\n\n      {showLegend ? (\n        <div className=\"flex flex-wrap items-end justify-between gap-x-6 gap-y-2\">\n          <div\n            data-slot=\"heatmap-chart-summary\"\n            className=\"flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-muted-foreground\"\n          >\n            {peakDatum ? (\n              <>\n                <span>Peak</span>\n                <span className=\"font-medium text-foreground\">\n                  {peakDatum.rowLabel} · {peakDatum.columnLabel}\n                </span>\n                <span aria-hidden=\"true\" className=\"text-border\">\n                  /\n                </span>\n                <span>\n                  <span className=\"font-medium text-foreground tabular-nums\">\n                    {valueFormatter(peakDatum.value)}\n                  </span>\n                  {unit ? ` ${unit}` : null}\n                </span>\n              </>\n            ) : null}\n          </div>\n          <div\n            data-slot=\"heatmap-chart-legend\"\n            className=\"ml-auto grid grid-cols-[auto_7.5rem_auto] items-center gap-x-2 gap-y-1 text-muted-foreground\"\n          >\n            <span>Less</span>\n            <span className=\"relative block h-2\">\n              {steps ? (\n                <span className=\"flex h-full gap-0.5\">\n                  {Array.from({ length: steps }, (_, i) => (\n                    <span\n                      key={i}\n                      className=\"h-full flex-1 rounded-[2px] inset-ring inset-ring-foreground/6 first:rounded-l-full last:rounded-r-full\"\n                      style={{\n                        backgroundColor: fillFor(color, i / (steps - 1)),\n                      }}\n                    />\n                  ))}\n                </span>\n              ) : (\n                <span\n                  className=\"block h-full rounded-full inset-ring inset-ring-foreground/6\"\n                  style={{ backgroundImage: legendGradient ?? undefined }}\n                />\n              )}\n              <span\n                aria-hidden=\"true\"\n                data-slot=\"heatmap-chart-legend-marker\"\n                className={cn(\n                  \"absolute -top-[3px] -bottom-[3px] w-[3px] -translate-x-1/2 rounded-full bg-foreground shadow-[0_0_0_1.5px_var(--color-card)] transition-[left,opacity] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none\",\n                  activeFraction == null ? \"opacity-0\" : \"opacity-100\",\n                )}\n                style={{\n                  left: `${Math.min(98.5, Math.max(1.5, (activeFraction ?? 0) * 100))}%`,\n                }}\n              />\n            </span>\n            <span>More</span>\n            <span\n              aria-hidden=\"true\"\n              className=\"col-start-2 flex justify-between text-[11px] leading-none tabular-nums\"\n            >\n              <span>{valueFormatter(0)}</span>\n              <span>{valueFormatter(top)}</span>\n            </span>\n          </div>\n        </div>\n      ) : null}\n    </div>\n  );\n}\n\nexport { HeatmapChart };\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"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/heatmap-chart. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
