{
  "title": "Line Gaps",
  "description": "Line chart handling missing or null data gaps with defined line breaks.",
  "name": "tanstack-charts-line-gaps",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/line/line-gaps.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, defineChart, 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 { TrendingUp } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface StockDatum {\n    date: Date;\n    close: number | null;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): StockDatum[] {\n    const baseDate = new Date(2025, 0, 1);\n    return Array.from({ length: 24 }, (_, i) => {\n        const d = new Date(baseDate);\n        d.setDate(baseDate.getDate() + i * 7);\n        // Introduce gaps in Q1 (weeks 4 to 8)\n        const isGap = i >= 4 && i <= 7;\n        return {\n            date: d,\n            close: isGap ? null : 150 + Math.sin(i * 0.4) * 25 + i * 2,\n        };\n    });\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    const p = points[0];\n    if (!p || !p.datum) return { title: \"\", rows: [] };\n    const d = p.datum as unknown as StockDatum;\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\" });\n    return {\n        title: dateStr,\n        rows: [\n            {\n                label: \"Close\",\n                value: d.close !== null ? `$${d.close.toFixed(2)}` : \"N/A (Gap)\",\n                color: p.color || \"var(--chart-1)\",\n            },\n        ],\n    };\n}\n\nexport function LineGaps() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        lineY(data, {\n                            id: \"stock-line\",\n                            x: \"date\",\n                            y: (row: StockDatum) => row.close,\n                            stroke: \"var(--chart-1)\",\n                            strokeWidth: 2.25,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleUtc,\n                            axis: {\n                                line: false,\n                                label: \"Week\",\n                                ticks: {\n                                    size: 0,\n                                    padding: 10,\n                                    format: (d: Date) => d.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\" }),\n                                },\n                            },\n                        },\n                        y: {\n                            scale: scaleLinear().domain([100, 220]),\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Close ($)\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                    },\n                    margin: { top: 24, right: 24, bottom: 32, left: 40 },\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>Asset Price with Data Gaps</CardTitle>\n                <CardDescription>Weekly closing prices highlighting missing reporting intervals</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=\"Asset Price with Data Gaps 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                    Market recovery following Q1 gap interval <TrendingUp className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Gaps indicate suspended trading sessions during system upgrade\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default LineGaps;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Line chart handling missing or null data gaps with defined line breaks. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "line"
    ]
  }
}