{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scatter-02",
  "description": "Features plotted by usage and satisfaction, split into four labelled quadrants with each point named.",
  "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/scatter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/scatter/scatter-02.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  chartAxisProps,\n  chartGridProps,\n  chartReferenceLabel,\n  chartReferenceProps,\n  chartValueAxisWidth,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  ChartPanelFigure,\n  ChartPanelTable,\n} from '@/registry/components/dashboardblocks/chart-panel'\nimport {\n  ScatterTooltipContent,\n  getMedian,\n} from '@/registry/components/dashboardblocks/scatter'\nimport { formatNumber, formatPercent } from '@/registry/lib/dashboardblocks/format'\nimport {\n  CartesianGrid,\n  LabelList,\n  ReferenceArea,\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 QuadrantItem {\n  label: string\n  x: number\n  y: number\n}\n\ninterface Scatter2Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  items?: QuadrantItem[]\n  /** Names for the four quadrants: top left, top right, bottom left, bottom right. */\n  quadrants: [string, string, string, string]\n  title: string\n  split?: { x: number; y: number }\n  x: {\n    domain: [number, number]\n    format: (value: number) => string\n    label: string\n    ticks?: number[]\n  }\n  y: {\n    domain: [number, number]\n    format: (value: number) => string\n    label: string\n    ticks?: number[]\n  }\n}\n\nconst exampleProps: Scatter2Props = {\n  description:\n    'How many accounts use each feature, against how satisfied they are with it.',\n  items: [\n    { label: 'Dashboards', x: 86, y: 4.4 },\n    { label: 'Alerts', x: 71, y: 4.1 },\n    { label: 'Exports', x: 64, y: 3.2 },\n    { label: 'API', x: 38, y: 4.5 },\n    { label: 'Scheduled reports', x: 29, y: 4.2 },\n    { label: 'Sharing', x: 57, y: 2.9 },\n    { label: 'Mobile app', x: 22, y: 2.7 },\n    { label: 'Annotations', x: 14, y: 3.6 },\n    { label: 'Integrations', x: 46, y: 3.9 },\n  ],\n  quadrants: ['Promote', 'Protect', 'Rethink', 'Fix'],\n  title: 'Feature priorities',\n  x: {\n    domain: [0, 100],\n    format: (value) => formatPercent(value / 100, { maximumFractionDigits: 0 }),\n    label: 'Usage',\n    ticks: [0, 25, 50, 75, 100],\n  },\n  y: {\n    domain: [2, 5],\n    format: (value) => formatNumber(value, { minimumFractionDigits: 1 }),\n    label: 'Satisfaction',\n    ticks: [2, 3, 4, 5],\n  },\n}\n\nconst Scatter2 = (props: Scatter2Props) => {\n  const { description, items = [], quadrants, errorMessage, status, title, x, y } = props\n  const state = getBlockState(status, items)\n  const split = props.split ?? {\n    x: getMedian(items.map((item) => item.x)),\n    y: getMedian(items.map((item) => item.y)),\n  }\n  const quadrantOf = (item: QuadrantItem) =>\n    quadrants[(item.y >= split.y ? 0 : 2) + (item.x >= split.x ? 1 : 0)]\n  const label = (\n    value: string,\n    position:\n      | 'insideTopLeft'\n      | 'insideTopRight'\n      | 'insideBottomLeft'\n      | 'insideBottomRight',\n  ) => ({ ...chartReferenceLabel, fontWeight: 500, position, value })\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            {state ? (\n              <div className='border-t pt-4'>\n                <BlockStateText className='text-sm' />\n              </div>\n            ) : (\n              <p className='text-muted-foreground border-t pt-4 text-sm'>\n                {`Split at ${props.split ? '' : 'the medians, '}${x.format(split.x)} ${x.label.toLowerCase()} and ${y.format(split.y)} ${y.label.toLowerCase()}.`}\n              </p>\n            )}\n            <ChartPanelFigure className='h-80'>\n              <ResponsiveContainer width='100%' height='100%'>\n                <ScatterChart\n                  aria-label={`${title} chart`}\n                  margin={{ top: 8, right: 16, bottom: 16, left: 0 }}\n                >\n                  <CartesianGrid {...chartGridProps} />\n                  <ReferenceArea\n                    fill='var(--color-muted)'\n                    fillOpacity={0.5}\n                    label={label(quadrants[1], 'insideTopRight')}\n                    x1={split.x}\n                    x2={x.domain[1]}\n                    y1={split.y}\n                    y2={y.domain[1]}\n                  />\n                  <ReferenceArea\n                    fillOpacity={0}\n                    label={label(quadrants[0], 'insideTopLeft')}\n                    x1={x.domain[0]}\n                    x2={split.x}\n                    y1={split.y}\n                    y2={y.domain[1]}\n                  />\n                  <ReferenceArea\n                    fillOpacity={0}\n                    label={label(quadrants[2], 'insideBottomLeft')}\n                    x1={x.domain[0]}\n                    x2={split.x}\n                    y1={y.domain[0]}\n                    y2={split.y}\n                  />\n                  <ReferenceArea\n                    fillOpacity={0}\n                    label={label(quadrants[3], 'insideBottomRight')}\n                    x1={split.x}\n                    x2={x.domain[1]}\n                    y1={y.domain[0]}\n                    y2={split.y}\n                  />\n                  <ReferenceLine {...chartReferenceProps} x={split.x} />\n                  <ReferenceLine {...chartReferenceProps} y={split.y} />\n                  <XAxis\n                    {...chartAxisProps}\n                    dataKey='x'\n                    domain={x.domain}\n                    label={{\n                      fill: 'var(--color-muted-foreground)',\n                      fontSize: 11,\n                      offset: -12,\n                      position: 'insideBottom',\n                      value: `${x.label} →`,\n                    }}\n                    name={x.label}\n                    tickFormatter={x.format}\n                    ticks={x.ticks}\n                    type='number'\n                  />\n                  <YAxis\n                    {...chartAxisProps}\n                    dataKey='y'\n                    domain={y.domain}\n                    name={y.label}\n                    tickFormatter={y.format}\n                    ticks={y.ticks}\n                    type='number'\n                    width={chartValueAxisWidth}\n                  />\n                  <Tooltip\n                    content={({ active, payload }) => {\n                      const item = payload?.[0]?.payload as QuadrantItem | undefined\n                      if (!active || !item) return null\n                      return (\n                        <ScatterTooltipContent\n                          color='var(--color-chart-2)'\n                          rows={[\n                            { label: x.label, value: x.format(item.x) },\n                            { label: y.label, value: y.format(item.y) },\n                            { label: 'Quadrant', value: quadrantOf(item) },\n                          ]}\n                          title={item.label}\n                        />\n                      )\n                    }}\n                    cursor={false}\n                  />\n                  <Scatter\n                    data={items}\n                    fill='var(--color-chart-2)'\n                    stroke='var(--color-background)'\n                    strokeWidth={2}\n                  >\n                    <LabelList\n                      dataKey='label'\n                      fill='var(--color-foreground)'\n                      fontSize={11}\n                      offset={8}\n                      position='top'\n                    />\n                  </Scatter>\n                </ScatterChart>\n              </ResponsiveContainer>\n            </ChartPanelFigure>\n            <ChartPanelTable\n              caption={`${title}: ${description}.`}\n              columns={[\n                { key: 'label', label: 'Feature' },\n                { format: x.format, key: 'x', label: x.label },\n                { format: y.format, key: 'y', label: y.label },\n                { key: 'quadrant', label: 'Quadrant' },\n              ]}\n              rows={items.map((item) => ({ ...item, quadrant: quadrantOf(item) }))}\n            />\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Scatter2,\n  exampleProps as scatter2ExampleProps,\n  type QuadrantItem,\n  type Scatter2Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/scatter/scatter-02.tsx"
    }
  ],
  "meta": {
    "shows": "Features plotted by usage and satisfaction, split into four labelled quadrants with each point named.",
    "size": "half",
    "usedWith": [
      "leaderboard-01",
      "data-table-02"
    ],
    "component": "Scatter2",
    "props": "{ description: string; items?: { label: string; x: number; y: number }[]; quadrants: [string, string, string, string]; title: string; split?: { x: number; y: number }; x: { domain: [number, number]; format: (value: number) => string; label: string; ticks?: number[] }; y: { domain: [number, number]; format: (value: number) => string; label: string; ticks?: number[] }; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
