Search this API

y.layout.tree
Class HVTreeLayouter

java.lang.Object
  extended by y.layout.CanonicMultiStageLayouter
      extended by y.layout.tree.HVTreeLayouter
All Implemented Interfaces:
Layouter

public class HVTreeLayouter
extends CanonicMultiStageLayouter

The HVTreeLayouter arranges the subgraphs of a tree horizontally and vertically.

Layout Style

The child nodes in a subtree are either placed above or next to each other.

Example of a horizontal-vertical tree layout

Concept

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.

Features

SUBTREE_ORIENTATION can be used to register a DataProvider that specifies an orientation for each subtree. If no DataProvider is registered with this key, all subtrees are arranged horizontally.

A custom node can be defined as root of the tree using a DataProvider registered with the graph with key SELECTED_ROOT_DPKEY.

 

Field Summary
protected  LayoutGraph graph
          The layout graph being acted upon.
static java.lang.Object HORIZONTAL_SUBTREE
          A subtree orientation specifier indicating that the subtree rooted at the associated node should be arranged horizontally.
static java.lang.Object SELECTED_ROOT_DPKEY
          A DataProvider key for marking the node that will be used as root node of the tree.
static java.lang.Object SUBTREE_ORIENTATION
          A DataProvider key for specifying a horizontal or vertical orientation for each subtree
static java.lang.Object VERTICAL_SUBTREE
          A subtree orientation specifier indicating that the subtree rooted at the associated node should be arranged vertically.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
HVTreeLayouter()
          Creates a new HVTreeLayouter instance with default settings.
 
Method Summary
 boolean canLayoutCore(LayoutGraph graph)
          Accepts all graphs with a tree structure.
 void doLayoutCore(LayoutGraph graph)
          Arranges the tree in horizontal and vertical subtrees.
 java.util.Comparator getComparator()
          Returns the Comparator that will be used for sorting the outgoing edges of each local root in the tree before they are being arranged.
 double getHorizontalSpace()
          Returns the horizontal distance between adjacent nodes.
protected  NodeCursor getSuccessors(Node localRoot)
          Retrieves all children of the given local root.
 double getVerticalSpace()
          Returns the vertical distance between adjacent nodes.
protected  boolean isHorizontalRoot(Node localRoot)
          Determines whether or not the subtree rooted at the given node should be arranged horizontally.
protected  boolean isVerticalRoot(Node localRoot)
          Determines whether or not the subtree rooted at the given node should be arranged vertically.
 void setComparator(java.util.Comparator comparator)
          Specifies the Comparator that will be used for sorting the outgoing edges of each local root in the tree before they are being arranged.
 void setComponentLayouterEnabled(boolean enabled)
          Specifies whether or not the LayoutStage used for arranging the components of the graph is activated.
 void setGroupNodeHidingEnabled(boolean groupNodeHidingEnabled)
          Specifies whether or not the LayoutStage used for hiding group nodes is activated.
 void setHorizontalSpace(double distance)
          Specifies the horizontal distance between adjacent nodes.
 void setParallelEdgeLayouterEnabled(boolean enabled)
          Specifies whether or not the LayoutStage used for routing parallel edges is activated.
 void setSelfLoopLayouterEnabled(boolean enabled)
          Specifies whether or not the LayoutStage used for routing self-loops is activated.
 void setVerticalSpace(double distance)
          Specifies the vertical distance between adjacent nodes.
 
Methods inherited from class y.layout.CanonicMultiStageLayouter
appendStage, calcLayout, calcLayout, canLayout, checkGroupNodeSize, checkNodeSize, doLayout, doLayout, enableOnlyCore, getComponentLayouter, getGroupNodeHider, getLabelLayouter, getLayoutOrientation, getOrientationLayouter, getParallelEdgeLayouter, getSelfLoopLayouter, getSubgraphLayouter, isComponentLayouterEnabled, isGroupNodeHidingEnabled, isLabelLayouterEnabled, isOrientationLayouterEnabled, isParallelEdgeLayouterEnabled, isSelfLoopLayouterEnabled, isSubgraphLayouterEnabled, prependStage, removeStage, setComponentLayouter, setGroupNodeHider, setLabelLayouter, setLabelLayouterEnabled, setLayoutOrientation, setOrientationLayouter, setOrientationLayouterEnabled, setParallelEdgeLayouter, setSelfLoopLayouter, setSubgraphLayouter, setSubgraphLayouterEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUBTREE_ORIENTATION

public static final java.lang.Object SUBTREE_ORIENTATION
A DataProvider key for specifying a horizontal or vertical orientation for each subtree

 
If no DataProvider is registered with this key, then all subtrees are considered horizontal.

HORIZONTAL_SUBTREE

public static final java.lang.Object HORIZONTAL_SUBTREE
A subtree orientation specifier indicating that the subtree rooted at the associated node should be arranged horizontally.

Sample Graph:

VERTICAL_SUBTREE

public static final java.lang.Object VERTICAL_SUBTREE
A subtree orientation specifier indicating that the subtree rooted at the associated node should be arranged vertically.

Sample Graph:

SELECTED_ROOT_DPKEY

public static final java.lang.Object SELECTED_ROOT_DPKEY
A DataProvider key for marking the node that will be used as root node of the tree.


graph

protected LayoutGraph graph
The layout graph being acted upon.

Constructor Detail

HVTreeLayouter

public HVTreeLayouter()
Creates a new HVTreeLayouter instance with default settings.

Method Detail

setHorizontalSpace

public void setHorizontalSpace(double distance)
Specifies the horizontal distance between adjacent nodes.

The distance needs to be non-negative.

Default Value:
The default value is 10.
Parameters:
distance - the horizontal distance between nodes
Throws:
java.lang.IllegalArgumentException - if the specified distance is negative
Sample Graphs:

10

50

getHorizontalSpace

public double getHorizontalSpace()
Returns the horizontal distance between adjacent nodes.

The distance needs to be non-negative.

Returns:
the horizontal distance between nodes
See Also:
setHorizontalSpace(double)

setVerticalSpace

public void setVerticalSpace(double distance)
Specifies the vertical distance between adjacent nodes.

The distance needs to be non-negative.

Default Value:
The default value is 10.
Parameters:
distance - the vertical distance between nodes
Throws:
java.lang.IllegalArgumentException - if the specified distance is negative
Sample Graphs:

10

50

getVerticalSpace

public double getVerticalSpace()
Returns the vertical distance between adjacent nodes.

The distance needs to be non-negative.

Returns:
the vertical distance between nodes
See Also:
setVerticalSpace(double)

setComponentLayouterEnabled

public void setComponentLayouterEnabled(boolean enabled)
Specifies whether or not the LayoutStage used for arranging the components of the graph is activated.

Overrides:
setComponentLayouterEnabled in class CanonicMultiStageLayouter
 
HVTreeLayouter can only handle single components. Disabling ComponentLayouter will lead to errors during execution.
Default Value:
The default value is true. The stage that arranges connected graph components is activated.
Parameters:
enabled - true if the stage that arranges the graph components is activated, false otherwise
See Also:
CanonicMultiStageLayouter.isComponentLayouterEnabled(), CanonicMultiStageLayouter.setComponentLayouter(LayoutStage), ComponentLayouter

setGroupNodeHidingEnabled

public void setGroupNodeHidingEnabled(boolean groupNodeHidingEnabled)
Specifies whether or not the LayoutStage used for hiding group nodes is activated.

Overrides:
setGroupNodeHidingEnabled in class CanonicMultiStageLayouter
 
HVTreeLayouter cannot handle group nodes. Disabling GroupNodeHider will lead to errors during execution.
Default Value:
The default value is true. The stage responsible for hiding group nodes is activated.
Parameters:
groupNodeHidingEnabled - true if the stage used for hiding group nodes is activated, false otherwise
See Also:
CanonicMultiStageLayouter.isGroupNodeHidingEnabled(), CanonicMultiStageLayouter.setGroupNodeHider(LayoutStage), GroupNodeHider

setParallelEdgeLayouterEnabled

public void setParallelEdgeLayouterEnabled(boolean enabled)
Specifies whether or not the LayoutStage used for routing parallel edges is activated.

Overrides:
setParallelEdgeLayouterEnabled in class CanonicMultiStageLayouter
 
HVTreeLayouter cannot handle parallel edges. Disabling ParallelEdgeLayouter will lead to errors during execution.
Default Value:
The default value is true. The stage that routes parallel edges is activated.
Parameters:
enabled - true if the stage responsible for routing parallel edges is activated, false otherwise
See Also:
CanonicMultiStageLayouter.isParallelEdgeLayouterEnabled(), CanonicMultiStageLayouter.setParallelEdgeLayouter(LayoutStage), ParallelEdgeLayouter

setSelfLoopLayouterEnabled

public void setSelfLoopLayouterEnabled(boolean enabled)
Specifies whether or not the LayoutStage used for routing self-loops is activated.

Overrides:
setSelfLoopLayouterEnabled in class CanonicMultiStageLayouter
 
HVTreeLayouter cannot handle self-loops. Disabling SelfLoopLayouter will lead to errors during execution.
Default Value:
The default value is true. The stage that routes self-loops is activated.
Parameters:
enabled - true if the stage responsible for routing self-loops is activated, false otherwise
See Also:
CanonicMultiStageLayouter.isSelfLoopLayouterEnabled(), CanonicMultiStageLayouter.setSelfLoopLayouter(LayoutStage), SelfLoopLayouter

doLayoutCore

public void doLayoutCore(LayoutGraph graph)
Arranges the tree in horizontal and vertical subtrees.

Specified by:
doLayoutCore in class CanonicMultiStageLayouter
Parameters:
graph - the input graph
Throws:
WrongGraphStructure - if the input graph is not a tree

canLayoutCore

public boolean canLayoutCore(LayoutGraph graph)
Accepts all graphs with a tree structure.

Specified by:
canLayoutCore in class CanonicMultiStageLayouter
Parameters:
graph - the input graph
Returns:
true if the given graph is a tree, false otherwise
See Also:
Trees.isTree(y.base.Graph)

isVerticalRoot

protected boolean isVerticalRoot(Node localRoot)
Determines whether or not the subtree rooted at the given node should be arranged vertically.

The orientation is retrieved from a DataProvider registered with SUBTREE_ORIENTATION. If no orientation is specified for this node, it is not a vertical root.

This method is called by doLayoutCore(LayoutGraph), before arranging a subtree. It may be overridden to customize the selection of vertical subtrees.

Parameters:
localRoot - the local root of a subtree
Returns:
true if the subtree of the local root is vertical, false otherwise
See Also:
isHorizontalRoot(Node)

isHorizontalRoot

protected boolean isHorizontalRoot(Node localRoot)
Determines whether or not the subtree rooted at the given node should be arranged horizontally.

The orientation is retrieved from a DataProvider registered with SUBTREE_ORIENTATION. If no orientation is specified for this node, it is not a horizontal root.

This method is called by doLayoutCore(LayoutGraph), before arranging a subtree. It may be overridden to customize the selection of horizontal subtrees.

Parameters:
localRoot - the local root of a subtree
Returns:
true if the subtree of the local root is horizontal, false otherwise
See Also:
isVerticalRoot(Node)

getSuccessors

protected NodeCursor getSuccessors(Node localRoot)
Retrieves all children of the given local root.

This method is called by doLayoutCore(LayoutGraph) to arrange the subtrees below the local root.

Parameters:
localRoot - the root of a subtree
Returns:
all successors of the given node

getComparator

public java.util.Comparator getComparator()
Returns the Comparator that will be used for sorting the outgoing edges of each local root in the tree before they are being arranged.

Returns:
a Comparator or null if the default order should be used
See Also:
setComparator(Comparator)

setComparator

public void setComparator(java.util.Comparator comparator)
Specifies the Comparator that will be used for sorting the outgoing edges of each local root in the tree before they are being arranged.

Default Value:
The default value is null. Only the built-in logic of the layout algorithm is used.
Parameters:
comparator - a Comparator or null if the default order should be used

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.