Skip to content

Commit

Permalink
Fix #54 - better multitouch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Aug 5, 2019
1 parent 77c7537 commit 0366e97
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/brush.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {dispatch} from "d3-dispatch";
import {dragDisable, dragEnable} from "d3-drag";
import {interpolate} from "d3-interpolate";
import {customEvent, event, mouse, select} from "d3-selection";
import {customEvent, event, clientPoint, select} from "d3-selection";
import {interrupt} from "d3-transition";
import constant from "./constant.js";
import BrushEvent from "./event.js";
Expand Down Expand Up @@ -315,6 +315,10 @@ function brush(dim) {
}
};

function pointer(target) {
return clientPoint(target, event.touches ? event.touches[0] : event);
}

function started() {
if (event.touches) { if (event.changedTouches.length < event.touches.length) return noevent(); }
else if (touchending) return;
Expand All @@ -338,7 +342,7 @@ function brush(dim) {
shifting = signX && signY && keys && event.shiftKey,
lockX,
lockY,
point0 = mouse(that),
point0 = pointer(that),
point = point0,
emit = emitter(that, arguments, true).beforestart();

Expand Down Expand Up @@ -386,7 +390,7 @@ function brush(dim) {
emit.start();

function moved() {
var point1 = mouse(that);
var point1 = pointer(that);
if (shifting && !lockX && !lockY) {
if (Math.abs(point1[0] - point[0]) > Math.abs(point1[1] - point[1])) lockY = true;
else lockX = true;
Expand Down

0 comments on commit 0366e97

Please sign in to comment.