Skip to content

Commit d0d665c

Browse files
committed
Optional touch array argument for d3.svg.touches.
By default, we probably want to use event.touches, but for "touchend" events it's useful to retrieve the positions of event.changedTouches.
1 parent bd90a2f commit d0d665c

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

d3.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,8 +3529,9 @@ function d3_svg_mousePoint(container, e) {
35293529
point = point.matrixTransform(container.getScreenCTM().inverse());
35303530
return [point.x, point.y];
35313531
};
3532-
d3.svg.touches = function(container) {
3533-
var touches = d3.event.changedTouches;
3532+
d3.svg.touches = function(container, touches) {
3533+
if (arguments.length < 2) touches = d3.event.touches;
3534+
35343535
return touches ? d3_array(touches).map(function(touch) {
35353536
var point = d3_svg_mousePoint(container, touch);
35363537
point.identifier = touch.identifier;
@@ -3889,8 +3890,11 @@ function d3_behavior_dragDispatch(type) {
38893890
}
38903891

38913892
function d3_behavior_dragPoint(container) {
3893+
// TODO Track touch points by identifier.
38923894
return d3.event.touches
38933895
? d3.svg.touches(container)[0]
3896+
: d3.event.changedTouches
3897+
? d3.svg.touches(container, d3.event.changedTouches)[0]
38943898
: d3.svg.mouse(container);
38953899
}
38963900

d3.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/behavior/drag.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ function d3_behavior_dragDispatch(type) {
6666
}
6767

6868
function d3_behavior_dragPoint(container) {
69+
// TODO Track touch points by identifier.
6970
return d3.event.touches
7071
? d3.svg.touches(container)[0]
72+
: d3.event.changedTouches
73+
? d3.svg.touches(container, d3.event.changedTouches)[0]
7174
: d3.svg.mouse(container);
7275
}
7376

src/svg/touches.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
d3.svg.touches = function(container) {
2-
var touches = d3.event.changedTouches;
1+
d3.svg.touches = function(container, touches) {
2+
if (arguments.length < 2) touches = d3.event.touches;
3+
34
return touches ? d3_array(touches).map(function(touch) {
45
var point = d3_svg_mousePoint(container, touch);
56
point.identifier = touch.identifier;

0 commit comments

Comments
 (0)