-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add multiselect #2140
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
Add multiselect #2140
Changes from 8 commits
b800e55
05b0dca
40fbca9
473d34d
02db56f
e8c18f0
ca4aaae
39a4dc4
ab92fd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,10 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { | |
// to pan (or to zoom if it already is pan) on shift | ||
if(e.shiftKey) { | ||
if(dragModeNow === 'pan') dragModeNow = 'zoom'; | ||
else dragModeNow = 'pan'; | ||
else if(!isSelectOrLasso(dragModeNow)) dragModeNow = 'pan'; | ||
} | ||
else if(e.ctrlKey) { | ||
dragModeNow = 'pan'; | ||
} | ||
} | ||
// all other draggers just pan | ||
|
@@ -168,13 +171,31 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { | |
else if(isSelectOrLasso(dragModeNow)) { | ||
dragOptions.xaxes = xa; | ||
dragOptions.yaxes = ya; | ||
|
||
// take over selection polygons from prev mode, if any | ||
if((e.shiftKey || e.altKey) && (plotinfo.selection && plotinfo.selection.polygons) && !dragOptions.polygons) { | ||
dragOptions.polygons = plotinfo.selection.polygons; | ||
dragOptions.mergedPolygons = plotinfo.selection.mergedPolygons; | ||
} | ||
// create new polygons, if shift mode | ||
else if((!e.shiftKey && !e.altKey) || ((e.shiftKey || e.altKey) && !plotinfo.selection)) { | ||
plotinfo.selection = {}; | ||
plotinfo.selection.polygons = dragOptions.polygons = []; | ||
plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = []; | ||
} | ||
|
||
prepSelect(e, startX, startY, dragOptions, dragModeNow); | ||
} | ||
} | ||
}; | ||
|
||
dragElement.init(dragOptions); | ||
|
||
// FIXME: this hack highlights selection once we enter select/lasso mode | ||
if(isSelectOrLasso(gd._fullLayout.dragmode) && plotinfo.selection) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a big fan of this behavior. @dfcreative is there a particular reason why you added this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant since #2135 |
||
showSelect(zoomlayer, dragOptions); | ||
} | ||
|
||
var x0, | ||
y0, | ||
box, | ||
|
@@ -526,6 +547,9 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) { | |
} | ||
|
||
updateSubplots([x0, y0, pw - dx, ph - dy]); | ||
|
||
if(plotinfo.ondrag) plotinfo.ondrag.call([x0, y0, pw - dx, ph - dy]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
||
ticksAndAnnotations(yActive, xActive); | ||
} | ||
|
||
|
@@ -902,6 +926,31 @@ function clearSelect(zoomlayer) { | |
zoomlayer.selectAll('.select-outline').remove(); | ||
} | ||
|
||
function showSelect(zoomlayer, dragOptions) { | ||
var outlines = zoomlayer.selectAll('path.select-outline').data([1, 2]), | ||
plotinfo = dragOptions.plotinfo, | ||
xaxis = plotinfo.xaxis, | ||
yaxis = plotinfo.yaxis, | ||
selection = plotinfo.selection, | ||
polygons = selection.mergedPolygons, | ||
xs = xaxis._offset, | ||
ys = yaxis._offset, | ||
paths = []; | ||
|
||
for(var i = 0; i < polygons.length; i++) { | ||
var ppts = polygons[i]; | ||
paths.push(ppts.join('L') + 'L' + ppts[0]); | ||
} | ||
|
||
if(paths.length) { | ||
outlines.enter() | ||
.append('path') | ||
.attr('class', function(d) { return 'select-outline select-outline-' + d; }) | ||
.attr('transform', 'translate(' + xs + ', ' + ys + ')') | ||
.attr('d', 'M' + paths.join('M') + 'Z'); | ||
} | ||
} | ||
|
||
function updateZoombox(zb, corners, box, path0, dimmed, lum) { | ||
zb.attr('d', | ||
path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) + | ||
|
@@ -924,9 +973,7 @@ function removeZoombox(gd) { | |
} | ||
|
||
function isSelectOrLasso(dragmode) { | ||
var modes = ['lasso', 'select']; | ||
|
||
return modes.indexOf(dragmode) !== -1; | ||
return dragmode === 'lasso' || dragmode === 'select'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Way better 🐎 . Thanks! |
||
} | ||
|
||
function xCorners(box, y0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to move this block into
prepSelect
so that all subplot types that support selections can allow multi-select? Right now, only cartesian and gl2d plot types allow it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep