heatmap
A table drawn as a heatmap: a matrix of rows and columns, or a calendar of days like a contributions chart.
When the climbing gym is busy
| 7:00 | 9:00 | 11:00 | 13:00 | 15:00 | 17:00 | 19:00 | 21:00 | |
|---|---|---|---|---|---|---|---|---|
| Mon | 12% | 18% | 22% | 31% | 28% | 64% | 81% | 46% |
| Tue | 15% | 16% | 20% | 29% | 30% | 70% | 88% | 52% |
| Wed | 11% | 17% | 24% | 33% | 27% | 61% | 79% | 44% |
| Thu | 14% | 19% | 21% | 30% | 32% | 73% | 92% | 58% |
| Fri | 10% | 14% | 19% | 26% | 35% | 55% | 48% | 30% |
| Sat | 8% | 42% | 76% | 85% | 80% | 62% | 40% | 18% |
| Sun | 6% | 38% | 71% | 78% | 69% | 50% | 27% | 9% |
Live preview needs WebGPU or WebGL 2. How full a climbing gym is by weekday and hour, as a heatmap of tiles that sweeps in on scroll.
This example failed to draw.
Usage
Put it on a <table>: for the grid, a header row naming the columns and the first cell of each row naming the row; for the calendar, rows of a date and a value (or a <dl> of dates and values), sized with CSS. start() registers heatmap, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add heatmap<div class="hm-frame"> <p class="hm-title" id="hm-busy" >When the climbing gym is busy</p> <table class="hm-table" aria-labelledby="hm-busy" data-dio="heatmap" > <thead> <tr> <th></th> <th scope="col">7:00</th> <th scope="col">9:00</th> <th scope="col">11:00</th> <th scope="col">13:00</th> <th scope="col">15:00</th> <th scope="col">17:00</th> <th scope="col">19:00</th> <th scope="col">21:00</th> </tr> </thead> <tbody> <tr> <th scope="row">Mon</th> <td>12%</td> <td>18%</td> <td>22%</td> <td>31%</td> <td>28%</td> <td>64%</td> <td>81%</td> <td>46%</td> </tr> <tr> <th scope="row">Tue</th> <td>15%</td> <td>16%</td> <td>20%</td> <td>29%</td> <td>30%</td> <td>70%</td> <td>88%</td> <td>52%</td> </tr> <tr> <th scope="row">Wed</th> <td>11%</td> <td>17%</td> <td>24%</td> <td>33%</td> <td>27%</td> <td>61%</td> <td>79%</td> <td>44%</td> </tr> <tr> <th scope="row">Thu</th> <td>14%</td> <td>19%</td> <td>21%</td> <td>30%</td> <td>32%</td> <td>73%</td> <td>92%</td> <td>58%</td> </tr> <tr> <th scope="row">Fri</th> <td>10%</td> <td>14%</td> <td>19%</td> <td>26%</td> <td>35%</td> <td>55%</td> <td>48%</td> <td>30%</td> </tr> <tr> <th scope="row">Sat</th> <td>8%</td> <td>42%</td> <td>76%</td> <td>85%</td> <td>80%</td> <td>62%</td> <td>40%</td> <td>18%</td> </tr> <tr> <th scope="row">Sun</th> <td>6%</td> <td>38%</td> <td>71%</td> <td>78%</td> <td>69%</td> <td>50%</td> <td>27%</td> <td>9%</td> </tr> </tbody> </table></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.hm-table', 'heatmap', { style: 'tile', motion: 'sweep', mode: 'grid', steps: 5, gap: 2, radius: 2, labels: true, legend: true, dim: 0.35, duration: 0.5, stagger: 0.02,})import { start } from '@dioramajs/diorama'import heatmap from '@dioramajs/data/heatmap'
const app = start()app.attach('.hm-table', heatmap({ style: 'tile', motion: 'sweep', mode: 'grid', steps: 5, gap: 2, radius: 2, labels: true, legend: true, dim: 0.35, duration: 0.5, stagger: 0.02,}))Markup it reads
data-dio-value: Exact value of a cell whose text is not a plain number, such as "busy".data-dio-date: The date of a calendar row whose cell text is not a date and holds no<time>.
Parts
Its own controls take your styles through ::part().
tooltip: The tooltip with the row and column, or the date, and the value as written.
Page transitions
Fades with the page. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
moderebuildsdata-dio-mode | 'grid' | 'calendar' | 'grid' |
|
stylerebuildsdata-dio-style | 'tile' | 'dot' | 'tile' |
|
motionrebuildsdata-dio-motion | 'sweep' | 'fade' | 'sweep' |
|
colorsrebuildsdata-dio-colors | string | '' | Colors of the scale from the lowest value to the highest, separated by spaces; empty uses a colorblind-safe blue, or blue and red around 0. |
stepsdata-dio-steps | number0 to 9 | 5 | Number of color bins the scale snaps to, as the legend shows them; 0 colors each value exactly. |
maxrebuildsdata-dio-max | number | 'auto'1 to 1000000 | 'auto' | Value at the top of the scale, for heatmaps compared side by side; auto takes the largest value. |
gapdata-dio-gap | number0 to 12 px | 2 | Gap between cells; 0 lets them touch. |
radiusdata-dio-radius | number0 to 12 px | 2 | Corner radius of a tile. |
labelsdata-dio-labels | boolean | true | Draws the row and column labels, or weekdays and months. |
legenddata-dio-legend | boolean | true | Draws the color scale with its lowest and highest values under the cells. |
dimdata-dio-dim | number0 to 1 | 0.35 | How much the hovered cell dims the others, less in its own row and column; 0 keeps them. |
durationdata-dio-duration | number0 to 3 s | 0.5 | Time one cell takes to come in; 0 shows the heatmap at once. |
staggerdata-dio-stagger | number0 to 0.1 s | 0.02 | Delay from one diagonal of cells to the next in the sweep; 0 brings them in together. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, opacity, reducedMotion, width and y
. Draws only while something on it moves, then stops. Only while the cells come in and for a few frames as a hovered cell fades in or out; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. The heatmap stands complete from the first frame; hover and the tooltip still work.
Runs on every device. A tap on a cell shows its value, a tap elsewhere hides it. Nothing else changes.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { heatmap: { reducedMotion: 'off' } } })Cost and quality
- Download
- 6.8 KB min+gzip the first time a page uses it
- GPU
- Two draw calls: all cells as one instanced call and the labels texture.
- Memory
- One canvas texture the size of the box at up to 2x pixel ratio, plus about 60 bytes per cell.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
Recipes
A year of activity
The calendar mode reads rows of a date and a value and lays them out like a contributions chart: a column per week, a row per weekday, month names on top. The week starts on Monday or Sunday as the page’s lang says. Days without a row stay empty.
Volunteer shifts covered in 2026
| Day | Shifts |
|---|
Live preview needs WebGPU or WebGL 2. A year of volunteer shifts as a calendar heatmap, busier on summer weekends.
This example failed to draw.
<div class="hm-frame"> <p class="hm-title" id="hm-year" >Volunteer shifts covered in 2026</p> <table class="hm-table" aria-labelledby="hm-year" data-dio="heatmap" data-dio-mode="calendar" > <thead> <tr> <th scope="col">Day</th> <th scope="col">Shifts</th> </tr> </thead> <tbody></tbody> </table></div>// A year of rows, one per day: a real page renders them on the server from its own records.export default function mount(example: HTMLElement): void { const body = example.querySelector('tbody') if (!body) return let seed = 11 const random = () => { seed = (seed * 16807) % 2147483647 return seed / 2147483647 } const rows: string[] = [] for (let d = 0; d < 365; d++) { const date = new Date(Date.UTC(2026, 0, 1 + d)) const iso = date.toISOString().slice(0, 10) const weekend = date.getUTCDay() === 0 || date.getUTCDay() === 6 const summer = Math.sin((d / 365) * Math.PI) ** 2 const shifts = random() < 0.12 ? 0 : Math.round((weekend ? 6 : 2) * summer + random() * 3) rows.push( `<tr><td><time datetime="${iso}">${iso}</time></td><td>${shifts}</td></tr>`, ) } body.innerHTML = rows.join('')}A date can be a <time datetime> in the cell, the cell’s text in 2026-03-14 form, or data-dio-date on the cell. A <dl> of <dt> dates and <dd> values reads the same way.
Change on both sides of zero
When values fall below and above zero, the scale turns into red for falls and blue for rises around a gray, with zero in the middle. steps="0" colors each value exactly instead of in bins.
<table data-dio="heatmap" data-dio-steps="0"> <thead> <tr> <th>Region</th> <th>Q1</th> <th>Q2</th> </tr> </thead> <tbody> <tr><th>North</th><td>+12%</td><td>-4%</td></tr> <tr><th>South</th><td>-9%</td><td>+3%</td></tr> </tbody></table>Several heatmaps on one scale
Each heatmap takes its top from its own largest value. Give heatmaps that sit side by side the same max so their colors compare; colors sets the scale from the lowest value to the highest.
Notes
The table is the source of truth. It stays in the page for screen readers and search engines, hidden only while the heatmap is drawn, and it shows as is without WebGL. A table grows to fit its rows whatever height it is given, so a long one needs display: block with a height and overflow: auto: the heatmap takes that box, and the plain table scrolls inside it.
Numbers are read the way people write them, as in chart: separators, a decimal comma, currency, % and suffixes. Zeros and empty cells stay faint, so gaps read as gaps. The default colors are one blue from light to dark that tells values apart with every common color vision deficiency; on a dark page the scale runs from dark to light. The legend under the cells names the lowest and the highest value.
It draws only while the cells come in and for a few frames as a hovered cell fades in or out. Under reduced motion the heatmap stands complete from the first frame. Style the tooltip with ::part(tooltip).