# Polar Coxcomb Nightingale Rose Chart

> Variable-radius polar sector chart displaying cyclical seasonal metrics.

A shadcn/ui block from the [@pacekit](https://ui.pacekit.dev/?utm_source=shadcn.exchange) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/pacekit/tanstack-charts-rose).

- Page, with a live preview: https://shadcn.exchange/r/pacekit/tanstack-charts-rose
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/pacekit/tanstack-charts-rose-light-f9aee398193eee26.png
- Registry item: https://ui.pacekit.dev/r/tanstack-charts-rose.json
- Listed: 2026-10-21, source last changed 2026-10-21

## Install

```bash
npx shadcn@latest add https://shadcn.exchange/r/pacekit/tanstack-charts-rose.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- npm packages: `@tanstack/charts`, `@tanstack/react-charts`, `d3-scale`
- Registry items: `card`

## Files

### `components/tanstack-charts/pie/rose.tsx`

```tsx
import { type ChartPoint, defineChart } from "@tanstack/charts";
import { motion } from "@tanstack/charts/motion";
import { polar, radialBarRadius } from "@tanstack/charts/polar";
import { tooltip } from "@tanstack/charts/tooltip";
import { Chart } from "@tanstack/react-charts/core";
import { useMemo } from "react";

import { scaleBand, scaleLinear } from "d3-scale";
import { Compass } from "lucide-react";

import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";

interface WindRoseDatum {
    direction: string;
    speed: number;
}

const motionRenderer = motion({
    initial: "always",
    transition: { type: "spring", stiffness: 170, damping: 18, mass: 1 },
});

const directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
const colors = [
    "var(--chart-1)",
    "var(--chart-2)",
    "var(--chart-3)",
    "var(--chart-4)",
    "var(--chart-5)",
    "var(--chart-1)",
    "var(--chart-2)",
    "var(--chart-3)",
];

function generateDemoData(): WindRoseDatum[] {
    return directions.map((dir, idx) => ({
        direction: dir,
        speed: Math.round(15 + Math.sin(idx * 0.8) * 12 + Math.random() * 8),
    }));
}

function shadcnTooltipContent<TDatum>(points: readonly ChartPoint<TDatum>[]) {
    if (points.length === 0) return { title: "", rows: [] };
    const d = points[0].datum as WindRoseDatum;
    if (!d) return { title: "", rows: [] };
    return {
        title: `Direction: ${d.direction}`,
        rows: [{ label: "Wind Velocity", value: `${d.speed} knots`, color: "var(--chart-1)" }],
    };
}

export function Rose() {
    const data = useMemo(() => generateDemoData(), []);

    const definition = useMemo(
        () =>
            defineChart(
                {
                    renderer: motionRenderer,
                    scales: {
                        x: null,
                        y: null,
                    },
                    marks: [
                        polar({
                            radiusRatio: 0.8,
                            scales: {
                                angle: { scale: () => scaleBand<string>().domain(directions) },
                                radius: {
                                    scale: scaleLinear().domain([0, 40]),
                                    range: [({ radius }) => radius * 0.25, ({ radius }) => radius],
                                },
                            },
                            marks: [
                                radialBarRadius(data, {
                                    id: "wind-bars",
                                    angle: "direction",
                                    radius: "speed",
                                    key: "direction",
                                    color: "direction",
                                    stroke: "var(--background)",
                                    strokeWidth: 1.5,
                                }),
                            ],
                        }),
                    ],
                    color: { domain: directions, range: colors },
                    margin: { top: 20, right: 20, bottom: 20, left: 20 },
                    theme: {
                        foreground: "var(--muted-foreground)",
                        grid: "var(--border)",
                        background: "transparent",
                    },
                },
                {
                    keyboard: true,
                    tooltip: {
                        use: tooltip,
                        className:
                            "font-sans shadow-none rounded-md bg-popover text-popover-foreground border p-2 text-xs",
                        anchor: "pointer",
                        placement: "auto",
                        content: (points) => shadcnTooltipContent(points),
                    },
                },
            ),
        [data],
    );

    return (
        <Card className="w-full max-w-xl">
            <CardHeader>
                <CardTitle>Polar Coxcomb Nightingale Rose Chart</CardTitle>
                <CardDescription>
                    Variable-radius polar sector chart displaying directional wind velocity metrics
                </CardDescription>
            </CardHeader>
            <CardContent>
                <div className="h-[250px] w-full">
                    <Chart
                        definition={definition}
                        renderer={motionRenderer}
                        height={250}
                        ariaLabel="Polar Coxcomb Nightingale Rose Chart"
                    />
                </div>
            </CardContent>
            <CardFooter className="flex-col items-start gap-2 text-sm">
                <div className="flex items-center gap-2 leading-none font-medium">
                    Equal-angle polar sectors scale outward proportionally to value{" "}
                    <Compass className="h-4 w-4 text-emerald-500" />
                </div>
                <div className="text-muted-foreground leading-none">
                    `radialBarRadius` projects variable radial lengths across fixed angular direction bands
                </div>
            </CardFooter>
        </Card>
    );
}

export default Rose;
```
