Skip to content

TkxHeatmap

TkxHeatmap is a matrix-style heatmap: categorical x and y axes with colour-coded cells. Reach for it for cohort retention, confusion matrices, correlation matrices, or hourly-traffic grids. For the date-driven GitHub-style activity calendar, use TkxCalendarHeatmap instead.

import { TkxHeatmap } from 'tekivex-ui';
<TkxHeatmap
data={[
{ x: 'Mon', y: '9am', value: 12 },
{ x: 'Mon', y: '10am', value: 30 },
{ x: 'Tue', y: '9am', value: 8 },
]}
showValues
/>
PropTypeDefaultDescription
dataTkxHeatmapCell[]Cells: { x, y, value, label? }. x/y are string | number.
xLabelsArray<string | number>derivedX-axis order; if omitted, sorted unique values from data.
yLabelsArray<string | number>derivedY-axis order; if omitted, sorted unique values from data.
cellSizenumber32Cell side length in px.
gapnumber2Spacing between cells in px.
colorScale'sequential' | 'diverging' | string[]'sequential'Built-in scale or custom hex stop array.
domain[number, number]derived[min, max] for colour mapping; defaults to data min/max.
showValuesbooleanfalseRender the value text inside each cell.
showLegendbooleantrueRender the colour legend.
legendPosition'right' | 'bottom''right'Legend placement.
formatValue(v: number) => stringString(v)Format cell and tooltip values.
emptyCellColorstringtheme.surfaceAltFill for an (x, y) pair with no datapoint.
ariaLabelstringautoAccessible name; auto-generated from grid size and range.
onCellClick(cell: TkxHeatmapCell) => voidFires when a cell that has data is clicked.

All other div attributes (except onClick) are spread onto the root.

  • Scales: 'sequential' lerps from a near-white tint to the theme primary; 'diverging' is a fixed red → white → blue ramp ideal for correlation matrices in [-1, 1]. A custom string[] is interpolated evenly across its stops.
  • Axis labels with mixed numeric/string values are sorted numerically only when every value parses as a number; otherwise they sort by localeCompare.
  • Long x-axis labels (wider than a cell) are automatically rotated -45°.
  • In-cell value text picks black or white per WCAG luminance for contrast, so it stays readable on any cell colour.
  • A degenerate domain (all values identical) maps every cell to the mid-colour.
  • onCellClick only fires for cells that have a datapoint — empty cells are not interactive.

src/components/TkxHeatmap.tsx