Comments (6)
Another example (from bl.ocks.org/e32cc94b26df9c5e28aa), is where you want to create a shared transition on multiple existing selections, such as:
var foo = d3.selectAll(".foo");
var bar = d3.selectAll(".bar");
You have to either create one transition and then re-select your selections:
var transition = d3.transition().duration(1000);
transition.selectAll(".foo").style("fill", "red");
transition.selectAll(".bar").style("stroke", "red");
Or you have to create multiple independent transitions:
foo.transition()
.duration(1000)
.style("fill", "red");
bar.transition()
.duration(1000)
.style("stroke", "red");
The latter is arguably easier but it’s a bit bad since the transitions won’t have the same id, or even necessarily the same start time. (Though the latter could be fixed in some cases if we switch to the d3.event’s timestamp per #18.) And you have to duplicate the timing parameters, unless you want to do something like this, which is cumbersome:
transition(foo).style("fill", "red");
transition(bar).style("stroke", "red");
function transition(selection) {
return selection.transition().duration(1000);
}
Here’s the transition.reselect method proposed above, which returns the corresponding transition for the specified selection. It could also be named transition.selection or transition.of.
var transition = d3.transition().duration(1000);
transition.reselect(foo).style("fill", "red");
transition.reselect(bar).style("stroke", "red");
And here’s the selection.transition(transition) method as proposed above:
var transition = d3.transition().duration(1000);
foo.transition(transition).style("fill", "red");
bar.transition(transition).style("stroke", "red");
It’s a bit shorter, which is nice. I worry about overloading it with selection.transition() and _selection.transition(_name*), but it seems similar enough not to be a big problem.
from d3-transition.
d3-timer 0.3 makes transitions scheduled during the same frame or event have consistent timing, at least.
from d3-transition.
Is this too short?
var transition = d3.transition().duration(1000);
transition.of(foo).style("fill", "red");
transition.of(bar).style("stroke", "red");
from d3-transition.
Or maybe you “apply” a transition to a selection?
var transition = d3.transition().duration(1000);
transition.apply(foo).style("fill", "red");
transition.apply(bar).style("stroke", "red");
from d3-transition.
The problem with the above suggestions is that it makes it seem like tweens and event listeners from the originating transition might be applied to the specified selection, when instead it’s creating a new transition (or reselecting an existing transition) on the selected elements. And if it’s create a new transition, it’s just inheriting the timing parameters, not everything else.
from d3-transition.
I feel like overloading selection.transition(transition) is the way to go.
from d3-transition.
Related Issues (20)
- transition.end() never resolves if 0 elements are matched HOT 2
- transition.easeVarying?
- [d3@6] transition.end() crashes HOT 3
- transitions are not iterable. HOT 1
- [v2.0.0] error: transition 1 not found HOT 4
- transition().style() fails to work as expected when applied to a starting property of 0px HOT 1
- transition().textTween not working HOT 1
- .end() with textTween causes uncaught promise when used at the same time as d3-force HOT 1
- transition.selectChild[ren] HOT 2
- Is there a way to control transition process?
- test 122 failure on Ubuntu HOT 2
- issues when doing .transition(t) HOT 6
- Can not bundle project with webpack minimize option. Cannot get final name for export 'easeCubicInOut' ... HOT 2
- Security patches
- Example for transition() isn't correct in READ.ME? HOT 2
- transition() prevents click events on iOS Safari/15.5 HOT 2
- Tranzicija
- Administrator
- d3-color version issue
- Opacity transition does not work properly for % values HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-transition.