# HeatCell (/docs/charts/heat-cell)

You lay out the grid — a matrix of tenants × hours, a custom calendar, a density chip in a sentence — and HeatCell is
the single cell inside it, showing how intense one value is against a known scale. Color is quantized into five discrete
steps, the most a reader reliably distinguishes at cell size and the same ramp ActivityGrid uses, so intensity means one
thing across the library. Continuous opacity would fake precision a 12-px cell can't deliver.

```tsx
<span className="inline-flex items-center gap-1.5">
  {[12, 35, 58, 79, 96].map((v) => (
    <HeatCell key={v} value={v} domain={[0, 100]} title={`Load ${v}`} style={{ width: 18, height: 18 }} />
  ))}
</span>
```

## Install

```tsx
import { HeatCell } from "@microcharts/react/heat-cell";

<HeatCell value={42} domain={[0, 100]} title="Load" />
```

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 { HeatCell } from "@microcharts/react/heat-cell/interactive";

<HeatCell
  value={42}
  domain={[0, 100]}
/>
```

## When to use it

Use it for table-cell matrices, custom grids, and intensity chips beside labels. For precise comparison use MiniBar or
DotPlot; for a time series, HeatStrip or ActivityGrid.

## The shared-domain rule

A lone cell has no data to auto-scale from, so `domain` defaults to `[0, 1]` — pass your grid's real scale. **Every cell
in one grid must share one domain**: per-cell auto-scaling would make the brightest hour of a quiet tenant look like the
brightest hour of a loud one.

```tsx
// one domain, computed once, shared by every cell
const domain: [number, number] = [0, Math.max(...allValues)];
rows.map((r) => r.hours.map((v) => <HeatCell value={v} domain={domain} />));
```

## Sizing

**a shared-domain row**

```tsx
// every cell calibrates against ONE domain — never per-cell auto-scale
{[12, 40, 62, 88].map((v) => (
  <HeatCell key={v} value={v} domain={[0, 100]} />
))}
```

**value chip**

```tsx
// wider cells can carry their number
<HeatCell value={8} domain={[0, 9]} label="value" style={{ width: 28, height: 28 }} />
```

## Variants

```tsx
<HeatCell value={70} domain={[0, 100]} shape="square" />
<HeatCell value={70} domain={[0, 100]} shape="round" />
<HeatCell value={70} domain={[0, 100]} shape="dot" />
```

```tsx
<HeatCell value={8} domain={[0, 9]} label="value" />
```

## Edge cases

```tsx
<HeatCell value={NaN} domain={[0, 100]} />
```

```tsx
<HeatCell value={-20} domain={[0, 100]} />
<HeatCell value={140} domain={[0, 100]} />
```

Values outside the `domain` clamp to the end steps and are never silently rescaled, so one out-of-range cell can't
restretch a grid. A zero-width domain renders the single mid step and logs a dev warning.

## Four homes

**In a sentence**

```tsx
<p>
  shard-a load just crossed{" "}
  <span className="mc-inline">
    <HeatCell value={76} domain={[0, 100]} summary={false} />
  </span>{" "}
  76% — level 4 of 5.
</p>
```

**In a table cell**

```tsx
// every cell in the grid shares ONE domain
<tr>
  <td>shard-a</td>
  {[18, 42, 76, 55].map((v) => (
    <td key={v}><HeatCell value={v} domain={[0, 100]} /></td>
  ))}
</tr>
```

**In a KPI card**

```tsx
<div className="kpi">
  <span className="figure">76%</span>
  <span className="unit">peak this cycle</span>
  {[18, 42, 76, 55].map((v) => (
    <HeatCell key={v} value={v} domain={[0, 100]} />
  ))}
</div>
```

**In a tab header**

```tsx
<button className="tab">
  shard-a <HeatCell value={76} domain={[0, 100]} />
</button>
```

## Accessibility

The accessible name carries the value _and_ its calibration: the shape cells above read **"70 — level 4 of 5."** The
color scale is never the only channel. Non-finite input renders a designed empty track and says **"No data."** The
interactive entry reveals the same reading on hover and focus, with ActivityGrid announcement parity.

This chart is a single unit, so there is nothing to rove between: a click, tap, `Enter` or `Space` selects it
and fires `onSelect`, and no selection stays pinned. That is the scalar half of the shared
[interaction contract](/docs/accessibility#one-interaction-contract).
Hover or focus also reveals the reading itself in a floating chip, for the sizes and label modes where the mark
does not print it; `readout={false}` drops the chip and keeps everything else.

## Props

| Prop | Type | Description |
| --- | --- | --- |
| `value` (required) | `number` | The value to calibrate. |
| `domain` | `[number, number]` | Calibration scale — defaults to [0, 1]; every cell in a grid must share one. |
| `steps` | `number` | Discrete perceptual steps (default 5, shared with ActivityGrid). |
| `shape` | `"square" \| "round" \| "dot"` | Shared cell vocabulary. |
| `label` | `"value" \| "none"` | Centered number when the cell doubles as a chip. |
| `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).
