v22.18.0 release notes

Gauge

Gauge displays a value on a scale as an arc, a dial with a needle or a linear bar, with colored ranges, ticks and labels, a center template and smooth transitions. It is a read-only meter drawn in SVG, rendered on the server, with no dependency.

View as .md
import { Gauge } from '@exhaustive-ui/core/gauge';

Gauge displays its value on a scale from min to max, 0 to 100 by default. The default arc type fills a half circle up to the value and writes the value in its center, formatted by valueFormatter. It is a read-only indicator, not an input: use Knob or Slider to let the user change a value. The label is a visible caption that also names the gauge for screen readers.

Storage used

startAngle and endAngle shape the arc, in degrees, 0 at the top and clockwise: -90 and 90 draw the default half circle, -135 and 135 three quarters of a circle. thickness sets the width of the arc, in units of the drawing, which is about 200 units wide, and reverse fills it from the end. color takes any CSS color, design token variables included.

Three quarters
Thin
Reverse

The radial type is a dial: a scale with major and minor ticks and labels, and a needle that points to the value, with the value under the needle. It goes from -135 to 135 degrees by default; startAngle and endAngle make a half dial or any other shape.

Speed
Engine speed

The linear type is a bar with a pointer and a scale. It is horizontal by default and takes the full width; it starts on the right in a right-to-left page. With orientation set to vertical the minimum is at the bottom and size is the height.

Upload progress
Temperature
Water level

ranges draws colored bands on the scale, from from to to. Without color or severity, they take the success, warn and danger colors of the theme in that order; severity picks a theme color and color any CSS color. The value takes the color of the range it is in, unless colorByRange is false or color is set.

The label of the range the value is in is displayed under the value and read by screen readers with it, so that the color is never the only information.

CPU load
Memory
Air quality index

scale configures the ticks and their labels. Radial and linear gauges have a scale by default, arc gauges when scale is set. step is the interval between two major ticks, a round step by default; ticks lists the values of the major ticks instead; minorTicks is the number of intervals between two major ticks, drawn with minor ticks; labels hides the labels when false, and labelFormatter formats them. false removes the scale.

Bandwidth
Fuel
Monthly budget

A center template replaces the value text of an arc or radial gauge. It receives the value as implicit variable, its percent on the scale, the formattedValue and the range the value is in. It is HTML, placed above the center of a half circle and on the center of a larger arc.

Sales goal
72 %of 100 sales
Daily steps
7,840Almost there

The gauge follows its value: the arc, the needle and the pointer move smoothly to the new value. animate set to false removes the transition, which is also disabled when the user prefers reduced motion. Move the slider to change the value of the three gauges.

Arc
Radial
Linear

A server dashboard: gauges of every type share the same ranges and fill their tile with size set to 100%, the drawing scaling with its viewBox. Each gauge is named by its caption and reads its value with its range.

CPU
Memory
Temperature
System disk
Data disk

Screen Reader

Gauge has the meter role with aria-valuenow, aria-valuemin and aria-valuemax, and an aria-valuetext made of the formatted value and the label of its range, for example "72 %, High". ariaValueText replaces it. The label caption names the gauge through aria-labelledby; ariaLabel and ariaLabelledBy name it without a visible caption, and the default name is "Gauge", the gauge text of labels. A null value has no aria-valuenow and reads "No value".

The SVG is hidden from assistive technologies: the meter carries the information. The value is displayed with the label of its range, so that the colors of the ranges are never the only information; when showValue hides them, display the value elsewhere. Some older screen readers do not support the meter role yet: role set to img turns the gauge into an image whose accessible name ends with the value text, "CPU: 72 %, High".

The gauge does not announce its changes, as a live value would interrupt the user all the time. When reaching a range matters, a critical level for example, announce it with a message or a toast. The transitions of the arc, the needle and the pointer are disabled when the user prefers reduced motion.

<p-gauge [value]="72" label="CPU" [ranges]="ranges" [valueFormatter]="percent" />

<p-gauge [value]="72" ariaLabel="CPU load" ariaValueText="72 percent" />

<p-gauge [value]="72" role="img" ariaLabel="CPU" />

<p-gauge [value]="null" [labels]="{ gauge: 'Jauge', noValue: 'Aucune valeur' }" />

Keyboard Support

The gauge is read-only and not focusable: screen reader users reach it with their reading keys.