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 controls how nodes interact with one another in a force simulation. Its signed strength determines the effect: a negative force mimics repulsion, spreading nodes apart, while a positive force mimics attraction, drawing them together. In D3, create it with d3.forceManyBody(). section 12.4.1

Use many-body force as one part of a force layout rather than as a complete layout by itself. Combine it with positioning forces to guide nodes, collision force to prevent overlap, centering force to move the whole cluster, and link force to pull connected nodes together. section 12.4 section 12.5

When building a network visualization, use it to shape node spacing:

  • Choose a negative many-body force when unrelated nodes should repel each other and remain visually separated. section 12.4.1
  • Choose a positive many-body force when nodes should attract one another. section 12.4.1
  • Balance it with link, collision, centering, and positioning forces to produce a readable arrangement. section 12.4

Character network

A Romeo and Juliet network represents characters as circles and shared scenes as links. Node size reflects each character’s number of lines, while nodes that share more scenes appear closer together. Many-body force participates in arranging the nodes alongside the other network forces. section 12.4.1 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 signs visually: negative strength pushes nodes apart, and positive strength pulls them together. section 12.4.1

How D3.js in Action, Third Edition covers it

How deep it goes
Defines the signed attraction and repulsion behavior but defers detailed force parameters and internals.
Examples
Uses a Romeo and Juliet character network and a beeswarm-like character chart.
What you can do after
Apply it via D3’s d3.forceManyBody() to make simulated nodes repel or attract.
How it connects
Connects force simulation with 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.