# Donut chart

Parts of a whole. Six parts at most; the rest fold into "Other" in neutral grey rather than a seventh hue. Segments are separated by a 2px gap; the total sits in the middle. The legend carries each part's value and share, so nothing depends on matching colours.

- Registry name: `donut-chart` (`@candor/donut-chart`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/donut-chart

## Install

```bash
npx candor-ui add donut-chart
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/donut-chart`.
It brings in: chart-frame, data, locale, scale.

## Example

```tsx
"use client"

import { DonutChart, type DonutPart } from "@/components/donut-chart"

const changes: DonutPart[] = [
  { label: "API handlers", value: 14 },
  { label: "UI components", value: 22 },
  { label: "Migrations", value: 9 },
  { label: "Background jobs", value: 7 },
  { label: "Feature flags", value: 5 },
  { label: "Dashboards", value: 3 },
  { label: "Infrastructure config", value: 2 },
]

export default function Example() {
  return <DonutChart className="max-w-xl" title="What’s changing" subtitle="Changes in the 4.2 release" parts={changes} totalLabel="changes" />
}
```

## <DonutChart>

Props:

- `title: string`: What the chart shows, above it.
- `subtitle?: string | undefined`: A line under the title, e.g. the period or unit.
- `parts: DonutPart[]`: The parts of the whole; past six, the smallest fold into Other.
- `format?: ValueFormat | undefined` (default `"number"`): How values are written: number, percent (0–1), currency (USD) or duration (seconds). Defaults to number.
- `totalLabel?: string | undefined`: The word under the total in the middle. Defaults to "Total".
- `state?: ChartState | undefined`: Loading, empty, partial or error. Parts that sum to zero show as empty.
- `className?: string | undefined`

## Strings (`donutChart`)

The fixed words, English by default. Override any of them under `donutChart` in `<LocaleProvider strings={{ donutChart: { … } }}>`; the table is exported as `donutChartStrings`.

- `total`: Total
- `other`: Other
- `empty`: Nothing to divide up yet.
- `value`: Value
- `share`: Share
- `ofTotal`: of total
- `part`: {label} {value}

## Types

### DonutPart

```ts
{ label: string; value: number }
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
