public class AspectRatioTreeLayout extends MultiStageLayout
AspectRatioTreeLayout
arranges tree graphs in a compact fashion.
Example layout with an aspect ratio of 0.5
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 child nodes.
The aspect ratio of each subtree can be specified individually. A IDataProvider
registered with SUBTREE_ASPECT_RATIO_DPKEY
returns the aspect ratio for each local root node.
A custom node can be defined as root of the tree using a IDataProvider
registered with the graph with key
SELECTED_ROOT_DPKEY
.
Modifier and Type | Field and Description |
---|---|
protected LayoutGraph |
graph
The input graph this algorithm is handling.
|
static NodeDpKey<Object> |
ROOT_PLACEMENT_DPKEY
A
DataProvider key for specifying the placement of each subtree root
If no root placement is specified for one of the subtree roots, the default root placement
will be used. |
static NodeDpKey<Boolean> |
SELECTED_ROOT_DPKEY
A
DataProvider key for marking the node that will be used as root node of the tree.
|
static NodeDpKey<Double> |
SUBTREE_ASPECT_RATIO_DPKEY
A
DataProvider key for specifying a target aspect ratio for each subtree
The aspect ratio needs to be greater than 0 . |
static NodeDpKey<Object> |
SUBTREE_ROUTING_POLICY_DPKEY
A
DataProvider key for specifying the routing direction for each subtree root
The children in a subtree are arranged either horizontally or vertically. |
Constructor and Description |
---|
AspectRatioTreeLayout()
Creates a new
AspectRatioTreeLayout instance with default settings. |
Modifier and Type | Method and Description |
---|---|
void |
applyLayoutCore(LayoutGraph graph)
Arranges the given graph considering the specified
aspect ratio . |
protected void |
createBends(IEdgeLayout edgeLayout,
Node localRoot,
Node child,
RootPlacement rootPlacement,
SubtreeArrangement routingPolicy)
Adds bends to the given
IEdgeLayout . |
double |
getAspectRatio()
Gets the default aspect ratio for this
AspectRatioTreeLayout . |
protected double |
getAspectRatio(Node localRoot)
Retrieves the aspect ratio for the subtree that is rooted at the given node.
|
double |
getBendDistance()
Gets the preferred distance between any two bends of an edge.
|
Comparator<Object> |
getComparator()
Gets the
Comparator that will be used for sorting the outgoing edges of
each local root in the tree before they are being arranged. |
double |
getHorizontalDistance()
Gets the horizontal distance between adjacent nodes.
|
RootPlacement |
getRootPlacement()
Gets the desired placement of the tree's root node.
|
protected RootPlacement |
getRootPlacement(Object localRoot)
Retrieves the root placement for the subtree that is rooted at the given node.
|
SubtreeArrangement |
getSubtreeArrangement()
Gets how the children of a local root are arranged and how the edges between them are routed.
|
protected SubtreeArrangement |
getSubtreeArrangement(Object localRoot)
Retrieves the routing for the subtree that is rooted at the given node.
|
protected INodeCursor |
getSuccessors(Node localRoot)
Retrieves all children of the given local root.
|
double |
getVerticalDistance()
Gets the vertical distance between adjacent nodes.
|
void |
setAspectRatio(double value)
Sets the default aspect ratio for this
AspectRatioTreeLayout . |
void |
setBendDistance(double value)
Sets the preferred distance between any two bends of an edge.
|
void |
setComparator(Comparator<Object> value)
Sets the
Comparator that will be used for sorting the outgoing edges of
each local root in the tree before they are being arranged. |
void |
setComponentLayoutEnabled(boolean value)
Sets whether or not the
ILayoutStage used for arranging the components of the graph is activated. |
void |
setHideGroupsStageEnabled(boolean value)
Sets whether or not the
ILayoutStage used for hiding group nodes is activated. |
void |
setHorizontalDistance(double value)
Sets the horizontal distance between adjacent nodes.
|
void |
setParallelEdgeRouterEnabled(boolean value)
Sets whether or not the
ILayoutStage used for routing parallel edges is activated. |
void |
setRootPlacement(RootPlacement value)
Sets the desired placement of the tree's root node.
|
void |
setSelfLoopRouterEnabled(boolean value)
Sets whether or not the
ILayoutStage used for routing self-loops is activated. |
void |
setSubtreeArrangement(SubtreeArrangement value)
Sets how the children of a local root are arranged and how the edges between them are routed.
|
void |
setVerticalDistance(double value)
Sets the vertical distance between adjacent nodes.
|
appendStage, applyLayout, checkNodeSize, disableAllStages, getComponentLayout, getHideGroupsStage, getLabeling, getLayoutOrientation, getOrientationLayout, getParallelEdgeRouter, getSelfLoopRouter, getSubgraphLayout, isComponentLayoutEnabled, isHideGroupsStageEnabled, isLabelingEnabled, isOrientationLayoutEnabled, isParallelEdgeRouterEnabled, isSelfLoopRouterEnabled, isSubgraphLayoutEnabled, prependStage, removeStage, setComponentLayout, setHideGroupsStage, setLabeling, setLabelingEnabled, setLayoutOrientation, setOrientationLayout, setOrientationLayoutEnabled, setParallelEdgeRouter, setSelfLoopRouter, setSubgraphLayout, setSubgraphLayoutEnabled
protected LayoutGraph graph
public static final NodeDpKey<Object> ROOT_PLACEMENT_DPKEY
DataProvider
key for specifying the placement of each subtree root
If no root placement is specified for one of the subtree roots, the default root placement
will be used.
public static final NodeDpKey<Boolean> SELECTED_ROOT_DPKEY
DataProvider
key for marking the node that will be used as root node of the tree.
public static final NodeDpKey<Double> SUBTREE_ASPECT_RATIO_DPKEY
DataProvider
key for specifying a target aspect ratio for each subtree
The aspect ratio needs to be greater than 0
.
1
: width and height of the layout should be the same0
and 1
: the height of the layout should be greater than its width1
: the width of the layout should be greater than its height
If no specific ratio is defined for a subtree, the layout algorithm falls back to the default
aspect ratio
.
public static final NodeDpKey<Object> SUBTREE_ROUTING_POLICY_DPKEY
DataProvider
key for specifying the routing direction for each subtree root
The children in a subtree are arranged either horizontally or vertically. The edges are routed to the top of the child
nodes or at the side, respectively. Directions depend on the layout orientation
and refer to LayoutOrientation.TOP_TO_BOTTOM
for this description.
If no specific routing policy is specified for a subtree root, the layout algorithm uses the default
routing direction
.
public AspectRatioTreeLayout()
AspectRatioTreeLayout
instance with default settings.public void applyLayoutCore(LayoutGraph graph)
aspect ratio
.applyLayoutCore
in class MultiStageLayout
InvalidGraphStructureException
- if the input graph is not a treegraph
- the input graphprotected void createBends(IEdgeLayout edgeLayout, Node localRoot, Node child, RootPlacement rootPlacement, SubtreeArrangement routingPolicy)
IEdgeLayout
.
This method is called by applyLayoutCore(LayoutGraph)
for each edge, after the nodes are placed, to route the
path of the edges. It may be overridden to apply a custom routing style.
edgeLayout
- the layout of the edge that is routedlocalRoot
- the local root of the subtreechild
- the child connected to the local root with the given edgerootPlacement
- the placement specifier of the local rootroutingPolicy
- the direction specifier for the routingpublic double getAspectRatio()
AspectRatioTreeLayout
.
This aspect ratio is used for all subtrees for which there is no specific aspect ratio defined in a IDataProvider
registered with SUBTREE_ASPECT_RATIO_DPKEY
.
The aspect ratio needs to have a positive value.
IllegalArgumentException
- if the specified aspect ratio is 0
or negativesetAspectRatio(double)
protected double getAspectRatio(Node localRoot)
If there is an individual aspect ratio for the subtree provided by a IDataProvider
registered with key
SUBTREE_ASPECT_RATIO_DPKEY
, that ratio will be returned. Otherwise, the default aspect ratio
will be returned.
This method is called by applyLayoutCore(LayoutGraph)
before a subtree is arranged. It may be overridden to use
another approach to define the aspect ratio for subtrees.
localRoot
- the root node of the subtreeSUBTREE_ASPECT_RATIO_DPKEY
,
getAspectRatio()
public double getBendDistance()
Additionally, the preferred bend distance governs the distance between the first and last edges and the corresponding ports.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativesetBendDistance(double)
public Comparator<Object> getComparator()
Comparator
that will be used for sorting the outgoing edges
of
each local root in the tree before they are being arranged.Comparator
, if the nodes (or better their whole subtrees) have equal sizes.null
. Only the built-in logic of the layout algorithm is used.Comparator
or null
if the default order should be usedsetComparator(Comparator)
public double getHorizontalDistance()
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativesetHorizontalDistance(double)
public RootPlacement getRootPlacement()
IllegalArgumentException
- if an unknown placement specifiers is setRootPlacement.CORNER
RootPlacement.TOP
, RootPlacement.CORNER
, RootPlacement.CORNER_SIDE
or
RootPlacement.CORNER_TOP
setRootPlacement(RootPlacement)
protected RootPlacement getRootPlacement(Object localRoot)
Either an individual root placement for the subtree (defined via a IDataProvider
registered with
ROOT_PLACEMENT_DPKEY
), or if there is none, the default root placement
is
returned.
This method is called by applyLayoutCore(LayoutGraph)
after a subtree is arranged to align the local root node.
It may be overridden to use another approach to define the root placement for a subtree.
localRoot
- the root of the subtreeROOT_PLACEMENT_DPKEY
,
getRootPlacement()
public SubtreeArrangement getSubtreeArrangement()
IllegalArgumentException
- if the specified routing policy is unknownSubtreeArrangement.HORIZONTAL
SubtreeArrangement.HORIZONTAL
or SubtreeArrangement.VERTICAL
setSubtreeArrangement(SubtreeArrangement)
protected SubtreeArrangement getSubtreeArrangement(Object localRoot)
Either an individual routing for the subtree (defined via a IDataProvider
registered with
SUBTREE_ROUTING_POLICY_DPKEY
), or if there is none, the default routing
is
returned.
This method is called by applyLayoutCore(LayoutGraph)
to determine the direction of the subtrees. It may be
overridden to use another approach to define the routing for a subtree.
localRoot
- the root of the subtreeSUBTREE_ROUTING_POLICY_DPKEY
,
getSubtreeArrangement()
protected INodeCursor getSuccessors(Node localRoot)
This method is called by applyLayoutCore(LayoutGraph)
to arrange the subtrees below the local root.
localRoot
- the root of a subtreepublic double getVerticalDistance()
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativesetVerticalDistance(double)
public void setAspectRatio(double value)
AspectRatioTreeLayout
.
This aspect ratio is used for all subtrees for which there is no specific aspect ratio defined in a IDataProvider
registered with SUBTREE_ASPECT_RATIO_DPKEY
.
The aspect ratio needs to have a positive value.
IllegalArgumentException
- if the specified aspect ratio is 0
or negativevalue
- the aspect ratiogetAspectRatio()
public void setBendDistance(double value)
Additionally, the preferred bend distance governs the distance between the first and last edges and the corresponding ports.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativevalue
- the preferred bend distancegetBendDistance()
public void setComparator(Comparator<Object> value)
Comparator
that will be used for sorting the outgoing edges
of
each local root in the tree before they are being arranged.Comparator
, if the nodes (or better their whole subtrees) have equal sizes.null
. Only the built-in logic of the layout algorithm is used.value
- a Comparator
or null
if the default order should be usedgetComparator()
public void setComponentLayoutEnabled(boolean value)
ILayoutStage
used for arranging the components of the graph is activated.setComponentLayoutEnabled
in class MultiStageLayout
AspectRatioTreeLayout
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 setHideGroupsStageEnabled(boolean value)
ILayoutStage
used for hiding group nodes is activated.setHideGroupsStageEnabled
in class MultiStageLayout
AspectRatioTreeLayout
cannot handle group nodes. Disabling HideGroupsStage
will lead to errors during
execution.true
. The stage responsible for hiding group nodes is activated.value
- true
if the stage used for hiding group nodes is activated, false
otherwiseMultiStageLayout.isHideGroupsStageEnabled()
,
MultiStageLayout.setHideGroupsStage(ILayoutStage)
,
HideGroupsStage
public void setHorizontalDistance(double value)
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativevalue
- the horizontal distance between nodesgetHorizontalDistance()
public void setParallelEdgeRouterEnabled(boolean value)
ILayoutStage
used for routing parallel edges is activated.setParallelEdgeRouterEnabled
in class MultiStageLayout
AspectRatioTreeLayout
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 setRootPlacement(RootPlacement value)
IllegalArgumentException
- if an unknown placement specifiers is setRootPlacement.CORNER
value
- one of RootPlacement.TOP
, RootPlacement.CORNER
, RootPlacement.CORNER_SIDE
or
RootPlacement.CORNER_TOP
getRootPlacement()
public void setSelfLoopRouterEnabled(boolean value)
ILayoutStage
used for routing self-loops is activated.setSelfLoopRouterEnabled
in class MultiStageLayout
AspectRatioTreeLayout
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 setSubtreeArrangement(SubtreeArrangement value)
IllegalArgumentException
- if the specified routing policy is unknownSubtreeArrangement.HORIZONTAL
value
- one of SubtreeArrangement.HORIZONTAL
or SubtreeArrangement.VERTICAL
getSubtreeArrangement()
public void setVerticalDistance(double value)
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativevalue
- the vertical distance between nodesgetVerticalDistance()