Commit 467f1490 authored by Mike Bostock's avatar Mike Bostock
Browse files

d3.touch defaults to changedTouches.

This way, it’s easier to tell whether the touch changed during the event. This
also fixes #1600 because the drag behavior now only dispatches a drag event on
elements that moved, even if multiple touches are active.
parent 38724915
...@@ -1144,7 +1144,10 @@ ...@@ -1144,7 +1144,10 @@
type: "dragstart" type: "dragstart"
}); });
function moved() { function moved() {
var position1 = position(parent, dragId), dx = position1[0] - position0[0], dy = position1[1] - position0[1]; var position1 = position(parent, dragId), dx, dy;
if (!position1) return;
dx = position1[0] - position0[0];
dy = position1[1] - position0[1];
dragged |= dx | dy; dragged |= dx | dy;
position0 = position1; position0 = position1;
dispatch({ dispatch({
...@@ -1156,7 +1159,7 @@ ...@@ -1156,7 +1159,7 @@
}); });
} }
function ended() { function ended() {
if (dragId != null && position(parent, dragId)) return; if (!position(parent, dragId)) return;
dragSubject.on(move + dragName, null).on(end + dragName, null); dragSubject.on(move + dragName, null).on(end + dragName, null);
dragRestore(dragged && d3.event.target === dragTarget); dragRestore(dragged && d3.event.target === dragTarget);
dispatch({ dispatch({
...@@ -2050,7 +2053,7 @@ ...@@ -2050,7 +2053,7 @@
d3.csv = d3.dsv(",", "text/csv"); d3.csv = d3.dsv(",", "text/csv");
d3.tsv = d3.dsv(" ", "text/tab-separated-values"); d3.tsv = d3.dsv(" ", "text/tab-separated-values");
d3.touch = function(container, touches, identifier) { d3.touch = function(container, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = d3_eventSource().touches; if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
if ((touch = touches[i]).identifier === identifier) { if ((touch = touches[i]).identifier === identifier) {
return d3_mousePoint(container, touch); return d3_mousePoint(container, touch);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -41,10 +41,11 @@ d3.behavior.drag = function() { ...@@ -41,10 +41,11 @@ d3.behavior.drag = function() {
dispatch({type: "dragstart"}); dispatch({type: "dragstart"});
function moved() { function moved() {
var position1 = position(parent, dragId), var position1 = position(parent, dragId), dx, dy;
dx = position1[0] - position0[0], if (!position1) return; // this touch didn’t move
dy = position1[1] - position0[1];
dx = position1[0] - position0[0];
dy = position1[1] - position0[1];
dragged |= dx | dy; dragged |= dx | dy;
position0 = position1; position0 = position1;
...@@ -58,7 +59,7 @@ d3.behavior.drag = function() { ...@@ -58,7 +59,7 @@ d3.behavior.drag = function() {
} }
function ended() { function ended() {
if (dragId != null && position(parent, dragId)) return; // this touch still active if (!position(parent, dragId)) return; // this touch didn’t end
dragSubject.on(move + dragName, null).on(end + dragName, null); dragSubject.on(move + dragName, null).on(end + dragName, null);
dragRestore(dragged && d3.event.target === dragTarget); dragRestore(dragged && d3.event.target === dragTarget);
dispatch({type: "dragend"}); dispatch({type: "dragend"});
......
...@@ -2,7 +2,7 @@ import "event"; ...@@ -2,7 +2,7 @@ import "event";
import "mouse"; import "mouse";
d3.touch = function(container, touches, identifier) { d3.touch = function(container, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = d3_eventSource().touches; if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) { if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
if ((touch = touches[i]).identifier === identifier) { if ((touch = touches[i]).identifier === identifier) {
return d3_mousePoint(container, touch); return d3_mousePoint(container, touch);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment