Segmented bar
ProOne whole in a few parts, as a bar that prints its figures or a thin bar above a list of the parts; parts with an order can take the theme's ramp, lightest to darkest (the reverse in dark mode). Not an M3 component (@windmorph/react-pro).
import { SegmentedBar, SegmentedList } from '@windmorph/react-pro/charts';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Purpose
How one whole splits, at a glance: visits by device, orders by channel, a survey's answers. SegmentedBar draws each part as a block as wide as its share, prints the share on it where it fits, and names the parts in a key below. SegmentedList draws the same parts as a thin bar that prints nothing, with each part's name, share and amount listed under it, for a narrow card or a side panel.
Use it where a pie or a donut would go: lengths along one line compare more exactly than angles. Two to five parts read best. To compare parts that don't add up to one whole, use Ranked bars; for one amount against a limit, a Meter. M3 has no charts, so it follows M3's colour roles, shapes and springs instead of a spec.
Parts and "Other"
partsare{ key, label, value }, drawn in the order you give them. Keep eachkeythe same across updates, so its block moves rather than being replaced. Colours go by order, so a part added before others moves their colours along; pinslotto keep a part's colour when parts come and go.- Six parts at most are drawn, since more stop being told apart by colour. Past six, the first five are drawn and the rest fold into one quiet part,
labels.other("Other"), whose amount is their sum. Put the largest first, so the smallest are the ones that fold. - Shares are of the whole. A value below nought, or one that isn't a number, counts as nothing toward it, while the readout, the list and the table still give the part's own value; one that isn't a number reads
labels.noValue("No value"), never "NaN". A part that counts as nothing draws nothing, on a bar and on a list's thin bar, though it keeps its key and its row; any other part keeps at least a 4px sliver. - Each part takes the next of the charts' eight colour slots, the first built from the theme's primary;
slot(1 to 8) pins one, so the same thing is the same colour on every chart of a page. "Other" takes the quiet colour.
Ordered parts
Parts that have an order (ratings from 1 to 5, age bands, answers from "Never" to "Always") take ordered: one hue, the theme's ramp from its lightest step to its darkest in light mode, the reverse in dark. Its five steps are spread over the parts in their order, so three parts take the first, middle and last steps. A pinned slot doesn't apply. Five ordered parts are drawn at most: past five, the first four are drawn and the rest fold into "Other", and a development build warns.
Behaviour
- Each part of a bar but "Other" prints its share, in white or black, whichever reads at 4.5:1 on its colour, where the part is wide enough for it: 2.75rem at least (44px at the default text size), and wider for a longer share ("33.33%" from your
formatShare), so larger text or a longer share needs a wider part rather than being clipped. A narrower part leaves it to the readout, the slider's value text and a frame's table view.formatSharewrites shares andformatValueamounts, in the page's locale by default. A share is a whole percentage by default, but one above nought never reads "0%" (under 0.5% it keeps one significant digit, "0.3%"), nor one short of the whole "100%" ("99.9%"). - The pointer reads the part under it, each part as wide as its share (in the gap between two, the nearer): a readout below the bar, by the part on its side with more room and never wider than the bar, gives its name, share and amount, and the other parts step back, dimming their colour but not their figures. A press or a tap reads a part and moves focus to the bar, so the arrow keys go on from it. A finger slides along the bar to read it while the page still scrolls up and down.
- From the keyboard the bar is one stop that starts on the first part: the arrow keys step through the parts, and Home and End go to the first and the last. Screen readers hear each part with where it is among them ("Phone: 5,120, 59%, 1 of 3",
labels.describePart). Escape hides the readout until another part, the pointer coming back or focus shows it again. A list has nothing to step through; its rows print every figure. - Patterns are on by default once there are two or more parts: each part and its key carry one (the first slot solid, a hatch for each slot after it, and a pattern per step when ordered), for anyone who doesn't tell the colours apart;
texture={false}turns them off. "Other" is always dotted, and forced colours always draw the patterns. Printed, the colours stay. - The parts grow to their shares when the bar first comes into view, and a change moves them to their new shares, on the spatial spring. One on screen as the page loads shows its shares at once, from the server's HTML. Under reduced motion the bar shows its final picture at once, wherever it is on the page.
- In a
ChartFrame, the frame's title names it, unless it has anaria-labeloraria-labelledbyof its own. ASegmentedBargives the frame its parts for the table view (part, amount and share); aSegmentedListgives none, since its rows are its figures. While the frame ispending, the parts' colours dim and their figures keep their contrast.
When not to use
To compare parts that don't add up to a whole, use Ranked bars; for a value against a limit, a Meter.
See also
- Ranked bars: Parts compared on one scale, largest first, with the rest in one row last; and a funnel's steps with each one's share of the step before. Not an M3 component (@windmorph/react-pro).
- Meter: A value on a known scale, such as storage used or a quota, with a warning past a threshold said in words, never by colour alone. Not an M3 component (@windmorph/react-pro).
- Chart frame: The card a chart sits in: its title names the chart, a switch shows the same numbers as a table, and it has empty, loading, pending and error states. Not an M3 component (@windmorph/react-pro).