Skip to content
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

Animation upon Data Update #80

Open
DCMattyG opened this issue Apr 8, 2022 · 5 comments
Open

Animation upon Data Update #80

DCMattyG opened this issue Apr 8, 2022 · 5 comments

Comments

@DCMattyG
Copy link

DCMattyG commented Apr 8, 2022

Is your feature request related to a problem? Please describe.
When updating the chart data, the chart doesn't perform the animation that it does when it's first rendered. It would be really nice to have this effect each time the data is changed (ideally as a user selects options from a drop-down menu or the like).

Describe the solution you'd like
Ability to "re-draw" the chart upon data update, or have the chart perform the initial expansion animation when the data is changed.

Describe alternatives you've considered
I've attempted resetting the ref's in React, but the Chart just seems to keep appending new charts to the DOM.

Additional context
N/A

@DavidC-75
Copy link

Before anything else, I should say how much I like this very configurable and flexible sunburst-chart ! I'm still experimenting and learning, but I really like it !

I am just following up on this old question (not an issue really), because I'd like to achieve the same effect.
It is actually well illustrated by an ancestor/fork of sunburst-chart, called the Zoomable sunburst with updating data:

Can the same thing be done using the current API ? or does that require changes to the component ?

The maths involved don't really scare me - I do a lot of (much more complicated) maths everyday... However, I really don't know anything about javascript and I don't have the faintest idea about the tools needed to develop this or to debug this.... A simple example would be awsome !

@vasturiano
Copy link
Owner

@DavidC-75 if you re-instantiate the chart (as opposed to just modifying the data array input to it), it should trigger the initial build-in animation since it's in fact a completely new chart.

@DavidC-75
Copy link

Well, the idea sounds simple enough.... As I said I am a complete novice when it comes to javascript and d3. I really don't know what I'm doing.... so very possibly I made a beginner's mistake, but when re-instantiating the chart after modifying the data array, I just get new charts and new charts (as reported by the OP) as the previous instances do not get deleted.... See below.

image

Any suggestions ? I don't want to be asking too much, but a simple example would really be great !

@vasturiano
Copy link
Owner

Assuming you have a reference to the DOM element the chart is associated with, you can force full re-initialization of the chart by emptying the DOM element and feed it once again to the component. Something like:

// initially, just once
const myChart = Sunburst();
myChart(myElement);

// ...

// later, to re-init
myElement.innerHTML = '';
myChart(myElement);

@DavidC-75
Copy link

Yes that works nicely, thanks a lot !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants