Search this API

y.layout.hierarchic
Class HierarchicLayouter

java.lang.Object
  extended by y.layout.CanonicMultiStageLayouter
      extended by y.layout.hierarchic.HierarchicLayouter
All Implemented Interfaces:
Layouter, PortConstraintKeys
Direct Known Subclasses:
HierarchicGroupLayouter

public class HierarchicLayouter
extends CanonicMultiStageLayouter
implements PortConstraintKeys

This class implements a layout algorithm for drawing directed graphs in a hierarchic way.

The algorithm places nodes in different horizontal layers, in such a way that most edges in the graph run from top to bottom.

Here is a sample output of the algorithm using top to bottom orientation and PENDULUM layout style.

HierarchicLayouter can handle port constraints. See classes PortConstraint and PortConstraintKeys on how to setup port constraint information for this algorithm.

HierarchicLayouter can consider edge label data when laying out a graph. That means that the layout of edge labels will be part of the resulting layout and the layout of nodes and edges is chosen in such a way that the edge labels do not conflict with the rest of the layout. See classes LabelLayoutData, LabelLayoutConstants LabelLayoutKeys and LabelLayoutTranslator on how to setup the integrated edge labeling algorithm.


Field Summary
static byte LAYERING_BFS
          Layering strategy specifier.
static byte LAYERING_FROM_SKETCH
          Layering strategy specifier.
static byte LAYERING_HIERARCHICAL_DOWNSHIFT
          Layering strategy specifier.
static byte LAYERING_HIERARCHICAL_OPTIMAL
          Layering strategy specifier.
static byte LAYERING_HIERARCHICAL_TIGHT_TREE
          Layering strategy specifier.
static byte LAYERING_HIERARCHICAL_TOPMOST
          Layering strategy specifier.
static byte LAYERING_STRATEGY_UNKNOWN
          Dummy layering strategy specifier.
static byte LAYERING_USER_DEFINED
          Layering strategy specifier.
static byte LINEAR_SEGMENTS
          Layout style specifier.
static byte MEDIAN_SIMPLEX
          Layout style specifier.
static byte PENDULUM
          Layout style specifier.
static byte POLYLINE
          Layout style specifier.
static byte ROUTE_ORTHOGONAL
          Edge routing style specifier.
static byte ROUTE_POLYLINE
          Edge routing style specifier.
static byte SIMPLEX
          Layout style specifier.
static byte TREE
          Layout style specifier.
 
Fields inherited from interface y.layout.PortConstraintKeys
SOURCE_GROUPID_KEY, SOURCE_PORT_CONSTRAINT_KEY, TARGET_GROUPID_KEY, TARGET_PORT_CONSTRAINT_KEY
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
HierarchicLayouter()
          Instantiates a new HierarchicLayouter.
 
Method Summary
 boolean canLayoutCore(LayoutGraph graph)
          Always returns true.
 void disposeMementoSupport()
          Disposes the memento support if it is existent, i.e. if it has been queried before by getMementoSupport()
 void doLayoutCore(LayoutGraph g)
          Layout the given graph.
 int getBendReductionThreshold()
          Returns the limit, when bends are removed and a straight line is drawn instead.
 Drawer getDrawer()
          Returns the Drawer, which is responsible for the third phase of the algorithm.
 Layerer getLayerer()
          Returns the Layerer, which is responsible for the first phase of the algorithm.
 byte getLayeringStrategy()
          Returns the currently set layering strategy.
protected  NodeList[] getLayerSequence(LayoutGraph g, NodeMap LAYER_KEY, int maxLayer)
          Determines the order of the nodes within their layers.
 LayerSequencer getLayerSequencer()
          Returns the LayerSequencer, which is responsible for the second phase of the algorithm.
 byte getLayoutStyle()
          Returns the currently set layout style or -1 if the style cannot be determined
 long getMaximalDuration()
          Returns a time limit for the algorithm in milliseconds
 MementoSupport getMementoSupport()
          Gets the cookie for the memento support of the hierarchic layout algorithm.
 double getMinimalEdgeDistance()
          Returns the minimal distance between edges that run in parallel.
 double getMinimalFirstSegmentLength()
          Returns the minimal length of first and last edge segments for edge routing.
 double getMinimalLayerDistance()
          Returns the minimal distance between two layers.
 double getMinimalNodeDistance()
          Returns the minimal distance between two nodes in the same layer.
 boolean getRemoveFalseCrossings()
          Returns whether or not false crossings should be removed from the layout.
 byte getRoutingStyle()
          Returns the routing style being used.
 boolean isPortConstraintOptimizationEnabled()
          Returns whether the algorithm tries to optimize PortConstraints, that are either PortConstraint.ANY_SIDE or null.
 boolean isSameLayerEdgeRoutingOptimizationEnabled()
          Returns whether the algorithm tries to optimize the routing of same layer edges whose PortConstraints don't impose the routing.
 void setBendReductionThreshold(int t)
          Sets the limit, when bends are removed and a straight line is drawn instead.
 void setDrawer(Drawer drawer)
          Sets the Drawer, which is responsible for the third phase of the algorithm.
 void setLayerer(Layerer layerer)
          Sets the Layerer, which is responsible for the first phase of the algorithm.
 void setLayeringStrategy(byte strategy)
          Sets a predefined layering strategy.
 void setLayerSequencer(LayerSequencer sequencer)
          Sets the LayerSequencer, which is responsible for the second phase of the algorithm.
 void setLayoutStyle(byte style)
          Sets the layout style for this layouter.
 void setMaximalDuration(long msec)
          Sets a time limit for the algorithm in milliseconds
 void setMinimalEdgeDistance(double d)
          Sets the minimal distance between edges that run in parallel.
 void setMinimalFirstSegmentLength(double minimalFirstSegmentLength)
          Sets the minimal length of first and last edge segments for edge routing.
 void setMinimalLayerDistance(double d)
          Sets the minimal distance between two layers.
 void setMinimalNodeDistance(double d)
          Sets the minimal distance between two nodes in the same layer.
 void setPortConstraintOptimizationEnabled(boolean enabled)
          Specifies whether the algorithm should try to optimize PortConstraints, that are either PortConstraint.ANY_SIDE or null.
 void setRemoveFalseCrossings(boolean b)
          Specifies whether or not false crossings should be removed from the layout.
 void setRoutingStyle(byte style)
          Sets the edge routing style.
 void setSameLayerEdgeRoutingOptimizationEnabled(boolean enabled)
          Determines whether the algorithm should try to optimize the routing of same layer edges whose PortConstraints don't impose the routing.
 
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, setComponentLayouterEnabled, setGroupNodeHider, setGroupNodeHidingEnabled, setLabelLayouter, setLabelLayouterEnabled, setLayoutOrientation, setOrientationLayouter, setOrientationLayouterEnabled, setParallelEdgeLayouter, setParallelEdgeLayouterEnabled, setSelfLoopLayouter, setSelfLoopLayouterEnabled, setSubgraphLayouter, setSubgraphLayouterEnabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PENDULUM

public static final byte PENDULUM
Layout style specifier. Draws the edges in a way that nodes are balanced nicely and the number of bends on an edge is kept small.

Note that this layout style is more time consuming than most of the other ones.

See Also:
Constant Field Values

LINEAR_SEGMENTS

public static final byte LINEAR_SEGMENTS
Layout style specifier. Draws the edges in a way that at most two bends are used per edge unless two edges cross.

See Also:
Constant Field Values

POLYLINE

public static final byte POLYLINE
Layout style specifier. Draws the edges in a polyline fashion. The layout tends to be very compact but the number of edge bends may be high.

See Also:
Constant Field Values

TREE

public static final byte TREE
Layout style specifier. Gives nice layouts if the graph is a tree.

See Also:
Constant Field Values

SIMPLEX

public static final byte SIMPLEX
Layout style specifier. Gives tight layouts with rather few bends.

See Also:
Constant Field Values

MEDIAN_SIMPLEX

public static final byte MEDIAN_SIMPLEX
Layout style specifier. Similar to SIMPLEX but more symmetric for the cost of a few more bends.

See Also:
Constant Field Values

ROUTE_POLYLINE

public static final byte ROUTE_POLYLINE
Edge routing style specifier. Routes the edges as polylines.

See Also:
Constant Field Values

ROUTE_ORTHOGONAL

public static final byte ROUTE_ORTHOGONAL
Edge routing style specifier. Routes the edges orthogonally, i.e. all edge segments are either vertically or horizontally aligned.

See Also:
Constant Field Values

LAYERING_HIERARCHICAL_TOPMOST

public static final byte LAYERING_HIERARCHICAL_TOPMOST
Layering strategy specifier. A simple hierarchical layering variant. All nodes with indegree zero will be assigned to the topmost layer of the layout. The number of separate layers will be as small as possible.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_HIERARCHICAL_OPTIMAL

public static final byte LAYERING_HIERARCHICAL_OPTIMAL
Layering strategy specifier. An optimal hierarchical layering strategy. The layer distance of an edge is the absolute difference between the layer numbers of its source and target node. Layer assignment will be done in such a way that the overall sum of the layer distances of all edges in the layout is minimal.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_HIERARCHICAL_TIGHT_TREE

public static final byte LAYERING_HIERARCHICAL_TIGHT_TREE
Layering strategy specifier. A heuristic that approximates the ranking done by LAYERING_HIERARCHICAL_OPTIMAL.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_HIERARCHICAL_DOWNSHIFT

public static final byte LAYERING_HIERARCHICAL_DOWNSHIFT
Layering strategy specifier. A fast heuristic that improves the the ranking done by LAYERING_HIERARCHICAL_TOPMOST by down shifting some nodes in the layering. The quality is usually worse than the one produced by Tight Tree Heuristic.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_BFS

public static final byte LAYERING_BFS
Layering strategy specifier. Layering based on a breadth first search (bfs). All edges will span at most one layer in the resulting drawing. Edges between nodes that belong to the same layer are possible. The nodes that will be placed in the first layer can be provided by a data provider bound to the input graph using the key BFSLayerer.CORE_NODES. If this data provider is not given, then nodes that have no incoming edges are placed in the first layer.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_FROM_SKETCH

public static final byte LAYERING_FROM_SKETCH
Layering strategy specifier. A layer assignment strategy that uses the initial y-coordinates of the nodes (x-coordinates when the layout orientation is horizontal) to determine a node layering. It tries to find a layering that is similar to the one in the input graph. When this layering strategy is used, the layouter may place nodes in the same layer, even though they are connected by an edge. These inner layer edges are always routed in an orthogonal style.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_USER_DEFINED

public static final byte LAYERING_USER_DEFINED
Layering strategy specifier. The ranks of the nodes will be given by the user. The node ranks must be provided by a data provider bound to the input graph using the key GivenLayersLayerer.LAYER_ID_KEY. Like LAYERING_FROM_SKETCH this layering allows inner layer edges.

See Also:
setLayeringStrategy(byte), Constant Field Values

LAYERING_STRATEGY_UNKNOWN

public static final byte LAYERING_STRATEGY_UNKNOWN
Dummy layering strategy specifier. Returned by getLayeringStrategy() if the current strategy is not known.

See Also:
Constant Field Values
Constructor Detail

HierarchicLayouter

public HierarchicLayouter()
Instantiates a new HierarchicLayouter.

Method Detail

setRoutingStyle

public void setRoutingStyle(byte style)
Sets the edge routing style. Possible values are ROUTE_POLYLINE and ROUTE_ORTHOGONAL. By default ROUTE_POLYLINE is set.


getRoutingStyle

public byte getRoutingStyle()
Returns the routing style being used.

See Also:
setRoutingStyle(byte)

setPortConstraintOptimizationEnabled

public void setPortConstraintOptimizationEnabled(boolean enabled)
Specifies whether the algorithm should try to optimize PortConstraints, that are either PortConstraint.ANY_SIDE or null.

Default is false.

Parameters:
enabled - whether optimization should be performed

isPortConstraintOptimizationEnabled

public boolean isPortConstraintOptimizationEnabled()
Returns whether the algorithm tries to optimize PortConstraints, that are either PortConstraint.ANY_SIDE or null.

Default is false.

Returns:
whether optimization is performed

setSameLayerEdgeRoutingOptimizationEnabled

public void setSameLayerEdgeRoutingOptimizationEnabled(boolean enabled)
Determines whether the algorithm should try to optimize the routing of same layer edges whose PortConstraints don't impose the routing. Default is true.

Parameters:
enabled - whether optimization should be performed

isSameLayerEdgeRoutingOptimizationEnabled

public boolean isSameLayerEdgeRoutingOptimizationEnabled()
Returns whether the algorithm tries to optimize the routing of same layer edges whose PortConstraints don't impose the routing.

Returns:
whether optimization is performed

setLayoutStyle

public void setLayoutStyle(byte style)
Sets the layout style for this layouter. Possible values are POLYLINE, LINEAR_SEGMENTS, MEDIAN_SIMPLEX, SIMPLEX, PENDULUM, and TREE. The default is set to LINEAR_SEGMENTS


getLayoutStyle

public byte getLayoutStyle()
Returns the currently set layout style or -1 if the style cannot be determined


setLayeringStrategy

public void setLayeringStrategy(byte strategy)
Sets a predefined layering strategy. This layouter assigns the nodes to separate layers. The nodes within each layer will be placed on the same horizontal line. The layers will be arranged vertically starting with the small-numbered layers. The rank of a node is the number of the layer it belongs to.

An important layering strategy for the hierarchic layout style is called Hierarchical Layering. A hierarchical layering tries to assign nodes to layers in a way that as much as possible edges of the graph will point to the main layout direction, i.e. the start nodes of the edges will have a smaller rank than the corresponding end nodes. Also, a hierarchical layering will never put two connected nodes in the same layer.

By default the layering strategy LAYERING_HIERARCHICAL_TIGHT_TREE is set.

Parameters:
strategy - one of LAYERING_HIERARCHICAL_TOPMOST, LAYERING_HIERARCHICAL_DOWNSHIFT, LAYERING_HIERARCHICAL_TIGHT_TREE, LAYERING_HIERARCHICAL_OPTIMAL, LAYERING_FROM_SKETCH, LAYERING_USER_DEFINED or LAYERING_BFS.

getLayeringStrategy

public byte getLayeringStrategy()
Returns the currently set layering strategy.

See Also:
setLayeringStrategy(byte)

setLayerer

public void setLayerer(Layerer layerer)
Sets the Layerer, which is responsible for the first phase of the algorithm.


getLayerer

public Layerer getLayerer()
Returns the Layerer, which is responsible for the first phase of the algorithm.


setLayerSequencer

public void setLayerSequencer(LayerSequencer sequencer)
Sets the LayerSequencer, which is responsible for the second phase of the algorithm.


getLayerSequencer

public LayerSequencer getLayerSequencer()
Returns the LayerSequencer, which is responsible for the second phase of the algorithm.


setDrawer

public void setDrawer(Drawer drawer)
Sets the Drawer, which is responsible for the third phase of the algorithm. The Drawer is responsible for the layout style of this layouter.


getDrawer

public Drawer getDrawer()
Returns the Drawer, which is responsible for the third phase of the algorithm. The Drawer is responsible for the layout style of this layouter.


setMinimalNodeDistance

public void setMinimalNodeDistance(double d)
Sets the minimal distance between two nodes in the same layer.


getMinimalNodeDistance

public double getMinimalNodeDistance()
Returns the minimal distance between two nodes in the same layer.


setMinimalEdgeDistance

public void setMinimalEdgeDistance(double d)
Sets the minimal distance between edges that run in parallel.


getMinimalEdgeDistance

public double getMinimalEdgeDistance()
Returns the minimal distance between edges that run in parallel.


setMinimalLayerDistance

public void setMinimalLayerDistance(double d)
Sets the minimal distance between two layers.


getMinimalLayerDistance

public double getMinimalLayerDistance()
Returns the minimal distance between two layers.


getMinimalFirstSegmentLength

public double getMinimalFirstSegmentLength()
Returns the minimal length of first and last edge segments for edge routing. This will be used for orthogonal edge routing, self-loops, same layer edges and bus connectors.

Returns:
the minimal length of first and last edge segments to use.

setMinimalFirstSegmentLength

public void setMinimalFirstSegmentLength(double minimalFirstSegmentLength)
Sets the minimal length of first and last edge segments for edge routing. This will be used for orthogonal edge routing, self-loops, same layer edges and bus connectors.

Parameters:
minimalFirstSegmentLength - the new minimal length of first and last edge segments

setRemoveFalseCrossings

public void setRemoveFalseCrossings(boolean b)
Specifies whether or not false crossings should be removed from the layout. A false crossing is a crossing between two edges that connect to the same upper or lower node.


getRemoveFalseCrossings

public boolean getRemoveFalseCrossings()
Returns whether or not false crossings should be removed from the layout.


setMaximalDuration

public void setMaximalDuration(long msec)
Sets a time limit for the algorithm in milliseconds


getMaximalDuration

public long getMaximalDuration()
Returns a time limit for the algorithm in milliseconds


setBendReductionThreshold

public void setBendReductionThreshold(int t)
Sets the limit, when bends are removed and a straight line is drawn instead.


getBendReductionThreshold

public int getBendReductionThreshold()
Returns the limit, when bends are removed and a straight line is drawn instead.


canLayoutCore

public boolean canLayoutCore(LayoutGraph graph)
Always returns true.

Specified by:
canLayoutCore in class CanonicMultiStageLayouter

doLayoutCore

public void doLayoutCore(LayoutGraph g)
Layout the given graph.

Specified by:
doLayoutCore in class CanonicMultiStageLayouter

getLayerSequence

protected NodeList[] getLayerSequence(LayoutGraph g,
                                      NodeMap LAYER_KEY,
                                      int maxLayer)
Determines the order of the nodes within their layers.


getMementoSupport

public MementoSupport getMementoSupport()
Gets the cookie for the memento support of the hierarchic layout algorithm. If there was no memento support registered with this instance before, this call will instantiate the memento support, otherwise the existing instance will be returned.

Returns:
the MementoSupport instance.

disposeMementoSupport

public void disposeMementoSupport()
Disposes the memento support if it is existent, i.e. if it has been queried before by getMementoSupport()


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