Skip to content

Commit e67138a

Browse files
committed
Merge branch 'zoom-multiple' into 3.3.3
2 parents 2378ab8 + 637fa99 commit e67138a

3 files changed

Lines changed: 77 additions & 44 deletions

File tree

d3.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ d3 = function() {
12011201
x: 0,
12021202
y: 0,
12031203
k: 1
1204-
}, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchmove = "touchmove.zoom", touchend = "touchend.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
1204+
}, translate0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
12051205
function zoom(g) {
12061206
g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on(mousemove, mousewheelreset).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
12071207
}
@@ -1351,21 +1351,24 @@ d3 = function() {
13511351
}
13521352
}
13531353
function touchstarted() {
1354-
var target = this, event_ = event.of(target, arguments), locations0, distance0 = 0, scale0, w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended), t = d3.select(target).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
1354+
var target = this, event_ = event.of(target, arguments), locations0 = {}, distance0 = 0, scale0, eventId = d3.event.changedTouches[0].identifier, touchmove = "touchmove.zoom-" + eventId, touchend = "touchend.zoom-" + eventId, w = d3.select(d3_window).on(touchmove, moved).on(touchend, ended), t = d3.select(target).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
13551355
d3_selection_interrupt.call(target);
13561356
started();
13571357
zoomstarted(event_);
13581358
function relocate() {
13591359
var touches = d3.touches(target);
13601360
scale0 = view.k;
1361-
locations0 = {};
13621361
touches.forEach(function(t) {
1363-
locations0[t.identifier] = location(t);
1362+
if (t.identifier in locations0) locations0[t.identifier] = location(t);
13641363
});
13651364
return touches;
13661365
}
13671366
function started() {
1368-
var now = Date.now(), touches = relocate();
1367+
var changed = d3.event.changedTouches;
1368+
for (var i = 0, n = changed.length; i < n; ++i) {
1369+
locations0[changed[i].identifier] = null;
1370+
}
1371+
var touches = relocate(), now = Date.now();
13691372
if (touches.length === 1) {
13701373
if (now - touchtime < 500) {
13711374
var p = touches[0], l = locations0[p.identifier];
@@ -1381,13 +1384,16 @@ d3 = function() {
13811384
}
13821385
}
13831386
function moved() {
1384-
var touches = d3.touches(target), p0 = touches[0], l0 = locations0[p0.identifier];
1385-
if (p1 = touches[1]) {
1386-
var p1, l1 = locations0[p1.identifier], scale1 = d3.event.scale;
1387-
if (scale1 == null) {
1388-
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1;
1389-
scale1 = distance0 && Math.sqrt(distance1 / distance0);
1387+
var touches = d3.touches(target), p0, l0, p1, l1;
1388+
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
1389+
p1 = touches[i];
1390+
if (l1 = locations0[p1.identifier]) {
1391+
if (l0) break;
1392+
p0 = p1, l0 = l1;
13901393
}
1394+
}
1395+
if (l1) {
1396+
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
13911397
p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
13921398
l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
13931399
scaleTo(scale1 * scale0);
@@ -1398,13 +1404,18 @@ d3 = function() {
13981404
}
13991405
function ended() {
14001406
if (d3.event.touches.length) {
1401-
relocate();
1402-
} else {
1403-
w.on(touchmove, null).on(touchend, null);
1404-
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
1405-
dragRestore();
1406-
zoomended(event_);
1407+
var changed = d3.event.changedTouches;
1408+
for (var i = 0, n = changed.length; i < n; ++i) {
1409+
delete locations0[changed[i].identifier];
1410+
}
1411+
for (var identifier in locations0) {
1412+
return void relocate();
1413+
}
14071414
}
1415+
w.on(touchmove, null).on(touchend, null);
1416+
t.on(mousedown, mousedowned).on(touchstart, touchstarted);
1417+
dragRestore();
1418+
zoomended(event_);
14081419
}
14091420
}
14101421
function mousewheeled() {

0 commit comments

Comments
 (0)