{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scatter",
  "title": "Scatter",
  "description": "Primitives for scatter plots and matrices: a least-squares line with the correlation coefficient described in words, a median, categorical colours in a fixed order, point tooltip content, and risk levels from likelihood and impact with a labelled swatch.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/chart.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/scatter.tsx",
      "content": "'use client'\n\nimport {\n  ChartTooltipFrame,\n  ChartTooltipItem,\n} from '@/registry/components/dashboardblocks/chart'\nimport type { ReactNode } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ninterface ScatterPoint {\n  x: number\n  y: number\n}\n\ninterface LineFit {\n  intercept: number\n  r: number\n  slope: number\n}\n\nfunction fitLine(points: ScatterPoint[]): LineFit {\n  const n = points.length\n  if (n < 2) return { intercept: points[0]?.y ?? 0, r: 0, slope: 0 }\n  const meanX = points.reduce((sum, point) => sum + point.x, 0) / n\n  const meanY = points.reduce((sum, point) => sum + point.y, 0) / n\n  let sxx = 0\n  let syy = 0\n  let sxy = 0\n  for (const point of points) {\n    sxx += (point.x - meanX) ** 2\n    syy += (point.y - meanY) ** 2\n    sxy += (point.x - meanX) * (point.y - meanY)\n  }\n  const slope = sxx > 0 ? sxy / sxx : 0\n  return {\n    intercept: meanY - slope * meanX,\n    r: sxx > 0 && syy > 0 ? sxy / Math.sqrt(sxx * syy) : 0,\n    slope,\n  }\n}\n\nfunction describeCorrelation(r: number) {\n  const size = Math.abs(r)\n  const strength =\n    size >= 0.7 ? 'strong' : size >= 0.4 ? 'moderate' : size >= 0.2 ? 'weak' : 'no clear'\n  if (strength === 'no clear') return 'no clear relationship'\n  return `${strength} ${r > 0 ? 'positive' : 'negative'}`\n}\n\nfunction getMedian(values: number[]) {\n  if (values.length === 0) return 0\n  const sorted = [...values].sort((a, b) => a - b)\n  const middle = Math.floor(sorted.length / 2)\n  return sorted.length % 2 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2\n}\n\nconst scatterPalette = [\n  'var(--color-chart-2)',\n  'var(--color-chart-3)',\n  'var(--color-chart-4)',\n  'var(--color-chart-5)',\n  'var(--color-chart-1)',\n]\n\ninterface ScatterTooltipRow {\n  label: string\n  value: string\n}\n\nfunction ScatterTooltipContent({\n  color,\n  rows,\n  title,\n}: {\n  color?: string\n  rows: ScatterTooltipRow[]\n  title: ReactNode\n}) {\n  return (\n    <ChartTooltipFrame>\n      <span className='flex items-center gap-1.5 font-medium'>\n        {color && (\n          <span\n            aria-hidden\n            className='size-2.5 shrink-0 rounded-full'\n            style={{ backgroundColor: color }}\n          />\n        )}\n        {title}\n      </span>\n      {rows.map((row) => (\n        <ChartTooltipItem key={row.label} name={row.label} value={row.value} />\n      ))}\n    </ChartTooltipFrame>\n  )\n}\n\ntype RiskLevel = 'low' | 'medium' | 'high' | 'critical'\n\nfunction getRiskLevel(likelihood: number, impact: number): RiskLevel {\n  const score = likelihood * impact\n  if (score >= 15) return 'critical'\n  if (score >= 8) return 'high'\n  if (score >= 4) return 'medium'\n  return 'low'\n}\n\nconst riskLevelConfig: Record<RiskLevel, { cell: string; label: string; text: string }> =\n  {\n    critical: {\n      cell: 'bg-red-500/25 dark:bg-red-500/30',\n      label: 'Critical',\n      text: 'text-red-700 dark:text-red-400',\n    },\n    high: {\n      cell: 'bg-orange-400/25 dark:bg-orange-500/25',\n      label: 'High',\n      text: 'text-orange-700 dark:text-orange-400',\n    },\n    low: {\n      cell: 'bg-emerald-500/15 dark:bg-emerald-500/15',\n      label: 'Low',\n      text: 'text-emerald-700 dark:text-emerald-400',\n    },\n    medium: {\n      cell: 'bg-amber-400/20 dark:bg-amber-400/20',\n      label: 'Medium',\n      text: 'text-amber-700 dark:text-amber-400',\n    },\n  }\n\nfunction RiskLevelLabel({ className, level }: { className?: string; level: RiskLevel }) {\n  const config = riskLevelConfig[level]\n  return (\n    <span\n      className={cn(\n        'inline-flex items-center gap-1.5 text-xs font-medium whitespace-nowrap',\n        config.text,\n        className,\n      )}\n    >\n      <span aria-hidden className={cn('size-2.5 rounded-[3px]', config.cell)} />\n      {config.label}\n    </span>\n  )\n}\n\nexport {\n  RiskLevelLabel,\n  ScatterTooltipContent,\n  describeCorrelation,\n  fitLine,\n  getMedian,\n  getRiskLevel,\n  riskLevelConfig,\n  scatterPalette,\n}\n\nexport type { LineFit, RiskLevel, ScatterPoint, ScatterTooltipRow }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/scatter.tsx"
    }
  ],
  "type": "registry:component"
}
