Heatmap
A grid of cells shaded by value. Define both axes yourself, or use the calendar, which lays out days like GitHub’s contribution graph.
Usage
import { Heatmap } from 'nyctoui/heatmap'
<Heatmap
rows={[{ key: 'mon', label: 'Mon' }, { key: 'tue', label: 'Tue' }]}
columns={[{ key: '9', label: '9am' }, { key: '10', label: '10am' }]}
data={[{ row: 'mon', column: '9', value: 4 }]}
aria-label="Deploys by weekday and hour"
/>Heatmap takes its rows and columns as data, each with a key and an optional label. Values point at a row and a column by key; entries for the same cell are added together, and cells with none are empty. Leave out a label to skip it, so labels don’t crowd the 10px cells.
Each cell falls into one of five steps, from empty up to the highest value. Hovering, focusing or tapping a cell shows its text in a tooltip, and the same text is its accessible name; set it with label. Where the grid doesn’t fit, it scrolls sideways and opens on the last columns, while the row labels stay put.
The grid is one tab stop. Arrow keys move between cells, Home and End go to the ends of a row, and with Ctrl or ⌘ to the first and last cell.
Good for
- A contribution graph of commits or activity over a year on a profile page.
- Deploys or incidents by weekday and hour in an ops dashboard.
- Bookings by day and time slot in a restaurant or a gym app.
- Habit or workout streaks in a fitness tracker.
Calendar
import { HeatmapCalendar } from 'nyctoui/heatmap'
<HeatmapCalendar
data={[{ date: '2026-11-18', value: 4 }]}
aria-label="Contributions in the last year"
/>HeatmapCalendar is the same grid with axes made from dates: a column per week, a row per weekday, months named above. Pass one entry per day or one per event. It ends today in the reader’s timezone unless you set endDate; a server can’t know that day, so without one the grid holds its space hidden until the page loads.
Anatomy
<Heatmap> // or <HeatmapCalendar>
<HeatmapGrid />
<HeatmapLegend />
</Heatmap>With no children, either root renders both parts. Write them out to place the legend yourself or put something beside it.
Examples
Custom axes
Deploys by weekday and hour: every other row labelled, a column label every six hours, and a name on each for the tooltip.
Column groups
columnGroups names runs of columns, here the weeks of a cycle. The calendar uses the same thing for months. With a label on every row, size="md" gives each 16px squares so the labels have room.
Neutral
Green reads as activity. On a page where color is kept for status, the neutral scale shades from gray to the brand color instead.
Capped scale
By default the highest value sets the top step, so one outlier can push every other cell into the lightest ones. Set max to the value that should fill a cell.
Thresholds
For data where most values are small, give each step its own lower bound with thresholds.
Range
startDate and endDate pick the days shown, here a quarter. weekStartsOn starts each column on Monday.
Selection
Pass selected and onSelectedChange to let people pick a cell, to filter a list of activity below, say. Click a cell or press Enter on it; picking it again clears it. Heatmap selects by { row, column }, the calendar by date.
Composed
The parts written out, with a note beside the legend and its labels changed.
Best practices
- Give the grid an
aria-labelthat says what it counts, such as “Deploys by weekday and hour”. - Show a
HeatmapLegendso people can read what each shade means. - Write each cell’s tooltip as a full sentence with the number, such as “12 deploys on Tuesday at 9am”.
- Set
thresholdsor amaxwhen one busy day would wash out the rest of the scale.
- Use a heatmap when people need exact numbers. Use a table, or show the number on hover as well.
- Label every row and column on a dense grid; skip some so the labels don’t crowd the cells.
API reference
Heatmap
A grid with axes you define. Renders a <div>; with no children, also the grid and legend.
| Prop | Type | Default |
|---|---|---|
rowsTop to bottom. label is drawn beside the row; name is used in the default cell text. | Array<{ key: string; label?: string; name?: string }> | — |
columnsStart to end. label is drawn above the column. | Array<{ key: string; label?: string; name?: string }> | — |
columnGroupsLabels over runs of columns, above the column labels. | Array<{ label?: string; span: number }> | — |
dataValues by row and column key. Entries for one cell are summed. | Array<{ row: string; column: string; value: number }> | — |
labelText for a cell’s tooltip and accessible name. The cell has row, column, value and level. | (cell: HeatmapCell) => string | — |
maxValue that fills a cell to the top step; the steps split 0 to max evenly. | number | largest value |
thresholdsLowest value of steps 1 to 4. Replaces the even split. | [number, number, number, number] | — |
colorThe color scale. | 'green' | 'neutral' | 'green' |
size10px squares, dense enough for a year, or 16px for small grids. | 'sm' | 'md' | 'sm' |
selectedSelected cell. For controlled use. | { row: string; column: string } | null | — |
defaultSelectedCell selected at first. For uncontrolled use. | { row: string; column: string } | null | — |
onSelectedChangeCalled when a cell is picked or cleared. This or a selection prop makes cells selectable. | (cell: { row; column } | null) => void | — |
aria-labelNames the grid. Pass this or aria-labelledby. | string | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
HeatmapCalendar
The grid with a column per week and a row per weekday. Renders a <div>; with no children, also the grid and legend.
| Prop | Type | Default |
|---|---|---|
dataValues by day. Strings start with YYYY-MM-DD; entries on one day are summed. | Array<{ date: string | Date; value: number }> | — |
endDateLast day shown. | string | Date | today |
startDateFirst day shown. | string | Date | 52 weeks before endDate |
weekStartsOnFirst row of each column: 0 is Sunday, 1 is Monday. | 0 | 1 | 0 |
localeLocale for month, weekday and date names. | string | 'en-US' |
labelText for a day’s tooltip and accessible name. The day has date, key, value and level. | (day: HeatmapCalendarDay) => string | — |
maxValue that fills a cell to the top step; the steps split 0 to max evenly. | number | largest value |
thresholdsLowest value of steps 1 to 4. Replaces the even split. | [number, number, number, number] | — |
colorThe color scale. | 'green' | 'neutral' | 'green' |
size10px squares, dense enough for a year, or 16px for small grids. | 'sm' | 'md' | 'sm' |
selectedSelected day as YYYY-MM-DD. For controlled use. | string | null | — |
defaultSelectedDay selected at first. For uncontrolled use. | string | null | — |
onSelectedChangeCalled when a day is picked or cleared. This or a selection prop makes days selectable. | (date: string | null) => void | — |
aria-labelNames the grid. Pass this or aria-labelledby. | string | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
HeatmapGrid
The cells with their labels, in a scroll area. Renders a <table> with role grid; sx styles the frame around it.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
HeatmapLegend
The scale from empty to highest. Sits at the end of its row. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
lessText before the scale. | ReactNode | 'Less' |
moreText after the scale. | ReactNode | 'More' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |