liveBook · Manning

D3.forceManyBody()

As explained in D3.js in Action, Third Edition

d3.forceManyBody() creates a D3 force that applies pairwise attraction or repulsion among nodes.

d3.forceManyBody() creates a force that changes how every node interacts with other nodes in a simulation. Use a negative value for repulsion, spreading nodes apart; use a positive value for attraction, drawing them together. section 12.4.1

Unlike positioning forces that pull nodes toward coordinates, a many-body force works between nodes. It is useful in a network layout, where repulsion can keep nodes from collapsing into the same area while other forces establish the overall arrangement. section 12.4.1 section 12.4.1

Reading the visible effect

In a force simulation, switching the many-body force from negative to positive changes the layout from nodes pushing apart to nodes pulling together. Combine it with forces such as centering, collision, and links to shape a network diagram. section 12.4.1 section 12.4.1

Figure 12.17 The many-body force influences how nodes interact with each other. A negative many-body force creates repulsion, while a positive one mimics attraction.
figure

Compare the two force directions: negative strength produces repulsion, while positive strength produces attraction. section 12.4.1

How D3.js in Action, Third Edition covers it

How deep it goes
Defines positive attraction and negative repulsion but defers configuration details and implementation mechanics.
Examples
Illustrates opposing attraction and repulsion behaviors and a Romeo and Juliet character network.
What you can do after
Apply it via D3’s force simulation to make nodes attract or repel one another.
How it connects
Contrasts positioning forces and connects with force simulation, collision force, centering force, and link force.

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.