Skip to content

Commit 87de776

Browse files
authoredMay 9, 2017
Merge pull request #1656 from plotly/select-skip-badnum
Skip BADNUM items in scatter select routine
2 parents 1ffb102 + 80cee01 commit 87de776

File tree

5 files changed

+49
-10
lines changed

5 files changed

+49
-10
lines changed
 

‎src/lib/polygon.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
var dot = require('./matrix').dot;
13+
var BADNUM = require('../constants/numerical').BADNUM;
1314

1415
var polygon = module.exports = {};
1516

@@ -73,7 +74,7 @@ polygon.tester = function tester(ptsIn) {
7374
var x = pt[0],
7475
y = pt[1];
7576

76-
if(x < xmin || x > xmax || y < ymin || y > ymax) {
77+
if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {
7778
// pt is outside the bounding box of polygon
7879
return false;
7980
}
@@ -86,7 +87,7 @@ polygon.tester = function tester(ptsIn) {
8687
var x = pt[0],
8788
y = pt[1];
8889

89-
if(x < xmin || x > xmax || y < ymin || y > ymax) {
90+
if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {
9091
// pt is outside the bounding box of polygon
9192
return false;
9293
}

‎src/traces/scatter/calc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
var isNumeric = require('fast-isnumeric');
1313

1414
var Axes = require('../../plots/cartesian/axes');
15+
var BADNUM = require('../../constants/numerical').BADNUM;
1516

1617
var subTypes = require('./subtypes');
1718
var calcColorscale = require('./colorscale_calc');
@@ -114,7 +115,7 @@ module.exports = function calc(gd, trace) {
114115
var cd = new Array(serieslen);
115116
for(i = 0; i < serieslen; i++) {
116117
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ?
117-
{x: x[i], y: y[i]} : {x: false, y: false};
118+
{x: x[i], y: y[i]} : {x: BADNUM, y: BADNUM};
118119

119120
if(trace.ids) {
120121
cd[i].id = String(trace.ids[i]);

‎src/traces/scatter/select.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = function selectPoints(searchInfo, polygon) {
4040
di = cd[i];
4141
x = xa.c2p(di.x);
4242
y = ya.c2p(di.y);
43+
4344
if(polygon.contains([x, y])) {
4445
selection.push({
4546
curveNumber: curveNumber,

‎test/jasmine/tests/calcdata_test.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Plotly = require('@lib/index');
22

3+
var BADNUM = require('@src/constants/numerical').BADNUM;
34
var createGraphDiv = require('../assets/create_graph_div');
45
var destroyGraphDiv = require('../assets/destroy_graph_div');
56

@@ -18,15 +19,15 @@ describe('calculated data and points', function() {
1819
it('should exclude null and undefined points when false', function() {
1920
Plotly.plot(gd, [{ x: [1, 2, 3, undefined, 5], y: [1, null, 3, 4, 5]}], {});
2021

21-
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: false, y: false}));
22-
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: false, y: false}));
22+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
23+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
2324
});
2425

2526
it('should exclude null and undefined points as categories when false', function() {
2627
Plotly.plot(gd, [{ x: [1, 2, 3, undefined, 5], y: [1, null, 3, 4, 5] }], { xaxis: { type: 'category' }});
2728

28-
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: false, y: false}));
29-
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: false, y: false}));
29+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
30+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
3031
});
3132
});
3233

@@ -192,9 +193,9 @@ describe('calculated data and points', function() {
192193
}});
193194

194195
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15}));
195-
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: false, y: false}));
196+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
196197
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 3, y: 12}));
197-
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: false, y: false}));
198+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({ x: BADNUM, y: BADNUM}));
198199
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14}));
199200
});
200201

@@ -269,7 +270,7 @@ describe('calculated data and points', function() {
269270
}});
270271

271272
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 15}));
272-
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: false, y: false}));
273+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: BADNUM, y: BADNUM}));
273274
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 5, y: 12}));
274275
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
275276
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));

‎test/jasmine/tests/select_test.js

+35
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,39 @@ describe('select box and lasso', function() {
322322
done();
323323
});
324324
});
325+
326+
it('should skip over BADNUM items', function(done) {
327+
var data = [{
328+
mode: 'markers',
329+
x: [null, undefined, NaN, 0, 'NA'],
330+
y: [NaN, null, undefined, 0, 'NA']
331+
}];
332+
var layout = {
333+
dragmode: 'select',
334+
width: 400,
335+
heigth: 400,
336+
};
337+
var gd = createGraphDiv();
338+
var pts;
339+
340+
Plotly.plot(gd, data, layout).then(function() {
341+
gd.on('plotly_selected', function(data) {
342+
pts = data.points;
343+
});
344+
345+
drag([[100, 100], [300, 300]]);
346+
expect(pts.length).toEqual(1);
347+
expect(pts[0].x).toEqual(0);
348+
expect(pts[0].y).toEqual(0);
349+
350+
return Plotly.relayout(gd, 'dragmode', 'lasso');
351+
})
352+
.then(function() {
353+
drag([[100, 100], [100, 300], [300, 300], [300, 100], [100, 100]]);
354+
expect(pts.length).toEqual(1);
355+
expect(pts[0].x).toEqual(0);
356+
expect(pts[0].y).toEqual(0);
357+
})
358+
.then(done);
359+
});
325360
});

0 commit comments

Comments
 (0)
Please sign in to comment.