Skip to content

Commit 493f2eb

Browse files
committed
Merge remote-tracking branch 'origin/interrupt-event' into 3.5
Conflicts: src/transition/each.js
2 parents 802ec82 + 4612d2f commit 493f2eb

5 files changed

Lines changed: 26 additions & 24 deletions

File tree

d3.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,7 +1261,7 @@
12611261
x: 0,
12621262
y: 0,
12631263
k: 1
1264-
}, translate0, center0, 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;
1264+
}, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, zooming = 0, 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;
12651265
function zoom(g) {
12661266
g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
12671267
}
@@ -1287,6 +1287,8 @@
12871287
};
12881288
zoomed(dispatch);
12891289
};
1290+
}).each("interrupt.zoom", function() {
1291+
zoomended(dispatch);
12901292
}).each("end.zoom", function() {
12911293
zoomended(dispatch);
12921294
});
@@ -1378,7 +1380,7 @@
13781380
}).map(y0.invert));
13791381
}
13801382
function zoomstarted(dispatch) {
1381-
dispatch({
1383+
if (!zooming++) dispatch({
13821384
type: "zoomstart"
13831385
});
13841386
}
@@ -1391,7 +1393,7 @@
13911393
});
13921394
}
13931395
function zoomended(dispatch) {
1394-
dispatch({
1396+
if (!--zooming) dispatch({
13951397
type: "zoomend"
13961398
});
13971399
}
@@ -8593,7 +8595,7 @@
85938595
} else {
85948596
d3_selection_each(this, function(node) {
85958597
var transition = node[ns][id];
8596-
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
8598+
(transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
85978599
});
85988600
}
85998601
return this;
@@ -8642,7 +8644,7 @@
86428644
if (delay <= elapsed) return start(elapsed - delay);
86438645
timer.c = start;
86448646
function start(elapsed) {
8645-
if (lock.active > id) return stop();
8647+
if (lock.active > id) return stop(false);
86468648
lock.active = id;
86478649
transition.event && transition.event.start.call(node, d, i);
86488650
transition.tween.forEach(function(key, value) {
@@ -8656,17 +8658,15 @@
86568658
}, 0, time);
86578659
}
86588660
function tick(elapsed) {
8659-
if (lock.active !== id) return stop();
8661+
if (lock.active !== id) return stop(false);
86608662
var t = elapsed / duration, e = ease(t), n = tweened.length;
86618663
while (n > 0) {
86628664
tweened[--n].call(node, e);
86638665
}
8664-
if (t >= 1) {
8665-
transition.event && transition.event.end.call(node, d, i);
8666-
return stop();
8667-
}
8666+
if (t >= 1) return stop(true);
86688667
}
8669-
function stop() {
8668+
function stop(end) {
8669+
if (transition.event) transition.event[end ? "end" : "interrupt"].call(node, d, i);
86708670
if (--lock.count) delete lock[id]; else delete node[namespace];
86718671
return 1;
86728672
}

d3.min.js

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

src/behavior/zoom.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ d3.behavior.zoom = function() {
1515
center, // explicit desired position of translate0 after zooming
1616
size = [960, 500], // viewport size; required for zoom interpolation
1717
scaleExtent = d3_behavior_zoomInfinity,
18+
zooming = 0,
1819
mousedown = "mousedown.zoom",
1920
mousemove = "mousemove.zoom",
2021
mouseup = "mouseup.zoom",
@@ -59,6 +60,9 @@ d3.behavior.zoom = function() {
5960
zoomed(dispatch);
6061
};
6162
})
63+
.each("interrupt.zoom", function() {
64+
zoomended(dispatch);
65+
})
6266
.each("end.zoom", function() {
6367
zoomended(dispatch);
6468
});
@@ -143,7 +147,7 @@ d3.behavior.zoom = function() {
143147
}
144148

145149
function zoomstarted(dispatch) {
146-
dispatch({type: "zoomstart"});
150+
if (!zooming++) dispatch({type: "zoomstart"});
147151
}
148152

149153
function zoomed(dispatch) {
@@ -152,7 +156,7 @@ d3.behavior.zoom = function() {
152156
}
153157

154158
function zoomended(dispatch) {
155-
dispatch({type: "zoomend"});
159+
if (!--zooming) dispatch({type: "zoomend"});
156160
}
157161

158162
function mousedowned() {

src/transition/each.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ d3_transitionPrototype.each = function(type, listener) {
1616
} else {
1717
d3_selection_each(this, function(node) {
1818
var transition = node[ns][id];
19-
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
19+
(transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
2020
});
2121
}
2222
return this;

src/transition/transition.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function d3_transitionNode(node, i, namespace, id, inherit) {
8383
timer.c = start;
8484

8585
function start(elapsed) {
86-
if (lock.active > id) return stop();
86+
if (lock.active > id) return stop(false);
8787
lock.active = id;
8888
transition.event && transition.event.start.call(node, d, i);
8989

@@ -100,7 +100,7 @@ function d3_transitionNode(node, i, namespace, id, inherit) {
100100
}
101101

102102
function tick(elapsed) {
103-
if (lock.active !== id) return stop();
103+
if (lock.active !== id) return stop(false);
104104

105105
var t = elapsed / duration,
106106
e = ease(t),
@@ -110,13 +110,11 @@ function d3_transitionNode(node, i, namespace, id, inherit) {
110110
tweened[--n].call(node, e);
111111
}
112112

113-
if (t >= 1) {
114-
transition.event && transition.event.end.call(node, d, i);
115-
return stop();
116-
}
113+
if (t >= 1) return stop(true);
117114
}
118115

119-
function stop() {
116+
function stop(end) {
117+
if (transition.event) transition.event[end ? "end" : "interrupt"].call(node, d, i);
120118
if (--lock.count) delete lock[id];
121119
else delete node[namespace];
122120
return 1;

0 commit comments

Comments
 (0)