Skip to content

Commit 172933c

Browse files
committed
image: return a transparent pixel if its value is not numeric
1 parent 742b83d commit 172933c

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/traces/image/plot.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010
var d3 = require('d3');
1111
var Lib = require('../../lib');
12+
var isNumeric = require('fast-isnumeric');
1213
var xmlnsNamespaces = require('../../constants/xmlns_namespaces');
1314
var constants = require('./constants');
1415

@@ -50,6 +51,7 @@ var scaler = function(trace) {
5051
return function(pixel) {
5152
var c = pixel.slice(0, n);
5253
for(var k = 0; k < n; k++) {
54+
if(!c[k] || !isNumeric(c[k])) return false;
5355
c[k] = s[k](c[k]);
5456
}
5557
return c;
@@ -142,7 +144,12 @@ module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
142144
var jpx0 = jpx(j); var jpx1 = jpx(j + 1);
143145
if(jpx1 === jpx0 || isNaN(jpx1) || isNaN(jpx0) || !z[j][i]) continue;
144146
c = trace._scaler(z[j][i]);
145-
context.fillStyle = trace.colormodel + '(' + fmt(c).join(',') + ')';
147+
if(c) {
148+
context.fillStyle = trace.colormodel + '(' + fmt(c).join(',') + ')';
149+
} else {
150+
// Return a transparent pixel
151+
context.fillStyle = 'rgba(0,0,0,0)';
152+
}
146153
context.fillRect(ipx0, jpx0, ipx1 - ipx0, jpx1 - jpx0);
147154
}
148155
}
7.14 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"data": [{
3+
"type": "image",
4+
"hoverinfo": "all",
5+
"z": [
6+
[
7+
[true, true, true],
8+
[false, false, false]
9+
]
10+
]
11+
}],
12+
"layout": {
13+
"width": 400,
14+
"height": 400
15+
}
16+
}

0 commit comments

Comments
 (0)