Data

Donut Morph

A donut chart whose slices slide and grow on springs, with the total rolling in the middle and a legend in percent.

Preview

Installation

Terminal
npx @usefluid/cli add donut-morph

Usage

DonutMorph.tsx
import { DonutMorph } from "./DonutMorph";

<DonutMorph label="Visits" parts={[{ label: "Direct", value: 420 }, { label: "Search", value: 260 }]} />

API reference

PropTypeDefaultDescription
labelstring—What is counted. Shown under the total and used as the accessible name.
parts{ label, value, color? }[]—One slice per part. Labels must be unique. Without a colour, parts take violet, teal, orange, pink and blue in order.
formatIntl.NumberFormatOptions—How the total and values are written, as in Intl.NumberFormat.
localestringthe browser'sLocale for numbers and percents.

Keyboard and screen readers

The ring is decoration; the legend is a list that reads each part with its percent and value. With reduced motion slices change at once.

Notes

Each slice has a slightly slower spring than the one before, so a change travels around the ring. slices in donut.ts turns values into starts and shares. Every colour is yours to change.

How it is made

Each slice has two springs, where it starts and how long it is, so when the numbers change the slices push each other around the ring instead of jumping. Later slices are a little slower, so the change travels around. The legend is a list that screen readers read with each percent.

For your agent

For your agent

Add Donut Morph to my project with the Fluid library. Use DonutMorph for the breakdowns of my dashboard, such as channels or plans, with my colours. Read my project first. Use my logo, my colours and my font through the --fluid-* variables. Keep 44px touch targets, visible focus and reduced motion. If I have no SVG logo, ask before making one up.