{
  "title": "GeoJSON Map",
  "description": "Spatial geographic boundary paths mapping data values to map regions.",
  "name": "tanstack-charts-geojson-map",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-geo"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/area/geojson-map.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart } from \"@tanstack/charts\";\nimport { geoShape } from \"@tanstack/charts/geo\";\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 { geoIdentity } from \"d3-geo\";\nimport { Map } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface GeoFeature {\n    type: \"Feature\";\n    properties: {\n        id: string;\n        name: string;\n        type: string;\n    };\n    geometry: {\n        type: \"Polygon\";\n        coordinates: number[][][];\n    };\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): { type: \"FeatureCollection\"; features: GeoFeature[] } {\n    const features: GeoFeature[] = [\n        {\n            type: \"Feature\",\n            properties: { id: \"room-1\", name: \"Main Hall\", type: \"reception\" },\n            geometry: {\n                type: \"Polygon\",\n                coordinates: [\n                    [\n                        [10, 10],\n                        [50, 10],\n                        [50, 40],\n                        [10, 40],\n                        [10, 10],\n                    ],\n                ],\n            },\n        },\n        {\n            type: \"Feature\",\n            properties: { id: \"room-2\", name: \"Conference Room A\", type: \"meeting\" },\n            geometry: {\n                type: \"Polygon\",\n                coordinates: [\n                    [\n                        [55, 10],\n                        [90, 10],\n                        [90, 40],\n                        [55, 40],\n                        [55, 10],\n                    ],\n                ],\n            },\n        },\n        {\n            type: \"Feature\",\n            properties: { id: \"room-3\", name: \"Executive Suite\", type: \"office\" },\n            geometry: {\n                type: \"Polygon\",\n                coordinates: [\n                    [\n                        [10, 45],\n                        [45, 45],\n                        [45, 80],\n                        [10, 80],\n                        [10, 45],\n                    ],\n                ],\n            },\n        },\n        {\n            type: \"Feature\",\n            properties: { id: \"room-4\", name: \"Engineering Hub\", type: \"workspace\" },\n            geometry: {\n                type: \"Polygon\",\n                coordinates: [\n                    [\n                        [50, 45],\n                        [90, 45],\n                        [90, 80],\n                        [50, 80],\n                        [50, 45],\n                    ],\n                ],\n            },\n        },\n    ];\n\n    return { type: \"FeatureCollection\", features };\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const feature = points[0].datum as GeoFeature;\n    if (!feature || !feature.properties) return { title: \"\", rows: [] };\n    return {\n        title: feature.properties.name,\n        rows: [\n            { label: \"Zone Type\", value: feature.properties.type, color: \"var(--chart-1)\" },\n            { label: \"ID\", value: feature.properties.id, color: \"var(--foreground)\" },\n        ],\n    };\n}\n\nexport function GeojsonMap() {\n    const geoData = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        geoShape(geoData.features, {\n                            key: (feature: GeoFeature) => feature.properties.id,\n                            projection: {\n                                type: geoIdentity,\n                                fit: geoData,\n                            },\n                            fill: \"var(--chart-1)\",\n                            fillOpacity: 0.25,\n                            stroke: \"var(--chart-1)\",\n                            strokeWidth: 2,\n                        }),\n                    ],\n                    scales: {\n                        x: null,\n                        y: null,\n                    },\n                    margin: 16,\n                    theme: {\n                        foreground: \"var(--muted-foreground)\",\n                        grid: \"var(--border)\",\n                        background: \"transparent\",\n                    },\n                },\n                {\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\",\n                        anchor: \"pointer\",\n                        placement: \"auto\",\n                        content: (points) => shadcnTooltipContent(points),\n                    },\n                },\n            ),\n        [geoData],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>GeoJSON Architectural Plan</CardTitle>\n                <CardDescription>Spatial polygon projection mapping for venue floor layouts</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=\"GeoJSON Architectural Plan 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                    4 spatial zones rendered with d3 identity projection <Map className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Custom GeoJSON feature collection mapped to SVG paths\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default GeojsonMap;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Spatial geographic boundary paths mapping data values to map regions. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack"
    ]
  }
}