C

TreeLayout

This layout algorithm arranges graphs with a tree structure.
ImplementsInheritance Hierarchy

Remarks

Layout Style

TreeLayout provides multiple different arrangements of trees and subtrees. It is easy to customize the order of edges, the port assigner and the arrangement of the nodes for each subtree.

Tree layout algorithms are commonly applied to visualize relational data and produce diagrams of high quality that are able to reveal possible hierarchical properties of the graph. More precisely, they find applications in dataflow analysis, software engineering, bioinformatics and business administration.

Example graph with a layout calculated by TreeLayout using default settings

Tree layout using different ISubtreePlacers and rotations

Concept

The layout algorithm starts from the leaves and continues with their parents, then with the parents of the parents and so on. When a node is processed, the algorithm will use the corresponding ISubtreePlacer instance to move its children (along with their subtrees) to a suitable position and to route the outgoing edges of this node. Then, the next local root node will be processed.

To avoid moving all nodes several times and to know the area that the subtrees occupy, the layout algorithm uses SubtreeShapes. These SubtreeShapes are moved and merged during layout calculation.

Features

Each subtree can have a different style of node placement. ISubtreePlacers are responsible for arranging subtrees and their common root node. They can be specified separately for each local root via layout data property subtreePlacers.

A custom node can be defined as root of the tree using layout data property treeRoot.

The layout algorithm can be configured to reserve space for node labels and place the edge labels along edges such that the labels won't overlap with other graph elements. Edge labels are placed according to the information stored in an EdgeLabelPreferredPlacement instance. However, the placement along the edge will only affect the order of multiple labels at the same edge. The algorithm will always place the labels close to the target node.

Grouping of nodes can also be handled by this layout algorithm. It is important that a group node contains a whole subtree. Otherwise, the group nodes may overlap with each other or with other nodes. Furthermore, the user may specify minimum size constraints for each group node using IMapper<K, V> key MINIMUM_GROUP_NODE_SIZE_DATA_KEY.

TreeLayout supports custom sorting of the outgoing edges of a node. For example, a ISubtreePlacer instance that implements IFromSketchSubtreePlacer provides a comparator that keeps the current order of siblings, allowing to extend the graph incrementally.

nodeTypes are considered such that the type of the nodes is used as a criterion for sorting the child nodes of a local root node, with the effect that nodes of the same type are placed consecutively, if possible. The primary ordering criterion is still specified by the childOrder.

How port placement constraints are handled depends on the selected portAssigners. In addition, the PortPlacementStage is applied as a postprocessing step.

This layout algorithm can only handle graphs with a tree structure. To make it applicable to general graphs, the treeReductionStage is used by default. This stage will temporarily remove some edges of the input graph until a tree is obtained. After the layout calculation, the stage will reinsert the edges that were removed and route them separately.

For particularly fast layout computations you may use the following configuration. Note that this limits the layout to specific styles. All settings not shown in the snippet must be set to their default values.

Configuration for fast layout computations
const subtreePlacer = new LevelAlignedSubtreePlacer()
subtreePlacer.busAlignment = busAlignment
subtreePlacer.layerSpacing = layerSpacing
subtreePlacer.rootAlignment = SubtreeRootAlignment.CENTER_OF_PORTS
subtreePlacer.edgeRoutingStyle = routingStyle
subtreePlacer.spacing = spacing // must be at most busAlignment * layerSpacing

const treeLayout = new TreeLayout({
  defaultSubtreePlacer: subtreePlacer,
})

Layout Stages

This class provides a configurable pipeline that contains various ILayoutStages. Each ILayoutStage can incorporate preprocessing or postprocessing steps into the layout calculation to streamline the input graph and enhance the resulting layout. Additionally, custom ILayoutStages can be added and executed either before or after the predefined ones.

The following default ILayoutStages are included:

With these layoutStages the layout algorithm is configured well, so they usually don't need to be changed.

Default Values of Properties

NameDefaultDescription
allowMultiParentfalse
Multi-parent structures are not allowed.
defaultPortAssignerTreeLayoutPortAssigner
defaultSubtreePlacerSingleLayerSubtreePlacer
edgeLabelPlacementEdgeLabelPlacement.INTEGRATED
Edge labels are placed by the layout algorithm.
nodeLabelPlacementNodeLabelPlacement.CONSIDER
Node labels are considered.

See Also

Developer's Guide

Members

Show:

Constructors

Creates a new TreeLayout instance with default settings.

Parameters

Properties

Gets or sets whether or not multi-parent structures are allowed for this tree layout.
If multi-parent structures are allowed, the directed input graph may contain structures of multiple nodes that share the same predecessors as well as the same successors. All nodes belonging to such a structure are placed side by side and the incident edges are routed in a bus-style manner.

As for the different ways in which the ISubtreePlacers route their edges, multi-parent structures only work for some ISubtreePlacer implementations:

The specified ITreeLayoutPortAssigner is ignored. The ports are always placed at the center.

If the input graph contains groups, all nodes belonging to the same multi-parent structure must be associated with the same group node, i.e., it is not possible to assign these nodes to different group nodes.
final

Property Value

true if multi-parent structures are allowed, false otherwise

Default Value

The default value is: false
Multi-parent structures are not allowed.

Sample Graphs

See Also

Developer's Guide
API
multiParentDescriptors
Gets the ComponentLayout from the layoutStages of this instance.
If you need to replace the instance, modify the layoutStages stack using replace. If you want to remove a stage, consider disabling it instead.
readonlyfinal

Throws

Exception ({ name: 'InvalidOperationError' })
If there is no instance of the respective type in the layoutStages.
Gets or sets the default ITreeLayoutPortAssigner used for those nodes that do not have an individual port assigner specified.
An ITreeLayoutPortAssigner can be assigned individually for the nodes using the layout data property portAssigners.
final

Property Value

the default TreeLayoutPortAssigner instance

Throws

Exception ({ name: 'ArgumentError' })
if the default ITreeLayoutPortAssigner is set to null

Default Value

The default value is: TreeLayoutPortAssigner

See Also

API
portAssigners
Gets or sets the default ISubtreePlacer instance that arranges all subtrees of local roots that do not have an individual subtree placer assigned.
To define individual subtree placers for each local root node, use the layout data property subtreePlacers.
final

Property Value

the default ISubtreePlacer instance

Throws

Exception ({ name: 'ArgumentError' })
if the default ISubtreePlacer is set to null

Default Value

The default value is: SingleLayerSubtreePlacer

See Also

Developer's Guide
API
subtreePlacers
Gets or sets how the layout handles the position of edge labels.
conversionfinal

Property Value

INTEGRATED if the layout algorithm places the edge labels avoiding overlaps, IGNORE if the edge labels are ignored by the layout algorithm, and GENERIC if the edge labels are placed by the GenericLabeling algorithm subsequently.

Default Value

The default value is: EdgeLabelPlacement.INTEGRATED
Edge labels are placed by the layout algorithm.

Sample Graphs

ShownSetting: IGNORE

See Also

Developer's Guide
Gets or sets whether or not to consider the initial coordinates of the graph elements.
This has an effect only if the defaultSubtreePlacer or the subtreePlacers are IFromSketchSubtreePlacers. It is possible to define a childOrder in addition which is applied after the from-sketch phase.
final

Default Value

The default value is: false
The existing drawing is not used as a sketch.

See Also

Developer's Guide
Gets or sets the layoutOrientation of this layout algorithm.
conversionfinal
Gets or sets how the layout handles the position of node labels.
conversionfinal

Property Value

CONSIDER if the layout algorithm takes the position and sizes of the node labels into account, IGNORE if the node labels are ignored by the layout algorithm, and GENERIC if the node labels are placed by the GenericLabeling algorithm subsequently.

Default Value

The default value is: NodeLabelPlacement.CONSIDER
Node labels are considered.

Sample Graphs

ShownSetting: IGNORE

See Also

Developer's Guide
Gets the ParallelEdgeRouter from the layoutStages of this instance.
If you need to replace the instance, modify the layoutStages stack using replace. If you want to remove a stage, consider disabling it instead.
readonlyfinal

Throws

Exception ({ name: 'InvalidOperationError' })
If there is no instance of the respective type in the layoutStages
Gets the SelfLoopRouter from the layoutStages of this instance.
If you need to replace the instance, modify the layoutStages stack using replace. If you want to remove a stage, consider disabling it instead.
readonlyfinal

Throws

Exception ({ name: 'InvalidOperationError' })
If there is no instance of the respective type in the layoutStages
Gets the TreeReductionStage from the layoutStages of this instance.
If you need to replace the instance, modify the layoutStages stack using replace. If you want to remove a stage, consider disabling it instead.
readonlyfinal

Throws

Exception ({ name: 'InvalidOperationError' })
If there is no instance of the respective type in the layoutStages

Methods

Calculates a tree layout of the graph.
In contrast to applyLayoutCore, graph and layout algorithm are prepared for an independent layout run.
The given graph will not be copied during the layout process and the layout will be immediately applied to the given graph.

Parameters

graph: LayoutGraph
the input graph
Arranges the given graph as a tree.
protectedfinal

Parameters

graph: LayoutGraph
The input graph
Returns an instance of LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel> that can be used to perform item-specific configurations for the TreeLayout.
The generic type arguments of the created layout data are compatible with instances of LayoutGraph, but the layout data is not bound to a specific graph instance. Therefore, the created layout data still has to be passed as an argument of applyLayout in order to be applied.

Parameters

graph: LayoutGraph
the graph that determines the generic type arguments of the created layout data

Return Value

TreeLayoutData<LayoutNode, LayoutEdge, LayoutNodeLabel, LayoutEdgeLabel>
an instance of layout data that can be used to perform item-specific configurations for the given TreeLayout.
Returns an instance of LayoutData<TNode, TEdge, TNodeLabel, TEdgeLabel> that can be used to perform item-specific configurations for the TreeLayout.
The generic type arguments of the created layout data are compatible with instances of IGraph, but the layout data is not bound to a specific graph instance. Therefore, the created layout data still has to be passed as an argument of applyLayout in order to be applied.
This method is not available unless the module view-layout-bridge is loaded. Either load the module 'view-layout-bridge' explicitly or ensure that the LayoutExecutor type is available at runtime.

Parameters

graph?: IGraph
the graph that determines the generic type arguments of the created layout data

Return Value

TreeLayoutData<INode, IEdge, ILabel, ILabel>
an instance of layout data that can be used to perform item-specific configurations for the given TreeLayout.

Constants

All constants are filtered. Go to Filters.