Search
Force-directed layout algorithms

Force-directed algorithms simulate forces acting between objects in the graph and iteratively run a physical simulation that pulls the objects closer or pushes them apart. At each iteration the energy associated with the simulated system decreases, and the node positions calculated by this process usually lead to evenly distributed nodes and uniform link lengths.

Spring-Embedder Graph Layout

Spring-Embedder is force-directed layout algorithm. It simulates a physical system in which nodes repulse each other, and the links between them act as confining springs. Graphs processed by Spring-Embedder have their nodes distributed uniformly across the diagram area. The algorithm can be applied on a graph by creating a SpringLayout object and calling its Arrange method. Members of SpringLayout allow you to set the desired distance between graph nodes and the number of iteration steps to use while calculating node positions. You can also specify to minimize link crossings. If you select that option, the algorithm would produce better result with more iteration steps. However, it needs more time to complete if more steps are specified. In VB.NET and C#, Spring-Embedder layout might be applied like this:

C#  Copy Code

using MindFusion.Diagramming;
using MindFusion.Diagramming.Layout;

...

private void button1_Click(object sender, EventArgs e)
{
    SpringLayout sl = new SpringLayout();
    sl.IterationCount = 500;
    sl.NodeDistance = 30;
    sl.Arrange(diagram);
}

Visual Basic  Copy Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim sl As New SpringLayout()
    sl.IterationCount = 500
    sl.NodeDistance = 30
    sl.Arrange(diagram)

End Sub

Grid Graph Layout

The GridLayout algorithm arranges diagram nodes in a grid, keeping connected nodes close together. The algorithm strives to achieve a small number of link crossings. It is based on an iterative process whose initial steps shuffle the grid nodes randomly. That can lead to very different results each time the algorithm is run.

To apply the layout to a diagram, create a GridLayout instance, set its members and invoke the Arrange method. Grid layout might be applied like this:

C#  Copy Code

using MindFusion.Diagramming;
using MindFusion.Diagramming.Layout;

...

private void button1_Click(object sender, EventArgs e)
{
    GridLayout gl = new GridLayout();
    gl.GridSize = 75;
    gl.Arrange(diagram);
}

Visual Basic  Copy Code

Imports MindFusion.Diagramming
Imports MindFusion.Diagramming.Layout

...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim gl As New GridLayout()
    gl.GridSize = 75
    gl.Arrange(diagram)

End Sub

Simulated Annealing Graph Layout

The AnnealLayout class implements the Simulated Annealing graph layout algorithm. Simulated Annealing is a general-purpose optimization method used to solve large-scale combinatorial problems by simulating the process of heating and cooling of metal to achieve freedom from defects. Finding a nice arrangement of a graph is a combinatorial problem that can be reduced to assigning costs to graph configurations and finding the minimum cost configuration. AnnealLayout assigns costs to graph configurations by evaluating different aesthetic criteria such as distance between nodes, length of links and the number of link crossings. Thus the best configuration found will have good aesthetic properties.

Circular Graph Layout

CircularLayout distributes nodes evenly on the circumference of a circle at positions that result in as few link crossing as possible. Set its Radius property to specify the size of the layout circle. Use SiftingRounds to set the number of fine-tuning crossing-reduction iterations.