{
  "title": "Hierarchy Tree",
  "description": "Tree layout algorithm mapping hierarchical package dependencies.",
  "name": "tanstack-charts-hierarchy-tree",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/bar/hierarchy-tree.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, dot, link, text } from \"@tanstack/charts\";\nimport { treeLayout } from \"@tanstack/charts/hierarchy/tree\";\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 } from \"d3-scale\";\nimport { Network } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface TreeRawDatum {\n    name: string;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): TreeRawDatum[] {\n    return [\n        { name: \"Root\" },\n        { name: \"Root.Analytics\" },\n        { name: \"Root.Analytics.Cluster\" },\n        { name: \"Root.Analytics.Graph\" },\n        { name: \"Root.Visualization\" },\n        { name: \"Root.Visualization.Axis\" },\n        { name: \"Root.Visualization.Scale\" },\n    ];\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const p = points[0];\n    const d = p.datum as any;\n    if (!d) return { title: \"\", rows: [] };\n    if (\"internal\" in d) {\n        return {\n            title: d.data?.name ?? d.name,\n            rows: [{ label: \"Node Type\", value: d.internal ? \"Group Node\" : \"Leaf Node\", color: \"var(--chart-1)\" }],\n        };\n    }\n    return {\n        title: \"Hierarchy Edge\",\n        rows: [\n            {\n                label: \"Link Path\",\n                value: `${d.sourceNode?.data?.name ?? \"Node\"} → ${d.targetNode?.data?.name ?? \"Node\"}`,\n                color: \"var(--foreground)\",\n            },\n        ],\n    };\n}\n\nexport function HierarchyTree() {\n    const rawData = useMemo(() => generateDemoData(), []);\n\n    const layout = useMemo(() => {\n        return treeLayout(rawData, {\n            path: \"name\",\n            delimiter: \".\",\n        });\n    }, [rawData]);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        link(layout.links, {\n                            id: \"hierarchy-links\",\n                            x1: \"x1\",\n                            y1: \"y1\",\n                            x2: \"x2\",\n                            y2: \"y2\",\n                            key: \"id\",\n                            stroke: \"var(--border)\",\n                            strokeOpacity: 0.8,\n                            strokeWidth: 1.5,\n                        }),\n                        dot(layout.nodes, {\n                            id: \"hierarchy-nodes\",\n                            x: \"x\",\n                            y: \"y\",\n                            key: \"id\",\n                            fill: \"var(--chart-1)\",\n                            r: 4,\n                        }),\n                        text(layout.nodes, {\n                            id: \"hierarchy-labels\",\n                            x: \"x\",\n                            y: \"y\",\n                            text: (n: any) => {\n                                const parts = (n.data?.name || n.name || \"\").split(\".\");\n                                return parts[parts.length - 1];\n                            },\n                            key: \"id\",\n                            fill: \"var(--foreground)\",\n                            fontSize: 10,\n                            anchor: (n: any) => (n.internal ? \"end\" : \"start\"),\n                            dx: (n: any) => (n.internal ? -6 : 6),\n                        }),\n                    ],\n                    scales: {\n                        x: { scale: scaleLinear },\n                        y: { scale: scaleLinear },\n                    },\n                    guides: false,\n                    margin: { top: 22, right: 90, bottom: 22, left: 60 },\n                    theme: {\n                        foreground: \"var(--muted-foreground)\",\n                        grid: \"transparent\",\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        [layout],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>Tidy Hierarchy Tree</CardTitle>\n                <CardDescription>\n                    Tree layout algorithm mapping hierarchical package namespace dependencies\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=\"Tidy Hierarchy Tree 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                    Tidy node distribution prevents label overlap across branches{\" \"}\n                    <Network className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Nodes positioned proportionally according to tree hierarchy level and parent relationships\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default HierarchyTree;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Tree layout algorithm mapping hierarchical package dependencies. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack"
    ]
  }
}