liveBook · Manning

Many-body force

As explained in D3.js in Action, Third Edition

A many-body force models interactions among nodes, producing attraction or repulsion based on its signed strength.

A many-body force changes how nodes interact with one another in a force simulation. With d3.forceManyBody(), a negative strength makes nodes repel; a positive strength makes them attract. Unlike a positioning force, it does not pull each node toward a chosen coordinate. section 12.4.1

Combine it with other forces to shape a layout: collision keeps nodes from overlapping, centering moves the whole group, and link force pulls connected nodes together. The simulation updates node positions as it runs. section 12.4 section 12.5

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 layouts to see how changing the sign switches node interaction from repulsion to attraction. section 12.4.1

How D3.js in Action, Third Edition covers it

How deep it goes
Defines the effect of positive and negative strength visually, without deriving the force calculations.
Examples
Compares repelling and attracting nodes in a figure and includes forceManyBody in a network-diagram implementation.
What it assumes
Builds on nodes and force simulations, introducing signed attraction and repulsion without mathematical derivation.
What you can do after
Operate/configure it with d3.forceManyBody() to choose whether simulated nodes repel or attract.
How it connects
Connects many-body force to force simulation, positioning force, collision force, centering force, and link force.

Related concepts

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.