Gauge

One reading against a known range, as an arc: CPU at 42%, a score of 8.4 out of 10. Thresholds colour it, and say in a word what the colour means.

Gauge

Use it

<x-ds::gauge label="CPU" :value="$cpu" :format="['suffix' => '%']" />

<x-ds::gauge label="Memory" :value="$memory" :format="['suffix' => '%']" :thresholds="[
    ['at' => 0, 'tone' => 'success'],
    ['at' => 70, 'tone' => 'warning'],
    ['at' => 90, 'tone' => 'danger', 'label' => 'Overloaded'],
]" />

<x-ds::gauge label="Score" :value="8.4" :max="10" :format="['decimals' => 1]" variant="ring" tone="accent" />

Props

PropTypeDefaultWhat it does
valuenumber or nullnullThe reading. null reads "No reading". Past either end the arc stops and the value still prints.
minnumber0The bottom of the range.
maxnumber100The top of the range.
labelstring—What is being measured. Always the accessible name. Required, unless you pass aria-label or aria-labelledby.
hideLabelboolfalseKeeps the name for screen readers and takes it off the screen.
variantsemi ringsemiA half circle with the range printed under it, or a full ring.
thresholdsarray—Bands of the range: each at, tone, and an optional label. Wins over tone.
toneneutral accent success warning dangerneutralThe arc's colour when there are no thresholds.
sizesm md lgmd
showValuebooltrueThe value in the middle.
formatarray[]How the value and range read; the keys are counter's.

Thresholds

From each band's at upward the arc takes its tone, and its label is shown and read with the value. Without a label the tone gives the word: success "Good", warning "Warning", danger "Critical"; neutral and accent give none. Bands are sorted for you. A value below the lowest at is neutral.

When to use which

Use it forExample
ProgressA task moving towards doneUploading, 64%
Usage meterAn allowance being used up, in its units42 of 50 credits
GaugeA reading that goes up and down within a rangeCPU at 42%

A gauge is the one to reach for when the value is a level, not a step towards finishing and not an amount spent: it can fall as well as rise, and the question is "is this healthy?". In a long list, prefer a usage meter or a number: a column of arcs is hard to compare.

Accessibility

  • role="meter", named by label, with aria-valuemin, aria-valuemax and aria-valuenow (clamped into the range, as a meter's value must be).
  • aria-valuetext is what is read: the printed value and the band's word, "76%, Warning"; past the range, "120%, above the maximum of 100%, Critical".
  • The word is on screen too, under the value or under the label, so colour is never the only thing that says it.
  • Not focusable, no keyboard interaction. It does not announce changes.

Don't

  • Don't use it for a task. That is a progress bar.
  • Don't use it for an allowance. "9 of 10 seats" is a usage meter, which says the units.
  • Don't give bands a tone without a word you'd stand behind. "Critical" at 60% CPU trains people to ignore it.
  • Don't use more than about four bands. Past that the colours stop meaning anything.

More in specs/gauge.md.


From the package repo: edit this page on GitHub.

Was this page helpful?