From dd9c30beb1b5cea8dbf2ab3c73f2605b40a4e414 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Fri, 13 Mar 2020 13:23:06 -0700 Subject: [PATCH] Use pointer events instead of mouse events for lasso selection (re: #5505) --- modules/behavior/lasso.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/behavior/lasso.js b/modules/behavior/lasso.js index a1bdbf7ce9..46e5ff4e4f 100644 --- a/modules/behavior/lasso.js +++ b/modules/behavior/lasso.js @@ -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; @@ -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(); } @@ -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; @@ -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); };