Skip to content

Commit 1f4eabb

Browse files
committed
allow prepSelect callers to set own fillRangeItems routine
- e.g. to allow mapbox subplot convert px coords to lon/lat w/o hackely mocking too many things
1 parent e8b8624 commit 1f4eabb

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

src/plots/cartesian/select.js

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ function getAxId(ax) { return ax._id; }
2525
module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
2626
var zoomLayer = dragOptions.gd._fullLayout._zoomlayer,
2727
dragBBox = dragOptions.element.getBoundingClientRect(),
28-
xs = dragOptions.plotinfo.xaxis._offset,
29-
ys = dragOptions.plotinfo.yaxis._offset,
28+
plotinfo = dragOptions.plotinfo,
29+
xs = plotinfo.xaxis._offset,
30+
ys = plotinfo.yaxis._offset,
3031
x0 = startX - dragBBox.left,
3132
y0 = startY - dragBBox.top,
3233
x1 = x0,
@@ -71,6 +72,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
7172
searchInfo,
7273
selection = [],
7374
eventData;
75+
7476
for(i = 0; i < gd.calcdata.length; i++) {
7577
cd = gd.calcdata[i];
7678
trace = cd[0].trace;
@@ -106,9 +108,41 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
106108

107109
function ascending(a, b) { return a - b; }
108110

111+
// allow subplots to override fillRangeItems routine
112+
var fillRangeItems;
113+
114+
if(plotinfo.fillRangeItems) {
115+
fillRangeItems = plotinfo.fillRangeItems;
116+
} else {
117+
if(mode === 'select') {
118+
fillRangeItems = function(eventData, poly) {
119+
var ranges = eventData.range = {};
120+
121+
for(i = 0; i < allAxes.length; i++) {
122+
var ax = allAxes[i];
123+
var axLetter = ax._id.charAt(0);
124+
125+
ranges[ax._id] = [
126+
ax.p2d(poly[axLetter + 'min']),
127+
ax.p2d(poly[axLetter + 'max'])
128+
].sort(ascending);
129+
}
130+
};
131+
} else {
132+
fillRangeItems = function(eventData, poly, pts) {
133+
var dataPts = eventData.lassoPoints = {};
134+
135+
for(i = 0; i < allAxes.length; i++) {
136+
var ax = allAxes[i];
137+
dataPts[ax._id] = pts.filtered.map(axValue(ax));
138+
}
139+
};
140+
}
141+
}
142+
109143
dragOptions.moveFn = function(dx0, dy0) {
110-
var poly,
111-
ax;
144+
var poly;
145+
112146
x1 = Math.max(0, Math.min(pw, dx0 + x0));
113147
y1 = Math.max(0, Math.min(ph, dy0 + y0));
114148

@@ -158,27 +192,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
158192
}
159193

160194
eventData = {points: selection};
161-
162-
if(mode === 'select') {
163-
var ranges = eventData.range = {},
164-
axLetter;
165-
166-
for(i = 0; i < allAxes.length; i++) {
167-
ax = allAxes[i];
168-
axLetter = ax._id.charAt(0);
169-
ranges[ax._id] = [
170-
ax.p2d(poly[axLetter + 'min']),
171-
ax.p2d(poly[axLetter + 'max'])].sort(ascending);
172-
}
173-
}
174-
else {
175-
var dataPts = eventData.lassoPoints = {};
176-
177-
for(i = 0; i < allAxes.length; i++) {
178-
ax = allAxes[i];
179-
dataPts[ax._id] = pts.filtered.map(axValue(ax));
180-
}
181-
}
195+
fillRangeItems(eventData, poly, pts);
182196
dragOptions.gd.emit('plotly_selecting', eventData);
183197
};
184198

0 commit comments

Comments
 (0)