{
  "title": "Quantitative Binned Heatmap",
  "description": "Two-dimensional quantitative binned density heatmap grid.",
  "name": "tanstack-charts-quantitative-binned-heatmap",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/heatmap/quantitative-binned-heatmap.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, binXY, defineChart, rect } from \"@tanstack/charts\";\nimport { motion } from \"@tanstack/charts/motion\";\nimport { tooltip } from \"@tanstack/charts/tooltip\";\nimport { Chart } from \"@tanstack/react-charts/core\";\nimport { useMemo } from \"react\";\n\nimport { scaleLinear, scaleSequential } from \"d3-scale\";\nimport { Grid } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface BinnedDatum {\n    culmen_length_mm: number;\n    culmen_depth_mm: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): BinnedDatum[] {\n    const results: BinnedDatum[] = [];\n    for (let i = 0; i < 120; i++) {\n        const length = 32 + (Math.sin(i * 0.4) + 1) * 12 + (i % 5);\n        const depth = 13 + (Math.cos(i * 0.5) + 1) * 4 + (i % 3);\n        results.push({ culmen_length_mm: length, culmen_depth_mm: depth });\n    }\n    return results;\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const d = points[0].datum as any;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: `Length ${d.x1}–${d.x2}mm · Depth ${d.y1}–${d.y2}mm`,\n        rows: [{ label: \"Sample Density\", value: `${d.count} observations`, color: \"var(--chart-1)\" }],\n    };\n}\n\nexport function QuantitativeBinnedHeatmap() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const cells = useMemo(() => {\n        const xBoundaries = [30, 34, 38, 42, 46, 50, 54, 58, 62];\n        const yBoundaries = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22];\n        return binXY(data, {\n            x: \"culmen_length_mm\",\n            y: \"culmen_depth_mm\",\n            xThresholds: xBoundaries,\n            yThresholds: yBoundaries,\n            outputs: { count: { reduce: \"count\" } },\n        }).filter((cell) => cell.count > 0);\n    }, [data]);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        rect(cells, {\n                            id: \"heatmap-cells\",\n                            x1: \"x1\",\n                            x2: \"x2\",\n                            y1: \"y1\",\n                            y2: \"y2\",\n                            color: \"count\",\n                            inset: 0.75,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleLinear().domain([30, 62]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Bill Length (mm)\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                        y: {\n                            scale: scaleLinear().domain([12, 22]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Bill Depth (mm)\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                    },\n                    color: {\n                        scale: scaleSequential,\n                        range: [\"var(--chart-5)\", \"var(--chart-1)\"],\n                    },\n                    margin: { top: 24, right: 24, bottom: 32, left: 45 },\n                    theme: {\n                        foreground: \"var(--muted-foreground)\",\n                        grid: \"var(--border)\",\n                        background: \"transparent\",\n                    },\n                },\n                {\n                    focus: \"group-x\",\n                    tooltip: {\n                        use: tooltip,\n                        className:\n                            \"font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs\",\n                        anchor: \"group-center\",\n                        placement: \"auto\",\n                        content: (points) => shadcnTooltipContent(points),\n                    },\n                },\n            ),\n        [cells],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>2D Binned Density Heatmap</CardTitle>\n                <CardDescription>Two-dimensional histogram binning quantitative bill length vs depth</CardDescription>\n            </CardHeader>\n            <CardContent>\n                <div className=\"h-[250px] w-full\">\n                    <Chart\n                        definition={definition}\n                        renderer={motionRenderer}\n                        height={250}\n                        ariaLabel=\"2D Binned Density Heatmap Chart\"\n                    />\n                </div>\n            </CardContent>\n            <CardFooter className=\"flex-col items-start gap-2 text-sm\">\n                <div className=\"flex items-center gap-2 leading-none font-medium\">\n                    Highest point density concentrates around 42mm x 16mm <Grid className=\"h-4 w-4 text-blue-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Color intensity scales sequentially based on observation count in each bin\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default QuantitativeBinnedHeatmap;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Two-dimensional quantitative binned density heatmap grid. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "heatmap"
    ]
  }
}