{
  "title": "Streamgraph Chart",
  "description": "Organic center-aligned streamgraph displaying continuous sector volume flows.",
  "name": "tanstack-charts-streamgraph",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/area/streamgraph.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, areaY, defineChart, stack } 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 { Waves } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface StreamDatum {\n    date: Date;\n    industry: string;\n    unemployed: number;\n}\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): StreamDatum[] {\n    const baseDate = new Date(2025, 0, 1);\n    const results: StreamDatum[] = [];\n\n    for (let i = 0; i < 12; i++) {\n        const d = new Date(baseDate);\n        d.setMonth(baseDate.getMonth() + i);\n        results.push({ date: d, industry: \"Media\", unemployed: 80 + Math.sin(i * 0.6) * 40 });\n        results.push({ date: d, industry: \"Retail\", unemployed: 140 + Math.cos(i * 0.4) * 50 });\n        results.push({ date: d, industry: \"Energy\", unemployed: 60 + Math.sin(i * 0.8) * 30 });\n        results.push({ date: d, industry: \"Finance\", unemployed: 110 + Math.cos(i * 0.7) * 35 });\n    }\n    return results;\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const dateVal = (points[0].datum as StreamDatum)?.date;\n    const dateObj = dateVal ? (dateVal instanceof Date ? dateVal : new Date(dateVal)) : null;\n    const titleStr =\n        dateObj && !isNaN(dateObj.getTime())\n            ? dateObj.toLocaleDateString(\"en-US\", { month: \"short\", year: \"numeric\" })\n            : \"\";\n    return {\n        title: titleStr,\n        rows: points.map((p) => {\n            const d = p.datum as StreamDatum;\n            return {\n                label: d.industry,\n                value: `${d.unemployed.toFixed(0)}k`,\n                color: p.color || \"var(--chart-1)\",\n            };\n        }),\n    };\n}\n\nexport function StreamgraphChart() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        areaY(data, {\n                            id: \"streamgraph-area\",\n                            x: \"date\",\n                            y: \"unemployed\",\n                            z: \"industry\",\n                            color: \"industry\",\n                            layout: stack({ offset: \"wiggle\", order: \"inside-out\" }),\n                            fillOpacity: 0.85,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: scaleUtc,\n                            axis: {\n                                line: false,\n                                label: \"Month\",\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\" });\n                                    },\n                                },\n                            },\n                        },\n                        y: {\n                            scale: scaleLinear,\n                            grid: true,\n                            axis: {\n                                line: false,\n                                label: \"Volume Stream\",\n                                ticks: { size: 0 },\n                            },\n                        },\n                    },\n                    color: {\n                        domain: [\"Media\", \"Retail\", \"Energy\", \"Finance\"],\n                        range: [\"var(--chart-1)\", \"var(--chart-2)\", \"var(--chart-3)\", \"var(--chart-4)\"],\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>Streamgraph Organic Flow</CardTitle>\n                <CardDescription>\n                    Center-aligned organic streamgraph representing smooth sector volume shifts\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=\"Streamgraph Organic Flow 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                    Wiggle baseline minimizes slope changes across organic streams{\" \"}\n                    <Waves className=\"h-4 w-4 text-cyan-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Symmetric layout highlights relative expansion and contraction of categories\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default StreamgraphChart;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Organic center-aligned streamgraph displaying continuous sector volume flows. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack"
    ]
  }
}