Skip to content

Commit

Permalink
image: handle missing pixels in z
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinerg committed Oct 22, 2019
1 parent dec9469 commit 15c06fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/traces/image/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = function hoverPoints(pointData, xval, yval) {
var nx = Math.floor((xval - cd0.x0) / trace.dx);
var ny = Math.floor(Math.abs(yval - cd0.y0) / trace.dy);

// return early if pixel is undefined
if(!cd0.z[ny][nx]) return;

var hoverinfo = cd0.hi || trace.hoverinfo;
var fmtColor;
if(hoverinfo) {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/image/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports.plot = function(gd, plotinfo, cdimage, imageLayer) {
for(var i = 0; i < cd0.w; i++) {
if(ipx(i + 1) === ipx(i)) continue;
for(var j = 0; j < cd0.h; j++) {
if(jpx(j + 1) === jpx(j)) continue;
if(jpx(j + 1) === jpx(j) || !z[j][i]) continue;
c = trace._scaler(z[j][i]);
context.fillStyle = trace.colormodel + '(' + fmt(c).join(',') + ')';
context.fillRect(ipx(i), jpx(j), ipx(i + 1) - ipx(i), jpx(j + 1) - jpx(j));
Expand Down
Binary file added test/image/baselines/image_with_gaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions test/image/mocks/image_with_gaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"data": [{
"type": "image",
"z": [
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
[[1, 0, 0], [0, 1, 0]],
[[1, 0, 0]]
],
"zmax": [1, 1, 1]
}],
"layout": {
"width": 400, "height": 400, "title": {"text": "Image with missing pixels"}
}
}

0 comments on commit 15c06fa

Please sign in to comment.