Documentation / Charts
Heatmap
The magnitude on a grid: load by day and hour, retention by cohort, a correlation matrix. Each row of data is a cell, identified by its column (x), its row (y) and its value (value).
It is the only chart of the kit where colour carries the measure rather than the identity: the ramp is sequential, or diverging around center for a gap from a reference. The scale legend is therefore shown by default: a grid without one shows a pattern but states no value. The ramp is continuous unless steps cuts it (a warning past seven classes); a missing pair is painted grey, never left blank.
"use client" component. The table view shows the grid pivoted.
Examples
Weekly load
A continuous sequential ramp; legendLabel says what the colour measures.
import { Heatmap } from "@synertech/ui";
const days = ["Lun", "Mar", "Mer", "Jeu", "Ven"];
const hours = ["7 h", "9 h", "11 h", "13 h", "15 h", "17 h", "19 h"];
const load = days.flatMap((day, row) =>
hours.map((hour, column) => {
const shape = [0.2, 0.75, 0.95, 0.55, 0.85, 0.7, 0.25][column];
const weight = [0.9, 1, 1.05, 0.95, 0.6][row];
return { day, hour, sessions: Math.round(shape * weight * 4200) };
})
);
export function Basic() {
return (
<Heatmap
title="Sessions par jour et par heure"
description="Cinq jours ouvrables, sept tranches horaires"
data={load}
x={{ key: "hour", label: "Heure" }}
y={{ key: "day", label: "Jour" }}
value="sessions"
legendLabel="Sessions"
height={260}
/>
);
}Stepped ramp
steps groups the values into clear classes, easier to name than a gradient.
import { Heatmap } from "@synertech/ui";
const days = ["Lun", "Mar", "Mer", "Jeu", "Ven"];
const hours = ["7 h", "9 h", "11 h", "13 h", "15 h", "17 h", "19 h"];
const load = days.flatMap((day, row) =>
hours.map((hour, column) => {
const shape = [0.2, 0.75, 0.95, 0.55, 0.85, 0.7, 0.25][column];
const weight = [0.9, 1, 1.05, 0.95, 0.6][row];
return { day, hour, sessions: Math.round(shape * weight * 4200) };
})
);
export function Stepped() {
return (
<Heatmap
title="Sessions par jour et par heure"
data={load}
x={{ key: "hour" }}
y={{ key: "day" }}
value="sessions"
legendLabel="Sessions"
steps={4}
height={240}
/>
);
}Retention by cohort
Missing pairs (cohorts too recent) are painted grey; showValues writes the value in every cell that has room for it.
import { Heatmap } from "@synertech/ui";
const cohorts = ["Jan", "Fév", "Mar", "Avr", "Mai"].flatMap((cohort, row) =>
["M0", "M1", "M2", "M3", "M4"].map((month, column) => ({
cohort,
month,
retention: column > 4 - row ? null : Math.round(100 * Math.pow(0.78 + row * 0.02, column)),
}))
);
export function Cohorts() {
return (
<Heatmap
title="Rétention par cohorte"
data={cohorts}
x={{ key: "month", label: "Mois depuis l’inscription" }}
y={{ key: "cohort", label: "Cohorte" }}
value="retention"
format={(value) => `${value} %`}
legendLabel="Rétention (%)"
showValues
tableView="toggle"
height={220}
/>
);
}Gap from a target
scale="diverging" centres the ramp on center (zero by default): two opposite hues for above and below.
import { useState } from "react";
import { Heatmap } from "@synertech/ui";
const variance = ["Nord", "Est", "Ouest", "Sud"].flatMap((region, row) =>
["T1", "T2", "T3", "T4"].map((quarter, column) => ({
region,
quarter,
gap: [
[12, 4, -6, -14],
[-8, -2, 9, 18],
[3, 11, 2, -5],
[-16, -9, 6, 14],
][row][column],
}))
);
export function Diverging() {
const [cell, setCell] = useState<string | null>(null);
return (
<div className="flex flex-col gap-3">
<Heatmap
title="Écart à la cible"
data={variance}
x={{ key: "quarter", label: "Trimestre" }}
y={{ key: "region", label: "Région" }}
value="gap"
scale="diverging"
format={(value) => `${value > 0 ? "+" : ""}${value} %`}
legendLabel="Écart (%)"
showValues
onCellClick={(clicked) =>
setCell(`${clicked.yLabel}, ${clicked.xLabel} : ${clicked.formattedValue}`)
}
height={220}
/>
<p className="text-sm text-gray-600 dark:text-gray-400">{cell ?? "Cliquez sur une case."}</p>
</div>
);
}API reference
Components
A magnitude on a grid: load by day and hour, retention by cohort, a correlation matrix.
The one chart of the kit where colour carries the measure rather than the identity — which is why the scale legend is on by default and why the data table matters more here than anywhere else. A grid without its legend shows a pattern and states no value.
The ramp stays continuous unless steps cuts it: past seven classes two neighbouring cells stop being tellable apart, and a fine grid is read as a wash anyway.
import { Heatmap } from "@synertech/ui";Props — HeatmapProps
| Prop | Type | Default | Description |
|---|---|---|---|
data• |
ChartDatum[] |
— | One row per cell: its column, its row and its value. |
value• |
string |
— | Field holding the value the colour encodes. |
x• |
ChartXAxisConfig |
— | Field holding the column each cell belongs to. |
y• |
ChartXAxisConfig |
— | Field holding the row each cell belongs to. |
actions |
ReactNode |
— | Slot on the right of the caption: an export button, a range picker. A filter that frames several panels belongs in a |
cellGap |
number |
2 |
Surface gap between two cells. |
cellRadius |
number |
2 |
|
center |
number |
0 |
Middle of a diverging ramp. Defaults to |
colors |
readonly string[] |
— | Replaces the ramp stops — any CSS colours. |
description |
ReactNode |
— | |
domain |
[number, number] |
— | Bounds the ramp covers. Defaults to the extent of the data. |
emptyState |
ReactNode |
— | Replaces the "no data" state: usually an |
error |
boolean |
false |
The data could not be loaded. Never the same thing as having none: a panel that says "no data" after a failed request states something false, and offers no way out. |
errorState |
ReactNode |
— | Replaces the whole built-in error state, message and button included. |
format |
(value: number) => string |
— | Formats a value, in the cells, the legend, the tooltip and the table. |
height |
number |
280 |
|
legend |
boolean | ChartLegendPosition |
true |
The scale legend. Mandatory reading, so it shows unless turned off. |
legendLabel |
ReactNode |
— | What the colour encodes — the measure and its unit. |
loading |
boolean |
false |
Dims the plot while fresh data loads; a first load shows a spinner. |
locale |
string |
— | BCP 47 tag the numbers and the dates are written in. Defaults to the |
onCellClick |
(cell: HeatmapCell) => void |
— | Called with the mark that was clicked. Enter and Space on the focused chart do the same for the mark the keyboard is on. |
onRetry |
() => void |
— | Draws the retry button in the error state, and is called when pressed. |
plotLabel |
string |
— | |
scale |
"sequential" | "diverging" |
"sequential" |
|
showValues |
boolean |
false |
Writes the value inside each cell that has room for it. |
size |
ChartSize |
"md" |
|
steps |
number |
— | Cuts the ramp into that many classes. Left unset the wash is continuous, which is how a fine grid is read anyway. |
tableView |
boolean | "toggle" |
false |
|
title |
ReactNode |
— | |
tooltip |
boolean | ((cell: HeatmapCell) => ReactNode) |
true |
|
width |
number |
— | |
xDomain |
ChartXValue[] |
— | Column order. Defaults to first appearance in the data. |
yDomain |
ChartXValue[] |
— | Row order. Defaults to first appearance in the data. |
+ 277 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Types
HeatmapCell
InterfaceA cell, as the tooltip and the click handler see it.
interface HeatmapCell| Field | Type | Default | Description |
|---|---|---|---|
color• |
string |
— | |
formattedValue• |
string |
— | |
value• |
number | null |
— |
|
x• |
ChartXValue |
— | |
xLabel• |
string |
— | |
y• |
ChartXValue |
— | |
yLabel• |
string |
— | |
datum |
ChartDatum |
— |