Usage guidesLayout

D3 force layout

Use D3’s force simulation to position nodes.

Overview

Use D3’s force simulation to position nodes.

When to use it

Use it when a network needs control over repulsion, link distance, or cooling speed.

Basic usage

Set the layout type with layout.type.

const graph = new Graph({
  container,
  data,
  layout: { type: 'd3-force' },
});

Options

OptionDescriptionTypeDefault
linkDistanceTarget distance between linked nodes.number or functionmax(200, √nodeCount × 80)
nodeStrengthForce between nodes. Negative values repel.number or function-30
alphaDecayRate at which the simulation cools on each step.number0.1
preventOverlapWhether to enable node collision detection.booleanfalse

Common layout options · Layout reference

Code example

The target link distance is 100, and negative nodeStrength repels nodes.

Loading example…
Drag to pan or scroll to zoom.
const layout = { type: 'd3-force', linkDistance: 100, nodeStrength: -120, preventOverlap: true, nodeSize: 24 };

Compare network layouts