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 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 that WpfDiagram tries 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.Wpf; |
Visual Basic Copy Code |
---|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click |
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.Wpf; |
Visual Basic Copy Code |
---|
Imports MindFusion.Diagramming.Wpf |
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.
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. Set SiftingRounds to set the number of fine-tuning crossing-reduction iterations.