Skip to content

Commit

Permalink
fix(heatmap): better handling of NaN values
Browse files Browse the repository at this point in the history
When a NaN value is included in heatmap data, no errors appear but two warnings are raised:
* The prop `node.color` is marked as required in `HeatMapCellTooltip`, but its value is `undefined`.
* Received NaN for the `children` attribute. If this is expected, cast the value to a string.

This commit addresses both of these, and adds a `nanColor` prop to `HeatMap` to allow specifying the color used for a cell that is NaN (defaults to #000000).
  • Loading branch information
martingordon authored and Raphaël Benitte committed Aug 24, 2018
1 parent efbda0f commit 02ef557
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/nivo-core/src/components/tooltip/BasicTooltip.js
Expand Up @@ -33,7 +33,7 @@ const BasicTooltip = props => {
{enableChip && <Chip color={color} style={chipStyle} />}
{value !== undefined ? (
<span>
{id}: <strong>{value}</strong>
{id}: <strong>{isNaN(value) ? String(value) : value}</strong>
</span>
) : (
id
Expand Down
3 changes: 2 additions & 1 deletion packages/nivo-heatmap/src/computeNodes.js
Expand Up @@ -25,6 +25,7 @@ export default ({
cellWidth,
cellHeight,
colorScale,
nanColor,
getLabelTextColor,

currentNode,
Expand All @@ -50,7 +51,7 @@ export default ({
width,
height,
value: d[key],
color: colorScale(d[key]),
color: isNaN(d[key]) ? nanColor : colorScale(d[key]),
}

let opacity = cellOpacity
Expand Down
2 changes: 2 additions & 0 deletions packages/nivo-heatmap/src/props.js
Expand Up @@ -47,6 +47,7 @@ export const HeatMapPropTypes = {
// theming
colors: quantizeColorScalePropType.isRequired,
colorScale: PropTypes.func.isRequired, // computed
nanColor: PropTypes.string,

// interactivity
isInteractive: PropTypes.bool,
Expand Down Expand Up @@ -89,6 +90,7 @@ export const HeatMapDefaultProps = {

// theming
colors: 'nivo',
nanColor: '#000000',

// interactivity
isInteractive: true,
Expand Down

0 comments on commit 02ef557

Please sign in to comment.