Skip to content

Commit

Permalink
Merge pull request #94 from d3/two
Browse files Browse the repository at this point in the history
2.0
  • Loading branch information
Fil authored Aug 23, 2020
2 parents 60e9a09 + df65078 commit 611e427
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 95 deletions.
114 changes: 57 additions & 57 deletions README.md

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "d3-transition",
"version": "1.3.2",
"version": "2.0.0-rc.6",
"publishConfig": {
"tag": "next"
},
"description": "Animated transitions for D3 selections.",
"keywords": [
"d3",
Expand Down Expand Up @@ -35,14 +38,17 @@
},
"sideEffects": true,
"dependencies": {
"d3-color": "1",
"d3-dispatch": "1",
"d3-ease": "1",
"d3-interpolate": "1",
"d3-selection": "^1.1.0",
"d3-timer": "1"
"d3-color": ">=2.0.0-rc.1",
"d3-dispatch": ">=2.0.0-rc.1",
"d3-ease": ">=2.0.0-rc.1",
"d3-interpolate": ">=2.0.0-rc.1",
"d3-timer": ">=2.0.0-rc.1"
},
"peerDependencies": {
"d3-selection": "2.0.0-rc.4"
},
"devDependencies": {
"d3-selection": ">=2.0.0-rc.1",
"eslint": "6",
"jsdom": "15",
"rollup": "1",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const config = {
indent: false,
extend: true,
banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`,
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
globals: Object.assign({}, ...Object.keys({...meta.dependencies, ...meta.peerDependencies}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
},
plugins: [],
onwarn(message, warn) {
Expand Down
2 changes: 1 addition & 1 deletion src/selection/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function inherit(node, id) {
var timing;
while (!(timing = node.__transition) || !(timing = timing[id])) {
if (!(node = node.parentNode)) {
return defaultTiming.time = now(), defaultTiming;
throw new Error(`transition ${id} not found`);
}
}
return timing;
Expand Down
3 changes: 3 additions & 0 deletions src/transition/end.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ export default function() {

schedule.on = on1;
});

// The selection was empty, resolve end immediately
if (size === 0) resolve();
});
}
3 changes: 2 additions & 1 deletion src/transition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ Transition.prototype = transition.prototype = {
duration: transition_duration,
ease: transition_ease,
easeVarying: transition_easeVarying,
end: transition_end
end: transition_end,
[Symbol.iterator]: selection_prototype[Symbol.iterator]
};
21 changes: 21 additions & 0 deletions test/selection/transition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,24 @@ tape("selection.transition(transition) reselects the existing transition with th
test.equal(transition2.tween("tween"), bar);
test.end();
});

tape("selection.transition(transition) throws an error if the specified transition is not found", function(test) {
var document = jsdom("<h1 id='one'></h1><h1 id='two'></h1>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
transition1 = d3_selection.select(one).transition(),
transition2 = d3_selection.select(two).transition().delay(50);
try {
d3_selection.select(two).transition(transition1);
test.fail();
} catch (error) {
test.deepEqual(error.message, `transition ${transition1._id} not found`);
}
try {
d3_selection.select(one).transition(transition2);
test.fail();
} catch (error) {
test.deepEqual(error.message, `transition ${transition2._id} not found`);
}
test.end();
});
2 changes: 0 additions & 2 deletions test/transition/delay-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ tape("transition.delay() returns the delay for the first non-null node", functio
test.strictEqual(d3_selection.select(two).transition(transition2).delay(), 50);
test.strictEqual(d3_selection.selectAll([null, one]).transition(transition1).delay(), 0);
test.strictEqual(d3_selection.selectAll([null, two]).transition(transition2).delay(), 50);
test.strictEqual(d3_selection.selectAll([one, two]).transition(transition1).delay(), 0);
test.strictEqual(d3_selection.selectAll([two, one]).transition(transition2).delay(), 50);
test.end();
});

Expand Down
2 changes: 0 additions & 2 deletions test/transition/duration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ tape("transition.duration() returns the duration for the first non-null node", f
test.strictEqual(d3_selection.select(two).transition(transition2).duration(), 50);
test.strictEqual(d3_selection.selectAll([null, one]).transition(transition1).duration(), 250);
test.strictEqual(d3_selection.selectAll([null, two]).transition(transition2).duration(), 50);
test.strictEqual(d3_selection.selectAll([one, two]).transition(transition1).duration(), 250);
test.strictEqual(d3_selection.selectAll([two, one]).transition(transition2).duration(), 50);
test.end();
});

Expand Down
12 changes: 12 additions & 0 deletions test/transition/each-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
var tape = require("tape"),
jsdom = require("../jsdom"),
d3_selection = require("d3-selection"),
d3_transition = require("../../");

tape("transition.each is the same as selection.each", function(test) {
test.equal(d3_transition.transition.prototype.each, d3_selection.selection.prototype.each);
test.end();
});

tape("transition.each() runs as expected", function(test) {
var root = jsdom().documentElement;
var a = 0;
d3_selection.select(root).transition().each(() => {++a});
test.equal(a, 1);
a = 0;
d3_selection.selectAll([null, root]).transition().each(() => {++a});
test.equal(a, 1);
test.end();
});
2 changes: 0 additions & 2 deletions test/transition/ease-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ tape("transition.ease() returns the easing function for the first non-null node"
test.strictEqual(d3_selection.select(two).transition(transition2).ease(), d3_ease.easeBounce);
test.strictEqual(d3_selection.selectAll([null, one]).transition(transition1).ease(), d3_ease.easeCubic);
test.strictEqual(d3_selection.selectAll([null, two]).transition(transition2).ease(), d3_ease.easeBounce);
test.strictEqual(d3_selection.selectAll([one, two]).transition(transition1).ease(), d3_ease.easeCubic);
test.strictEqual(d3_selection.selectAll([two, one]).transition(transition2).ease(), d3_ease.easeBounce);
test.end();
});

Expand Down
5 changes: 3 additions & 2 deletions test/transition/merge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ tape("transition.merge(other) merges elements from the specified other transitio
var document = jsdom("<h1 id='one'></h1><h1 id='two'></h1>"),
one = document.querySelector("#one"),
two = document.querySelector("#two"),
transition1 = d3_selection.selectAll([null, two]).transition(),
transition2 = d3_selection.selectAll([one, null]).transition(transition1),
transition0 = d3_selection.select(document.documentElement).transition(),
transition1 = d3_selection.selectAll([null, two]).transition(transition0),
transition2 = d3_selection.selectAll([one, null]).transition(transition0),
transition3 = transition1.merge(transition2);
test.equal(transition3 instanceof d3_transition.transition, true);
test.deepEqual(transition3._groups, [[one, two]]);
Expand Down
8 changes: 8 additions & 0 deletions test/transition/size-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
var tape = require("tape"),
jsdom = require("../jsdom"),
d3_selection = require("d3-selection"),
d3_transition = require("../../");

tape("transition.size is the same as selection.size", function(test) {
test.equal(d3_transition.transition.prototype.size, d3_selection.selection.prototype.size);
test.end();
});

tape("transition.size() returns the expected value", function(test) {
var root = jsdom().documentElement;
test.equal(d3_selection.select(root).transition().size(), 1);
test.equal(d3_selection.selectAll([null, root]).transition().size(), 1);
test.end();
});
45 changes: 25 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,37 @@ d3-color@1:
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-1.4.0.tgz#89c45a995ed773b13314f06460df26d60ba0ecaf"
integrity sha512-TzNPeJy2+iEepfiL92LAAB7fvnp/dV2YwANPVHdDWmYMm23qIJBYww3qT8I8C1wXrmrg4UWs7BKc2tKIgyjzHg==

d3-dispatch@1:
version "1.0.6"
resolved "https://registry.yarnpkg.com/d3-dispatch/-/d3-dispatch-1.0.6.tgz#00d37bcee4dd8cd97729dd893a0ac29caaba5d58"
integrity sha512-fVjoElzjhCEy+Hbn8KygnmMS7Or0a9sI2UzGwoB7cCtvI1XpVN9GpoYlnb3xt2YV66oXYb1fLJ8GMvP4hdU1RA==
"d3-color@1 - 2":
version "1.3.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-1.3.0.tgz#675818359074215b020dc1d41d518136dcb18fa9"
integrity sha512-NHODMBlj59xPAwl2BDiO2Mog6V+PrGRtBfWKqKRrs9MCqlSkIEb0Z/SfY7jW29ReHTDC/j+vwXhnZcXI3+3fbg==

d3-ease@1:
version "1.0.6"
resolved "https://registry.yarnpkg.com/d3-ease/-/d3-ease-1.0.6.tgz#ebdb6da22dfac0a22222f2d4da06f66c416a0ec0"
integrity sha512-SZ/lVU7LRXafqp7XtIcBdxnWl8yyLpgOmzAk0mWBI9gXNzLDx5ybZgnRbH9dN/yY5tzVBqCQ9avltSnqVwessQ==
"d3-dispatch@1 - 2":
version "1.0.5"
resolved "https://registry.yarnpkg.com/d3-dispatch/-/d3-dispatch-1.0.5.tgz#e25c10a186517cd6c82dd19ea018f07e01e39015"
integrity sha512-vwKx+lAqB1UuCeklr6Jh1bvC4SZgbSqbkGBLClItFBIYH4vqDJCA7qfoy14lXmJdnBOdxndAMxjCbImJYW7e6g==

d3-interpolate@1:
version "1.3.3"
resolved "https://registry.yarnpkg.com/d3-interpolate/-/d3-interpolate-1.3.3.tgz#cef4ba06dfccebcc45e4ae9d4d836a931a945076"
integrity sha512-wTsi4AqnC2raZ3Q9eqFxiZGUf5r6YiEdi23vXjjKSWXFYLCQNUtBVMk6uk2tg4cOY6YrjRdmSmI/Mf0ze1zPzQ==
"d3-ease@1 - 2":
version "1.0.5"
resolved "https://registry.yarnpkg.com/d3-ease/-/d3-ease-1.0.5.tgz#8ce59276d81241b1b72042d6af2d40e76d936ffb"
integrity sha512-Ct1O//ly5y5lFM9YTdu+ygq7LleSgSE4oj7vUt9tPLHUi8VCV7QoizGpdWRWAwCO9LdYzIrQDg97+hGVdsSGPQ==

"d3-interpolate@1 - 2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/d3-interpolate/-/d3-interpolate-1.3.2.tgz#417d3ebdeb4bc4efcc8fd4361c55e4040211fd68"
integrity sha512-NlNKGopqaz9qM1PXh9gBF1KSCVh+jSFErrSlD/4hybwoNX/gt1d8CDbDW+3i+5UOHhjC6s6nMvRxcuoMVNgL2w==
dependencies:
d3-color "1"

d3-selection@^1.1.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/d3-selection/-/d3-selection-1.4.1.tgz#98eedbbe085fbda5bafa2f9e3f3a2f4d7d622a98"
integrity sha512-BTIbRjv/m5rcVTfBs4AMBLKs4x8XaaLkwm28KWu9S2vKNqXkXt2AH2Qf0sdPZHjFxcWg/YL53zcqAz+3g4/7PA==
"[email protected] - 2":
version "1.4.0"
resolved "https://registry.yarnpkg.com/d3-selection/-/d3-selection-1.4.0.tgz#ab9ac1e664cf967ebf1b479cc07e28ce9908c474"
integrity sha512-EYVwBxQGEjLCKF2pJ4+yrErskDnz5v403qvAid96cNdCMr8rmCYfY5RGzWz24mdIbxmDf6/4EAH+K9xperD5jg==

d3-timer@1:
version "1.0.10"
resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-1.0.10.tgz#dfe76b8a91748831b13b6d9c793ffbd508dd9de5"
integrity sha512-B1JDm0XDaQC+uvo4DT79H0XmBskgS3l6Ve+1SBCfxgmtIb1AVrPIoqd+nPSv+loMX8szQ0sVUhGngL7D5QPiXw==
"d3-timer@1 - 2":
version "1.0.9"
resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-1.0.9.tgz#f7bb8c0d597d792ff7131e1c24a36dd471a471ba"
integrity sha512-rT34J5HnQUHhcLvhSB9GjCkN0Ddd5Y8nCwDBG2u6wQEeYxT/Lf51fTFFkldeib/sE/J0clIe0pnCfs6g/lRbyg==

dashdash@^1.12.0:
version "1.14.1"
Expand Down

0 comments on commit 611e427

Please sign in to comment.