This commit is contained in:
Mike Bostock 2014-11-15 14:19:49 -08:00
Родитель 2dc51055b4
Коммит 94168faabc
4 изменённых файлов: 46 добавлений и 40 удалений

37
d3.js поставляемый
Просмотреть файл

@ -1008,8 +1008,8 @@
if (lock) ++lock.active;
});
};
function d3_selection_interrupt() {
var lock = this.__transition__;
function d3_selection_interrupt(that) {
var lock = that.__transition__;
if (lock) ++lock.active;
}
d3.select = function(node) {
@ -1375,6 +1375,16 @@
view.x += p[0] - l[0];
view.y += p[1] - l[1];
}
function zoomTo(that, p, l, k) {
that.__chart__ = {
x: view.x,
y: view.y,
k: view.k
};
scaleTo(Math.pow(2, k));
translateTo(center0 = p, l);
d3.select(that).transition().duration(350).call(zoom.event);
}
function rescale() {
if (x1) x1.domain(x0.range().map(function(x) {
return (x - view.x) / view.k;
@ -1404,7 +1414,7 @@
}
function mousedowned() {
var that = this, target = d3.event.target, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(that);
d3_selection_interrupt(that);
zoomstarted(dispatch);
function moved() {
dragged = 1;
@ -1419,7 +1429,6 @@
}
function touchstarted() {
var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(that);
started();
zoomstarted(dispatch);
subject.on(mousedown, null).on(touchstart, started);
@ -1442,11 +1451,9 @@
var touches = relocate(), now = Date.now();
if (touches.length === 1) {
if (now - touchtime < 500) {
var p = touches[0], l = locations0[p.identifier];
scaleTo(view.k * 2);
translateTo(p, l);
var p = touches[0];
zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
d3_eventPreventDefault();
zoomed(dispatch);
}
touchtime = now;
} else if (touches.length > 1) {
@ -1456,6 +1463,7 @@
}
function moved() {
var touches = d3.touches(that), p0, l0, p1, l1;
d3_selection_interrupt(that);
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
p1 = touches[i];
if (l1 = locations0[p1.identifier]) {
@ -1492,7 +1500,7 @@
function mousewheeled() {
var dispatch = event.of(this, arguments);
if (mousewheelTimer) clearTimeout(mousewheelTimer); else translate0 = location(center0 = center || d3.mouse(this)),
d3_selection_interrupt.call(this), zoomstarted(dispatch);
d3_selection_interrupt(this), zoomstarted(dispatch);
mousewheelTimer = setTimeout(function() {
mousewheelTimer = null;
zoomended(dispatch);
@ -1503,15 +1511,8 @@
zoomed(dispatch);
}
function dblclicked() {
var l = location(center0 = d3.mouse(this)), k = Math.log(view.k) / Math.LN2;
this.__chart__ = {
x: view.x,
y: view.y,
k: view.k
};
scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
translateTo(center0, l);
d3.select(this).transition().duration(350).call(zoom.event);
var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
}
return d3.rebind(zoom, event, "on");
};

10
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -141,6 +141,17 @@ d3.behavior.zoom = function() {
view.y += p[1] - l[1];
}
function zoomTo(that, p, l, k) {
that.__chart__ = {x: view.x, y: view.y, k: view.k};
scaleTo(Math.pow(2, k));
translateTo(center0 = p, l);
d3.select(that).transition()
.duration(350) // TODO allow this to be customized?
.call(zoom.event);
}
function rescale() {
if (x1) x1.domain(x0.range().map(function(x) { return (x - view.x) / view.k; }).map(x0.invert));
if (y1) y1.domain(y0.range().map(function(y) { return (y - view.y) / view.k; }).map(y0.invert));
@ -169,7 +180,7 @@ d3.behavior.zoom = function() {
location0 = location(d3.mouse(that)),
dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(that);
d3_selection_interrupt(that);
zoomstarted(dispatch);
function moved() {
@ -199,7 +210,6 @@ d3.behavior.zoom = function() {
subject = d3.select(that),
dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(that);
started();
zoomstarted(dispatch);
@ -236,11 +246,9 @@ d3.behavior.zoom = function() {
if (touches.length === 1) {
if (now - touchtime < 500) { // dbltap
var p = touches[0], l = locations0[p.identifier];
scaleTo(view.k * 2);
translateTo(p, l);
var p = touches[0];
zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
d3_eventPreventDefault();
zoomed(dispatch);
}
touchtime = now;
} else if (touches.length > 1) {
@ -254,6 +262,9 @@ d3.behavior.zoom = function() {
var touches = d3.touches(that),
p0, l0,
p1, l1;
d3_selection_interrupt(that);
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
p1 = touches[i];
if (l1 = locations0[p1.identifier]) {
@ -300,7 +311,7 @@ d3.behavior.zoom = function() {
function mousewheeled() {
var dispatch = event.of(this, arguments);
if (mousewheelTimer) clearTimeout(mousewheelTimer);
else translate0 = location(center0 = center || d3.mouse(this)), d3_selection_interrupt.call(this), zoomstarted(dispatch);
else translate0 = location(center0 = center || d3.mouse(this)), d3_selection_interrupt(this), zoomstarted(dispatch);
mousewheelTimer = setTimeout(function() { mousewheelTimer = null; zoomended(dispatch); }, 50);
d3_eventPreventDefault();
scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
@ -309,16 +320,10 @@ d3.behavior.zoom = function() {
}
function dblclicked() {
var l = location(center0 = d3.mouse(this)),
var p = d3.mouse(this),
k = Math.log(view.k) / Math.LN2;
this.__chart__ = {x: view.x, y: view.y, k: view.k};
scaleTo(Math.pow(2, d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1));
translateTo(center0, l);
d3.select(this).transition()
.duration(350) // TODO allow this to be customized?
.call(zoom.event);
zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
}
return d3.rebind(zoom, event, "on");

Просмотреть файл

@ -10,7 +10,7 @@ d3_selectionPrototype.interrupt = function(name) {
});
};
function d3_selection_interrupt() {
var lock = this.__transition__;
function d3_selection_interrupt(that) {
var lock = that.__transition__;
if (lock) ++lock.active;
}