Skip to content

Commit

Permalink
Use pointer events instead of mouse events for lasso selection (re: #…
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Mar 13, 2020
1 parent de1bfe6 commit dd9c30b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modules/behavior/lasso.js
Expand Up @@ -7,6 +7,9 @@ import { uiLasso } from '../ui/lasso';

export function behaviorLasso(context) {

// use pointer events on supported platforms; fallback to mouse events
var _pointerPrefix = 'PointerEvent' in window ? 'pointer' : 'mouse';

var behavior = function(selection) {
var lasso;

Expand All @@ -17,8 +20,8 @@ export function behaviorLasso(context) {
lasso = null;

d3_select(window)
.on('mousemove.lasso', mousemove)
.on('mouseup.lasso', mouseup);
.on(_pointerPrefix + 'move.lasso', mousemove)
.on(_pointerPrefix + 'up.lasso', mouseup);

d3_event.stopPropagation();
}
Expand Down Expand Up @@ -62,8 +65,8 @@ export function behaviorLasso(context) {

function mouseup() {
d3_select(window)
.on('mousemove.lasso', null)
.on('mouseup.lasso', null);
.on(_pointerPrefix + 'move.lasso', null)
.on(_pointerPrefix + 'up.lasso', null);

if (!lasso) return;

Expand All @@ -76,12 +79,12 @@ export function behaviorLasso(context) {
}

selection
.on('mousedown.lasso', mousedown);
.on(_pointerPrefix + 'down.lasso', mousedown);
};


behavior.off = function(selection) {
selection.on('mousedown.lasso', null);
selection.on(_pointerPrefix + 'down.lasso', null);
};


Expand Down

0 comments on commit dd9c30b

Please sign in to comment.