The following algorithms arrange the diagram in a way that shows the semantics of individual items or the overall graph structure, such as hierarchical relations between objects, loops and decisions in flowcharts, assignments of nodes to layers or swimlanes.
If application's data is structured hierarchically, it is appropriate to apply tree layout on it. To do this, create a TreeLayout object and call its Arrange method. Members of TreeLayout control many aspects of the layout process. The type of layout can be directional or radial. You can choose how much space to leave between tree levels and between nodes on the same level. For directional layouts, the style of links in the arranged tree can be set to straight, orthogonal or curved. Global tree direction and alignment can be customized too. In VB.NET and C#, tree layout might be applied like this:
C#
![]() |
---|
using MindFusion.Diagramming; ... private void button1_Click(object sender, EventArgs e) |
Visual Basic
![]() |
---|
Imports MindFusion.Diagramming ... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tl As New TreeLayout() End Sub |
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. In C# and VB.NET, layered layout can be applied like this:
C#
![]() |
---|
using MindFusion.Diagramming; ... private void btnArrange_Click(object sender, System.EventArgs e) |
Visual Basic
![]() |
---|
Imports MindFusion.Diagramming ... Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ll = New LayeredLayout() End Sub |
FlowchartLayout recognizes program code -like patterns in the graph, such as loops, sequences and if/switch branchings, and arranges them recursively. FlowchartLayout could be used to arrange other types of graphs as well, though with some restrictions. For example it treats all back links as loops in the code, and expects that they are nested - loop links starting closer to the stop node should end closer to the start node. Another similar restriction is that there shouldn't be any cross-links that connect different branches of a decision sub-graph.
SwimlaneLayout can be used to arrange process diagrams in which nodes representing activities are placed in swimlanes representing resources. The index of the resource allocated to an activity should be assigned to the corresponding node's LayoutTraits[SwimlaneLayoutTraits.Lane].
By default, the algorithm works with the diagram's LaneGrid, but its SwimlaneGrid property can be set to any class that implements ISwimlaneGrid. This allows applying the layout to a custom-drawn grid rendered through a custom control template, or one composed of locked background nodes.
HierarchicalLayout places nodes on user-defined levels, such that if the source graph is level-planar, all links are guaranteed to have a single segment and not intersect. The layout method requires that for each node LayoutTraits contains a HierarchicalLayoutTraits.Level entry specifying the level, and no two connected nodes must be on the same level.