{"name":"comparison","type":"registry:ui","files":[{"path":"comparison.ts","type":"registry:ui","content":"import { escapeHtml } from \"@/components/ui/charts/tooltip\";\nimport type { ChartConfig } from \"@/components/ui/charts/chart\";\n\n/**\n * Period-over-period comparison. A series names a second data key holding\n * the same measure for an earlier period; the chart draws it as a quiet\n * ghost of the series and the tooltip shows the earlier value and the change.\n */\n\nexport const COMPARE_PREFIX = \"__compare-\";\n/** A finer dash than the dashed stroke variant, so the ghost never reads as a forecast. */\nexport const COMPARE_DASH: [number, number] = [2, 3];\nexport const COMPARE_OPACITY = 0.45;\n\nexport function compareSeriesId(key: string) {\n  return `${COMPARE_PREFIX}${key}`;\n}\n\nexport function readCompareValue(row: Record<string, unknown> | undefined, key: string) {\n  const raw = row?.[key];\n  if (raw === null || raw === undefined || raw === \"\") return null;\n  const value = Number(raw);\n  return Number.isFinite(value) ? value : null;\n}\n\nexport function compareValues(\n  data: Record<string, unknown>[],\n  key: string,\n): (number | null)[] {\n  return data.map((row) => readCompareValue(row, key));\n}\n\n/** Change as a signed percentage, or null when it has no meaning. */\nexport function percentChange(current: number | null, previous: number | null) {\n  if (current === null || previous === null || previous === 0) return null;\n  return ((current - previous) / Math.abs(previous)) * 100;\n}\n\nexport function formatChange(change: number | null) {\n  if (change === null || !Number.isFinite(change)) return \"—\";\n  const rounded = Math.abs(change) >= 10 ? change.toFixed(0) : change.toFixed(1);\n  if (Number(rounded) === 0) return \"0%\";\n  return `${change > 0 ? \"+\" : \"−\"}${rounded.replace(\"-\", \"\")}%`;\n}\n\nexport function compareLabel(config: ChartConfig, compareKey: string) {\n  const label = config[compareKey]?.label;\n  return typeof label === \"string\" ? label : \"Previous\";\n}\n\n/**\n * The tooltip line under a series row: the earlier period's label and value,\n * then the change. The change stays in the tooltip's own ink; the arrow and\n * sign carry direction, so the row does not lean on red and green.\n */\nexport function comparisonDetailHtml(params: {\n  current: number | null;\n  previous: number | null;\n  label: string;\n  format?: (value: number) => string;\n  dimmed?: string;\n}): string {\n  const { current, previous, label, dimmed = \"\" } = params;\n  const format = params.format ?? ((value: number) => value.toLocaleString());\n  const change = percentChange(current, previous);\n  const arrow = change === null || Math.abs(change) < 0.05 ? \"\" : change > 0 ? \"↑ \" : \"↓ \";\n  const previousText = previous === null ? \"—\" : format(previous);\n  return `<div class=\"flex w-full items-center justify-between gap-4 pl-[18px] leading-none${dimmed}\">\n          <span class=\"text-muted-foreground\">${escapeHtml(label)}</span>\n          <span class=\"flex items-center gap-1.5 font-mono tabular-nums\">\n            <span class=\"text-muted-foreground\">${escapeHtml(previousText)}</span>\n            <span class=\"text-foreground font-medium\">${escapeHtml(arrow + formatChange(change))}</span>\n          </span>\n        </div>`;\n}\n","target":"components/ui/comparison.ts"}],"registryDependencies":["https://www.honestui.com/r/chart.json","https://www.honestui.com/r/tooltip.json"]}