{
  "title": "Contour Topography",
  "description": "Topographic vector field isoline contours indicating spatial wind speed gradients.",
  "name": "tanstack-charts-contour-topography",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/area/contour-topography.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, dot } from \"@tanstack/charts\";\nimport { motion } from \"@tanstack/charts/motion\";\nimport { contour } from \"@tanstack/charts/spatial/contour\";\nimport { tooltip } from \"@tanstack/charts/tooltip\";\nimport { Chart } from \"@tanstack/react-charts/core\";\nimport { useMemo } from \"react\";\n\nimport { scaleLinear, scaleThreshold } from \"d3-scale\";\nimport { Compass } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface GridCell {\n    u: number;\n    v: number;\n    x: number;\n    y: number;\n    val: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nconst contourThresholds = [2, 5, 8, 11, 14];\n\nfunction generateDemoGrid() {\n    const width = 20;\n    const height = 15;\n    const data: GridCell[] = [];\n\n    for (let j = 0; j < height; j++) {\n        for (let i = 0; i < width; i++) {\n            const u = Math.sin(i * 0.4) * 8 + 6;\n            const v = Math.cos(j * 0.5) * 8 + 6;\n            const val = Math.hypot(u, v);\n            data.push({ u, v, x: i, y: j, val });\n        }\n    }\n    return { width, height, data };\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const d = points[0].datum as GridCell;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: `Grid Location (${d.x}, ${d.y})`,\n        rows: [\n            {\n                label: \"Wind Velocity\",\n                value: `${d.val.toFixed(1)} m/s`,\n                color: \"var(--chart-1)\",\n            },\n            {\n                label: \"Vector (U, V)\",\n                value: `${d.u.toFixed(1)}, ${d.v.toFixed(1)} m/s`,\n                color: \"var(--muted-foreground)\",\n            },\n        ],\n    };\n}\n\nexport function ContourTopography() {\n    const grid = useMemo(() => generateDemoGrid(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        contour(grid.data, {\n                            id: \"contour-isobands\",\n                            width: grid.width,\n                            height: grid.height,\n                            value: (row: GridCell) => Math.hypot(row.u, row.v),\n                            thresholds: contourThresholds,\n                            stroke: \"var(--background)\",\n                            strokeWidth: 0.75,\n                        }),\n                        dot(grid.data, {\n                            id: \"contour-grid-dots\",\n                            x: \"x\",\n                            y: \"y\",\n                            r: 2,\n                            fill: \"var(--foreground)\",\n                            fillOpacity: 0.25,\n                            states: [\n                                {\n                                    when: { focus: \"primary\" },\n                                    style: { r: 5, fill: \"var(--chart-1)\", fillOpacity: 1 },\n                                },\n                            ],\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleLinear().domain([0, grid.width]),\n                            axis: false,\n                        },\n                        y: {\n                            scale: scaleLinear().domain([0, grid.height]),\n                            axis: false,\n                        },\n                    },\n                    color: {\n                        scale: scaleThreshold<number, string>,\n                        domain: contourThresholds.slice(1),\n                        range: [\n                            \"var(--chart-5)\",\n                            \"var(--chart-4)\",\n                            \"var(--chart-3)\",\n                            \"var(--chart-2)\",\n                            \"var(--chart-1)\",\n                        ],\n                    },\n                    margin: { top: 20, right: 24, bottom: 24, left: 24 },\n                    theme: {\n                        foreground: \"var(--muted-foreground)\",\n                        grid: \"transparent\",\n                        background: \"transparent\",\n                    },\n                },\n                {\n                    focus: \"nearest\",\n                    keyboard: true,\n                    tooltip: {\n                        use: tooltip,\n                        className:\n                            \"font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs pointer-events-none transition-all duration-75\",\n                        anchor: \"pointer\",\n                        placement: \"auto\",\n                        content: (points) => shadcnTooltipContent(points),\n                    },\n                },\n            ),\n        [grid],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>Topographic Wind Velocity Contours</CardTitle>\n                <CardDescription>\n                    Filled vector field isoline contours indicating spatial wind speed gradients\n                </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=\"Topographic Wind Velocity Contours 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                    High velocity core (dark blue) centers over central grid origin{\" \"}\n                    <Compass className=\"h-4 w-4 text-blue-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Hover over grid observation points to view localized wind speed vectors\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default ContourTopography;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Topographic vector field isoline contours indicating spatial wind speed gradients. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack"
    ]
  }
}