heatmap — 6.0.0

Render categorical status matrices or threshold-colored numeric grids with labels and legends.

Signature

Signature
heatmap(spec: HeatmapSpec): string

Executable examples

Categorical heatmap

Source
heatmap({
  columns: ['Linux', 'macOS', 'Windows'],
  rows: ["Node 22","Node 24"],
  data: [['pass', 'pass', 'fail'], ['pass', 'pending', 'pass']],
  levels: [
    { value: 'pass', symbol: '●', color: 'ansiGreen', label: 'Passed' },
    { value: 'pending', symbol: '○', color: 'ansiYellow', label: 'Pending' },
    { value: 'fail', symbol: '×', color: 'ansiRed', label: 'Failed' },
  ],
  legend: true,
});
Terminal output
         Linux  macOS  Windows
Node 22    ●      ●       ×
Node 24    ●      ○       ●

● Passed  ○ Pending  × Failed

Threshold heatmap

Source
heatmap({
  data: [[42, 68, 83], [35, 79, null]],
  threshold: {
    value: 80,
    belowColor: 'ansiCyan',
    aboveColor: 'ansiBrightRed',
    belowSymbol: '·',
    aboveSymbol: '!',
  },
});
Terminal output
·  ·  !
·  ·

HeatmapSpec

Complete discrete heatmap or status-matrix specification.

type HeatmapSpec = HeatmapBaseSpec & (Readonly<{
  /** Matrix of categorical values; `null` reserves an empty cell. */
  data: readonly (readonly HeatmapValue[])[];
  /** Exact visual mapping for categorical or already-binned values. */
  levels: readonly HeatmapLevel[];
  threshold?: never;
}> | Readonly<{
  /** Matrix of finite numeric values; `null` reserves an empty cell. */
  data: readonly (readonly (number | null)[])[];
  levels?: never;
  /** Binary visual mapping for raw numeric values. */
  threshold: HeatmapThreshold;
}>);

rows

readonly string[]Optional

Optional row labels; length must match the data row count.

Related executable examples: Categorical heatmap

columns

readonly string[]Optional

Optional column labels; length must match the widest data row.

Related executable examples: Categorical heatmap

title

stringOptional

Title rendered above the matrix.

Related executable examples: Categorical heatmap

legend

booleanOptional

Renders a level or threshold legend below the matrix.

Related executable examples: Categorical heatmap

symbols

HeatmapSymbolsOptional

Per-call glyph overrides.

Related executable examples: Categorical heatmap

data

readonly (readonly HeatmapValue[])[] | readonly (readonly (number | null)[])[]Required

Matrix of categorical values; null reserves an empty cell.

Related executable examples: Categorical heatmap, Threshold heatmap

levels

readonly HeatmapLevel[] | neverOptional

Exact visual mapping for categorical or already-binned values.

Related executable examples: Categorical heatmap

threshold

never | HeatmapThresholdOptional

Binary visual mapping for raw numeric values.

Related executable examples: Threshold heatmap

HeatmapLevel

Visual mapping for one non-null heatmap value.

type HeatmapLevel = Readonly<{
  /** Exact non-null cell value matched by this level. */
  value: Exclude<HeatmapValue, null>;
  /** One-column glyph. Defaults to the heatmap cell symbol. */
  symbol?: string;
  /** ANSI color applied to matching cells and their legend marker. */
  color?: Color;
  /** Legend text. Defaults to the string form of `value`. */
  label?: string;
}>;

value

Exclude<HeatmapValue, null>Required

Exact non-null cell value matched by this level.

Related executable examples: Categorical heatmap

symbol

stringOptional

One-column glyph. Defaults to the heatmap cell symbol.

Related executable examples: Categorical heatmap

color

ColorOptional

ANSI color applied to matching cells and their legend marker.

Related executable examples: Categorical heatmap

label

stringOptional

Legend text. Defaults to the string form of value.

Related executable examples: Categorical heatmap

HeatmapThreshold

Binary visual mapping selected by comparing numeric cells with one threshold.

type HeatmapThreshold = Readonly<{
  /** Finite comparison value. */
  value: number;
  /** ANSI color used for cells below the threshold. */
  belowColor: Color;
  /** Color used when a cell value equals or exceeds the threshold. */
  aboveColor: Color;
  /** One-column glyph used below the threshold. */
  belowSymbol?: string;
  /** One-column glyph used at or above the threshold. */
  aboveSymbol?: string;
  /** Legend text for values below the threshold. */
  belowLabel?: string;
  /** Legend text for values at or above the threshold. */
  aboveLabel?: string;
}>;

value

numberRequired

Finite comparison value.

Related executable examples: Threshold heatmap

belowColor

ColorRequired

ANSI color used for cells below the threshold.

Related executable examples: Threshold heatmap

aboveColor

ColorRequired

Color used when a cell value equals or exceeds the threshold.

Related executable examples: Threshold heatmap

belowSymbol

stringOptional

One-column glyph used below the threshold.

Related executable examples: Threshold heatmap

aboveSymbol

stringOptional

One-column glyph used at or above the threshold.

Related executable examples: Threshold heatmap

belowLabel

stringOptional

Legend text for values below the threshold.

Related executable examples: Threshold heatmap

aboveLabel

stringOptional

Legend text for values at or above the threshold.

Related executable examples: Threshold heatmap

HeatmapSymbols

Per-call heatmap glyph overrides.

type HeatmapSymbols = Readonly<{
  /** Default one-column categorical cell glyph. */
  cell?: string;
  /** Default one-column glyph for values below a threshold. */
  belowThreshold?: string;
  /** Default one-column glyph for values at or above a threshold. */
  aboveThreshold?: string;
  /** One-column glyph used for `null`. */
  empty?: string;
  /** Display-safe text inserted between cells. */
  gap?: string;
}>;

cell

stringOptional

Default one-column categorical cell glyph.

Related executable examples: Categorical heatmap

belowThreshold

stringOptional

Default one-column glyph for values below a threshold.

Related executable examples: Threshold heatmap

aboveThreshold

stringOptional

Default one-column glyph for values at or above a threshold.

Related executable examples: Threshold heatmap

empty

stringOptional

One-column glyph used for null.

Related executable examples: Categorical heatmap

gap

stringOptional

Display-safe text inserted between cells.

Related executable examples: Categorical heatmap