# DualWindowMeter (/docs/charts/dual-window-meter)

DualWindowMeter answers "is the level compliant against its target both right now and on average — momentary spikes vs
sustained drift?". From one raw series it computes two rolling means: a thin fast window that reacts instantly and a
thick slow window that carries the sustained read, both against a target line. It is the general form of any noisy
metric with a compliance target.

```tsx
<DualWindowMeter
  data={Array.from({ length: 60 }, (_, i) => -22 + Math.sin(i / 3) * 4 + Math.sin(i / 11) * 2 - (i > 40 ? 2 : 0))}
  target={-23}
  title="Loudness"
  format={{ maximumFractionDigits: 1 }}
  width={300}
  height={28}
/>
```

## Install

```tsx
import { DualWindowMeter } from "@microcharts/react/dual-window-meter";

<DualWindowMeter
  data={samples}
  target={-23}
  format={{ maximumFractionDigits: 1 }}
  title="Loudness"
/>
```

Setup (package + stylesheet): [Quickstart](/docs/quickstart#set-up-with-an-ai-agent) or paste [`/agent-setup.md`](/agent-setup.md) into your agent.


## When to use it

- **Good for** — loudness / LUFS metering, latency SLO or CPU-headroom compliance.
- **Avoid for** — a single series (Sparkline) or anything without a target to compare against.


## Variants

```tsx
const samples = Array.from(
  { length: 60 },
  (_, i) => -22 + Math.sin(i / 3) * 4 + Math.sin(i / 11) * 2,
);

<DualWindowMeter data={samples} target={-23} band={[-25, -21]} />
```

```tsx
const samples = Array.from(
  { length: 60 },
  (_, i) => -22 + Math.sin(i / 3) * 4 + Math.sin(i / 11) * 2,
);

// both window sizes are part of the reading — state them, never hide them

<DualWindowMeter data={samples} target={-23} windows={[5, 20]} />
```

```tsx
const samples = Array.from(
  { length: 60 },
  (_, i) => -22 + Math.sin(i / 3) * 4 + Math.sin(i / 11) * 2 - (i > 40 ? 2 : 0),
);

<DualWindowMeter
  data={samples}
  target={-23}
  format={{ maximumFractionDigits: 1 }}
  locale="de-DE"
/>
```

With a `locale`, the right-edge readings and the accessible summary follow that locale's decimal mark — the fast reading
above renders "-23,9", not "-23.9", and the accessible name reads "Slow window -25 vs target -23; fast -23,9."

## Edge cases

```tsx
// 10 samples with the default windows=[3, 30]: the fast trace fills at
// sample 3, the slow trace never fills — it stays absent rather than
// faking a partial-window value, and its readout shows "—"
<DualWindowMeter
  data={[48, 48.3, 48.6, 48.9, 49.2, 49.5, 49.8, 50.1, 50.4, 50.7]}
  target={50}
/>
```


## Why this default

Thin-fast, thick-slow because the sustained read should carry more ink — a momentary spike on the fast trace matters
less than a slow-window drift away from target. The window sizes are part of the reading, not a hidden implementation
detail — `windows` is an explicit prop, and the examples that change it state both sizes. Both traces always share one
domain; a trace begins only where its window has filled, never faking a partial-window value.

## Accessibility

The accessible name leads with the sustained read — **"Slow window -25 vs target -23; fast -23,9."** The interactive
entry roves the samples with ←/→, announcing the fast value, the slow value, and the target at each point.

The interactive entry follows the shared [interaction contract](/docs/accessibility#one-interaction-contract):
arrow keys rove between units on both axes, `Home` and `End` jump to the ends, and a click, tap, `Enter` or
`Space` selects a unit — pinning its readout so it survives blur, until you select it again or press `Escape`.
On touch, a tap pins and a drag scrubs.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `data` (required) | `number[]` | Raw samples; two rolling means are computed. |
| `target` (required) | `number` | The compliance line — required. |
| `windows` | `[number, number]` | Fast/slow integration windows (samples). |
| `band` | `[number, number]` | A compliance corridor instead of one line. |
| `domain` | `[number, number]` | Fix the vertical scale instead of auto-fitting both traces. |
| `animate` | `boolean` | (interactive) Opt-in entrance motion when the chart mounts client-side — add `import "@microcharts/react/motion"` once. Inert on the server, on hydrated server HTML, and under `prefers-reduced-motion`. |

Plus the shared grammar — `data`, `domain`, `color`, `title`, `summary`, `format` — and the layout props (`width`, `height`, `className`, `style`) that every chart accepts. Interactive entries also share `animate` and `live`, and — wherever a chart has more than one navigable unit — `onActive`, `onSelect`, `selectedIndex` and `defaultSelectedIndex`; and — wherever the chart shows a hover value — `readout`. See [the shared grammar](/docs/quickstart#the-shared-grammar).
