# Angular Gauge Component

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.

## Basic

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex justify-center">
            <p-gauge [value]="72" label="Storage used" [valueFormatter]="percent" />
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeBasicDemo {
    percent = (value: number) => `${value} %`;
}
```

## Arc

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-wrap justify-center gap-8">
            <p-gauge [value]="64" label="Three quarters" [startAngle]="-135" [endAngle]="135" />
            <p-gauge [value]="38" label="Thin" [thickness]="6" color="var(--p-primary-color)" />
            <p-gauge [value]="81" label="Reverse" [reverse]="true" [thickness]="24" />
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeArcDemo {
}
```

## Radial

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-wrap justify-center gap-8">
            <p-gauge type="radial" [value]="88" [min]="0" [max]="220" label="Speed" [valueFormatter]="speed" />
            <p-gauge type="radial" [value]="3.2" [min]="0" [max]="8" [startAngle]="-90" [endAngle]="90" label="Engine speed" [valueFormatter]="rpm" />
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeRadialDemo {
    speed = (value: number) => `${value} km/h`;

    rpm = (value: number) => `${value}k rpm`;
}
```

## Linear

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-col gap-8">
            <p-gauge type="linear" [value]="42" label="Upload progress" [valueFormatter]="percent" />
            <div class="flex flex-wrap justify-center gap-12">
                <p-gauge type="linear" orientation="vertical" [value]="21" [min]="-10" [max]="40" label="Temperature" [valueFormatter]="celsius" />
                <p-gauge type="linear" orientation="vertical" [value]="7.5" [min]="0" [max]="10" size="14rem" label="Water level" [valueFormatter]="meters" />
            </div>
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeLinearDemo {
    percent = (value: number) => `${value} %`;

    celsius = (value: number) => `${value} °C`;

    meters = (value: number) => `${value} m`;
}
```

## Ranges

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule, GaugeRange } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-col gap-8">
            <div class="flex flex-wrap justify-center gap-8">
                <p-gauge [value]="72" [ranges]="ranges" label="CPU load" [valueFormatter]="percent" />
                <p-gauge type="radial" [value]="91" [ranges]="ranges" label="Memory" [valueFormatter]="percent" />
            </div>
            <p-gauge type="linear" [value]="38" [min]="0" [max]="150" [ranges]="airQuality" label="Air quality index" />
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeRangesDemo {
    ranges: GaugeRange[] = [
        { from: 0, to: 60, label: 'Normal' },
        { from: 60, to: 85, label: 'High' },
        { from: 85, to: 100, label: 'Critical' }
    ];

    airQuality: GaugeRange[] = [
        { from: 0, to: 50, color: '#15803d', label: 'Good' },
        { from: 50, to: 100, color: '#ca8a04', label: 'Moderate' },
        { from: 100, to: 150, severity: 'danger', label: 'Unhealthy' }
    ];

    percent = (value: number) => `${value} %`;
}
```

## Scale and Labels

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule, GaugeScale } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-col gap-8">
            <div class="flex flex-wrap justify-center gap-8">
                <p-gauge [value]="1.8" [min]="0" [max]="5" [scale]="arcScale" label="Bandwidth" [valueFormatter]="gbps" />
                <p-gauge type="radial" [value]="65" [scale]="fuelScale" label="Fuel" [valueFormatter]="percent" />
            </div>
            <p-gauge type="linear" [value]="1450" [min]="0" [max]="2000" [scale]="budgetScale" label="Monthly budget" [valueFormatter]="euros" />
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeScaleDemo {
    arcScale: GaugeScale = { step: 1, minorTicks: 4 };

    fuelScale: GaugeScale = { ticks: [0, 25, 50, 75, 100], minorTicks: 1, labelFormatter: (value: number) => ({ 0: 'E', 25: '¼', 50: '½', 75: '¾', 100: 'F' })[value] ?? `${value}` };

    budgetScale: GaugeScale = { step: 500, minorTicks: 5, labelFormatter: (value: number) => `${value / 1000}k` };

    gbps = (value: number) => `${value} Gb/s`;

    percent = (value: number) => `${value} %`;

    euros = (value: number) => `${value} €`;
}
```

## Center Template

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.

```typescript
import { Component } from '@angular/core';
import { GaugeModule, GaugeRange } from '@exhaustive-ui/core/gauge';

@Component({
    template: `
        <div class="card flex flex-wrap justify-center gap-8">
            <p-gauge [value]="72" label="Sales goal">
                <ng-template #center let-percent="percent">
                    <span class="text-4xl font-bold">{{ percent }} %</span>
                    <span class="text-sm text-muted-color">of 100 sales</span>
                </ng-template>
            </p-gauge>
            <p-gauge [value]="7840" [min]="0" [max]="10000" [startAngle]="-135" [endAngle]="135" [ranges]="ranges" label="Daily steps">
                <ng-template #center let-formatted="formattedValue" let-range="range">
                    <span class="text-3xl font-bold">{{ formatted }}</span>
                    <span class="text-sm text-muted-color">{{ range?.label }}</span>
                </ng-template>
            </p-gauge>
        </div>
    `,
    standalone: true,
    imports: [GaugeModule]
})
export class GaugeTemplateDemo {
    ranges: GaugeRange[] = [
        { from: 0, to: 5000, severity: 'secondary', label: 'Keep going' },
        { from: 5000, to: 10000, severity: 'success', label: 'Almost there' }
    ];
}
```

## Live Value

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.

```typescript
import { Component, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { GaugeModule, GaugeRange } from '@exhaustive-ui/core/gauge';
import { SliderModule } from '@exhaustive-ui/core/slider';
import { ToggleSwitchModule } from '@exhaustive-ui/core/toggleswitch';

@Component({
    template: `
        <div class="card flex flex-col items-center gap-8">
            <div class="flex flex-wrap items-center justify-center gap-6 w-full max-w-xl">
                <p-slider [ngModel]="value()" (ngModelChange)="value.set($event)" ariaLabel="Value" class="flex-1 min-w-48" />
                <div class="flex items-center gap-2">
                    <p-toggle-switch inputId="gauge-live-animate" [ngModel]="animate()" (ngModelChange)="animate.set($event)" />
                    <label for="gauge-live-animate">Animate</label>
                </div>
            </div>
            <div class="flex flex-wrap items-center justify-center gap-8 w-full">
                <p-gauge [value]="value()" [ranges]="ranges" [animate]="animate()" label="Arc" />
                <p-gauge type="radial" [value]="value()" [ranges]="ranges" [animate]="animate()" label="Radial" />
                <p-gauge type="linear" orientation="vertical" [value]="value()" [ranges]="ranges" [animate]="animate()" size="14rem" label="Linear" />
            </div>
        </div>
    `,
    standalone: true,
    imports: [GaugeModule, SliderModule, ToggleSwitchModule, FormsModule]
})
export class GaugeLiveDemo {
    value = signal(40);

    animate = signal(true);

    ranges: GaugeRange[] = [
        { from: 0, to: 50, label: 'Low' },
        { from: 50, to: 80, label: 'Medium' },
        { from: 80, to: 100, label: 'High' }
    ];
}
```

## Dashboard

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.

```typescript
import { Component, signal } from '@angular/core';
import { ButtonModule } from '@exhaustive-ui/core/button';
import { GaugeModule, GaugeRange } from '@exhaustive-ui/core/gauge';

interface Disk {
    id: string;
    label: string;
    value: number;
    max: number;
    ranges: GaugeRange[];
}

function diskRanges(max: number): GaugeRange[] {
    return [
        { from: 0, to: max * 0.8, label: 'Normal' },
        { from: max * 0.8, to: max * 0.9, label: 'Almost full' },
        { from: max * 0.9, to: max, label: 'Full' }
    ];
}

@Component({
    template: `
        <div class="card flex flex-col gap-6">
            <div class="flex justify-end">
                <p-button label="Refresh the metrics" severity="secondary" [outlined]="true" (onClick)="refresh()" />
            </div>
            <div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4">
                <div class="flex justify-center p-4 border border-surface rounded-border">
                    <p-gauge [value]="cpu()" [ranges]="ranges" size="100%" label="CPU" [valueFormatter]="percent" />
                </div>
                <div class="flex justify-center p-4 border border-surface rounded-border">
                    <p-gauge [value]="memory()" [ranges]="ranges" [startAngle]="-135" [endAngle]="135" size="100%" label="Memory" [valueFormatter]="percent" />
                </div>
                <div class="flex justify-center p-4 border border-surface rounded-border">
                    <p-gauge type="radial" [value]="temperature()" [min]="20" [max]="100" [ranges]="temperatureRanges" size="100%" label="Temperature" [valueFormatter]="celsius" />
                </div>
                <div class="flex flex-col justify-center gap-6 p-4 border border-surface rounded-border">
                    @for (disk of disks(); track disk.id) {
                        <p-gauge type="linear" [value]="disk.value" [max]="disk.max" [ranges]="disk.ranges" [label]="disk.label" [valueFormatter]="gigabytes" />
                    }
                </div>
            </div>
        </div>
    `,
    standalone: true,
    imports: [GaugeModule, ButtonModule]
})
export class GaugeDashboardDemo {
    cpu = signal(46);

    memory = signal(71);

    temperature = signal(58);

    disks = signal<Disk[]>([
        { id: 'system', label: 'System disk', value: 182, max: 256, ranges: diskRanges(256) },
        { id: 'data', label: 'Data disk', value: 930, max: 1000, ranges: diskRanges(1000) }
    ]);

    ranges: GaugeRange[] = [
        { from: 0, to: 70, label: 'Normal' },
        { from: 70, to: 90, label: 'High' },
        { from: 90, to: 100, label: 'Critical' }
    ];

    temperatureRanges: GaugeRange[] = [
        { from: 20, to: 70, label: 'Normal' },
        { from: 70, to: 85, label: 'Hot' },
        { from: 85, to: 100, label: 'Overheating' }
    ];

    percent = (value: number) => `${value} %`;

    celsius = (value: number) => `${value} °C`;

    gigabytes = (value: number) => `${value} GB`;

    refresh() {
        const random = (min: number, max: number) => Math.round(min + Math.random() * (max - min));

        this.cpu.set(random(5, 100));
        this.memory.set(random(30, 98));
        this.temperature.set(random(35, 95));
        this.disks.update((disks) => disks.map((disk) => ({ ...disk, value: random(disk.max * 0.4, disk.max) })));
    }
}
```

## Accessibility

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.

## 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. It is a read-only meter drawn in SVG.

### Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| dt | Object | undefined | Defines scoped design tokens of the component. |
| unstyled | boolean | undefined | Indicates whether the component should be rendered without styles. |
| pt | GaugePassThrough | undefined | Used to pass attributes to DOM elements inside the component. |
| ptOptions | PassThroughOptions | undefined | Used to configure passthrough(pt) options of the component. |
| type | GaugeType | 'arc' | Shape of the gauge: a thick arc, a dial with a needle or a linear bar. |
| value | number | null | Value to display, clamped between  `min`  and  `max` . Null displays an empty gauge with the  `noValue`  text. |
| min | number | 0 | Minimum of the scale. |
| max | number | 100 | Maximum of the scale. |
| ranges | GaugeRange[] | - | Colored bands of the scale, for example good, warning and critical. Each range takes its  `color` , else the theme color of its  `severity` , else the success, warn and danger colors in order. The label of the range the value is in is displayed and read with the value. |
| scale | boolean \| GaugeScale | - | Ticks and labels of the scale;  `true`  for the default scale,  `false`  for none. Arc gauges have no scale by default, radial and linear gauges have one. |
| reverse | boolean | false | Whether the scale goes from the end to the start: counterclockwise, from right to left or from top to bottom. |
| startAngle | number | - | Angle where the scale starts, in degrees, 0 at the top and clockwise. Defaults to -90 for an arc and -135 for a radial gauge. |
| endAngle | number | - | Angle where the scale ends, in degrees, 0 at the top and clockwise. Defaults to 90 for an arc and 135 for a radial gauge. |
| orientation | GaugeOrientation | 'horizontal' | Direction of a linear gauge. |
| thickness | number | - | Thickness of the arc, of the bar or of the ranges of a dial, in units of the drawing: an arc gauge is about 200 units wide, a horizontal gauge 300. Defaults to 16 for an arc, 6 for a radial gauge and 12 for a linear gauge. |
| size | string \| number | - | Width of an arc, radial or horizontal gauge, height of a vertical one: a number of pixels or any CSS length. The drawing scales with it. Defaults to the  `gauge.size`  design token, the full width for a horizontal gauge. |
| color | string | - | Color of the value arc or bar, any CSS color. Defaults to the color of the range the value is in, else to the  `gauge.value.background`  design token. |
| colorByRange | boolean | true | Whether the value arc or bar takes the color of the range the value is in. |
| valueFormatter | (value: number) => string | - | Formats the value displayed and read by screen readers, for example  `(value) => value + ' %'` . Defaults to the number formatted for the locale of the application. |
| showValue | boolean | true | Whether the value and the label of its range are displayed. When they are hidden, display the value elsewhere: the color and the needle are not enough for everyone. |
| animate | boolean | true | Whether a change of value moves the arc, the needle or the pointer smoothly. The transition is disabled when the user prefers reduced motion. |
| label | string | - | Visible caption of the gauge, also its accessible name. |
| role | GaugeRole | 'meter' | Role of the gauge:  `meter` , or  `img`  for assistive technologies that do not support the meter role; the value text is then part of the accessible name. |
| ariaLabel | string | - | Accessible name of the gauge. Defaults to the  `label` , else to the  `gauge`  text of  `labels` . |
| ariaLabelledBy | string | - | Id of the element that labels the gauge. |
| ariaValueText | string | - | Text read by screen readers for the value. Defaults to the formatted value followed by the label of its range, for example "72 %, Warning". |
| labels | Partial<GaugeLabels> | - | Texts of the component. Missing keys keep their default. |

### Templates

| Name | Type | Description |
|------|------|-------------|
| center | TemplateRef<GaugeCenterTemplateContext> | Custom content in the center of an arc or radial gauge, in place of the value text, for example a value with a unit and a caption. |

## Pass Through Options

| Name | Type | Description |
|------|------|-------------|
| host | PassThroughOption<HTMLElement, I> | Used to pass attributes to the host's DOM element, with the meter role. |
| root | PassThroughOption<HTMLElement, I> | Used to pass attributes to the root's DOM element, the host. |
| body | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the element that holds the SVG and the center template. |
| svg | PassThroughOption<SVGElement, I> | Used to pass attributes to the SVG element, hidden from assistive technologies. |
| track | PassThroughOption<SVGElement, I> | Used to pass attributes to the track, the full scale behind the value. |
| value | PassThroughOption<SVGElement, I> | Used to pass attributes to the value arc or bar. |
| ranges | PassThroughOption<SVGGElement, I> | Used to pass attributes to the group of the colored ranges. |
| range | PassThroughOption<SVGElement, I> | Used to pass attributes to each colored range. |
| ticks | PassThroughOption<SVGGElement, I> | Used to pass attributes to the group of the ticks and their labels. |
| majorTick | PassThroughOption<SVGLineElement, I> | Used to pass attributes to each major tick. |
| minorTick | PassThroughOption<SVGLineElement, I> | Used to pass attributes to each minor tick. |
| tickLabel | PassThroughOption<SVGTextElement, I> | Used to pass attributes to each label of the scale. |
| needle | PassThroughOption<SVGGElement, I> | Used to pass attributes to the needle of the radial gauge. |
| needleCap | PassThroughOption<SVGCircleElement, I> | Used to pass attributes to the circle at the base of the needle. |
| pointer | PassThroughOption<SVGGElement, I> | Used to pass attributes to the pointer of the linear gauge. |
| valueText | PassThroughOption<SVGTextElement, I> | Used to pass attributes to the text of the value. |
| rangeLabel | PassThroughOption<SVGTextElement, I> | Used to pass attributes to the label of the range the value is in. |
| center | PassThroughOption<HTMLDivElement, I> | Used to pass attributes to the element that holds the center template. |
| label | PassThroughOption<HTMLSpanElement, I> | Used to pass attributes to the visible caption of the  `label`  input. |

## Theming

### CSS Classes

| Class | Description |
|-------|-------------|
| p-gauge | Class name of the root element |
| p-gauge-label | Class name of the visible caption |
| p-gauge-body | Class name of the element that holds the SVG and the center template |
| p-gauge-svg | Class name of the SVG element |
| p-gauge-track | Class name of the track |
| p-gauge-value | Class name of the value arc or bar |
| p-gauge-ranges | Class name of the group of the ranges |
| p-gauge-range | Class name of a range |
| p-gauge-ticks | Class name of the group of the ticks |
| p-gauge-tick-major | Class name of a major tick |
| p-gauge-tick-minor | Class name of a minor tick |
| p-gauge-tick-label | Class name of a label of the scale |
| p-gauge-needle | Class name of the needle |
| p-gauge-needle-cap | Class name of the cap of the needle |
| p-gauge-pointer | Class name of the pointer of a linear gauge |
| p-gauge-value-text | Class name of the value text |
| p-gauge-range-label | Class name of the label of the current range |
| p-gauge-center | Class name of the center template container |

### Design Tokens

| Token | CSS Variable | Description |
|-------|--------------|-------------|
| gauge.size | --p-gauge-size | Width of an arc or radial gauge, of root |
| gauge.vertical.size | --p-gauge-vertical-size | Height of a vertical linear gauge, of root |
| gauge.gap | --p-gauge-gap | Gap between the gauge and its caption, of root |
| gauge.color | --p-gauge-color | Color of root |
| gauge.transition.duration | --p-gauge-transition-duration | Transition duration of the value, the needle and the pointer, of root |
| gauge.label.color | --p-gauge-label-color | Color of label |
| gauge.label.font.size | --p-gauge-label-font-size | Font size of label |
| gauge.label.font.weight | --p-gauge-label-font-weight | Font weight of label |
| gauge.track.background | --p-gauge-track-background | Background of track |
| gauge.value.background | --p-gauge-value-background | Background of value |
| gauge.value.text.color | --p-gauge-value-text-color | Color of value text |
| gauge.value.text.font.weight | --p-gauge-value-text-font-weight | Font weight of value text |
| gauge.value.text.arc.font.size | --p-gauge-value-text-arc-font-size | Font size of the value text of an arc gauge, of value text |
| gauge.value.text.radial.font.size | --p-gauge-value-text-radial-font-size | Font size of the value text of a radial gauge, of value text |
| gauge.value.text.linear.font.size | --p-gauge-value-text-linear-font-size | Font size of the value text of a linear gauge, of value text |
| gauge.range.success.background | --p-gauge-range-success-background | Success background of range |
| gauge.range.info.background | --p-gauge-range-info-background | Info background of range |
| gauge.range.warn.background | --p-gauge-range-warn-background | Warn background of range |
| gauge.range.danger.background | --p-gauge-range-danger-background | Danger background of range |
| gauge.range.secondary.background | --p-gauge-range-secondary-background | Secondary background of range |
| gauge.range.label.color | --p-gauge-range-label-color | Color of range label |
| gauge.range.label.font.weight | --p-gauge-range-label-font-weight | Font weight of range label |
| gauge.range.label.font.size | --p-gauge-range-label-font-size | Font size of range label |
| gauge.range.label.small.font.size | --p-gauge-range-label-small-font-size | Font size of the range label of radial and linear gauges, of range label |
| gauge.tick.color | --p-gauge-tick-color | Color of tick |
| gauge.tick.label.color | --p-gauge-tick-label-color | Color of tick label |
| gauge.tick.label.font.size | --p-gauge-tick-label-font-size | Font size of tick label |
| gauge.needle.background | --p-gauge-needle-background | Background of needle |
| gauge.pointer.background | --p-gauge-pointer-background | Background of pointer |

