Skip to content

Commit d8ed7a7

Browse files
committed
selection range event data
1 parent 89c1655 commit d8ed7a7

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/plots/cartesian/axes.js

+1
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ axes.setConvert = function(ax) {
634634
ax.c2l = (ax.type==='log') ? toLog : num;
635635
ax.l2c = (ax.type==='log') ? fromLog : num;
636636
ax.l2d = function(v) { return ax.c2d(ax.l2c(v)); };
637+
ax.p2d = function(v) { return ax.p2l(ax.l2d(v)); };
637638

638639
// set scaling to pixels
639640
ax.setScale = function(){

src/plots/cartesian/select.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
3232
pw = dragOptions.xaxes[0]._length,
3333
ph = dragOptions.yaxes[0]._length,
3434
xAxisIds = dragOptions.xaxes.map(getAxId),
35-
yAxisIds = dragOptions.yaxes.map(getAxId);
35+
yAxisIds = dragOptions.yaxes.map(getAxId),
36+
allAxes = dragOptions.xaxes.concat(dragOptions.yaxes);
3637

3738
if(mode === 'lasso') {
3839
var pts = filteredPolygon([[x0, y0]], constants.BENDPX);
@@ -80,8 +81,14 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
8081
});
8182
}
8283

84+
function axValue(ax) {
85+
var index = (ax._id.charAt(0) === 'y') ? 1 : 0;
86+
return function(v) { return ax.p2d(v[index]); };
87+
}
88+
8389
dragOptions.moveFn = function(dx0, dy0) {
84-
var poly;
90+
var poly,
91+
ax;
8592
x1 = Math.max(0, Math.min(pw, dx0 + x0));
8693
y1 = Math.max(0, Math.min(ph, dy0 + y0));
8794

@@ -129,6 +136,27 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
129136
}
130137

131138
eventData = {points: selection};
139+
140+
if(mode === 'select') {
141+
var ranges = eventData.range = {},
142+
axLetter;
143+
144+
for(i = 0; i < allAxes.length; i++) {
145+
ax = allAxes[i];
146+
axLetter = ax._id.charAt(0);
147+
ranges[ax._id] = [
148+
ax.p2d(poly[axLetter + 'min']),
149+
ax.p2d(poly[axLetter + 'max'])].sort();
150+
}
151+
}
152+
else {
153+
var dataPts = eventData.lassoPoints = {};
154+
155+
for(i = 0; i < allAxes.length; i++) {
156+
ax = allAxes[i];
157+
dataPts[ax._id] = pts.filtered.map(axValue(ax));
158+
}
159+
}
132160
dragOptions.gd.emit('plotly_selecting', eventData);
133161
};
134162

0 commit comments

Comments
 (0)