{
  "title": "Recharts Mixed Bars",
  "description": "Hybrid bar chart combining stacked bars alongside single comparison bars.",
  "name": "tanstack-charts-recharts-mixed-bars",
  "dependencies": [
    "@tanstack/charts",
    "@tanstack/react-charts",
    "d3-scale"
  ],
  "registryDependencies": [
    "card"
  ],
  "type": "registry:block",
  "files": [
    {
      "path": "components/blocks/tanstack-charts/bar/recharts-mixed-bars.tsx",
      "type": "registry:block",
      "content": "import { type ChartPoint, barY, defineChart, group } 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 { Columns3 } from \"lucide-react\";\n\nimport { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from \"@/components/ui/card\";\n\ninterface WeatherDatum {\n    date: Date;\n    precipitation: number;\n    wind: number;\n    temp_max: number;\n}\n\ntype BarSlot = \"stack\" | \"independent\";\n\nconst motionRenderer = motion({\n    initial: \"always\",\n    transition: { type: \"spring\", stiffness: 170, damping: 18, mass: 1 },\n});\n\nfunction generateDemoData(): WeatherDatum[] {\n    const results: WeatherDatum[] = [];\n    for (let i = 0; i < 7; i++) {\n        const date = new Date(Date.UTC(2024, 6, 1 + i));\n        results.push({\n            date,\n            precipitation: Math.floor(4 + Math.random() * 12),\n            wind: Math.floor(3 + Math.random() * 8),\n            temp_max: Math.floor(18 + Math.random() * 10),\n        });\n    }\n    return results;\n}\n\nfunction shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {\n    if (points.length === 0) return { title: \"\", rows: [] };\n    const d = points[0].datum as WeatherDatum;\n    if (!d) return { title: \"\", rows: [] };\n    return {\n        title: d.date.toLocaleDateString(\"en-US\", {\n            weekday: \"short\",\n            month: \"short\",\n            day: \"numeric\",\n            timeZone: \"UTC\",\n        }),\n        rows: [\n            { label: \"Precipitation\", value: `${d.precipitation} mm`, color: \"var(--chart-1)\" },\n            { label: \"Wind Speed\", value: `${d.wind} km/h`, color: \"var(--chart-2)\" },\n            { label: \"Max Temp\", value: `${d.temp_max}°C`, color: \"var(--chart-3)\" },\n        ],\n    };\n}\n\nexport function RechartsMixedBars() {\n    const data = useMemo(() => generateDemoData(), []);\n\n    const groupScale = useMemo(() => scaleBand<BarSlot>().domain([\"stack\", \"independent\"]).paddingInner(0.1), []);\n\n    const definition = useMemo(\n        () =>\n            defineChart(\n                {\n                    renderer: motionRenderer,\n                    marks: [\n                        barY(data, {\n                            x: \"date\",\n                            y1: 0,\n                            y2: \"precipitation\",\n                            z: () => \"stack\",\n                            fill: \"var(--chart-1)\",\n                            layout: group({ scale: groupScale }),\n                            inset: 1,\n                            radius: 2,\n                        }),\n                        barY(data, {\n                            x: \"date\",\n                            y1: \"precipitation\",\n                            y2: (row: WeatherDatum) => row.precipitation + row.wind,\n                            z: () => \"stack\",\n                            fill: \"var(--chart-2)\",\n                            layout: group({ scale: groupScale }),\n                            inset: 1,\n                            radius: 2,\n                        }),\n                        barY(data, {\n                            x: \"date\",\n                            y: \"temp_max\",\n                            z: () => \"independent\",\n                            fill: \"var(--chart-3)\",\n                            layout: group({ scale: groupScale }),\n                            inset: 1,\n                            radius: 2,\n                        }),\n                    ],\n                    scales: {\n                        x: {\n                            scale: () => scaleBand<Date>().paddingInner(0.2).paddingOuter(0.05),\n                            axis: {\n                                ticks: {\n                                    format: (v: Date) =>\n                                        v.toLocaleDateString(\"en-US\", { month: \"short\", day: \"numeric\", timeZone: \"UTC\" }),\n                                },\n                                label: \"Date\",\n                            },\n                        },\n                        y: { scale: scaleLinear, grid: true, axis: { label: \"Value Metrics\" } },\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                    keyboard: true,\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: \"pointer\",\n                        placement: \"auto\",\n                        content: (points) => shadcnTooltipContent(points),\n                    },\n                },\n            ),\n        [data, groupScale],\n    );\n\n    return (\n        <Card className=\"w-full max-w-xl\">\n            <CardHeader>\n                <CardTitle>Mixed Stacked & Grouped Bars</CardTitle>\n                <CardDescription>\n                    Hybrid bar chart combining stacked bars alongside independent adjacent bars\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=\"Mixed Stacked & Grouped Bars 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                    Stacked slot combines precipitation + wind alongside temperature bar{\" \"}\n                    <Columns3 className=\"h-4 w-4 text-emerald-500\" />\n                </div>\n                <div className=\"text-muted-foreground leading-none\">\n                    Custom group layout scale allocates inner slots for stacked and unstacked series\n                </div>\n            </CardFooter>\n        </Card>\n    );\n}\n\nexport default RechartsMixedBars;\n"
    }
  ],
  "mcp": {
    "description": "Renders responsive data visualization with dark mode styling and customizable tooltips. Hybrid bar chart combining stacked bars alongside single comparison bars. Relies on card. Use when presenting data insights or analytics dashboards.",
    "tags": [
      "chart",
      "tanstack",
      "bar"
    ]
  }
}