Skip to content

Commit 1451802

Browse files
committed
bring back scene2d mouseContainer + add updateFx to toggle dragmode
- make mouseContainer transparent to pointer events on 'lasso' and 'select' dragmodes, this enables selection while keeping the current (and much faster) gl2d hover/click logic when dragmode is set to 'pan' or 'zoom' (the default).
1 parent 8b8d2e3 commit 1451802

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/plot_api/subroutines.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,10 @@ exports.doModeBar = function(gd) {
386386
scene.updateFx(fullLayout.dragmode, fullLayout.hovermode);
387387
}
388388

389-
// no need to do this for gl2d subplots,
390-
// Plots.linkSubplots takes care of it all.
389+
subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d');
390+
for(i = 0; i < subplotIds.length; i++) {
391+
fullLayout._plots[subplotIds[i]]._scene2d.updateFx();
392+
}
391393

392394
return Plots.previousPromises(gd);
393395
};

src/plots/gl2d/scene2d.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,15 @@ proto.makeFramework = function() {
147147
// create div to catch the mouse event
148148
var mouseContainer = this.mouseContainer = document.createElement('div');
149149
mouseContainer.style.position = 'absolute';
150+
mouseContainer.style['pointer-events'] = 'auto';
150151

151152
// append canvas, hover svg and mouse div to container
152153
var container = this.container;
153154
container.appendChild(canvas);
154155
container.appendChild(svgContainer);
155-
// container.appendChild(mouseContainer);
156+
container.appendChild(mouseContainer);
157+
158+
this.updateFx();
156159
};
157160

158161
proto.toImage = function(format) {
@@ -359,7 +362,7 @@ proto.destroy = function() {
359362

360363
if(!this.staticPlot) this.container.removeChild(this.canvas);
361364
this.container.removeChild(this.svgContainer);
362-
// this.container.removeChild(this.mouseContainer);
365+
this.container.removeChild(this.mouseContainer);
363366

364367
this.fullData = null;
365368
this.glplot = null;
@@ -507,7 +510,16 @@ proto.updateTraces = function(fullData, calcData) {
507510
this.glplot.objects.sort(function(a, b) {
508511
return a._trace.index - b._trace.index;
509512
});
513+
};
510514

515+
proto.updateFx = function() {
516+
var dragmode = this.fullLayout.dragmode;
517+
518+
if(dragmode === 'lasso' || dragmode === 'select') {
519+
this.mouseContainer.style['pointer-events'] = 'none';
520+
} else {
521+
this.mouseContainer.style['pointer-events'] = 'auto';
522+
}
511523
};
512524

513525
proto.emitPointAction = function(nextSelection, eventType) {

0 commit comments

Comments
 (0)