Add test for transition.remove.

Also fix a bug where it would be possible for an earlier to transition to become
the lock owner. We now guarantee that the lock owner can only increase while
transitions are scheduled on an element.
This commit is contained in:
Mike Bostock 2011-08-21 15:54:17 -07:00
Родитель 8cc290a00a
Коммит 51c7e58fdb
7 изменённых файлов: 61 добавлений и 13 удалений

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

@ -1811,9 +1811,10 @@ function d3_transition(groups) {
node = this,
delay = groups[j][i].delay - elapsed,
duration = groups[j][i].duration,
lock = node.__transition__ || (node.__transition__ = {active: 0});
lock = node.__transition__;
lock.owner = id;
if (!lock) lock = node.__transition__ = {active: 0, owner: id};
else if (lock.owner < id) lock.owner = id;
delay <= 0 ? start(0) : d3.timer(start, delay);
function start(elapsed) {

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

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

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

@ -31,9 +31,10 @@ function d3_transition(groups) {
node = this,
delay = groups[j][i].delay - elapsed,
duration = groups[j][i].duration,
lock = node.__transition__ || (node.__transition__ = {active: 0});
lock = node.__transition__;
lock.owner = id;
if (!lock) lock = node.__transition__ = {active: 0, owner: id};
else if (lock.owner < id) lock.owner = id;
delay <= 0 ? start(0) : d3.timer(start, delay);
function start(elapsed) {

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

@ -14,25 +14,25 @@ suite.addBatch({
"with no delay": {
topic: timer(),
"first calls after 17 ms or less": function(info) {
assert.inDelta(info.start - info.scheduled, 17, 15);
assert.inDelta(info.start - info.scheduled, 17, 20);
},
"calls until the function returns true": function(info) {
assert.equal(info.count, 4);
},
"calls every 17 ms": function(info) {
assert.inDelta(info.stop - info.start, 17 * 3, 15);
assert.inDelta(info.stop - info.start, 17 * 3, 20);
}
},
"with a specified delay": {
topic: timer(250),
"first calls after the delay": function(info) {
assert.inDelta(info.start - info.scheduled, 250, 15);
assert.inDelta(info.start - info.scheduled, 250, 20);
},
"calls until the function returns true": function(info) {
assert.equal(info.count, 4);
},
"calls every 17 ms": function(info) {
assert.inDelta(info.stop - info.start, 17 * 3, 15);
assert.inDelta(info.stop - info.start, 17 * 3, 20);
}
}
}

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

@ -42,7 +42,7 @@ module.exports = {
},
"invokes the listener after the specified delay": function(result) {
assert.inDelta(result.delay, [150, 150], 17);
assert.inDelta(result.delay, [150, 150], 20);
},
"invokes each listener exactly once, in order": function(result) {
assert.deepEqual(result.count, [2, 4]);
@ -120,7 +120,7 @@ module.exports = {
},
"invokes the listener after the specified delay": function(result) {
assert.inDelta(result.delay, [150, 150], 17);
assert.inDelta(result.delay, [150, 150], 20);
},
"invokes each listener exactly once, in order": function(result) {
assert.deepEqual(result.count, [2, 4]);

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

@ -0,0 +1,46 @@
require("../env");
require("../../d3");
var assert = require("assert");
module.exports = {
topic: function() {
var cb = this.callback,
t = d3.select("body").append("div").transition().remove();
t.each("end", function() { cb(null, t); });
},
"removes the selected elements": function(transition) {
assert.domEqual(transition[0][0].node.parentNode, null);
},
"when the element is already removed": {
topic: function() {
var cb = this.callback,
t = d3.select("body").append("div").remove().transition().remove();
t.each("end", function() { cb(null, t); });
},
"does nothing": function(transition) {
assert.domEqual(transition[0][0].node.parentNode, null);
}
},
// Since these tests are triggered inside the end event of the above topic,
// transitions will inherit ids from the original transition. But we want to
// test concurrent transitions, so we use timeouts to avoid inheritance. This
// test also verifies that if multiple transitions are created at the same
// time, the last transition becomes the owner.
"when another transition is scheduled": {
topic: function() {
var cb = this.callback,
s = d3.select("body").append("div");
setTimeout(function() {
s.transition().duration(150).remove().each("end", function() { cb(null, s); });
s.transition().delay(250);
}, 10);
},
"does nothing": function(selection) {
assert.domEqual(selection[0][0].parentNode, document.body);
}
}
};

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

@ -32,7 +32,7 @@ suite.addBatch({
"attr": require("./transition-test-attr"),
"style": require("./transition-test-style"),
"text": require("./transition-test-text"),
// remove
"remove": require("./transition-test-remove"),
// Animation
"delay": require("./transition-test-delay"),