Skip to content

Commit 4e4709c

Browse files
committed
Fix selection.interrupt.
Even if no further transitions are scheduled on the element, we must still advance the active counter to interrupt the active transition. Fixes d3#2165. Also added better tests that verify interruption.
1 parent 4a4c3ce commit 4e4709c

8 files changed

Lines changed: 53 additions & 22 deletions

File tree

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.5.2",
3+
"version": "3.5.3",
44
"main": "d3.js",
55
"scripts": [
66
"d3.js"

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"animation",
1111
"canvas"
1212
],
13-
"version": "3.5.2",
13+
"version": "3.5.3",
1414
"main": "d3.js",
1515
"scripts": [
1616
"d3.js"

d3.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
!function() {
22
var d3 = {
3-
version: "3.5.2"
3+
version: "3.5.3"
44
};
55
if (!Date.now) Date.now = function() {
66
return +new Date();
@@ -8575,12 +8575,8 @@
85758575
return function() {
85768576
var lock, active;
85778577
if ((lock = this[ns]) && (active = lock[lock.active])) {
8578-
if (--lock.count) {
8579-
delete lock[lock.active];
8580-
lock.active += .5;
8581-
} else {
8582-
delete this[ns];
8583-
}
8578+
if (--lock.count) delete lock[lock.active]; else delete this[ns];
8579+
lock.active += .5;
85848580
active.event && active.event.interrupt.call(this, this.__data__, active.index);
85858581
}
85868582
};

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.5.2",
3+
"version": "3.5.3",
44
"description": "A JavaScript visualization library for HTML and SVG.",
55
"keywords": [
66
"dom",

src/selection/interrupt.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ function d3_selection_interruptNS(ns) {
1414
return function() {
1515
var lock, active;
1616
if ((lock = this[ns]) && (active = lock[lock.active])) {
17-
if (--lock.count) {
18-
delete lock[lock.active];
19-
lock.active += .5;
20-
} else {
21-
delete this[ns];
22-
}
17+
if (--lock.count) delete lock[lock.active];
18+
else delete this[ns];
19+
lock.active += .5;
2320
active.event && active.event.interrupt.call(this, this.__data__, active.index);
2421
}
2522
};

src/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
!function(){
2-
var d3 = {version: "3.5.2"}; // semver
2+
var d3 = {version: "3.5.3"}; // semver

test/selection/interrupt-test.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,50 @@ suite.addBatch({
1313
},
1414
"interrupts the active transition": function(d3) {
1515
var selection = d3.select("body").append("div"),
16-
transition = selection.transition();
17-
assert.equal(selection.node().__transition__.active, 0); // transition hasn’t yet started
16+
transition = selection.transition(),
17+
lock = selection.node().__transition__;
18+
assert.equal(lock.active, 0); // transition hasn’t yet started
1819
d3.timer.flush();
19-
assert.equal(selection.node().__transition__.active, transition.id); // transition has started
20+
assert.equal(lock.active, transition.id); // transition has started
2021
selection.interrupt();
21-
assert.isUndefined(selection.node().__transition__); // transition was interrupted
22+
assert.greater(lock.active, transition.id); // transition was interrupted
23+
assert.lesser(lock.active, transition.id + 1); // future transitions not interrupted
24+
assert.isUndefined(selection.node().__transition__); // transition was cleared
25+
},
26+
"the interrupted transition’s tweens do not receive any further calls": function(d3) {
27+
var selection = d3.select("body").append("div"),
28+
ticks = 0,
29+
transition = selection.transition().tween("test", function() { return function() { ++ticks; }; });
30+
d3.timer.flush();
31+
var ticks0 = ticks;
32+
assert.greater(ticks0, 0);
33+
d3.timer.flush();
34+
var ticks1 = ticks;
35+
assert.greater(ticks, ticks0);
36+
selection.interrupt();
37+
d3.timer.flush();
38+
assert.equal(ticks, ticks1);
39+
},
40+
"the interrupted transition does not emit an end event": {
41+
topic: function(d3) {
42+
var callback = this.callback,
43+
selection = d3.select("body").append("div");
44+
45+
selection.transition()
46+
.duration(250)
47+
.each("end", function() { callback(null, "fail"); });
48+
49+
setTimeout(function() {
50+
selection.interrupt();
51+
}, 100);
52+
53+
setTimeout(function() {
54+
callback(null, "success");
55+
}, 750);
56+
},
57+
"": function(result) {
58+
assert.equal(result, "success");
59+
}
2260
},
2361
"does not prevent a future scheduled transition": function(d3) {
2462
var selection = d3.select("body").append("div"),

0 commit comments

Comments
 (0)