MDK Logo

HeatmapLegend

HeatmapLegend — a gradient bar with low/high scale labels, matching the gradient used by @link Heatmap.

HeatmapLegend — a gradient bar with low/high scale labels, matching the gradient used by {@link Heatmap}.

import { HeatmapLegend } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
minRequiredstring | numberValue (or pre-formatted label) at the low end of the scale.
maxRequiredstring | numberValue (or pre-formatted label) at the high end of the scale.
unitOptionalstring | undefinedUnit suffix appended to `min`/`max`.
labelOptionalstring | undefinedHeading above the gradient bar (e.g. "Temperature").
colorsOptionalreadonly string[] | undefinedGradient stops low→high. Defaults to `HEATMAP_GRADIENT`.
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>)