ForceDirectedLayout class

Force-directed layout treats the graph as if it were a system of physical bodies with repulsive electrical, attractional gravitational, and spring forces acting on them and between them.

Electrical forces come both from the field at the vertex's location as well as from neighboring vertexes and are quadratic by distance. Gravitational forces come from the field at the vertex's location and are constant. Spring forces are only exerted between two different vertexes that are connected by an edge and are linear by distance.

The electrical forces on a vertex are the sum of the electrical charge times the electrical field at that location (#electricalCharge, #electricalFieldX, #electricalFieldY) and the electrical forces of all nearby vertexes divided by the square of the distance between them. You can easily assign the electrical charge for all vertexes by assigning #defaultElectricalCharge. By default there is no electrical field, so all forces are due to nearby charged vertexes. For efficiency, #infinityDistance determines a cut-off distance between vertexes for which to consider any influence.

The gravitational forces on a vertex are the sum of the gravitational mass times the gravitational field at that location (#gravitationalMass, #gravitationalFieldX, #gravitationalFieldY). You can easily assign the gravitational mass for all vertexes by assigning #defaultGravitationalMass. By default there is no gravitational field.

The spring forces on a vertex are only exerted by the edges connecting it with other vertexes. The force along an edge is the stiffness of the spring times the difference of the distance between the vertexes and the nominal length of the spring (#springStiffness, #springLength) divided by the distance between the vertexes. When the distance is less than the nominal length, the force pushes the vertexes apart; when the distance is greater, the force pulls them together. You can easily assign the spring length and stiffness for all edges by assigning #defaultSpringLength and #defaultSpringStiffness.

When the distance between two vertexes is less than one unit, this uses a random number generator to decide which direction the forces should go. For layouts that start with all of the vertexes at the same location, this results in potentially dramatically different results. Set #randomNumberGenerator to null in order to produce reproducible results given the same initial vertex locations.

The algorithm seeks a configuration of the bodies with locally minimal energy, i.e. vertex positions such that the sum of the forces on each vertex is zero. This is achieved by repeatedly computing the forces on each vertex, moving them, and repeating. Computations stop when no vertex moves more than #epsilonDistance or when #maxIterations have happened.

The layout cannot guarantee that it provides optimal positioning of nodes. Nodes will normally not overlap each other, but when there is a dense interconnectivity overlaps might not be avoidable.

If you want to experiment interactively with most of the properties, try the Force Directed Layout sample. See samples that make use of ForceDirectedLayout in the samples index.

This layout makes use of a LayoutNetwork of ForceDirectedVertexes and ForceDirectedEdges that normally correspond to the Nodes and Links of the Diagram.

Implemented types
Available extensions
Annotations
  • @JS()
  • @staticInterop

Constructors

ForceDirectedLayout([dynamic init])
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited