New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG Animations with D3 #316
Comments
Can you put this into a codesandbox? |
Just by looking at it, props.cx/cy aren’t numbers, they’re classes, Scatterpoint isn’t gonna understand their meaning (unless that’s your own class and it uses animate.g/div/path/etc inside). Remove the „native“ flag first, that’s used when you animate native dom styles, attributes or innerText. The g.style/opacity could be animated like that, but it’s gotta be animated.g in that case. In your case it wouldn’t make much difference because foreign React components can only be animated by rendering out their props 60fps. See: http://react-spring.surge.sh/perf Btw the accessors can all be:
|
@drcmda - thanks for the feedback. I’ll try to build up a example, gonna be tricky due to number of dependencies but it if helps them absolutely! Few answers to your questions:
Any idea why it wouldn’t be rendering at all except when duration is specified? |
Oh, I thought I saw native in there. Duration shouldn’t interfere with rendering. A real example makes it easier for me to help out, often it’s some minor typo or wrong config that messes stuff up, I’ll see it right away. If it’s a bug I’ll fix it. |
@drcmda - I found the issue. The item count I'm passing is about 150, if I change that to something like 10, it works just fine. Here is 10 - https://www.screencast.com/t/CZpF3tAG8 In the 150 scenario it basically never renders. Now if I add Here is a demo, it shows 10 by default then you can comment out the splice to see it fail. https://codesandbox.io/s/8kqoyx9262 |
Any ideas @drcmda ? |
It's probably too many. Transition isn't virtualized and 450 items means 450 keyframes + springs + requestAnimationFrames. "trail" also adds up, 450 * 100ms is 45 seconds delay for the last item. Springs can take array data, that's always been my approach with stuff like d3, one spring, and interpolated arrays.
|
Something like this maybe: https://codesandbox.io/embed/wkxz90lj58 This uses a relatively cheap spring and interpolates the trailing difference. Makes me think, maybe supporting config={[....]} array would be a nice addition, that way you could hand out different configs (with additive delay in them). Edit: it's even easier, just use a delta of 0-1 and interpolate. |
@drcmda - Interesting - the spring 0-1 feels like an odd API but I'll give it a try. |
made some more edits to clean it up. 0-1 is basically a timeline, start to finish. With a data-set that can grow i wouldn't risk using springs for each and every element. |
How would I make this animate on the update now? Example a user resorts the data, it should animate to its new position. I added the reset flag but all that does is make it start as if it were entering again. I suppose I would need to track the previous and the target positions which is gonna get really nasty. Also, its only 150, not 450 ;P |
in a previous version i've used arrays, that'll work, too. then you can update and track positions. enter/exit type of stuff with hundreds of elements is gonna get hard. Perhaps i can optimize more and use a single RAF queue for all springs, but that won't happen until the next major. TS is maintained by contributors, i don't know/use it. Could you add a PR? |
@drcmda - can you show me an example of what you are thinking? Maybe I can help. |
array animations like: <Spring native from={{ x: items.map(d => 0) }} to={{ x: items.map(d => d.x) }}>
{props => items.map((item, index) => (
<animated.circle cx={props.x.payload[index]} />
|
This is pretty rough but something like this might work:
Might need to use a merge diff sort like react-move and react-motion uses too - https://github.com/chenglou/react-motion/blob/master/src/mergeDiff.js |
I'm using react-move and wanting to try out react-spring for performance reasons.
When I tried to move the code over, my transitions are not working right; basically i'm moving opacity and x but the console shows the numbers just spinning on forever.
I added duration to the config and it actually rendered but it was really slow.
In react-move I have the following code:
my migrated code looks like this:
Any hints to what it might be would be very helpful!
The text was updated successfully, but these errors were encountered: