{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scatter-01",
  "description": "Pages plotted by load time and conversion rate, grouped by section, with a trend line and how strong the link is.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart-panel.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/scatter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/scatter/scatter-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartAxisProps,\n  chartGridProps,\n  chartLineCursor,\n  chartReferenceProps,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelLegend,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  ScatterTooltipContent,\n  describeCorrelation,\n  fitLine,\n  scatterPalette,\n} from '@/registry/components/dashboardblocks/scatter'\nimport {\n  formatNumber,\n  formatPercent,\n  formatPoints,\n  formatSigned,\n} from '@/registry/lib/dashboardblocks/format'\nimport {\n  CartesianGrid,\n  ReferenceLine,\n  ResponsiveContainer,\n  Scatter,\n  ScatterChart,\n  Tooltip,\n  XAxis,\n  YAxis,\n} from 'recharts'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface CorrelationPoint {\n  group: string\n  label: string\n  x: number\n  y: number\n}\n\ninterface Scatter1Props extends BlockStateProps {\n  description: string\n  groups: string[]\n  /** Leave out, or pass none, to show the empty state. */\n  points?: CorrelationPoint[]\n  title: string\n  x: { format: (value: number) => string; label: string }\n  y: {\n    format: (value: number) => string\n    formatChange?: (value: number) => string\n    label: string\n  }\n}\n\nconst noise = (index: number) =>\n  ((index * 2_654_435_761) % 4_294_967_296) / 4_294_967_296 - 0.5\n\nconst GROUPS = ['Marketing', 'Docs', 'Checkout']\n\nconst exampleProps: Scatter1Props = {\n  description:\n    'Each dot is a page: its median load time against its conversion rate, over the last 30 days.',\n  groups: GROUPS,\n  points: Array.from({ length: 42 }, (_, index) => {\n    const group = GROUPS[index % 3]\n    const load = 0.8 + ((index * 37) % 42) / 12 + noise(index + 7) * 0.4\n    const base = group === 'Checkout' ? 7.4 : group === 'Marketing' ? 5.2 : 3.6\n    return {\n      group,\n      label: `/${group.toLowerCase()}/${index + 1}`,\n      x: Math.round(load * 100) / 100,\n      y: Math.max(0.3, Math.round((base - load * 0.95 + noise(index) * 1.6) * 100) / 100),\n    }\n  }),\n  title: 'Load time vs conversion',\n  x: {\n    format: (value) => `${formatNumber(value, { minimumFractionDigits: 1 })} s`,\n    label: 'Load time',\n  },\n  y: {\n    format: (value) => formatPercent(value / 100, { minimumFractionDigits: 1 }),\n    formatChange: (value) => formatPoints(value, { minimumFractionDigits: 1 }),\n    label: 'Conversion',\n  },\n}\n\nconst formatCorrelation = (r: number) =>\n  `${r < 0 ? '−' : ''}${formatNumber(Math.abs(r), {\n    maximumFractionDigits: 2,\n    minimumFractionDigits: 2,\n  })}`\n\nconst Scatter1 = (props: Scatter1Props) => {\n  const { description, groups, points = [], errorMessage, status, title, x, y } = props\n  const state = getBlockState(status, points)\n  const fit = fitLine(points)\n  const xs = points.map((point) => point.x)\n  const minX = Math.min(...xs)\n  const maxX = Math.max(...xs)\n  const xTicks = Array.from({ length: Math.ceil(maxX) + 1 }, (_, index) => index)\n  const colorOf = (group: string) =>\n    scatterPalette[Math.max(0, groups.indexOf(group)) % scatterPalette.length]\n  const perUnit = fit.slope\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            <dl className='grid grid-cols-2 gap-x-6 gap-y-4 border-t pt-4'>\n              <div className='flex flex-col gap-1'>\n                <dt className='text-muted-foreground text-sm'>Correlation (r)</dt>\n                <dd>\n                  <KPIValue value={fit.r} format={formatCorrelation} />\n                </dd>\n                <BlockReady className='text-sm'>\n                  <dd className='text-muted-foreground text-sm first-letter:uppercase'>\n                    {describeCorrelation(fit.r)}\n                  </dd>\n                </BlockReady>\n              </div>\n              {state !== 'empty' && state !== 'error' && (\n                <div className='flex flex-col gap-1'>\n                  <dt className='text-muted-foreground text-sm'>Trend</dt>\n                  <dd>\n                    <KPIValue\n                      className='text-2xl'\n                      value={perUnit}\n                      format={(value) => formatSigned(value, y.formatChange ?? y.format)}\n                    />\n                  </dd>\n                  <BlockReady className='text-sm'>\n                    <dd className='text-muted-foreground text-sm'>\n                      {y.label.toLowerCase()} for each {x.format(1)} more{' '}\n                      {x.label.toLowerCase()}\n                    </dd>\n                  </BlockReady>\n                </div>\n              )}\n            </dl>\n            <ChartPanelLegend\n              items={[\n                ...groups.map((group) => ({\n                  color: colorOf(group),\n                  label: group,\n                  shape: 'rect' as const,\n                })),\n                {\n                  color: 'var(--color-muted-foreground)',\n                  label: 'Trend',\n                  shape: 'line' as const,\n                },\n              ]}\n            />\n            <ChartPanelFigure className='h-64'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <ScatterChart\n                  aria-label={`${title} chart`}\n                  margin={{ top: 8, right: 12, bottom: 16, left: 0 }}\n                >\n                  <CartesianGrid {...chartGridProps} />\n                  <XAxis\n                    {...chartAxisProps}\n                    dataKey='x'\n                    domain={[0, xTicks[xTicks.length - 1]]}\n                    label={{\n                      fill: 'var(--color-muted-foreground)',\n                      fontSize: 11,\n                      position: 'insideBottom',\n                      offset: -12,\n                      value: x.label,\n                    }}\n                    name={x.label}\n                    tickFormatter={x.format}\n                    ticks={xTicks}\n                    type='number'\n                  />\n                  <YAxis\n                    {...chartAxisProps}\n                    dataKey='y'\n                    domain={[0, 'auto']}\n                    name={y.label}\n                    tickFormatter={y.format}\n                    type='number'\n                    width={chartValueAxisWidth}\n                  />\n                  <ReferenceLine\n                    {...chartReferenceProps}\n                    ifOverflow='hidden'\n                    segment={[\n                      { x: minX, y: fit.intercept + fit.slope * minX },\n                      { x: maxX, y: fit.intercept + fit.slope * maxX },\n                    ]}\n                    strokeWidth={1.5}\n                  />\n                  <Tooltip\n                    content={({ active, payload }) => {\n                      const point = payload?.[0]?.payload as CorrelationPoint | undefined\n                      if (!active || !point) return null\n                      return (\n                        <ScatterTooltipContent\n                          color={colorOf(point.group)}\n                          rows={[\n                            { label: x.label, value: x.format(point.x) },\n                            { label: y.label, value: y.format(point.y) },\n                          ]}\n                          title={point.label}\n                        />\n                      )\n                    }}\n                    cursor={chartLineCursor}\n                  />\n                  {groups.map((group) => (\n                    <Scatter\n                      key={group}\n                      data={points.filter((point) => point.group === group)}\n                      fill={colorOf(group)}\n                      fillOpacity={0.8}\n                      name={group}\n                      stroke='var(--color-background)'\n                      strokeWidth={1.5}\n                    />\n                  ))}\n                </ScatterChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}. Correlation r = ${formatCorrelation(fit.r)}.`}\n              columns={[\n                { key: 'label', label: 'Page' },\n                { key: 'group', label: 'Group' },\n                { format: x.format, key: 'x', label: x.label },\n                { format: y.format, key: 'y', label: y.label },\n              ]}\n              rows={points}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Scatter1,\n  exampleProps as scatter1ExampleProps,\n  type CorrelationPoint,\n  type Scatter1Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/scatter/scatter-01.tsx"
    }
  ],
  "meta": {
    "shows": "Pages plotted by load time and conversion rate, grouped by section, with a trend line and how strong the link is.",
    "size": "half",
    "usedWith": [
      "data-table-03",
      "distribution-01"
    ],
    "component": "Scatter1",
    "props": "{ description: string; groups: string[]; points?: { group: string; label: string; x: number; y: number }[]; title: string; x: { format: (value: number) => string; label: string }; y: { format: (value: number) => string; formatChange?: (value: number) => string; label: string }; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
