# MicroBox (/docs/charts/micro-box)

MicroBox prints a five-number summary in a table row: min, Q1, median, Q3, max. Whiskers run to the min and max by
default, because Tukey fences imply a normality assumption most product data doesn't meet. `whiskers="tukey"` switches
to those fences and exposes fence-breakers as dots, capped at 3 per side (the furthest). Precomputed `stats` whose
values aren't monotonic are refused with a dev warning rather than drawn as a plausible-looking box.

```tsx
<MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} title="p95 latency" width={220} height={32} />
```

## Install

```tsx
import { MicroBox } from "@microcharts/react/micro-box";

<MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} title="p95 latency" />
```

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 { MicroBox } from "@microcharts/react/micro-box/interactive";

<MicroBox
  data={latencies}
/>
```

## When to use it

Use it for latency percentile rows (p50/p95/p99) and spread beside a stat; precomputed `stats` is the production path.
For distribution shape use HistogramStrip. Fewer than 5 observations render as dots rather than a box.

## Sizing

**precomputed stats (production path)**

```tsx
<MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} />
```

**shared domain rows**

```tsx
<MicroBox stats={p50} domain={[0, 300]} />
<MicroBox stats={p95} domain={[0, 300]} />
```

## Variants

```tsx
const values = [...Array.from({ length: 20 }, (_, i) => 40 + i), 400, 500];

<MicroBox data={values} whiskers="tukey" />
```

## Edge cases

```tsx
// < 5 values → dots, never a fake box
<MicroBox data={[3, 7, 9]} />
```

```tsx
// a degenerate IQR collapses the box to a 1-unit tick; the domain pads
// ±1 around the value so the mark stays centered and visible
<MicroBox data={[7, 7, 7, 7, 7, 7]} />
```

Under 5 observations MicroBox draws the raw values as dots, never a box built from too few of them. An all-equal series
has a degenerate IQR: the box collapses to a 1-unit tick, and the domain pads ±1 around the value so the mark stays
centered and visible.

## Four homes

**In a sentence**

```tsx
<p>
  Checkout latency this week{" "}
  <span className="mc-inline">
    <MicroBox stats={{ min: 40, q1: 88, median: 110, q3: 145, max: 320 }} width={90} height={16} summary={false} />
  </span>{" "}
  — median 110ms, tail past 300ms.
</p>
```

**In a table cell**

```tsx
<td>
  <MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} width={70} height={16} />
</td>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">42 ms</span>
  <span className="unit">median, IQR 35–51</span>
  <MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} width={200} height={30} />
</div>
```

**In a tab header**

```tsx
<button className="tab">
  Prod <MicroBox stats={{ min: 12, q1: 35, median: 42, q3: 51, max: 96 }} width={44} height={14} />
</button>
```

## Accessibility

The accessible name is the five-number reading: **"Median 50.5, middle half 45.25 to 55.75, range 40 to 500."** The
interactive entry roves a fixed 5-stop model (min → Q1 → median → Q3 → max) and announces each stat (**"Median: 42."**).

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` | `number[]` | Raw observations (exclusive with stats). |
| `stats` | `{ min; q1; median; q3; max }` | Precomputed server aggregates. |
| `whiskers` | `"minmax" \| "tukey"` | Tukey exposes outliers as dots. |
| `outliers` | `boolean` | Render outlier dots in tukey mode. |
| `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).
