MDK Logo

Heatmap

Heatmap — a generic grid of value-coloured cells on a low→high gradient. Presentational and domain-agnostic: pass a row-major matrix of cells and an optional…

Heatmap — a generic grid of value-coloured cells on a low→high gradient.

Presentational and domain-agnostic: pass a row-major matrix of cells and an optional [min, max] range (auto-derived otherwise). Use renderCell to overlay domain content (socket borders, selection, tooltips) without forking the primitive — the grid still owns each cell's background colour. Pair with {@link HeatmapLegend} for a gradient scale.

import { Heatmap } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
dataRequiredHeatmapCell[][]Rows of cells (row-major). Rows may be ragged.
minOptionalnumber | undefinedRange floor; auto-derived from the finite values when omitted.
maxOptionalnumber | undefinedRange ceiling; auto-derived from the finite values when omitted.
colorsOptionalreadonly string[] | undefinedGradient stops low→high. Defaults to the cold→hot `HEATMAP_GRADIENT`.
emptyColorOptionalstring | undefinedColour used for `null` cells.
showValuesOptionalboolean | undefinedRender each cell's value/label as text.
renderCellOptional((cell: HeatmapCell, context: HeatmapCellContext) => React.ReactNode) | undefinedOverride the cell's inner content — e.g. to overlay socket borders, selection, or tooltips for a PDU grid. The primitive still owns the cell's background colour (passed via `context.color`).
ariaLabelOptionalstring | undefinedAccessible label for the grid.
classNameOptionalstring | undefined

Usage

A generic grid of value-coloured cells on a low→high gradient, plus a matching HeatmapLegend. Presentational and domain-agnostic — pass a row-major matrix of cells and an optional [min, max] range (auto-derived otherwise).

Use renderCell to overlay domain content (e.g. PDU socket borders, selection, tooltips) without forking the primitive; the grid still owns each cell's background colour.

Heatmap props

PropTypeRequiredDefaultDescription
dataHeatmapCell[][]yesRow-major matrix of cells ({ value, label?, key? }); rows may be ragged
minnumbernoautoRange floor (maps to the first gradient stop)
maxnumbernoautoRange ceiling (maps to the last stop)
colorsreadonly string[]noHEATMAP_GRADIENTGradient stops low→high
emptyColorstringno#000000Colour for null cells
showValuesbooleannofalseRender each cell's value/label as text
renderCell(cell, ctx) => ReactNodenoOverride cell content; ctx is { color, row, col }
ariaLabelstringno"Heatmap"Accessible label for the grid
classNamestringnoAdditional class for the root element

HeatmapLegend props

PropTypeRequiredDefaultDescription
minnumber | stringyesLow-end value or pre-formatted label
maxnumber | stringyesHigh-end value or pre-formatted label
unitstringnoUnit suffix appended to min/max
labelstringnoHeading above the gradient bar
colorsreadonly string[]noHEATMAP_GRADIENTGradient stops low→high
classNamestringnoAdditional class for the root element

Notes

  • The colour scale is exported as getHeatmapColor(value, min, max, stops?) and the default palette as HEATMAP_GRADIENT (cold→hot: blue → green → yellow → red) from @tetherto/mdk-react-devkit.
  • null values render emptyColor and no text.
  • Values outside [min, max] are clamped to the end stops.

Example

/** * Runnable example for Heatmap + HeatmapLegend. */import { Heatmap, HeatmapLegend } from "@tetherto/mdk-react-devkit"const rows = [  [{ value: 20 }, { value: 35 }, { value: 50 }, { value: 42 }],  [{ value: 60 }, { value: 72 }, { value: null }, { value: 55 }],  [{ value: 44 }, { value: 81 }, { value: 66 }, { value: 30 }],]export const HeatmapExample = () => (  <div className="mdk-example-row">    <Heatmap data={rows} showValues />    <HeatmapLegend label="Temperature" min={20} max={81} unit="°C" />  </div>)