Skip to content

Commit 1c0e7b8

Browse files
committed
[poc] add 'nancolor' to heatmap
1 parent 775682f commit 1c0e7b8

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

src/plot_api/plot_api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ function _restyle(gd, aobj, _traces) {
13141314
// objects need to be made) but not a recalc
13151315
var replotAttrs = [
13161316
'zmin', 'zmax', 'zauto',
1317-
'xgap', 'ygap',
1317+
'xgap', 'ygap', 'nancolor',
13181318
'marker.cmin', 'marker.cmax', 'marker.cauto',
13191319
'line.cmin', 'line.cmax',
13201320
'marker.line.cmin', 'marker.line.cmax',

src/traces/heatmap/attributes.js

+7
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ module.exports = extendFlat({}, {
9090
role: 'style',
9191
description: 'Sets the vertical gap (in pixels) between bricks.'
9292
},
93+
nancolor: {
94+
valType: 'color',
95+
dflt: 'rgba(0,0,0,0)',
96+
role: 'style',
97+
description: 'Sets the color associated with NaN values in `z`.'
98+
99+
}
93100
},
94101
colorscaleAttrs,
95102
{ autocolorscale: extendFlat({}, colorscaleAttrs.autocolorscale, {dflt: false}) },

src/traces/heatmap/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2929
}
3030

3131
coerce('text');
32+
coerce('nancolor');
3233

3334
var zsmooth = coerce('zsmooth');
3435
if(zsmooth === false) {

src/traces/heatmap/plot.js

+16-13
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,23 @@ function plotOne(gd, plotinfo, cd) {
282282
return padding;
283283
}
284284

285+
var nanTc = tinycolor(trace.nancolor).toRgb(),
286+
nanColor = [nanTc.r, nanTc.g, nanTc.b, nanTc.a];
287+
285288
function setColor(v, pixsize) {
286-
if(v !== undefined) {
287-
var c = sclFunc(v);
288-
c[0] = Math.round(c[0]);
289-
c[1] = Math.round(c[1]);
290-
c[2] = Math.round(c[2]);
291-
292-
pixcount += pixsize;
293-
rcount += c[0] * pixsize;
294-
gcount += c[1] * pixsize;
295-
bcount += c[2] * pixsize;
296-
return c;
297-
}
298-
return [0, 0, 0, 0];
289+
pixcount += pixsize;
290+
291+
var c = v !== undefined ? sclFunc(v) : nanColor;
292+
293+
c[0] = Math.round(c[0]);
294+
c[1] = Math.round(c[1]);
295+
c[2] = Math.round(c[2]);
296+
297+
rcount += c[0] * pixsize;
298+
gcount += c[1] * pixsize;
299+
bcount += c[2] * pixsize;
300+
301+
return c;
299302
}
300303

301304
function putColor(pixels, pxIndex, c) {

0 commit comments

Comments
 (0)