Layout Stages

A layout stage, as already explained in the section called “The Layout Stages Concept”, serves as a standardized container that encapsulates arbitrary layout functionality and provides a general means to string together multiple layout stages into a compound layout process. It is an implementation of interface ILayoutStage and most commonly also an extension of abstract class AbstractLayoutStage.

The encapsulated layout functionality of the predefined yFiles layout stages covers special-purpose layouts (see Table 10.18, “Layout stages that provide special-purpose layout functionality”) as well as enhancements to the layout process of specific layout styles (for example, tree layout and orthogonal layout) and edge routing styles, respectively (see orthogonal edge routing).

Table 10.17, “Predefined layout stages” lists another kind of layout stages that contribute to the inner workings of a layout process itself.

Table 10.17. Predefined layout stages

Classname Description
ComponentLayouter Arranges the connected components of a graph. Part of the default compound layout process as established by class CanonicMultiStageLayouter.
CompositeLayoutStage Allows to establish a custom compound layout process consisting of multiple layout stages. See below for an example of using class CompositeLayoutStage to create a custom layout process.
FixedGroupLayoutStage Used to prevent an existing layout inside a group node from being altered when calculating a layout for a grouped graph.
LayoutMultiplexer Enables using individual layout algorithms for components (when used as the core layouter of class ComponentLayouter) or for the contents of group nodes (when used as the core layouter of class RecursiveGroupLayouter).
RecursiveGroupLayouter Provides support for recursively calculating a layout for grouped graphs.
GreedyMISLabeling, SALabeling Place labels without altering the graph layout. See also the section called “Generic Labeling”.

Purpose and usage of ComponentLayouter is described in the section called “Class ComponentLayouter”. Note that this section also shows how to use class LayoutMultiplexer in conjunction with ComponentLayouter in order to have different layout algorithms applied to the separate components of a graph.

Using class CompositeLayoutStage to create a custom layout process is shown in the following code example:

Example 10.13. Defining a custom compound layout process using CompositeLayoutStage

// 'hierarchic' is of type yWorks.yFiles.Layout.Hierarchic.HierarchicLayouter.

// String together a label layout process.
CompositeLayoutStage ll = new CompositeLayoutStage();
ll.AppendStage(new LabelLayoutTranslator());
ll.AppendStage(new LabelLayoutDataRefinement());
// Set the compound label layout process as the label layouter for 
// HierarchicLayouter.
hierarchic.LabelLayouter = ll;
hierarchic.LabelLayouterEnabled = true;

Table 10.18, “Layout stages that provide special-purpose layout functionality” lists layout stages that provide special-purpose layout functionality.

Table 10.18. Layout stages that provide special-purpose layout functionality

Classname Description
GraphLayoutLineWrapper "Line-wraps" or "column-wraps" a graph layout. Best suited for use in conjunction with hierarchic layout.

The description of class GraphLayoutLineWrapper explains the options of this layout stage and how to use it.

Tutorial Demo Code

The following tutorial demo code has examples on how to use FixedGroupLayoutStage and RecursiveGroupLayouter:

  • MixedLayoutDemo shows how RecursiveGroupLayouter can be used when calculating a layout for a grouped graph
  • the layout module class OrthogonalLayoutModule.cs from the LayoutModulesWindow demo application presents the technique of prepending an orthogonal layout with an invocation of FixedGroupLayoutStage in order to avoid altering the layout of group node contents