Skip to content

Commit

Permalink
fix #121; add transition.selectChild[ren]
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 7, 2021
1 parent 1ac7984 commit 692f025
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/transition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Transition.prototype = transition.prototype = {
constructor: Transition,
select: transition_select,
selectAll: transition_selectAll,
selectChild: selection_prototype.selectChild,
selectChildren: selection_prototype.selectChildren,
filter: transition_filter,
merge: transition_merge,
selection: transition_selection,
Expand Down
20 changes: 20 additions & 0 deletions test/transition/selectChild-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from "assert";
import {selectAll} from "d3-selection";
import {transition} from "../../src/index.js";
import it from "../jsdom.js";

it("transition.selectChild(selector) selects the child matching the specified selector, then derives a transition", "<h1 id='one'><child/></h1><h1 id='two'><child/></h1>", () => {
const one = document.querySelector("#one");
const two = document.querySelector("#two");
const t1 = selectAll([one, two]).data([1, 2]).transition().delay(function(d) { return d * 10; });
const t2 = t1.selectChild("child");
assert.strictEqual(t2 instanceof transition, true);
assert.deepStrictEqual(t2._groups, [[one.firstChild, two.firstChild]]);
assert.strictEqual(t2._parents, t1._parents);
assert.strictEqual(t2._name, t1._name);
assert.strictEqual(t2._id, t1._id);
assert.strictEqual(one.firstChild.__data__, 1);
assert.strictEqual(two.firstChild.__data__, 2);
assert.strictEqual(one.firstChild.__transition[t1._id].delay, 10);
assert.strictEqual(two.firstChild.__transition[t1._id].delay, 20);
});
20 changes: 20 additions & 0 deletions test/transition/selectChildren-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from "assert";
import {selectAll} from "d3-selection";
import {transition} from "../../src/index.js";
import it from "../jsdom.js";

it("transition.selectChildren(selector) selects the children matching the specified selector, then derives a transition", "<h1 id='one'><child/></h1><h1 id='two'><child/></h1>", () => {
const one = document.querySelector("#one");
const two = document.querySelector("#two");
const t1 = selectAll([one, two]).data([1, 2]).transition().delay(function(d) { return d * 10; });
const t2 = t1.selectChildren("child");
assert.strictEqual(t2 instanceof transition, true);
assert.deepStrictEqual(t2._groups.map(group => Array.from(group)), [[one.firstChild], [two.firstChild]]);
assert.deepStrictEqual(t2._parents, [one, two]);
assert.strictEqual(t2._name, t1._name);
assert.strictEqual(t2._id, t1._id);
assert.strictEqual("__data__" in one.firstChild, false);
assert.strictEqual("__data__" in two.firstChild, false);
assert.strictEqual(one.firstChild.__transition[t1._id].delay, 10);
assert.strictEqual(two.firstChild.__transition[t1._id].delay, 20);
});

0 comments on commit 692f025

Please sign in to comment.