{
  "title": "Delaunay Network",
  "description": "2D Delaunay spatial triangulation mesh network.",
  "name": "tanstack-charts-delaunay-network",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/line/delaunay-network.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, dot } from \"@tanstack/charts\";\nimport { motion } from \"@tanstack/charts/motion\";\nimport { delaunayLink } from \"@tanstack/charts/spatial/delaunay\";\nimport { tooltip } from \"@tanstack/charts/tooltip\";\nimport { Chart } from \"@tanstack/react-charts/core\";\nimport { useMemo } from \"react\";\n\nimport { scaleLinear } from \"d3-scale\";\nimport { Share2 } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface PointDatum {\n    id: string;\n    weight: number;\n    mpg: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): PointDatum[] {\n    const results: PointDatum[] = [];\n    for (let i = 0; i < 20; i++) {\n        const weight = 1800 + i * 150 + Math.sin(i * 1.4) * 200;\n        const mpg = 42 - i * 1.2 + Math.cos(i * 1.1) * 4;\n        results.push({ id: `P-${i + 1}`, weight: Math.round(weight), mpg: Math.max(10, Number(mpg.toFixed(1))) });\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 PointDatum;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: d.id,\n        rows: [\n            { label: \"Weight\", value: `${d.weight} lbs`, color: \"var(--chart-1)\" },\n            { label: \"MPG\", value: `${d.mpg} mpg`, color: \"var(--foreground)\" },\n        ],\n    };\n}\n\nexport function DelaunayNetwork() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        delaunayLink(data, {\n                            id: \"delaunay-links\",\n                            x: \"weight\",\n                            y: \"mpg\",\n                            key: (d: PointDatum) => d.id,\n                            stroke: \"var(--border)\",\n                            strokeOpacity: 0.8,\n                            strokeWidth: 1,\n                        }),\n                        dot(data, {\n                            id: \"delaunay-dots\",\n                            x: \"weight\",\n                            y: \"mpg\",\n                            key: (d: PointDatum) => d.id,\n                            fill: \"var(--chart-1)\",\n                            stroke: \"var(--background)\",\n                            strokeWidth: 1.5,\n                            r: 4.5,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleLinear().domain([1500, 5000]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Weight (lb)\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                        y: {\n                            scale: scaleLinear().domain([5, 48]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Fuel Economy (mpg)\",\n                                ticks: { size: 0 },\n                            },\n                        },\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>Delaunay Spatial Triangulation</CardTitle>\n                <CardDescription>Spatial mesh network connecting points via 2D Delaunay triangulation</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=\"Delaunay Spatial Triangulation 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                    Mesh edges connect neighboring spatial clusters optimal proximity{\" \"}\n                    <Share2 className=\"h-4 w-4 text-cyan-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Delaunay triangulation maximizes minimum angles of all triangles in mesh\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default DelaunayNetwork;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. 2D Delaunay spatial triangulation mesh network. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack"
    ]
  }
}