diff --git a/src/plots/cartesian/set_convert.js b/src/plots/cartesian/set_convert.js index a7d28d24655..2070dc30cb6 100644 --- a/src/plots/cartesian/set_convert.js +++ b/src/plots/cartesian/set_convert.js @@ -184,10 +184,13 @@ module.exports = function setConvert(ax) { // that aren't in the first etc. // TODO: sorting options - do the sorting // progressively here as we insert? - if(ax._categories.indexOf(v)===-1) ax._categories.push(v); + + if(v !== null && v !== undefined && ax._categories.indexOf(v) === -1){ + ax._categories.push(v); + } var c = ax._categories.indexOf(v); - return c===-1 ? constants.BADNUM : c; + return c === -1 ? constants.BADNUM : c; }; ax.d2l = ax.d2c; diff --git a/test/image/baselines/axes_category_null.png b/test/image/baselines/axes_category_null.png new file mode 100644 index 00000000000..bc75883b8fc Binary files /dev/null and b/test/image/baselines/axes_category_null.png differ diff --git a/test/image/mocks/axes_category_null.json b/test/image/mocks/axes_category_null.json new file mode 100644 index 00000000000..1dff64f4b46 --- /dev/null +++ b/test/image/mocks/axes_category_null.json @@ -0,0 +1,44 @@ +{ + "data": [ + { + "x": [ + 1, + 2, + null, + 4, + 5 + ], + "y": [ + 1, + 2, + 3, + 4, + 5 + ], + "connectgaps": false, + "uid": "8ac13a" + } + ], + "layout": { + "title": "null categories", + "xaxis": { + "type": "category", + "range": [ + -0.18336673346693386, + 3.1833667334669338 + ], + "autorange": true + }, + "yaxis": { + "type": "linear", + "range": [ + 0.7070063694267517, + 5.292993630573249 + ], + "autorange": true + }, + "height": 450, + "width": 1000, + "autosize": true + } +} diff --git a/test/jasmine/tests/calcdata_test.js b/test/jasmine/tests/calcdata_test.js new file mode 100644 index 00000000000..df134e774cc --- /dev/null +++ b/test/jasmine/tests/calcdata_test.js @@ -0,0 +1,31 @@ +var Plotly = require('@lib/index'); + +var createGraphDiv = require('../assets/create_graph_div'); +var destroyGraphDiv = require('../assets/destroy_graph_div'); + +describe('calculated data and points', function() { + describe('connectGaps', function() { + + var gd; + + beforeEach(function() { + gd = createGraphDiv(); + }); + + afterEach(destroyGraphDiv); + + it('should exclude null and undefined points when false', function() { + Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5]}], {}); + + expect(gd.calcdata[0][1]).toEqual({ x: false, y: false}); + expect(gd.calcdata[0][3]).toEqual({ x: false, y: false}); + }); + + it('should exclude null and undefined points as categories when false', function() { + Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5] }], { xaxis: { type: 'category' }}); + + expect(gd.calcdata[0][1]).toEqual({ x: false, y: false}); + expect(gd.calcdata[0][3]).toEqual({ x: false, y: false}); + }); + }); +});