Skip to content

Commit 4d8b274

Browse files
committed
Implement new selection interface for box trace type [1852]
- Needs cleanup in select.js - Controlling code in cartesian/select.js needs a change due to a false assumption about hoverData: box produces a multi-element hoverData array whereas only the first element is really the clicked point
1 parent a79dea7 commit 4d8b274

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

src/traces/box/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Box.plot = require('./plot').plot;
2020
Box.style = require('./style').style;
2121
Box.styleOnSelect = require('./style').styleOnSelect;
2222
Box.hoverPoints = require('./hover').hoverPoints;
23-
Box.selectPoints = require('./select');
23+
Box.getPointsIn = require('./select').getPointsIn;
24+
Box.toggleSelected = require('./select').toggleSelected;
2425

2526
Box.moduleType = 'trace';
2627
Box.name = 'box';

src/traces/box/select.js

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
'use strict';
1010

11-
module.exports = function selectPoints(searchInfo, polygon) {
11+
// TODO Remove eventually
12+
function selectPoints(searchInfo, polygon) {
1213
var cd = searchInfo.cd;
1314
var xa = searchInfo.xaxis;
1415
var ya = searchInfo.yaxis;
@@ -43,5 +44,86 @@ module.exports = function selectPoints(searchInfo, polygon) {
4344
}
4445
}
4546

47+
return selection;
48+
}
49+
50+
exports.getPointsIn = function(searchInfo, polygon) {
51+
var pointsIn = [];
52+
var cd = searchInfo.cd;
53+
var xa = searchInfo.xaxis;
54+
var ya = searchInfo.yaxis;
55+
var i;
56+
var j;
57+
var pt;
58+
var x;
59+
var y;
60+
61+
for(i = 0; i < cd.length; i++) {
62+
for(j = 0; j < (cd[i].pts || []).length; j++) {
63+
pt = cd[i].pts[j];
64+
x = xa.c2p(pt.x);
65+
y = ya.c2p(pt.y);
66+
67+
if(polygon.contains([x, y])) {
68+
pointsIn.push(pt.i);
69+
}
70+
}
71+
}
72+
73+
return pointsIn;
74+
};
75+
76+
exports.toggleSelected = function(searchInfo, selected, pointIds) {
77+
var selection = [];
78+
var modifyAll = !Array.isArray(pointIds);
79+
var cd = searchInfo.cd;
80+
var xa = searchInfo.xaxis;
81+
var ya = searchInfo.yaxis;
82+
var pointId;
83+
var pt;
84+
var ptPos;
85+
var i;
86+
var j;
87+
88+
if(!modifyAll) {
89+
// console.log(pointIds);
90+
}
91+
92+
// Mutate state
93+
// if(!modifyAll) {
94+
// for(i = 0; i < pointIds.length; i++) {
95+
// pointId = pointIds[i];
96+
// for(j = 0; j < cd.length; j++) {
97+
// ptPos = cd[j].pts.indexOf(pointId);
98+
// if(ptPos > -1) {
99+
// pt = cd[j].pts[ptPos];
100+
// pt.selected = selected ? 1 : 0;
101+
// }
102+
// }
103+
// }
104+
// }
105+
106+
107+
for(i = 0; i < cd.length; i++) {
108+
for(j = 0; j < (cd[i].pts || []).length; j++) {
109+
pt = cd[i].pts[j];
110+
111+
if(modifyAll) pt.selected = selected ? 1 : 0;
112+
else {
113+
if(pointIds.indexOf(pt.i) > -1) {
114+
pt.selected = selected ? 1 : 0;
115+
}
116+
}
117+
118+
if(pt.selected) {
119+
selection.push({
120+
pointNumber: pt.i,
121+
x: xa.c2d(pt.x),
122+
y: ya.c2d(pt.y)
123+
});
124+
}
125+
}
126+
}
127+
46128
return selection;
47129
};

0 commit comments

Comments
 (0)