# Pie Chart - Donut with Text

Use this template for a compact static-SVG donut chart when the main story is a total value plus
proportional category slices.

`widget-code.html` is a single `<svg>` root — no `<canvas>`, no Chart.js, no `<script>`. Every
slice's share is a permanent legend row instead of a hover tooltip.

## Use When

- Category composition matters more than exact rank.
- The reader needs one total value in the middle of the chart.
- The visual can fit in one inline card with one focal point.
- The data has 2-5 slices and all values share the same unit.

## Avoid When

- Exact category comparison is the main story. Use `bar-chart-multiple` instead.
- Values include negatives or mixed units. Use a table instead.
- There are more than five categories. Group small categories into `other` before rendering.
- The total is not meaningful. Use a ranking or proportion bar instead.

## Data Shape

Illustrative only — replace both the numbers and the arc path coordinates in `widget-code.html`
together when adapting; there is no runtime data-binding layer, and the arc paths must be
recomputed by hand for new proportions (see Visual Rules below for the math).

```json
{
  "title": "Pie Chart - Donut with Text",
  "nameKey": "browser",
  "dataKey": "visitors",
  "centerLabel": "Visitors",
  "chartData": [
    { "browser": "chrome", "visitors": 275 },
    { "browser": "safari", "visitors": 200 }
  ]
}
```

## Visual Rules

- Keep the donut centered, outer radius ~90 units, inner radius ~55 units (a clearly-a-ring
  thickness, not a near-solid disc and not a hairline).
- Show the total value as the center metric (`--dui-text`, mono/tabular figures) and the unit
  label below it (`--dui-text-muted`, caption size).
- Use `--dui-chart-series-1`/`-2`/`-3`/`-4` for up to four peer slices, `--dui-chart-other` for a
  5th/long-tail slice. Give each slice a `stroke: var(--dui-surface)` seam so adjacent slices of
  similar hue don't visually merge.
- Always include a legend row per slice with a color swatch, the category name, the raw value,
  and the percentage — this replaces the hover tooltip.
- **Arc path math** (do this before writing the `<path>` elements, not after):
  1. Convert each value to a fraction of the total, then to a degree span (`fraction * 360`).
  2. Starting angle for the first slice is `-90` (12 o'clock); each subsequent slice starts where
     the previous one ended.
  3. For a slice from `start` to `end` degrees at radius `R` (outer) / `r` (inner), centered at
     `(cx, cy)`: point at angle `θ` is `(cx + R·cos(θ·π/180), cy + R·sin(θ·π/180))` (SVG's y-down
     axis makes increasing `θ` sweep clockwise starting from the top when `θ` starts at `-90`).
  4. Path: `M <outerStart> A R R 0 <largeArc>,1 <outerEnd> L <innerEnd> A r r 0 <largeArc>,0
     <innerStart> Z`, where `largeArc = 1` only if `end - start > 180`.
  5. Verify the last slice's end point equals the first slice's start point (closes the ring) —
     if it doesn't, a rounding error means a visible gap or overlap at the seam.
- Do not add conclusion, recommendation, or analysis copy inside the widget.

## Edge Cases

- Non-numeric/negative values become `0` for that slice.
- If every value is invalid or `0`, do not emit this chart — fall back to Markdown.
- If one slice is much larger than the others, keep every legend row visible so small slices stay
  identifiable — do not drop rows to save space.
- If category labels are long, shorten the legend name and keep the full name in the surrounding
  response text.

## Acceptance Checks

- `widget-code.html`'s only root element is `<svg>`; no `<canvas>`, no `<script>`.
- Every slice has a matching legend row with value and percentage; percentages sum to ~100%.
- The arc seam closes (no visible gap or overlap between the last and first slice).
- `templates/manifest.json` marks `pie-donut-text` as `ready`.
