Skip to content

Add 'nancolor' heatmap attribute #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ function _restyle(gd, aobj, _traces) {
// objects need to be made) but not a recalc
var replotAttrs = [
'zmin', 'zmax', 'zauto',
'xgap', 'ygap',
'xgap', 'ygap', 'nancolor',
'marker.cmin', 'marker.cmax', 'marker.cauto',
'line.cmin', 'line.cmax',
'marker.line.cmin', 'marker.line.cmax',
Expand Down
7 changes: 7 additions & 0 deletions src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ module.exports = extendFlat({}, {
role: 'style',
description: 'Sets the vertical gap (in pixels) between bricks.'
},
nancolor: {
valType: 'color',
dflt: 'rgba(0,0,0,0)',
role: 'style',
description: 'Sets the color associated with NaN values in `z`.'

}
},
colorscaleAttrs,
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmap/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}

coerce('text');
coerce('nancolor');

var zsmooth = coerce('zsmooth');
if(zsmooth === false) {
Expand Down
29 changes: 16 additions & 13 deletions src/traces/heatmap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,23 @@ function plotOne(gd, plotinfo, cd) {
return padding;
}

var nanTc = tinycolor(trace.nancolor).toRgb(),
nanColor = [nanTc.r, nanTc.g, nanTc.b, nanTc.a];

function setColor(v, pixsize) {
if(v !== undefined) {
var c = sclFunc(v);
c[0] = Math.round(c[0]);
c[1] = Math.round(c[1]);
c[2] = Math.round(c[2]);

pixcount += pixsize;
rcount += c[0] * pixsize;
gcount += c[1] * pixsize;
bcount += c[2] * pixsize;
return c;
}
return [0, 0, 0, 0];
pixcount += pixsize;

var c = v !== undefined ? sclFunc(v) : nanColor;

c[0] = Math.round(c[0]);
c[1] = Math.round(c[1]);
c[2] = Math.round(c[2]);

rcount += c[0] * pixsize;
gcount += c[1] * pixsize;
bcount += c[2] * pixsize;

return c;
}

function putColor(pixels, pxIndex, c) {
Expand Down