Skip to content

Bug null data #286

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 5 commits into from
Feb 26, 2016
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
7 changes: 5 additions & 2 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, maybe we should make that standard: http://eslint.org/docs/rules/no-eq-null

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;
Expand Down
Binary file added test/image/baselines/axes_category_null.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions test/image/mocks/axes_category_null.json
Original file line number Diff line number Diff line change
@@ -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
}
}
31 changes: 31 additions & 0 deletions test/jasmine/tests/calcdata_test.js
Original file line number Diff line number Diff line change
@@ -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});
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah man 🎉

});
});
});