React API Reference
Public TypeScript types, component props, layout results, and validation rules.
Import the public API from @taewooyo/heatmap-react:
import { Heatmap, computeHeatmapLayout } from "@taewooyo/heatmap-react";
import { useHeatmapState } from "@taewooyo/heatmap-react";
import type { HeatmapProps, HeatmapNode, HeatmapLayoutOptions, HeatmapLayoutCell, HeatmapDisplayPolicy, HeatmapInteraction, HeatmapMotion, HeatmapStyle } from "@taewooyo/heatmap-react";HeatmapNode
| Field | Type | Meaning |
|---|---|---|
id | string | Required, non-blank, unique among direct siblings; may repeat in separate branches. |
label | string | Required display and accessibility text. |
value | number | Required finite area weight; only positive weights receive area. |
metric | number? | Optional finite signed color metric. |
color | string? | Optional color override in #RRGGBB or #RRGGBBAA format. |
imageUrl | string? | Optional host-owned image URL. |
children | readonly HeatmapNode[]? | Nested nodes; absent or empty means a leaf. |
The input must not contain cycles. metric changes color but not area. The core does not fetch imageUrl.
Heatmap props
HeatmapProps extends HeatmapLayoutOptions and adds these component props:
| Prop | Type | Default / behavior |
|---|---|---|
data | HeatmapNode | Required root tree; pass a new reference for updates. |
className | string? | Applied to the root SVG. |
ariaLabel | string? | "Heatmap"; accessible chart name. |
cellGap | number? | 1; non-negative finite inset in SVG units. |
selectedId | string | null | null; selects matching leaf IDs. |
selectedKey | string | null | null; path-derived leaf key, takes precedence over selectedId. |
selectedBorderColor | string? | "#0f172a"; selected-leaf outline color. |
tooltipHoverDelayMs | number? | 400; non-negative integer dwell time in milliseconds. |
logoMaxSize | number? | 48; non-negative finite maximum SVG image size. |
metricFormatter | (metric: number) => string | Signed number; formats cell and tooltip text. |
valueFormatter | (value: number) => string | String(value) by default; adds the source value to cell descriptions and tooltips. |
valueLabel | string | "Value"; accessible label paired with the formatted source value. |
onLeafClick | (node, cell) => void | Called when a leaf is clicked or activated with Enter/Space. |
onLeafLongClick | (node, cell) => void | Called after a 500 ms touch hold. |
onGroupClick | (node, cell) => void | Called when a group header is clicked or keyboard-activated. |
onLeafHover | (node | null) => void | Receives the hovered leaf, or null after exit. |
state | HeatmapState? | State from useHeatmapState; enables built-in drill-down and selection. |
displayPolicy, style, interaction, motion | configuration objects | Compose-aligned rendering and interaction settings. |
Compose-aligned configuration
React uses SVG pixels where Compose uses Dp. The configuration objects share Compose's setting names and corresponding defaults.
| Object | Fields |
|---|---|
HeatmapStyle | borderColor, groupHeaderColor, groupHeaderTextColor, selectedBorderColor, leafTextColor |
HeatmapDisplayPolicy | hideContentBelow, showMetricAbove, showLabelAbove, cellContentPadding, adaptiveContent, metricFormatter |
HeatmapInteraction | drillDownOnGroupClick, selectLeafOnClick, showTooltipOnLongClick, tooltipDurationMillis, showTooltipOnHover, tooltipHoverDelayMillis |
HeatmapMotion | enabled, durationMillis, initialScale, pressScale, pressedAlpha, pressDurationMillis |
The older flat props (metricFormatter, selectedBorderColor, and tooltipHoverDelayMs) remain supported. Values in the configuration objects take precedence. Hover tooltips default to off, like Compose.
useHeatmapState(root)
Use this hook when React should manage drill-down and leaf selection like Compose:
const state = useHeatmapState(data);
<Heatmap data={data} state={state} width={960} height={600} />It exposes visibleNode, breadcrumbs, selectedNode, selectedId, canNavigateUp, and the same
navigation/selection operations as Compose: drillDown, navigateUp, navigateTo,
navigateToBreadcrumb, reset, select, isSelected, and clearSelection.
The component uses SVG with adaptive text and optional round images. Fill changes use a 240 ms CSS transition. Hover tooltips are opt-in through interaction.showTooltipOnHover; the application owns touch detail presentation.
HeatmapLayoutOptions
| Option | Type | Default / validation |
|---|---|---|
width | number | Required positive integer SVG width. |
height | number | Required positive integer SVG height. |
groupHeaderHeight | number? | 20; non-negative integer. |
maximumAbsoluteMetric | number? | 10; positive finite metric magnitude mapped to palette endpoints. |
palette | { negative: string; neutral: string; positive: string }? | Core default; each color must be #RRGGBB or #RRGGBBAA. |
computeHeatmapLayout(root, options)
Use the pure layout entry point without rendering React:
const cells = computeHeatmapLayout(market, { width: 960, height: 480 });
const visibleLeaves = cells.filter((cell) => cell.visible && cell.isLeaf);It returns readonly HeatmapLayoutCell[] in tree traversal order. Each cell has the original node, path-derived key, parentIndex (-1 at the root), depth, x, y, width, height, computed CSS hex color, isLeaf, and visible. Invisible cells should not be drawn. key distinguishes identical IDs in different branches.
Invalid dimensions, metric values, colors, cycles, or duplicate sibling IDs throw an error. The component uses this function internally; consumers normally only need Heatmap.
For Kotlin/Compose APIs, use the separate Kotlin API Reference and generated Dokka reference.
Version 0.3.0 additions
ResponsiveHeatmapacceptscontainerStyleandcontainerClassNameinstead of explicit width/height. Supply a bounded height.fallbackis rendered before measurement or while hidden.emptyContentis shown when no positive visual items exist; the default isNo data.- The source value is included in accessible names by default.
valueFormatterchanges its text, andvalueLabellocalizes the accessible label. state.navigationPathandstate.navigateToPath(path)use root-relative ID arrays.state.drillDown(node)opens an exact nested group from the current data. Strings address direct children.
Updates with the same root ID retain valid paths and selection. A different root ID resets both.
motion.enabled = false also disables fill-color transitions.