Skip to content

Commit 7fd123f

Browse files
committed
Fix d3#1609 - add transition "interrupt" event.
This is necessary for transitions to perform any cleanup in the case they are interrupted (superseded) by another transition or an explicit interrupt.
1 parent a10b226 commit 7fd123f

4 files changed

Lines changed: 15 additions & 19 deletions

File tree

d3.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8549,7 +8549,7 @@
85498549
} else {
85508550
d3_selection_each(this, function(node) {
85518551
var transition = node.__transition__[id];
8552-
(transition.event || (transition.event = d3.dispatch("start", "end"))).on(type, listener);
8552+
(transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
85538553
});
85548554
}
85558555
return this;
@@ -8590,7 +8590,7 @@
85908590
if (delay <= elapsed) return start(elapsed - delay);
85918591
timer.c = start;
85928592
function start(elapsed) {
8593-
if (lock.active > id) return stop();
8593+
if (lock.active > id) return stop(false);
85948594
lock.active = id;
85958595
transition.event && transition.event.start.call(node, d, i);
85968596
transition.tween.forEach(function(key, value) {
@@ -8604,17 +8604,15 @@
86048604
}, 0, time);
86058605
}
86068606
function tick(elapsed) {
8607-
if (lock.active !== id) return stop();
8607+
if (lock.active !== id) return stop(false);
86088608
var t = elapsed / duration, e = ease(t), n = tweened.length;
86098609
while (n > 0) {
86108610
tweened[--n].call(node, e);
86118611
}
8612-
if (t >= 1) {
8613-
transition.event && transition.event.end.call(node, d, i);
8614-
return stop();
8615-
}
8612+
if (t >= 1) return stop(true);
86168613
}
8617-
function stop() {
8614+
function stop(end) {
8615+
if (transition.event) transition.event[end ? "end" : "interrupt"].call(node, d, i);
86188616
if (--lock.count) delete lock[id]; else delete node.__transition__;
86198617
return 1;
86208618
}

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/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.__transition__[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
@@ -76,7 +76,7 @@ function d3_transitionNode(node, i, id, inherit) {
7676
timer.c = start;
7777

7878
function start(elapsed) {
79-
if (lock.active > id) return stop();
79+
if (lock.active > id) return stop(false);
8080
lock.active = id;
8181
transition.event && transition.event.start.call(node, d, i);
8282

@@ -93,7 +93,7 @@ function d3_transitionNode(node, i, id, inherit) {
9393
}
9494

9595
function tick(elapsed) {
96-
if (lock.active !== id) return stop();
96+
if (lock.active !== id) return stop(false);
9797

9898
var t = elapsed / duration,
9999
e = ease(t),
@@ -103,13 +103,11 @@ function d3_transitionNode(node, i, id, inherit) {
103103
tweened[--n].call(node, e);
104104
}
105105

106-
if (t >= 1) {
107-
transition.event && transition.event.end.call(node, d, i);
108-
return stop();
109-
}
106+
if (t >= 1) return stop(true);
110107
}
111108

112-
function stop() {
109+
function stop(end) {
110+
if (transition.event) transition.event[end ? "end" : "interrupt"].call(node, d, i);
113111
if (--lock.count) delete lock[id];
114112
else delete node.__transition__;
115113
return 1;

0 commit comments

Comments
 (0)