Split bar

One 100% bar cut into the parts of a whole: plan mix, storage by type, ticket status. Plain elements, no SVG: each segment a flex item whose basis is its share, 2px of surface between neighbours, a minimum width so a sliver never vanishes, and rounding on the outer ends only. total leaves the rest of the track empty.

Anatomy

← x-ds-chart only when `interactive`
← legend="inline" only
Photos 150 GB · 30%
…
    legend: swatch, name, "150 GB · 30%"
← legend="below" Part, Value, Share, the rest and the total
PartTokenWhy
Segmentsseries-1 … series-8 by position; a row's tone or series insteadspecs/chart-series.md
The restthe progress track, fg/10It is the empty part of the same bar the progress and usage meter draw.
Gapgap-0.5, 2px, showing the surface behindNo track colour behind the segments, so the gap is the surface in either theme.
Thicknesssm 8, md 12, lg 20px
Least widthsm 8, md 12, lg 20px — as wide as the bar is tallA 0.4% segment at an end would otherwise be shaved to nothing by the rounding.
Endsfirst:rounded-s-full last:rounded-e-fullLogical, so a right-to-left page rounds the right ends too.

Widths

A segment's basis is its exact share of the whole, as an inline style (a class built from a number is invisible to Tailwind). Every segment may shrink, so the 2px gaps come out of all of them in proportion; the least width keeps a sliver from shrinking away. The printed shares are whole percentages from Chart::percentages(), with the rest of the track taking part, so on screen they always add up to 100. A part above zero that rounds to 0% is printed as <1%: it is on the bar, so "0%" would be wrong.

A value of zero is a real answer ("no blocked tickets"): it is listed in the legend and the table and draws no segment.

Legend

legend
below (default)The chart legend under the bar: swatch, name, number.
inlineEach part's name and number above its own segment while the segment is wide enough to hold them, and in a line under the bar while it is not. Nothing is measured: the width a label needs is estimated (Chart::textWidth()), the box width at which its segment reaches that is worked out from the share, and the label above gets Chart::below() of it while the stand-in below gets Chart::above(), its exact opposite. Every part is named in one place at every width.
noneNo names on screen: the summary then lists every part. Use it only where the parts are named beside the bar already.

showValues picks the number: value, percent or both (default, "150 GB · 30%").

Data

CaseResult
[], or everything zero with no totalds::empty-state, bare
total larger than the sumthe rest draws as track, named remainderLabel ("Remaining") in the legend, the readout and the table
total smaller than the sum, or not a numberignored: the whole is the sum
a negative or a non-numberthrows, naming the part
more than eight partsthrows: one per series colour

The summary

role="img", generated by Chart::whole(). With a legend: "Storage: 3 parts, 246 GB of 500 GB; the largest is Photos at 30%." With legend="none", every part: "Open 18 (27%), Solved 41 (62%), …; total 66." summary replaces it; table adds part, value and share, the rest, and the total.

Accessibility

Without the scriptWith it
Roleimg on the bargroup, keeping the name; each segment img, "Photos: 150 GB (30%)"
Keyboardnoneone Tab stop; any arrow moves to the next / previous segment (the rest included), Home / End to the ends, Escape puts the readout away
Focus ring—on the segment, outline-offset-2: it is a box, so its own ring is the right shape
Readout—on hover, tap and focus; aria-hidden

Names are always in words (legend, inline names or the summary), never the colour alone.

Do not

  • Do not use it for an allowance being used up. That is ds::usage-meter, a meter with warning and danger thresholds (and segments when the used part needs breaking down); a task's completion is ds::progress.
  • Do not use it for parts that do not add up to one whole.
  • Do not use it to compare two parts closely. Only the first segment starts at a common line, so the others are hard to measure against each other; use ds::bar-chart.
  • Do not pass negatives. It throws.

From the package repo: edit this page on GitHub.

Was this page helpful?