Donut (S2)
Donut is a pre-alpha component — it has no finalized Spectrum 2 design yet
and is imported from the pre-alpha subpath.
The Donut component displays a donut (or pie, via holeRatio={0}) chart. Each data point
becomes a segment sized by metric and colored by color.
import { Chart, Legend } from '@spectrum-charts/react-spectrum-charts-s2';
import { Donut, DonutSummary, SegmentLabel } from '@spectrum-charts/react-spectrum-charts-s2/pre-alpha';
<Chart data={data}>
<Donut metric="count" color="browser" />
<Legend title="Browsers" position="right" highlight isToggleable />
</Chart>
Tooltips and popovers
Donut supports ChartInspect and ChartPopover like other S2 chart mark components.
Unlike the base package, S2 does not have a ChartTooltip component — use ChartInspect
instead.
Interactive donut segments and their direct or advanced labels animate opacity on hover.
Legend hover, controlled highlights, and popover selection share the animation state.
Set animations={false} or animationTypes={[]}
on Chart to keep instant opacity changes instead. A donut without interactive children
or highlighting remains static.
Inside a Donut, both render default content without children: the segment's color swatch and
series name, followed by its share of the visible total and short-number value (e.g.
65.2% (23K)), formatted with the chart locale. When children are provided, their content
replaces the default content.
<Donut metric="count" color="browser">
<ChartInspect />
<ChartPopover width="auto">
{(datum) => (
<div>
{datum.browser}: {datum.count} visitors
</div>
)}
</ChartPopover>
</Donut>
Draw-in animation
Add 'drawIn' to the chart's animationTypes to sweep the segments clockwise over one
second with a quadratic ease-in. Full-circle donuts and pies start at the top;
semicircle donuts start at the left. Direct and advanced labels start a 50ms linear fade
as soon as their own slice finishes drawing. All text rows and swatches fade together;
the final label finishes about 50ms after the donut.
Hover dimming and existing small-segment and collision rules still apply. The center
summary stays visible throughout.
<Chart data={data} animationTypes={['hover', 'drawIn']}>
<Donut metric="count" color="browser">
<SegmentLabel value />
</Donut>
</Chart>
Draw-in is off by default. animations={false} disables it even when 'drawIn' is
listed. It runs when the Vega view is created, including after data or spec changes;
resizing an existing view does not replay it. Empty-state rings remain static.
Center summary (DonutSummary)
The DonutSummary component displays a label and aggregate value in the center of the
donut. If isBoolean is set on the parent Donut, the summary shows the first data point's
value as a percentage instead of a sum.
<Donut metric="count" color="browser" holeRatio={0.8}>
<DonutSummary label="Visitors" />
</Donut>
DonutSummary props
| name | type | default | description |
|---|---|---|---|
| hideValue | boolean | false | Hides the value portion of the summary, only showing the label. |
| label | string | – | Label displayed under the summary value. |
| numberFormat | string | 'shortNumber' | A d3-format specifier for the summary value. |