Skip to content

Best practices for updating a D3 graph layout #1567

Answered by mbostock
ccattuto asked this question in Q&A
Discussion options

You must be logged in to vote

You don’t have to create a new chart from scratch every time something changes; you can instead update an existing chart. But this tends to be more work than simply redrawing the chart from scratch: you need to track the dependencies from state to display explicitly so that when a certain bit of state changes, you update the corresponding part of the display.

Here’s an example of using the resize helper to update an existing chart rather than redraw it from scratch. When the page loads, a detached “skeleton” chart is initially drawn (in the selection svg). Then there’s an updateChart method that you can call whenever you want to update the chart; it performs the minimal update necessary t…

Replies: 2 comments 3 replies

Comment options

Fil
Aug 9, 2024
Collaborator

You must be logged in to vote
3 replies
@ccattuto
Comment options

@mbostock
Comment options

@ccattuto
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ccattuto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants