Skip to main content
100%

Update Force-Directed Layout D3.v4 Different Datasets

✓ Published0🌍 Public
RRosaRomeroGomez
Last edited Jan 30, 2018
Created on Jan 30, 2018

This example demonstrates how to update a force-directed graph when a user action loads a new dataset, using D3 v4’s enter-update-exit pattern. A button swaps between two JSON datasets containing nodes and links from a character network. The code uses `d3.forceSimulation`, `d3.forceLink`, and `d3.forceManyBody` to compute layout, while SVG circles and lines are bound to the data. Dragging is enabled via `d3.drag`, and the simulation restarts with new data when the dataset changes.

AI-generated description

Sometimes you find situations in which some user action results in loading a new dataset for your force-directed graph. This update action may result either in the display of a completely new force-directed graph or a subset of such graph. To address this need, this is my approach using the enter-update-exit pattern for the force-directed graph in D3.v4.

It seems to work pretty decently, but if you find any bugs or suggestions, please feel free to tell me.

mit Licensed

Similar vizzes