Skip to content

Commit f712283

Browse files
committed
Merge pull request #286 from plotly/bug-null-data
Bug null data
2 parents 2576519 + a04550f commit f712283

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

src/plots/cartesian/set_convert.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,13 @@ module.exports = function setConvert(ax) {
184184
// that aren't in the first etc.
185185
// TODO: sorting options - do the sorting
186186
// progressively here as we insert?
187-
if(ax._categories.indexOf(v)===-1) ax._categories.push(v);
187+
188+
if(v !== null && v !== undefined && ax._categories.indexOf(v) === -1){
189+
ax._categories.push(v);
190+
}
188191

189192
var c = ax._categories.indexOf(v);
190-
return c===-1 ? constants.BADNUM : c;
193+
return c === -1 ? constants.BADNUM : c;
191194
};
192195

193196
ax.d2l = ax.d2c;
20.5 KB
Loading
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
1,
6+
2,
7+
null,
8+
4,
9+
5
10+
],
11+
"y": [
12+
1,
13+
2,
14+
3,
15+
4,
16+
5
17+
],
18+
"connectgaps": false,
19+
"uid": "8ac13a"
20+
}
21+
],
22+
"layout": {
23+
"title": "null categories",
24+
"xaxis": {
25+
"type": "category",
26+
"range": [
27+
-0.18336673346693386,
28+
3.1833667334669338
29+
],
30+
"autorange": true
31+
},
32+
"yaxis": {
33+
"type": "linear",
34+
"range": [
35+
0.7070063694267517,
36+
5.292993630573249
37+
],
38+
"autorange": true
39+
},
40+
"height": 450,
41+
"width": 1000,
42+
"autosize": true
43+
}
44+
}

test/jasmine/tests/calcdata_test.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var Plotly = require('@lib/index');
2+
3+
var createGraphDiv = require('../assets/create_graph_div');
4+
var destroyGraphDiv = require('../assets/destroy_graph_div');
5+
6+
describe('calculated data and points', function() {
7+
describe('connectGaps', function() {
8+
9+
var gd;
10+
11+
beforeEach(function() {
12+
gd = createGraphDiv();
13+
});
14+
15+
afterEach(destroyGraphDiv);
16+
17+
it('should exclude null and undefined points when false', function() {
18+
Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5]}], {});
19+
20+
expect(gd.calcdata[0][1]).toEqual({ x: false, y: false});
21+
expect(gd.calcdata[0][3]).toEqual({ x: false, y: false});
22+
});
23+
24+
it('should exclude null and undefined points as categories when false', function() {
25+
Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5] }], { xaxis: { type: 'category' }});
26+
27+
expect(gd.calcdata[0][1]).toEqual({ x: false, y: false});
28+
expect(gd.calcdata[0][3]).toEqual({ x: false, y: false});
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)