public class ClassicTreeLayout extends MultiStageLayout
ClassicTreeLayout
is designed to arrange directed and undirected trees that have a unique
root node. All children are placed below their parent in relation to the main layout direction. The edges of the graph
are routed as straight-line segments or in an orthogonal bus-like fashion.
Tree layout algorithms are commonly used for visualizing relational data and for producing diagrams of high quality that are able to reveal possible hierarchic properties of the graph. More precisely, they find applications in dataflow analysis, software engineering, bioinformatics and business administration.
A Dendrogram A graph containing group nodes Left-to-right layout with global layering
The layout algorithm starts from the root and recursively assigns coordinates to all tree nodes. In this manner, leaf nodes will be placed first, while each parent node is placed centered above its children.
The layout algorithm supports custom sorting of sibling nodes by using a specific NodeOrderComparator
. Each tree
node may have an individual NodeOrderComparator
that is stored in a IDataProvider
registered with the
graph with NodeOrderComparator.NODE_ORDER_COMPARABLE_DPKEY
. If this NodeOrderComparator
uses the initial
coordinates of the nodes, it allows the incremental insertion of child nodes while keeping the relative locations of the
other nodes.
A custom node can be defined as root of the tree using a IDataProvider
registered with the graph with key
SELECTED_ROOT_DPKEY
.
ClassicTreeLayout
can be configured to
reserve space for node labels
. It can also place 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 a PreferredPlacementDescriptor
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 IDataProvider
key
GroupingKeys.MINIMUM_NODE_SIZE_DPKEY
.
This layout algorithm can only handle graphs with a tree structure. To apply it to a general graph, a TreeReductionStage
can be appended. 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.
Modifier and Type | Field and Description |
---|---|
static NodeDpKey<Boolean> |
SELECTED_ROOT_DPKEY
A
DataProvider key for marking the node that will be used as root node of the tree.
|
Constructor and Description |
---|
ClassicTreeLayout()
Creates a new
ClassicTreeLayout instance with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayoutCore(LayoutGraph graph)
Arranges the given graph as a tree.
|
double |
getBusAlignment()
Gets the vertical bus alignment for orthogonally routed edge buses.
|
Comparator<Object> |
getComparator()
Gets the
Comparator instance that is used for sorting the outgoing edges of each node of the tree. |
EdgeRoutingStyle |
getEdgeRoutingStyle()
Gets the edge routing style used by this layout algorithm.
|
LeafPlacement |
getLeafPlacement()
Gets the layout policy for leaf nodes.
|
double |
getMinimumLayerDistance()
Gets the minimum distance between two adjacent layers.
|
double |
getMinimumNodeDistance()
Gets the minimum horizontal distance between adjacent nodes within the same layer.
|
AbstractRotatableNodePlacer.Matrix |
getModificationMatrix()
Gets the modification matrix used for rotating / mirroring the layout.
|
PortStyle |
getPortStyle()
Gets the port assignment policy that will be applied.
|
double |
getVerticalAlignment()
Gets the vertical alignment of the nodes within their corresponding layers.
|
boolean |
isGlobalLayeringEnforced()
Gets whether or not a global layering is enforced, that is, each node spans exactly one layer.
|
boolean |
isGroupingSupported()
Gets whether or not group nodes are handled by the layout algorithm.
|
boolean |
isIntegratedEdgeLabelingEnabled()
Gets whether or not the layout algorithm reserves space for edge labels and places them.
|
boolean |
isNodeLabelConsiderationEnabled()
Gets whether or not the layout algorithm reserves space for node labels.
|
void |
setBusAlignment(double value)
Sets the vertical bus alignment for orthogonally routed edge buses.
|
void |
setComparator(Comparator<Object> value)
Sets the
Comparator instance that is used for sorting the outgoing edges of each node of the tree. |
void |
setComponentLayoutEnabled(boolean value)
Sets whether or not the
ILayoutStage used for arranging the components of the graph is activated. |
void |
setEdgeRoutingStyle(EdgeRoutingStyle value)
Sets the edge routing style used by this layout algorithm.
|
void |
setGlobalLayeringEnforced(boolean value)
Sets whether or not a global layering is enforced, that is, each node spans exactly one layer.
|
void |
setGroupingSupported(boolean value)
Sets whether or not group nodes are handled by the layout algorithm.
|
void |
setIntegratedEdgeLabelingEnabled(boolean value)
Sets whether or not the layout algorithm reserves space for edge labels and places them.
|
void |
setLeafPlacement(LeafPlacement value)
Sets the layout policy for leaf nodes.
|
void |
setMinimumLayerDistance(double value)
Sets the minimum distance between two adjacent layers.
|
void |
setMinimumNodeDistance(double value)
Sets the minimum horizontal distance between adjacent nodes within the same layer.
|
void |
setModificationMatrix(AbstractRotatableNodePlacer.Matrix value)
Sets the modification matrix used for rotating / mirroring the layout.
|
void |
setNodeLabelConsiderationEnabled(boolean value)
Sets whether or not the layout algorithm reserves space for node labels.
|
void |
setParallelEdgeRouterEnabled(boolean value)
Sets whether or not the
ILayoutStage used for routing parallel edges is activated. |
void |
setPortStyle(PortStyle value)
Sets the port assignment policy that will be applied.
|
void |
setSelfLoopRouterEnabled(boolean value)
Sets whether or not the
ILayoutStage used for routing self-loops is activated. |
void |
setVerticalAlignment(double value)
Sets the vertical alignment of the nodes within their corresponding layers.
|
appendStage, applyLayout, checkNodeSize, disableAllStages, getComponentLayout, getHideGroupsStage, getLabeling, getLayoutOrientation, getOrientationLayout, getParallelEdgeRouter, getSelfLoopRouter, getSubgraphLayout, isComponentLayoutEnabled, isHideGroupsStageEnabled, isLabelingEnabled, isOrientationLayoutEnabled, isParallelEdgeRouterEnabled, isSelfLoopRouterEnabled, isSubgraphLayoutEnabled, prependStage, removeStage, setComponentLayout, setHideGroupsStage, setHideGroupsStageEnabled, setLabeling, setLabelingEnabled, setLayoutOrientation, setOrientationLayout, setOrientationLayoutEnabled, setParallelEdgeRouter, setSelfLoopRouter, setSubgraphLayout, setSubgraphLayoutEnabled
public ClassicTreeLayout()
ClassicTreeLayout
instance with default settings.public void applyLayoutCore(LayoutGraph graph)
applyLayoutCore
in class MultiStageLayout
graph
- the input graphpublic double getBusAlignment()
The bus alignment determines the relative position of an edge bus between two subsequent layers. The value of this
property must lie within the interval [0,1]
where:
0
places the bus at the top, directly below the parent node.0.5
places the bus in the middle between parent and child nodes.1
places the bus at the bottom, directly above the child nodes.IllegalArgumentException
- if busAlignment
is not in [0,1]
EdgeRoutingStyle.ORTHOGONAL
layout style with global layering
enforced.EdgeRoutingStyle.ORTHOGONAL
layout style with child placement policy
LeafPlacement.ALL_LEAVES_ON_SAME_LAYER
.
[0,1]
setEdgeRoutingStyle(EdgeRoutingStyle)
,
setGlobalLayeringEnforced(boolean)
,
setLeafPlacement(LeafPlacement)
,
setBusAlignment(double)
public Comparator<Object> getComparator()
Comparator
instance that is used for sorting the outgoing edges of each node of the tree.
This comparator defines the relative order of the child nodes in the layout.
Comparator
. An implementation that compares the x-coordinates of the nodes.Comparator
instancesetComparator(Comparator)
public EdgeRoutingStyle getEdgeRoutingStyle()
If EdgeRoutingStyle.PLAIN
is set, the edges will be routed as straight-line segments. If EdgeRoutingStyle.ORTHOGONAL
is set, all edges will be routed orthogonally in a bus-like fashion.
IllegalArgumentException
- if an invalid layout style is providedEdgeRoutingStyle.PLAIN
. Edges are routed as straight-line segments.EdgeRoutingStyle.PLAIN
or EdgeRoutingStyle.ORTHOGONAL
setEdgeRoutingStyle(EdgeRoutingStyle)
public LeafPlacement getLeafPlacement()
IllegalArgumentException
- if the specified policy is unknownLeafPlacement.SIBLINGS_ON_SAME_LAYER
. Sibling nodes are placed on the same layer.setLeafPlacement(LeafPlacement)
public double getMinimumLayerDistance()
IllegalArgumentException
- if the given distance is negativesetMinimumLayerDistance(double)
public double getMinimumNodeDistance()
IllegalArgumentException
- if the given distance is negativesetMinimumNodeDistance(double)
public AbstractRotatableNodePlacer.Matrix getModificationMatrix()
AbstractRotatableNodePlacer.Matrix.DEFAULT
setModificationMatrix(AbstractRotatableNodePlacer.Matrix)
public PortStyle getPortStyle()
PortStyle.NODE_CENTER
. Ports are placed at the center of the nodes.setPortStyle(PortStyle)
public double getVerticalAlignment()
The value for the vertical alignment is considered as relative to the height of the corresponding layer, which is determined by the maximum height of the nodes that belong to the particular layer.
The value of this property must lie within the interval [0,1]
, where:
0
corresponds to top-alignment.0.5
corresponds to center-alignment.1
corresponds to bottom-alignment.IllegalArgumentException
- if vertical alignment value does not lie within [0,1]
global layering
is not enforced, the value of this property is usually ignored.[0,1]
setGlobalLayeringEnforced(boolean)
,
setVerticalAlignment(double)
public boolean isGlobalLayeringEnforced()
If it is enabled, the algorithm ensures that nodes never span more than one layer. Otherwise, nodes with larger size might span two or more layers such that a more compact layout is produced.
This setting can be advantageous, if the hierarchical structure of the tree should be emphasized.
false
. Global layering is disabled.true
if global layering is enforced, false
otherwisegetVerticalAlignment()
,
setVerticalAlignment(double)
,
setGlobalLayeringEnforced(boolean)
public boolean isGroupingSupported()
true
. Grouping is enabled.true
if grouping is supported, false
otherwiseMultiStageLayout.setHideGroupsStageEnabled(boolean)
,
setGroupingSupported(boolean)
public boolean isIntegratedEdgeLabelingEnabled()
To define the desired placement for each label add a PreferredPlacementDescriptor
on
IEdgeLabelLayout
.
This method is a convenience method that assures that the label layouter
is of
type LabelLayoutTranslator
and EdgeLabelTranslationEnabled
is set to true
.
FreeEdgeLabelLayoutModel
as the label model for the edges.labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Integrated edge labeling is disabled.true
if integrated edge labeling is enabled, false
otherwisesetIntegratedEdgeLabelingEnabled(boolean)
public boolean isNodeLabelConsiderationEnabled()
labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Node labels are not considered.true
if node labels are considered, false
otherwisesetNodeLabelConsiderationEnabled(boolean)
public void setBusAlignment(double value)
The bus alignment determines the relative position of an edge bus between two subsequent layers. The value of this
property must lie within the interval [0,1]
where:
0
places the bus at the top, directly below the parent node.0.5
places the bus in the middle between parent and child nodes.1
places the bus at the bottom, directly above the child nodes.IllegalArgumentException
- if busAlignment
is not in [0,1]
EdgeRoutingStyle.ORTHOGONAL
layout style with global layering
enforced.EdgeRoutingStyle.ORTHOGONAL
layout style with child placement policy
LeafPlacement.ALL_LEAVES_ON_SAME_LAYER
.
value
- a value from the interval [0,1]
setEdgeRoutingStyle(EdgeRoutingStyle)
,
setGlobalLayeringEnforced(boolean)
,
setLeafPlacement(LeafPlacement)
,
getBusAlignment()
public void setComparator(Comparator<Object> value)
Comparator
instance that is used for sorting the outgoing edges of each node of the tree.
This comparator defines the relative order of the child nodes in the layout.
Comparator
. An implementation that compares the x-coordinates of the nodes.value
- a Comparator
instancegetComparator()
public void setComponentLayoutEnabled(boolean value)
ILayoutStage
used for arranging the components of the graph is activated.setComponentLayoutEnabled
in class MultiStageLayout
ClassicTreeLayout
can only handle single components. Disabling ComponentLayout
will lead to errors during execution.true
. The stage that arranges connected graph components is activated.value
- true
if the stage that arranges the graph components is activated, false
otherwiseMultiStageLayout.isComponentLayoutEnabled()
,
MultiStageLayout.setComponentLayout(ILayoutStage)
,
ComponentLayout
public void setEdgeRoutingStyle(EdgeRoutingStyle value)
If EdgeRoutingStyle.PLAIN
is set, the edges will be routed as straight-line segments. If EdgeRoutingStyle.ORTHOGONAL
is set, all edges will be routed orthogonally in a bus-like fashion.
IllegalArgumentException
- if an invalid layout style is providedEdgeRoutingStyle.PLAIN
. Edges are routed as straight-line segments.value
- one of EdgeRoutingStyle.PLAIN
or EdgeRoutingStyle.ORTHOGONAL
getEdgeRoutingStyle()
public void setGlobalLayeringEnforced(boolean value)
If it is enabled, the algorithm ensures that nodes never span more than one layer. Otherwise, nodes with larger size might span two or more layers such that a more compact layout is produced.
This setting can be advantageous, if the hierarchical structure of the tree should be emphasized.
false
. Global layering is disabled.value
- true
if global layering is enforced, false
otherwisegetVerticalAlignment()
,
setVerticalAlignment(double)
,
isGlobalLayeringEnforced()
public void setGroupingSupported(boolean value)
true
. Grouping is enabled.value
- true
if grouping is supported, false
otherwiseMultiStageLayout.setHideGroupsStageEnabled(boolean)
,
isGroupingSupported()
public void setIntegratedEdgeLabelingEnabled(boolean value)
To define the desired placement for each label add a PreferredPlacementDescriptor
on
IEdgeLabelLayout
.
This method is a convenience method that assures that the label layouter
is of
type LabelLayoutTranslator
and EdgeLabelTranslationEnabled
is set to true
.
FreeEdgeLabelLayoutModel
as the label model for the edges.labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Integrated edge labeling is disabled.value
- true
if integrated edge labeling is enabled, false
otherwiseisIntegratedEdgeLabelingEnabled()
public void setLeafPlacement(LeafPlacement value)
IllegalArgumentException
- if the specified policy is unknownLeafPlacement.SIBLINGS_ON_SAME_LAYER
. Sibling nodes are placed on the same layer.value
- one of the predefined layout policies for leaf nodesgetLeafPlacement()
public void setMinimumLayerDistance(double value)
IllegalArgumentException
- if the given distance is negativevalue
- the non-negative minimum distancegetMinimumLayerDistance()
public void setMinimumNodeDistance(double value)
IllegalArgumentException
- if the given distance is negativevalue
- the non-negative minimum distancegetMinimumNodeDistance()
public void setModificationMatrix(AbstractRotatableNodePlacer.Matrix value)
AbstractRotatableNodePlacer.Matrix.DEFAULT
value
- the current modification matrixgetModificationMatrix()
public void setNodeLabelConsiderationEnabled(boolean value)
labeling algorithm
will be
overwritten and when disabling it, any currently specified labeling algorithm will be disabled via property
LabelingEnabled
. Therefore, it is recommended to only use this
convenience property instead of manually changing the mentioned other properties.false
. Node labels are not considered.value
- true
if node labels are considered, false
otherwiseisNodeLabelConsiderationEnabled()
public void setParallelEdgeRouterEnabled(boolean value)
ILayoutStage
used for routing parallel edges is activated.setParallelEdgeRouterEnabled
in class MultiStageLayout
ClassicTreeLayout
cannot handle parallel edges. Disabling ParallelEdgeRouter
will lead to errors during execution.true
. The stage that routes parallel edges is activated.value
- true
if the stage responsible for routing parallel edges is activated, false
otherwiseMultiStageLayout.isParallelEdgeRouterEnabled()
,
MultiStageLayout.setParallelEdgeRouter(ILayoutStage)
,
ParallelEdgeRouter
public void setPortStyle(PortStyle value)
PortStyle.NODE_CENTER
. Ports are placed at the center of the nodes.value
- one of the predefined port assignment policiesgetPortStyle()
public void setSelfLoopRouterEnabled(boolean value)
ILayoutStage
used for routing self-loops is activated.setSelfLoopRouterEnabled
in class MultiStageLayout
ClassicTreeLayout
cannot handle self-loops. Disabling SelfLoopRouter
will lead
to errors during execution.true
. The stage that routes self-loops is activated.value
- true
if the stage responsible for routing self-loops is activated, false
otherwiseMultiStageLayout.isSelfLoopRouterEnabled()
,
MultiStageLayout.setSelfLoopRouter(ILayoutStage)
,
SelfLoopRouter
public void setVerticalAlignment(double value)
The value for the vertical alignment is considered as relative to the height of the corresponding layer, which is determined by the maximum height of the nodes that belong to the particular layer.
The value of this property must lie within the interval [0,1]
, where:
0
corresponds to top-alignment.0.5
corresponds to center-alignment.1
corresponds to bottom-alignment.IllegalArgumentException
- if vertical alignment value does not lie within [0,1]
global layering
is not enforced, the value of this property is usually ignored.value
- a value from the interval [0,1]
setGlobalLayeringEnforced(boolean)
,
getVerticalAlignment()