Skip to content

Commit 15c06fa

Browse files
committed
image: handle missing pixels in z
1 parent dec9469 commit 15c06fa

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/traces/image/hover.js

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ module.exports = function hoverPoints(pointData, xval, yval) {
2828
var nx = Math.floor((xval - cd0.x0) / trace.dx);
2929
var ny = Math.floor(Math.abs(yval - cd0.y0) / trace.dy);
3030

31+
// return early if pixel is undefined
32+
if(!cd0.z[ny][nx]) return;
33+
3134
var hoverinfo = cd0.hi || trace.hoverinfo;
3235
var fmtColor;
3336
if(hoverinfo) {

src/traces/image/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
120120
for(var i = 0; i < cd0.w; i++) {
121121
if(ipx(i + 1) === ipx(i)) continue;
122122
for(var j = 0; j < cd0.h; j++) {
123-
if(jpx(j + 1) === jpx(j)) continue;
123+
if(jpx(j + 1) === jpx(j) || !z[j][i]) continue;
124124
c = trace._scaler(z[j][i]);
125125
context.fillStyle = trace.colormodel + '(' + fmt(c).join(',') + ')';
126126
context.fillRect(ipx(i), jpx(j), ipx(i + 1) - ipx(i), jpx(j + 1) - jpx(j));
11.7 KB
Loading

test/image/mocks/image_with_gaps.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"data": [{
3+
"type": "image",
4+
"z": [
5+
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
6+
[[1, 0, 0], [0, 1, 0]],
7+
[[1, 0, 0]]
8+
],
9+
"zmax": [1, 1, 1]
10+
}],
11+
"layout": {
12+
"width": 400, "height": 400, "title": {"text": "Image with missing pixels"}
13+
}
14+
}

0 commit comments

Comments
 (0)