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`
…
← the rest of `total`
← inline: the parts too narrow to name above
- …
legend: swatch, name, "150 GB · 30%"
← legend="below"
Part, Value, Share, the rest and the total
| Part | Token | Why |
|---|---|---|
| Segments | series-1 … series-8 by position; a row's tone or series instead | specs/chart-series.md |
| The rest | the progress track, fg/10 | It is the empty part of the same bar the progress and usage meter draw. |
| Gap | gap-0.5, 2px, showing the surface behind | No track colour behind the segments, so the gap is the surface in either theme. |
| Thickness | sm 8, md 12, lg 20px | |
| Least width | sm 8, md 12, lg 20px — as wide as the bar is tall | A 0.4% segment at an end would otherwise be shaved to nothing by the rounding. |
| Ends | first:rounded-s-full last:rounded-e-full | Logical, 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. |
inline | Each 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. |
none | No 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
| Case | Result |
|---|---|
[], or everything zero with no total | ds::empty-state, bare |
total larger than the sum | the rest draws as track, named remainderLabel ("Remaining") in the legend, the readout and the table |
total smaller than the sum, or not a number | ignored: the whole is the sum |
| a negative or a non-number | throws, naming the part |
| more than eight parts | throws: 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 script | With it | |
|---|---|---|
| Role | img on the bar | group, keeping the name; each segment img, "Photos: 150 GB (30%)" |
| Keyboard | none | one 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, ameterwith warning and danger thresholds (andsegmentswhen the used part needs breaking down); a task's completion isds::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.