From 93a70be6f2468a7a33187f6bd92c34ec7a46b99e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20T=C3=A9treault-Pinard?= Date: Thu, 16 Mar 2017 19:44:29 -0400 Subject: [PATCH] don't try to fill z 2D with nulls in convert xyz column - as Lib.distinctVals + Lib.findBin don't work properly (and shouldn't) for non-numeric values --- src/traces/heatmap/convert_column_xyz.js | 13 +++++++----- test/jasmine/tests/heatmap_test.js | 25 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/traces/heatmap/convert_column_xyz.js b/src/traces/heatmap/convert_column_xyz.js index c118de79f12..796aca7f43d 100644 --- a/src/traces/heatmap/convert_column_xyz.js +++ b/src/traces/heatmap/convert_column_xyz.js @@ -10,6 +10,7 @@ 'use strict'; var Lib = require('../../lib'); +var BADNUM = require('../../constants/numerical').BADNUM; module.exports = function convertColumnXYZ(trace, xa, ya) { @@ -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) { + 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; diff --git a/test/jasmine/tests/heatmap_test.js b/test/jasmine/tests/heatmap_test.js index f56d6dd341f..48cb7b13715 100644 --- a/test/jasmine/tests/heatmap_test.js +++ b/test/jasmine/tests/heatmap_test.js @@ -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'); @@ -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() {