{
  "title": "Dumbbell Plot",
  "description": "Dumbbell chart comparing dual-period point shifts across discrete categories.",
  "name": "tanstack-charts-dumbbell",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/line/dumbbell.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, dot, link } 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 { scaleBand, scaleLinear } from \"d3-scale\";\nimport { ArrowLeftRight } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface DumbbellDatum {\n    city: string;\n    v1980: number;\n    v2015: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): DumbbellDatum[] {\n    return [\n        { city: \"New York\", v1980: 4.2, v2015: 7.8 },\n        { city: \"San Francisco\", v1980: 3.8, v2015: 8.4 },\n        { city: \"Chicago\", v1980: 4.0, v2015: 6.2 },\n        { city: \"Houston\", v1980: 3.5, v2015: 5.9 },\n        { city: \"Boston\", v1980: 4.1, v2015: 7.1 },\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 DumbbellDatum;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: d.city,\n        rows: [\n            { label: \"1980 Ratio\", value: d.v1980.toFixed(1), color: \"var(--chart-1)\" },\n            { label: \"2015 Ratio\", value: d.v2015.toFixed(1), color: \"var(--chart-2)\" },\n            { label: \"Net Shift\", value: `+${(d.v2015 - d.v1980).toFixed(1)}`, color: \"var(--foreground)\" },\n        ],\n    };\n}\n\nexport function DumbbellChart() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        link(data, {\n                            id: \"dumbbell-connector\",\n                            x1: \"v1980\",\n                            y1: \"city\",\n                            x2: \"v2015\",\n                            y2: \"city\",\n                            stroke: \"var(--border)\",\n                            strokeWidth: 2,\n                        }),\n                        dot(data, {\n                            id: \"dumbbell-1980\",\n                            x: \"v1980\",\n                            y: \"city\",\n                            fill: \"var(--chart-1)\",\n                            r: 4.5,\n                        }),\n                        dot(data, {\n                            id: \"dumbbell-2015\",\n                            x: \"v2015\",\n                            y: \"city\",\n                            fill: \"var(--chart-2)\",\n                            r: 4.5,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleLinear().domain([2, 10]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"90th/10th Percentile Wage Ratio\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                        y: {\n                            scale: () => scaleBand<string>().padding(0.3),\n                            axis: {\n                                line: false,\n                                ticks: { size: 0 },\n                            },\n                        },\n                    },\n                    color: {\n                        domain: [\"1980\", \"2015\"],\n                        range: [\"var(--chart-1)\", \"var(--chart-2)\"],\n                    },\n                    margin: { top: 24, right: 24, bottom: 32, left: 100 },\n                    theme: {\n                        foreground: \"var(--muted-foreground)\",\n                        grid: \"var(--border)\",\n                        background: \"transparent\",\n                    },\n                },\n                {\n                    focus: \"group-y\",\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>Metro Inequality Shift (1980 vs 2015)</CardTitle>\n                <CardDescription>Dumbbell plot comparing historical baseline and current wage ratios</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=\"Metro Inequality Shift 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                    San Francisco experienced largest ratio expansion (+4.6){\" \"}\n                    <ArrowLeftRight className=\"h-4 w-4 text-orange-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Blue dots mark 1980 baseline; Orange dots denote 2015 measurement\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default DumbbellChart;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Dumbbell chart comparing dual-period point shifts across discrete categories. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "line"
    ]
  }
}