# QueueDepth (/docs/charts/queue-depth)

A support queue sits at 214 against a capacity of 100, and the question is whether it is draining or growing. QueueDepth
draws the queue **depth** as a zero-anchored area — a stock, not a rate — against a dashed **capacity** hairline.
Wherever the depth runs above capacity, the top edge is re-stroked in the negative ink, so a breach changes the _shape_
of the edge as well as its color and survives greyscale. The endpoint carries the current value and a trend glyph (▴/▾)
fit over the last quarter of the window: a low-precision direction cue, which is why the summary names that window in
words rather than projecting a finish.

```tsx
<QueueDepth
  data={[42, 55, 70, 88, 96, 120, 150, 182, 214]}
  capacity={100}
  title="Support queue"
  width={260}
  height={30}
/>
```

## Install

```tsx
import { QueueDepth } from "@microcharts/react/queue-depth";

<QueueDepth
  data={[42, 55, 70, 88, 96, 120, 150, 182, 214]}
  capacity={100}
  title="Support queue"
/>
```

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 { QueueDepth } from "@microcharts/react/queue-depth/interactive";

<QueueDepth
  data={data}
  capacity={100}
/>
```

## When to use it

Use it for a support-queue backlog in a KPI card, a work-in-progress stock against its WIP limit, and a will-it-drain
read in a tab header. For a rate rather than a stock use Sparkline; for a single count use Delta.

## Sizing

**draining below capacity**

```tsx
<QueueDepth data={[214, 190, 150, 120, 96, 70, 48]} capacity={100} />
```

**no capacity reference**

```tsx
<QueueDepth data={[42, 55, 70, 88, 96, 120, 150, 182, 214]} />
```

## Variants

```tsx
const backlog = [42, 55, 70, 88, 96, 120, 150, 182, 214];

<QueueDepth data={[214, 190, 150, 120, 96, 70, 48]} capacity={100} />
<QueueDepth data={backlog} />
<QueueDepth data={backlog} capacity={100} label="none" />
```

```tsx
<QueueDepth
  data={[420, 560, 720, 880, 1040, 1280, 1560, 1880, 2140]}
  capacity={1000}
  locale="de-DE"
/>
```

With a `locale`, both the endpoint label and the accessible summary's numbers follow that locale's own grouping. In
German the summary reads **"2.140 queued, 2,1× capacity, growing over the last quarter."** rather than "2,140 queued,
2.1× capacity".

## Edge cases

```tsx
// with no capacity the area still draws, but there's nothing to breach —
// the summary reports depth and trend without a capacity clause
<QueueDepth data={[42, 55, 70, 88, 96, 120, 150, 182, 214]} />
```

```tsx
<QueueDepth data={[90, 70, 50, 30]} capacity={100} />
```

```tsx
// null / NaN / ±Infinity break the area into separate runs — a measured
// gap, never interpolated across
<QueueDepth data={[10, null, 40, null, 80, 120]} capacity={100} />
```

With no `capacity`, the area still draws and the summary reads **"214 queued, growing over the last quarter."** The
capacity clause drops, because there is nothing to compare against. A queue that stays under capacity reports **"30
queued, within capacity, draining over the last quarter."** and never re-strokes the edge. Gaps
(`null`/`NaN`/`±Infinity`) split the area into separate runs rather than drawing a line across missing periods.

## Four homes

**In a sentence**

```tsx
<p>
  Support queue backlog{" "}
  <span className="mc-inline">
    <QueueDepth data={data} capacity={100} summary={false} />
  </span>{" "}
  — 64 open, approaching capacity.
</p>
```

**In a table cell**

```tsx
<td>
  <QueueDepth data={data} capacity={100} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">64</span>
  <span className="unit">open tickets</span>
  <QueueDepth data={data} capacity={100} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Tier 1 <QueueDepth data={data} capacity={100} />
</button>
```

## Accessibility

The accessible name states the current depth, the capacity relationship, and the trend: **"214 queued, 2.1× capacity,
growing over the last quarter."** When the depth stays under capacity the middle clause becomes "within capacity"; with
no `capacity` it drops. The interactive entry steps the periods, announcing each depth and whether it is above capacity
(**"t8: 214 queued, above capacity."**).

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[]` | Backlog depth per period (≥ 0). null / NaN / ±Infinity are gaps. |
| `capacity` | `number` | Steady-state capacity: a dashed hairline; spans above it re-stroke negative. |
| `label` | `"last" \| "none"` | Endpoint value + trend glyph (▴/▾), default 'last', or nothing. |
| `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).
