Barnabé Monnot
Barnabé Monnot

Reputation: 1163

Speed up d3 force layout with many nodes and links

I wanted to produce a visualization that contains a good deal of nodes with the d3 force layout (more than 500 hundred nodes). While it is working correctly with as much as 200 hundred nodes it gets very slow with about 500, in the sense that the layout hiccups from one frame to the next and events like mouseover on nodes are far from being responsive. This made me ask several questions.

Thank you for your input !

Upvotes: 4

Views: 2701

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109232

One way of doing this would be to handle not every tick event, but only a fraction of them, e.g. skipping a specified number or dynamically adapting the number of events depending on other considerations.

If you want smooth movements, add a transition between the positions set in the handled tick events. You can of course combine these ideas as well and skip events while the transition is running, handling the first one after it has been completed.

Upvotes: 2

Related Questions