Laying out the Diagram

The diagram can be arranged automatically by calling its arrange method and specifying a layout algorithm. Different layout algorithms are implemented by the various Layout classes from the MindFusion.Graphs namespace. To apply one of them, create an instance of the respective class, customize its properties and pass it as an argument to arrange. It is also possible to lay out the contents of an individual ContainerNode by calling the container’s arrange method.

Layered Graph Layout

The LayeredLayout algorithm arranges diagram nodes in layers according to several criteria, most important of which are: connected nodes must be placed close together; links must flow in one direction if possible; links must cross as few layers as possible; links must not cross other links. To apply the layout to a diagram, create a LayeredLayout instance, set its members and invoke the arrange method.

Spring-Embedder Graph Layout

SpringEmbedder 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 the arrange method. Members of SpringLayout allow you to set the desired distance between graph nodes and the number of iteration steps to run while processing the simulation.

Tree Layout

If application’s data is structured hierarchically, it is appropriate to apply tree layout on it. To do this, create a TreeLayout instance and call the arrange method. The difference between two classes is where they place child nodes in relation to their parent; the former centers the parent above its children, the latter arranges children in columns at a horizontal offset form their parent. Members of both classes control the tree direction, how much space to leave between tree levels and between nodes on the same level.

Fractal Layout

The FractalLayout tree layout algorithm places child nodes symmetrically around their parent node. Nodes at the lowest level are arranged directly in a circle around their parent. At the upper level, the already arranged nodes form branches that are arranged in a circle around the new parent node. The algorithm is recursively repeated till the highest level is reached.