{
  "title": "Calendar Heatmap",
  "description": "12-week matrix cell calendar heatmap displaying daily observations.",
  "name": "tanstack-charts-calendar-heatmap",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/heatmap/calendar-heatmap.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, cell, defineChart } 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 { scaleBand, scaleThreshold } from \"d3-scale\";\nimport { Calendar } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface CalendarCellDatum {\n    week: number;\n    day: string;\n    precipitation: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nconst weekdays = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\n\nfunction generateDemoData(): CalendarCellDatum[] {\n    const results: CalendarCellDatum[] = [];\n    for (let w = 0; w < 12; w++) {\n        for (let d = 0; d < 7; d++) {\n            const val = Math.max(0, Math.sin(w * 0.5 + d * 0.8) * 12 + (w % 3) * 2 - 2);\n            results.push({ week: w, day: weekdays[d], precipitation: val });\n        }\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 CalendarCellDatum;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: `Week ${d.week + 1} (${d.day})`,\n        rows: [\n            {\n                label: \"Precipitation\",\n                value: `${d.precipitation.toFixed(1)} mm`,\n                color: \"var(--chart-1)\",\n            },\n        ],\n    };\n}\n\nexport function CalendarHeatmap() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        cell(data, {\n                            id: \"calendar-cells\",\n                            x: \"week\",\n                            y: \"day\",\n                            color: \"precipitation\",\n                            inset: 1.5,\n                            radius: 3,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: () => scaleBand<number>().paddingInner(0.06).paddingOuter(0.03),\n                            axis: {\n                                line: false,\n                                label: \"Week\",\n                                ticks: {\n                                    size: 0,\n                                    format: (v: number) => `W${v + 1}`,\n                                },\n                            },\n                        },\n                        y: {\n                            scale: () => scaleBand<string>().domain(weekdays).paddingInner(0.06).paddingOuter(0.03),\n                            axis: {\n                                line: false,\n                                ticks: { size: 0 },\n                            },\n                        },\n                    },\n                    color: {\n                        scale: scaleThreshold<number, string>,\n                        domain: [3, 7, 12],\n                        range: [\"var(--chart-5)\", \"var(--chart-4)\", \"var(--chart-2)\", \"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        [data],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>Daily Rainfall Calendar Matrix</CardTitle>\n                <CardDescription>12-week calendar grid displaying daily rainfall intensity</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=\"Daily Rainfall Calendar Matrix 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                    Mid-week days show peak precipitation concentration{\" \"}\n                    <Calendar className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Cells map day-of-week rows against sequential weekly columns\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default CalendarHeatmap;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. 12-week matrix cell calendar heatmap displaying daily observations. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "heatmap"
    ]
  }
}