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

DualWindowMeter computes two rolling means from one raw series: a thin fast window that reacts instantly, and a thick
slow window that carries the sustained read. Both run against a target line, so a momentary spike stays separable from
sustained drift. The slow trace is the thicker of the two because drift away from target matters more than a spike, and
the window sizes are part of the reading, so `windows` is an explicit prop. 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.

## Try it

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

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

## When to use it

Use it for loudness and LUFS metering, latency SLO compliance, and CPU-headroom compliance. For a single series use
Sparkline, and reach for something else when there is no target to compare against.

## Sizing

**latency SLO cell**

```tsx
<DualWindowMeter data={samples} target={200} width={80} height={16} />
```

**with corridor**

```tsx
<DualWindowMeter data={samples} target={70} band={[60, 80]} />
```

## 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" rather than "-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}
/>
```

Both traces share one domain, and each begins only where its window has filled. With the default `windows={[3, 30]}` and
the 10 samples above, the fast trace starts at sample 3 and the slow trace never appears at all; its readout shows "—"
instead of a partial-window value.

## Four homes

**In a sentence**

```tsx
<p>
  Integrated loudness{" "}
  <span className="mc-inline">
    <DualWindowMeter data={samples} target={-23} summary={false} />
  </span>{" "}
  — −22 LUFS, within broadcast target.
</p>
```

**In a table cell**

```tsx
<td>
  <DualWindowMeter data={samples} target={-23} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">−22</span>
  <span className="unit">LUFS integrated</span>
  <DualWindowMeter data={samples} target={-23} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Track 1 <DualWindowMeter data={samples} target={-23} />
</button>
```

## 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, press `Escape`, or
press outside the chart. 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).
