Heat map
A grid of cells coloured by value, for spotting hot and cold combinations.
Preview
Customers by industry and plan
| Customers | Starter | Growth | Enterprise |
|---|---|---|---|
| Health | 133 | 224 | 91 |
| Media | 438 | 220 | 19 |
| Retail | 465 | 245 | 31 |
| Tech | 246 | 395 | 66 |
Usage
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
export const Example = () => (
<ChartsProvider>
<div style={{ height: 320 }}>
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
/>
</div>
</ChartsProvider>
);
const rows = [
{ plan: 'Starter', industry: 'Health', customers: 133 },
{ plan: 'Growth', industry: 'Health', customers: 224 },
{ plan: 'Enterprise', industry: 'Health', customers: 91 },
{ plan: 'Starter', industry: 'Media', customers: 438 },
{ plan: 'Growth', industry: 'Media', customers: 220 },
{ plan: 'Enterprise', industry: 'Media', customers: 19 },
{ plan: 'Starter', industry: 'Retail', customers: 465 },
{ plan: 'Growth', industry: 'Retail', customers: 245 },
{ plan: 'Enterprise', industry: 'Retail', customers: 31 },
{ plan: 'Starter', industry: 'Tech', customers: 246 },
{ plan: 'Growth', industry: 'Tech', customers: 395 },
{ plan: 'Enterprise', industry: 'Tech', customers: 66 },
];Install with npm install em-kit. Needs <ChartsProvider> once and a parent with a height: Quick start.
Examples
Custom colour scale
Your own cold, middle and hot colours. minColor, midColor and maxColor; the cell text switches between dark and light for contrast.
Show full code (37 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
export const Example = () => (
<ChartsProvider>
<div style={{ height: 320 }}>
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
minColor="#ecfeff"
midColor="#22d3ee"
maxColor="#155e75"
/>
</div>
</ChartsProvider>
);
const rows = [
{ plan: 'Starter', industry: 'Health', customers: 133 },
{ plan: 'Growth', industry: 'Health', customers: 224 },
{ plan: 'Enterprise', industry: 'Health', customers: 91 },
{ plan: 'Starter', industry: 'Media', customers: 438 },
{ plan: 'Growth', industry: 'Media', customers: 220 },
{ plan: 'Enterprise', industry: 'Media', customers: 19 },
{ plan: 'Starter', industry: 'Retail', customers: 465 },
{ plan: 'Growth', industry: 'Retail', customers: 245 },
{ plan: 'Enterprise', industry: 'Retail', customers: 31 },
{ plan: 'Starter', industry: 'Tech', customers: 246 },
{ plan: 'Growth', industry: 'Tech', customers: 395 },
{ plan: 'Enterprise', industry: 'Tech', customers: 66 },
];<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
minColor="#ecfeff"
midColor="#22d3ee"
maxColor="#155e75"
/>Thresholds
Everything in the bottom fifth of the range fully cold and the top fifth fully hot, so outliers don’t wash out the rest. Thresholds take a raw value or a percentage of the range: minThreshold: '20%', maxThreshold: '80%'.
Show full code (36 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
export const Example = () => (
<ChartsProvider>
<div style={{ height: 320 }}>
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
minThreshold="20%"
maxThreshold="80%"
/>
</div>
</ChartsProvider>
);
const rows = [
{ plan: 'Starter', industry: 'Health', customers: 133 },
{ plan: 'Growth', industry: 'Health', customers: 224 },
{ plan: 'Enterprise', industry: 'Health', customers: 91 },
{ plan: 'Starter', industry: 'Media', customers: 438 },
{ plan: 'Growth', industry: 'Media', customers: 220 },
{ plan: 'Enterprise', industry: 'Media', customers: 19 },
{ plan: 'Starter', industry: 'Retail', customers: 465 },
{ plan: 'Growth', industry: 'Retail', customers: 245 },
{ plan: 'Enterprise', industry: 'Retail', customers: 31 },
{ plan: 'Starter', industry: 'Tech', customers: 246 },
{ plan: 'Growth', industry: 'Tech', customers: 395 },
{ plan: 'Enterprise', industry: 'Tech', customers: 66 },
];const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
minThreshold="20%"
maxThreshold="80%"
/>Colours only
No numbers in the cells, for a compact pattern view; the values stay in the exports.
Show full code (35 lines)
import { ChartsProvider, HeatMap, dimension, measure, results } from 'em-kit';
const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
export const Example = () => (
<ChartsProvider>
<div style={{ height: 320 }}>
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
showValues={false}
/>
</div>
</ChartsProvider>
);
const rows = [
{ plan: 'Starter', industry: 'Health', customers: 133 },
{ plan: 'Growth', industry: 'Health', customers: 224 },
{ plan: 'Enterprise', industry: 'Health', customers: 91 },
{ plan: 'Starter', industry: 'Media', customers: 438 },
{ plan: 'Growth', industry: 'Media', customers: 220 },
{ plan: 'Enterprise', industry: 'Media', customers: 19 },
{ plan: 'Starter', industry: 'Retail', customers: 465 },
{ plan: 'Growth', industry: 'Retail', customers: 245 },
{ plan: 'Enterprise', industry: 'Retail', customers: 31 },
{ plan: 'Starter', industry: 'Tech', customers: 246 },
{ plan: 'Growth', industry: 'Tech', customers: 395 },
{ plan: 'Enterprise', industry: 'Tech', customers: 66 },
];const industry = dimension({ name: 'industry', title: 'Industry' });
const plan = dimension({ name: 'plan', title: 'Plan' });
const customers = measure({ name: 'customers', title: 'Customers' });
<HeatMap
title="Customers by industry and plan"
rowDimension={industry}
columnDimension={plan}
measure={customers}
results={results(rows)}
showValues={false}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
rowDimensionrequired | Dimension | The dimension down the side of the grid. | |
columnDimensionrequired | Dimension | The dimension across the top of the grid. | |
measurerequired | Measure | The number behind each cell’s colour and label. | |
resultsrequired | DataResponse | Your query’s state: { isLoading, data, error }, where data is your rows. results(rows) builds it from an array. | |
columnWidth | number | A fixed width for the value columns, in pixels. | |
displayNullAs | string | Text shown where a value is null, for example "–". | |
firstColumnWidth | number | A fixed width for the row-label column, in pixels. | |
maxColor | string | Colour of the highest values. | |
maxThreshold | string | Values at this get maxColor; values above it darken further. A number as a string, or a percentage of the range such as "80%". | |
midColor | string | Colour of the values in the middle of the range. | |
minColor | string | Colour of the lowest values. | |
minThreshold | string | Values at this get minColor; values below it fade further towards white. A number as a string ("100"), or a percentage of the range such as "20%". | |
showValues | boolean | true | Print the value in each cell. |
onCellClicked | ( | Called with the clicked cell’s row and column values.HeatMapOptionsClickArg = { rowDimensionValue: string | undefined; rowDimensionTimeRange: TimeRange; columnDimensionValue: string | undefined; columnDimensionTimeRange: TimeRange; } | |
componentName | string | A name for this component, included in the interaction events it dispatches on the DOM, for your analytics. | |
trackingId | string | An id included in the same events, to tell two instances apart. | |
title | string | The card’s title. A "key|fallback" string is looked up in your translations. | |
description | string | Smaller text under the title. Translates like title. | |
tooltip | string | Text for an info icon beside the title. | |
hideMenu | boolean | false | Hide the card’s header: the title, description and menu. |
menuOptions | ( | ["csv", | Which entries the card menu offers. Pass [] for none. |
A blank default means the prop is unset unless you pass it.
| Type | Definition |
|---|---|
TimeRange | { from: Date |What a click’s TimeRange holds: Events. |
Field options
HeatMap reads only the common options in a field’s inputs.
Keyboard
| Key | Where | What it does |
|---|---|---|
Tab, Shift + Tab | Grid | Moves from cell to cell: every cell takes focus. |
Enter or Space | Cell | Calls onCellClicked with the cell’s row and column values, if you passed it. |
The card menu’s keys, and what is still missing, are in Accessibility.