Distribution Bar
One 100% stacked bar of a breakdown, with a legend of shares and the hovered part brought forward.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
items | DistributionItem[] | [] | The breakdown, { label, value, color?, key? } in any unit. Accepts a JSON string as an attribute. |
label | string | — | Label when the default slot is empty. |
sort | 'none' | 'descending' | none | Orders the parts largest first; none (the default) keeps the order given. |
max-items | number | 0 | Most parts drawn; past it, the smallest items are summed into one "Other" part. 0 (the default) draws every item. |
legend-content | 'percent' | 'value' | 'both' | percent | What each legend entry shows after its label: its percent share (the default), its value, or both. |
precision | number | 1 | Most decimal places of a share. A share too small to show at it reads "<0.1%". |
interactive | boolean | false | Makes the legend entries buttons and the segments clickable, both firing item-click. |
Slots
| Name | Description |
|---|---|
(default) | Label shown above the bar; also its accessible name. Falls back to the label attribute. |
header-end | Content at the end of the label row, such as a total or a link. |
Events
| Name | Type | Description |
|---|---|---|
item-click | CustomEvent<DistributionItemClickDetail> | Fired with interactive when a segment or a legend entry is activated. detail is the part: its key, label, value and share, and for "Other" the items it sums. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
header | Row holding the label and the header-end slot. |
label | Container of the label. |
bar | The bar; carries role="img" unless interactive. |
segment | Each part's segment of the bar. |
tooltip | Bubble over the bar naming the hovered part. |
legend | List of the parts under the bar. |
legend-item | One entry of the legend; a button with interactive. |
swatch | Colour mark of a legend entry. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-distribution-bar--width | pixel | 100% | Width of the bar; the host is a block. |
--c2-distribution-bar--gap | pixel | 8px | Space between the header, the bar and the legend. |
--c2-distribution-bar--transition-duration | time | 150ms | How long dimming and resizing take. |
--c2-distribution-bar__bar--height | pixel | 8px | |
--c2-distribution-bar__bar--border-radius | border-radius | 999px | Rounds the ends of the bar. |
--c2-distribution-bar__bar--background-color | color | #e4e4e7 | Colour of the empty bar, when nothing has a value. |
--c2-distribution-bar__segment--gap | pixel | 2px | Space between two segments. |
--c2-distribution-bar__segment--min-width | pixel | 2px | Narrowest a segment gets, so a tiny share stays visible. |
--c2-distribution-bar__segment__dimmed--opacity | opacity | 0.35 | Opacity of the other parts while one is hovered or focused. |
--c2-distribution-bar__segment-1--color | color | #0265dc | Fill of the 1st, 9th, 17th… part without a color. The eight follow the theme's chart series. |
--c2-distribution-bar__segment-2--color | color | #ea580c | |
--c2-distribution-bar__segment-3--color | color | #0f766e | |
--c2-distribution-bar__segment-4--color | color | #db2777 | |
--c2-distribution-bar__segment-5--color | color | #a16207 | |
--c2-distribution-bar__segment-6--color | color | #7c3aed | |
--c2-distribution-bar__segment-7--color | color | #0891b2 | |
--c2-distribution-bar__segment-8--color | color | #52525b | |
--c2-distribution-bar__other--color | color | #a1a1aa | Fill of the "Other" part. |
--c2-distribution-bar__label--color | color | #18181b | |
--c2-distribution-bar__label--font-size | font-size | 14px | |
--c2-distribution-bar__label--font-weight | font-weight | 600 | |
--c2-distribution-bar__legend--display | display | flex | none hides the legend; the bar still names every part to a screen reader. |
--c2-distribution-bar__legend--row-gap | pixel | 4px | Space between two rows of legend entries. |
--c2-distribution-bar__legend--column-gap | pixel | 16px | Space between two legend entries on a row. |
--c2-distribution-bar__legend--color | color | #18181b | Colour of a legend entry's label. |
--c2-distribution-bar__legend--font-size | font-size | 12px | |
--c2-distribution-bar__legend-value--color | color | #71717a | Colour of a legend entry's share or value. |
--c2-distribution-bar__swatch--size | pixel | 8px | |
--c2-distribution-bar__swatch--border-radius | border-radius | 999px | |
--c2-distribution-bar__legend-item--border-radius | border-radius | 4px | Corners of the focus ring and hover fill of an interactive legend entry. |
--c2-distribution-bar__legend-item__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | Focus ring of an interactive legend entry. |
--c2-distribution-bar__legend-item__hover--background-color | color | #f4f4f5 | Fill behind an interactive legend entry under the pointer. |
--c2-distribution-bar__tooltip--background-color | color | #18181b | |
--c2-distribution-bar__tooltip--color | color | #fafafa | |
--c2-distribution-bar__tooltip--font-size | font-size | 12px | |
--c2-distribution-bar__tooltip--padding | padding | 4px 8px | |
--c2-distribution-bar__tooltip--border-radius | border-radius | 6px | |
--c2-distribution-bar__tooltip--box-shadow | box-shadow | 0 8px 24px rgba(24, 24, 27, 0.08) | |
--c2-distribution-bar__tooltip--display | display | block | none turns the hover bubble off; the hovered part is still brought forward. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under distribution-bar, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Distribution | — |
other | Other | — |
empty | No data | — |
summary | {0}: {1} | {0} name {1} parts |
part | {0} {1} | {0} label {1} share |
both | {0} · {1} | {0} share {1} value |
below | <{0} | {0} smallest |