-
Notifications
You must be signed in to change notification settings - Fork 59
Automatic Layout
Bruno Silva edited this page Jun 11, 2025
·
1 revision
🚧
When using the automatic layout, the placement of vertices is determined by a force-directed algorithm.
The default constructor of ForceDirectedSpringGravityLayoutStrategy
uses (experimentally determined) values that can fit most graphs, namely:
repulsiveForce = 25
attractionForce = 3
attractionScale = 10
gravity = 0.01
However, depending on your needs, these can be adjusted. The following table explains these parameters and their effect:
Parameter | Effect | Increase to... | Decrease to... |
---|---|---|---|
repulsiveForce |
Prevents vertices from clustering | Reduce overlaps, spread out more | Allow denser clusters |
attractionForce |
Pulls adjacent vertices together | Tighten clusters, emphasize edges | Let related nodes drift |
attractionScale |
Defines “natural” edge length | Increase distance between connected | Reduce distance between connected |
acceleration | Multiplies final forces before applying to positions | Make layout faster (but risk unstable) | Stabilize movements, slower convergence |
gravity |
Pulls all vertices to the center of the panel | Faster convergence, less separation | Slow convergence, more separation |
You can use the following table as a reference to derive more optimal values for the intended type of graph visualization:
Type | repulsiveForce |
attractionForce |
attractionScale |
acceleration |
---|---|---|---|---|
Sparse | 15–20 | 2–3 | 15–20 | 0.7–0.9 |
Dense | 30–50 | 5–8 | 5–10 | 0.5–0.8 |
Balanced | 20–30 | 3–5 | 8–12 | 0.7–0.85 |