{
  "title": "Area Stack Expanded",
  "description": "An expanded stacked area chart illustrating traffic distribution ratios normalized to 100% built with TanStack Charts.",
  "name": "tanstack-charts-area-stack-expanded",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale",
    "d3-shape"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/area/area-stack-expanded.tsx",
      "type": "registry:block",
      "content": "import { areaY, defineChart, lineY } from \"@tanstack/charts\";\nimport { d3Curve } from \"@tanstack/charts/d3/shape\";\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, scalePoint } from \"d3-scale\";\nimport { curveNatural } from \"d3-shape\";\n\nimport { Card, CardContent, CardDescription, CardHeader, CardTitle } from \"@/components/ui/card\";\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nconst chartData = [\n    { month: \"January\", desktop: 186, mobile: 80, other: 45 },\n    { month: \"February\", desktop: 305, mobile: 200, other: 100 },\n    { month: \"March\", desktop: 237, mobile: 120, other: 150 },\n    { month: \"April\", desktop: 73, mobile: 190, other: 50 },\n    { month: \"May\", desktop: 209, mobile: 130, other: 100 },\n    { month: \"June\", desktop: 214, mobile: 140, other: 160 },\n].map((item) => {\n    const total = item.desktop + item.mobile + item.other;\n    const pctOther = item.other / total;\n    const pctMobile = item.mobile / total;\n    const pctDesktop = item.desktop / total;\n\n    return {\n        ...item,\n        y0Other: 0,\n        y1Other: pctOther,\n        y0Mobile: pctOther,\n        y1Mobile: pctOther + pctMobile,\n        y0Desktop: pctOther + pctMobile,\n        y1Desktop: pctOther + pctMobile + pctDesktop,\n    };\n});\n\nexport function AreaStackExpanded() {\n    const definition = useMemo(() => {\n        return defineChart({\n            renderer: motionRenderer,\n            motion: {\n                transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n            },\n            focus: \"group-x\",\n            tooltip: {\n                use: tooltip,\n                motion: { type: \"spring\", stiffness: 170, damping: 18 },\n                className: \"font-sans! shadow-none! capitalize!\",\n                content: (points) => {\n                    const datum = points[0]?.datum as (typeof chartData)[number];\n                    if (!datum) return { rows: [] };\n                    const total = datum.desktop + datum.mobile + datum.other;\n                    return {\n                        title: String(points[0].xValue),\n                        rows: [\n                            {\n                                label: \"Desktop\",\n                                value: `${datum.desktop} (${Math.round((datum.desktop / total) * 100)}%)`,\n                                color: \"var(--chart-1)\",\n                            },\n                            {\n                                label: \"Mobile\",\n                                value: `${datum.mobile} (${Math.round((datum.mobile / total) * 100)}%)`,\n                                color: \"var(--chart-2)\",\n                            },\n                            {\n                                label: \"Other\",\n                                value: `${datum.other} (${Math.round((datum.other / total) * 100)}%)`,\n                                color: \"var(--chart-3)\",\n                            },\n                        ],\n                    };\n                },\n            },\n            marks: [\n                areaY(chartData, {\n                    id: \"other\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Other,\n                    fill: \"var(--chart-3)\",\n                    fillOpacity: 0.15,\n                    curve: d3Curve(curveNatural),\n                }),\n                lineY(chartData, {\n                    id: \"other-line\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Other,\n                    stroke: \"var(--chart-3)\",\n                    strokeWidth: 2,\n                    curve: d3Curve(curveNatural),\n                    points: false,\n                }),\n                areaY(chartData, {\n                    id: \"mobile\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Mobile,\n                    fill: \"var(--chart-2)\",\n                    fillOpacity: 0.4,\n                    curve: d3Curve(curveNatural),\n                }),\n                lineY(chartData, {\n                    id: \"mobile-line\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Mobile,\n                    stroke: \"var(--chart-2)\",\n                    strokeWidth: 2,\n                    curve: d3Curve(curveNatural),\n                    points: false,\n                }),\n                areaY(chartData, {\n                    id: \"desktop\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Desktop,\n                    fill: \"var(--chart-1)\",\n                    fillOpacity: 0.4,\n                    curve: d3Curve(curveNatural),\n                }),\n                lineY(chartData, {\n                    id: \"desktop-line\",\n                    x: (d) => d.month.slice(0, 3),\n                    y: (d) => d.y1Desktop,\n                    stroke: \"var(--chart-1)\",\n                    strokeWidth: 2,\n                    curve: d3Curve(curveNatural),\n                    points: false,\n                }),\n            ],\n            scales: {\n                x: {\n                    scale: scalePoint().domain(chartData.map((d) => d.month.slice(0, 3))),\n                },\n                y: {\n                    scale: scaleLinear().domain([0, 1]),\n                    grid: true,\n                },\n            },\n        });\n    }, []);\n\n    return (\n        <Card className=\"gap-4\">\n            <CardHeader>\n                <CardTitle className=\"text-lg\">Normalized Revenue Share</CardTitle>\n                <CardDescription>\n                    Relative revenue distribution between Enterprise and SMB account tiers\n                </CardDescription>\n            </CardHeader>\n            <CardContent>\n                <Chart\n                    definition={definition}\n                    renderer={motionRenderer}\n                    height={250}\n                    ariaLabel=\"Expanded stacked area chart illustrating traffic distribution ratios normalized to 100%\"\n                />\n            </CardContent>\n        </Card>\n    );\n}\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. An expanded stacked area chart illustrating traffic distribution ratios normalized to 100% built with TanStack Charts. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "area"
    ]
  }
}