# Heatmap

> An animated heatmap for React and shadcn, for activity calendars or weekday-by-hour grids.

A calendar of days by weeks, or a matrix such as weekday by hour, coloured on a five-step sequential scale. Colours flood in as a diagonal wave and cross-fade when the data changes; the active cell lights its row and column as a ring and a rolling tooltip glide to it.

- Tier: Eased Pro
- Interaction: Hover
- Page: https://eased.dev/components/heatmap
- Installs: motion

## Install

Heatmap ships with Eased Pro (https://eased.dev/#pricing). Members add the `@eased-pro` registry with their token (https://eased.dev/account), then run:

```bash
npx shadcn add @eased-pro/heatmap
```

A grid of cells coloured by value on a sequential scale, as a calendar of days by weeks or a matrix such as weekday by hour, built on the free chart core.

## When to use

- Activity over a year, one cell per day: deploys, commits, sign-ins, workouts. The calendar shows weekly rhythm and quiet stretches at a glance.
- Two categorical axes with one value where they meet: requests by weekday and hour, bookings by day and time slot. The pattern matters more than any one number.
- Comparing the same grid across datasets, environments or periods: a fixed `domain` keeps the colours comparable, and switching cross-fades every cell.

## When not to use

- Exact values or rankings: a [Bar Chart](/components/bar-chart) compares lengths more precisely than shades.
- A trend over time with one value per point: use a [Line Chart](/components/line-chart) or [Area Chart](/components/area-chart).
- Values that run below and above a midpoint (profit and loss, change against a baseline): a sequential scale reads them as one direction. Use a bar chart with a zero line.

## Usage

```tsx example.tsx
import { Heatmap } from "@/components/eased/heatmap/heatmap";

const deploys = [
  { date: "2026-10-12", value: 4 },
  { date: "2026-10-13", value: 7 },
  { date: "2026-10-14", value: 0 },
  // …one entry per day
];

export function Example() {
  return (
    <Heatmap
      layout="calendar"
      data={deploys}
      label="Deploys per day, last 12 months"
      format={(v) => `${v} ${v === 1 ? "deploy" : "deploys"}`}
    />
  );
}
```

## Examples

### Matrix

Rows and columns name the axes; `data[row][column]` holds the values. Keep row names short, since they label the rows. Column names are thinned to an even step (every 3 hours, every 6) when the grid is narrow.

```tsx
const hours = Array.from({ length: 24 }, (_, h) => `${String(h).padStart(2, "0")}:00`);

<Heatmap
  layout="matrix"
  rows={["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]}
  columns={hours}
  data={requestsByDayAndHour}
  label="API requests by weekday and hour, last 7 days"
  format={(v) => `${compact.format(v)} requests`}
/>
```

### Comparing datasets

By default the scale runs from 0 to a round number above the largest value, so each dataset uses the whole ramp. Pass the same `domain` to every dataset when the colours should mean the same number in each.

```tsx
<Heatmap layout="calendar" data={deploys[env]} domain={[0, 20]} label={`Deploys to ${env}`} />
```

### The colour scale on its own

The scale is `sequentialScale` from the free chart core, for a cohort or retention table of your own.

```tsx
import { sequentialScale } from "@/components/eased/_primitives/chart-core/sequential";

const scale = sequentialScale([0, 1], { steps: 5 });
<td style={{ background: scale.color(0.42) }}>42%</td>;
```

## API reference

### Heatmap

| Prop | Type | Default | Description |
|---|---|---|---|
| `layout` | `"calendar" \| "matrix"` | | Days by weeks with month labels, or rows by columns. |
| `data` | `{ date, value }[]` (calendar), `(number \| null)[][]` (matrix) | | Calendar: one entry per ISO date, in any order; days missing between the first and last are empty. Matrix: `data[row][column]`. `null` is no data. |
| `rows` | `string[]` | | Matrix only. Row names, top to bottom. |
| `columns` | `string[]` | | Matrix only. Column names, left to right. |
| `rowAxis` | `string` | `"Row"` | Matrix only. What the rows are, e.g. `"Day"`: the hidden table's first header. |
| `weekStart` | `0 \| 1` | `1` | Calendar only. The first row: Sunday or Monday. |
| `label` | `string` | | Names the figure, the slider and the hidden table. |
| `format` | `(value: number) => string` | | Values in the tooltip and screen reader text. Include the unit. |
| `domain` | `[number, number]` | | The values the scale spans. Default 0 to a round number above the largest value. |
| `steps` | `number` | `5` | Colour steps, 2 to 9. |
| `color` | `string` | `chartColor(1)` | The hue the scale builds to. |
| `legend` | `boolean` | `true` | The colour scale under the grid. Hovering a step lights the cells in it. |
| `zeroIsEmpty` | `boolean` | `true` for a calendar, `false` for a matrix | Draw a value of exactly 0 as empty, like a missing one. |
| `onActiveChange` | `(cell \| null) => void` | | The hovered, focused or tapped cell: `{ row, column, value, label, date? }`. |
| `className` | `string` | `""` | Appended to the root's classes. |

In a calendar a value of exactly 0 draws empty, in the line colour, rather than as the lightest step: a day with no deploys reads as nothing happened. A matrix draws 0 as the lightest step unless you pass `zeroIsEmpty`. The colours are `color-mix` of theme tokens, so the scale follows light and dark with the rest of the page. Calendar cells stay square and stop at 18px; a short calendar sits at the left of a wider box.

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Focuses the grid and activates the newest day (calendar) or the first cell (matrix). |
| `←` / `→` | Previous or next column: a week in a calendar. |
| `↑` / `↓` | Previous or next row. In a calendar, the previous or next day, running on into the next week. |
| `Page Up` / `Page Down` | Calendar: four weeks back or forward. Matrix: the first or last row. |
| `Home` / `End` | The first or last cell in the row. |
| `Ctrl` + `Home` / `End` | The first or last cell. |
| `Escape` | Clears the highlight and tooltip. The ring stays on the cell while the grid has focus, and the arrows carry on from it. |

## Accessibility

- The grid is one `role="slider"` named by `label`. Its `aria-valuetext` reads the active cell's full date or row and column, and its value ("Thursday, 15 October 2026: 7 deploys"); with no cell active it names the highest one.
- A visually hidden `<table>` lists every value: one row per day for a calendar, rows by columns for a matrix. The cells, labels, tooltip and legend are `aria-hidden`.
- The grid's description (`aria-describedby`) spells out its keys, since a slider that moves in two directions is not what a screen reader user expects.
- The ring on the active cell is the focus indicator: keyboard focus activates a cell, and the ring stays on it after Escape, so it is visible whenever the grid has focus.
- The scale is one hue that changes evenly in Oklab lightness, so it reads under every colour vision deficiency. Neighbouring steps differ by only 1.28–1.56:1 in contrast, and empty cells sit 1.44:1 (light) and 1.65:1 (dark) from the surface, so shade is never the only way to read a value: the tooltip, the slider and the table give the number behind every cell.
- Touch: a tap activates the cell under it and keeps it until the next tap; the page and a scrolling calendar still pan over the grid.

## Motion

The colours flood in once, the first time the grid scrolls into view: each cell cross-fades from the empty colour to its own on a diagonal wave from the top left, 400ms of stagger in all, so the eye reads the shape of the whole before any one cell. New data cross-fades every cell's colour over 300ms (ease standard) with no stagger. Pointing at a cell lights its row and column while the rest fade to 40% over 150ms; a ring glides to the cell on `snappy`, and the tooltip trails it on `smooth` with the value rolling from cell to cell and as data changes. A calendar too narrow for its year (under 10px a week) scrolls at 14px a week instead of shrinking past legibility, opened on the latest week with a fade where there is more, and keyboard moves scroll the active week into view. Reduced motion: no wave, no cross-fade, no glide; the highlight and tooltip appear at once.

## Notes for AI

Pick Heatmap for daily activity over months (calendar) or for one value across two categorical axes such as weekday and hour (matrix). Pass `format` with the unit, short row names, and a fixed `domain` when several datasets should share colours. Under a toggle, keep the component mounted and swap `data`, so the cells cross-fade.

Do not build a separate legend, tooltip or table (all three are built in), do not colour cells yourself (pass `color` to change the hue, `steps` to change the ramp), and do not wrap it in another slider or `role="img"`; the grid already is the accessible control. Do not use it for values that run both sides of zero.

## Related

- [Bar Chart](/components/bar-chart): exact comparisons between categories.
- [Line Chart](/components/line-chart): one value over time.
- [Donut Chart](/components/donut-chart): shares of one total.
