Skip to content

Fix xyz column convert routine for columns containing nulls #1491

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

Merged
merged 1 commit into from
Mar 17, 2017
Merged
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
13 changes: 8 additions & 5 deletions src/traces/heatmap/convert_column_xyz.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

var Lib = require('../../lib');
var BADNUM = require('../../constants/numerical').BADNUM;


module.exports = function convertColumnXYZ(trace, xa, ya) {
Expand Down Expand Up @@ -38,16 +39,18 @@ module.exports = function convertColumnXYZ(trace, xa, ya) {
y = yColdv.vals,
z = Lib.init2dArray(y.length, x.length);

var ix, iy, text;
var text;

if(hasColumnText) text = Lib.init2dArray(y.length, x.length);

for(i = 0; i < colLen; i++) {
ix = Lib.findBin(xCol[i] + xColdv.minDiff / 2, x);
iy = Lib.findBin(yCol[i] + yColdv.minDiff / 2, y);
if(xCol[i] !== BADNUM && yCol[i] !== BADNUM) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right - because xCol and yCol have already gone through d2c so anything invalid (null, text, whatever) will have become BADNUM - nice.

var ix = Lib.findBin(xCol[i] + xColdv.minDiff / 2, x);
var iy = Lib.findBin(yCol[i] + yColdv.minDiff / 2, y);

z[iy][ix] = zCol[i];
if(hasColumnText) text[iy][ix] = textCol[i];
z[iy][ix] = zCol[i];
if(hasColumnText) text[iy][ix] = textCol[i];
}
}

trace.x = x;
Expand Down
25 changes: 25 additions & 0 deletions test/jasmine/tests/heatmap_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Plotly = require('@lib/index');
var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');
var setConvert = require('@src/plots/cartesian/set_convert');

var convertColumnXYZ = require('@src/traces/heatmap/convert_column_xyz');
var Heatmap = require('@src/traces/heatmap');
Expand Down Expand Up @@ -264,6 +265,30 @@ describe('heatmap convertColumnXYZ', function() {
[,, 4.234497, 4.321701, 4.450315, 4.416136,,, ]
]);
});

it('should convert x/y/z columns with nulls to z(x,y)', function() {
xa = { type: 'linear' };
ya = { type: 'linear' };

setConvert(xa);
setConvert(ya);

trace = {
x: [0, 0, 0, 5, null, 5, 10, 10, 10],
y: [0, 5, 10, 0, null, 10, 0, 5, 10],
z: [0, 50, 100, 50, null, 255, 100, 510, 1010]
};

convertColumnXYZ(trace, xa, ya);

expect(trace.x).toEqual([0, 5, 10]);
expect(trace.y).toEqual([0, 5, 10]);
expect(trace.z).toEqual([
[0, 50, 100],
[50, undefined, 510],
[100, 255, 1010]
]);
});
});

describe('heatmap calc', function() {
Expand Down