# Meter group

Several values in one bar, such as the parts of a storage quota, with a legend of labels and values.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-meter-group`
- Source: [libs/ui/src/lib/molecules/meter-group/meter-group.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/meter-group/meter-group.ts)

```typescript title="Import"
import { MeterGroup } from '@vigdx/ui/meter-group';
```

## Basic

`values` is a list of `{ label, value, color? }`; `max` (default 100) is a full bar. The legend shows each value as a percentage of `max`, formatted for the active locale.

```typescript title="meter-group-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MeterGroup, type MeterGroupValue } from '@vigdx/ui/meter-group';

@Component({
  selector: 'app-meter-group-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MeterGroup],
  template: `<vig-meter-group label="Storage" [values]="usage" />`,
})
export class MeterGroupBasicDemo {
  protected readonly usage: MeterGroupValue[] = [
    { label: 'Apps', value: 16 },
    { label: 'Photos', value: 24 },
    { label: 'Messages', value: 9 },
    { label: 'System', value: 12 },
  ];
}
```

## Units, colors and legend

`formatValue` is a function of the value and `max` for the legend and the screen-reader text. `color` takes a theme color name (`primary`, `secondary`, `info`, `success`, `warning`, `error`, `accent`); without it the segments take `METER_GROUP_PALETTE` in order. An unknown name falls back to the palette with a dev-mode warning. `patterns` adds a pattern (stripes, hatching) to each segment and its swatch, so they match by shape too. `legend` is `end` (below), `start` (above) or `none`; `size` sets the bar thickness, which follows the font. Values past `max` are cut off in the bar; the legend and the screen-reader text keep the real numbers. The bar shares its width, less the 2px gaps, in proportion to the values and draws every non-zero segment at least 2px wide, so very small values are approximated: the legend gives them exactly.

```typescript title="meter-group-format.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { MeterGroup, type MeterGroupValue } from '@vigdx/ui/meter-group';

@Component({
  selector: 'app-meter-group-format',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [MeterGroup],
  template: `
    <div class="flex flex-col gap-8">
      <vig-meter-group
        label="Storage (128 GB)"
        [values]="disk"
        [max]="128"
        [formatValue]="gigabytes"
        size="lg"
      />
      <vig-meter-group label="Support tickets" [values]="tickets" legend="start" patterns />
    </div>
  `,
})
export class MeterGroupFormatDemo {
  protected readonly disk: MeterGroupValue[] = [
    { label: 'Documents', value: 18.5 },
    { label: 'Media', value: 52 },
    { label: 'Backups', value: 30 },
  ];
  protected readonly tickets: MeterGroupValue[] = [
    { label: 'Resolved', value: 52, color: 'success' },
    { label: 'Waiting', value: 23, color: 'warning' },
    { label: 'Escalated', value: 8, color: 'error' },
    { label: 'New', value: 17, color: 'info' },
  ];
  private readonly number = new Intl.NumberFormat('en', { maximumFractionDigits: 1 });
  protected readonly gigabytes = (value: number) => `${this.number.format(value)} GB`;
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="meter-group"][data-part="label"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="meter-group"]`

| Part | Element | data-state |
| --- | --- | --- |
| `label` | The label naming the meter (`aria-labelledby`). |   |
| `track` | The `role="meter"` bar. |   |
| `segment` | One value in the bar (at least 2px wide). |   |
| `remainder` | The unused rest of the bar, up to `max`. |   |
| `legend` | The `<ul>` legend. |   |
| `legend-item` | One legend entry. |   |
| `swatch` | The color (or forced-colors pattern) of an entry. |   |
| `legend-label` | The label of an entry. |   |
| `legend-value` | The formatted value of an entry. |   |

## Accessibility

- The bar is one `role="meter"` named by `label` (keep it with `hideLabel` for screen readers only). Its value is the sum of the segments and its `aria-valuetext` lists every segment and the total ("Apps: 16%, Photos: 24%, …, total 61% of 100%", `labels.totalLabel` for the total, `labels.segmentLabel`), so a screen reader that lands on the meter hears all parts at once. One meter per segment would be announced as unrelated meters, with no names of their own in some screen readers; the visible legend repeats the parts as a plain list that every screen reader reads.
- Segment colors are theme tokens that hold 3:1 against the page in the kit's light and dark palettes. A 2px gap shows the page between segments, so neighbours need contrast with the page, not with each other; the legend gives every value in text, so color is never the only cue, and `patterns` matches segments to legend entries by shape too. A rebranded `--color-primary` must keep 3:1 against the background for this to hold.
- Forced-colors mode replaces the colors with six system-color patterns, one per palette color (solid, diagonal, vertical, horizontal and reverse diagonal stripes, cross-hatching), drawn in the bar and the legend swatches alike, and outlines the bar.

## API

### MeterGroup

Selector: `vig-meter-group` · Kind: component

Several values in one bar, such as the parts of a storage quota, with a legend of labels and values.

**Example :**

```html
<vig-meter-group label="Storage" [values]="usage" />
```

The bar is one `role="meter"` named by `label`: its value is the sum of the segments and its `aria-valuetext` lists every segment and the total ("Apps: 20%, Photos: 35%, total 55% of 100%"), so a screen reader that reaches the meter hears all parts at once. The legend repeats them as a visible list. Segment colors are theme tokens (`color`, or `METER_GROUP_PALETTE` in order); a 2px gap separates neighbours, so each segment needs contrast with the page only, not with the next one. The bar shares its width, less the gaps, in proportion to the values, and draws every non-zero segment at least 2px wide, so tiny values are approximated. Forced-colors mode draws a pattern per segment; `patterns` draws them in normal mode too.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `formatValue` | `((value: number, max: number) => string) \| undefined` | `undefined` | Text of a value in the legend and in `aria-valuetext`, e.g. `(value) => value + ' GB'`; the share of `max` as a locale percentage by default. |
| `hideLabel` | `boolean` | `false` | Keeps the label for screen readers only. |
| `label` (required) | `string` | — | Names the meter; shown above the bar unless `hideLabel`. |
| `labels` | `Partial<MeterGroupLabels>` | — | Texts (i18n); locale defaults. |
| `legend` | `MeterGroupLegend` | `'end'` | Legend above (`start`) or below (`end`) the bar, or `none`. |
| `max` | `number \| undefined` | `100` | The value of a full bar; segments past it are cut off. Default 100. |
| `patterns` | `boolean` | `false` | Draws a pattern over each segment and swatch (stripes, hatching), so segments and their legend entries match by shape, not by hue alone. |
| `size` | `MeterGroupSize` | `'md'` | Bar thickness; it scales with the font. |
| `values` | `readonly MeterGroupValue[]` | `[]` | The segments, in order along the bar. |
