{
  "title": "Pointer Tooltip",
  "description": "Interactive pointer tooltip dynamically tracking spatial mouse cursor position.",
  "name": "tanstack-charts-pointer-tooltip",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/tooltip/pointer-tooltip.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, dot, lineY } 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 { scaleLinear, scaleUtc } from \"d3-scale\";\nimport { MousePointer } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface PointerDatum {\n    Date: Date;\n    Close: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): PointerDatum[] {\n    const baseDate = new Date(2025, 0, 1);\n    return Array.from({ length: 18 }, (_, i) => {\n        const d = new Date(baseDate);\n        d.setDate(baseDate.getDate() + i * 5);\n        return {\n            Date: d,\n            Close: 140 + Math.sin(i * 0.5) * 22 + i * 1.5,\n        };\n    });\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const d = points[0].datum as PointerDatum;\n    if (!d || !d.Date) return { title: \"\", rows: [] };\n    const dateObj = d.Date instanceof Date ? d.Date : new Date(d.Date);\n    const dateStr = isNaN(dateObj.getTime())\n        ? \"\"\n        : dateObj.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\", year: \"numeric\" });\n    return {\n        title: dateStr,\n        rows: [\n            {\n                label: \"Asset Close\",\n                value: `$${d.Close.toFixed(2)}`,\n                color: points[0].color || \"var(--chart-1)\",\n            },\n        ],\n    };\n}\n\nexport function PointerTooltipChart() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        lineY(data, {\n                            id: \"pointer-line\",\n                            x: \"Date\",\n                            y: \"Close\",\n                            stroke: \"var(--chart-1)\",\n                            strokeWidth: 2.25,\n                        }),\n                        dot(data, {\n                            id: \"apple-points\",\n                            x: \"Date\",\n                            y: \"Close\",\n                            fill: \"var(--chart-1)\",\n                            r: 4,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleUtc,\n                            axis: {\n                                line: false,\n                                label: \"Date\",\n                                ticks: {\n                                    size: 0,\n                                    padding: 10,\n                                    format: (d: any) => {\n                                        const dateObj = d instanceof Date ? d : new Date(d);\n                                        return isNaN(dateObj.getTime())\n                                            ? \"\"\n                                            : dateObj.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\" });\n                                    },\n                                },\n                            },\n                        },\n                        y: {\n                            scale: scaleLinear().domain([120, 180]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Price ($)\",\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: \"point\",\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>Interactive Pointer Tooltip</CardTitle>\n                <CardDescription>\n                    Precision point-anchored tooltip following cursor positioning directly\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=\"Interactive Pointer Tooltip 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                    Point tooltip anchors smoothly over nearest focused datum node{\" \"}\n                    <MousePointer className=\"h-4 w-4 text-blue-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Point anchor mode binds popover positioning dynamically to spatial node coordinates\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default PointerTooltipChart;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Interactive pointer tooltip dynamically tracking spatial mouse cursor position. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "tooltip"
    ]
  }
}