y.layout.hierarchic
Class HierarchicLayouter

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

public class HierarchicLayouter
extends CanonicMultiStageLayouter
implements PortConstraintKeys

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

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

Here is an sample output of the layouter using top to bottom orientation and HierarchicLayouter.PENDULUM layout style.

HierarchicLayouter is a layouter that can handle port constraints. See classes PortConstraint and PortConstraintKeys on how to setup port constraint information for this layouter.

HierarchicLayouter can consider edge label data when laying out a graph. That means that the 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 label layout feature.


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_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 currently set 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 currently set 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 hierarchich 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()
          Whether or not false crossings should be removed from the layout.
 byte getRoutingStyle()
          Returns the routing style being used.
 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 setRemoveFalseCrossings(boolean b)
          Whether or not false crossings should be removed from the layout.
 void setRoutingStyle(byte style)
          Sets the edge routing style.
 
Methods inherited from class y.layout.CanonicMultiStageLayouter
appendStage, calcLayout, calcLayout, canLayout, 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 at the nodes are balanced nicely and the number of bends on a edge is kept small.

Note that this layout style is more time consuming than 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.

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:
HierarchicLayouter.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:
HierarchicLayouter.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 HierarchicLayouter.LAYERING_HIERARCHICAL_OPTIMAL.

See Also:
HierarchicLayouter.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 HierarchicLayouter.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:
HierarchicLayouter.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 dataprovider bound to the input graph using the key BFSLayerer.CORE_NODES. If this dataprovider is not given, then nodes that have no incoming edges are placed in the first layer.

See Also:
HierarchicLayouter.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:
HierarchicLayouter.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 dataprovider bound to the input graph using the key GivenLayersLayerer.LAYER_ID_KEY. Like HierarchicLayouter.LAYERING_FROM_SKETCH this layering allows inner layer edges.

See Also:
HierarchicLayouter.setLayeringStrategy(byte), 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 HierarchicLayouter.ROUTE_POLYLINE and HierarchicLayouter.ROUTE_ORTHOGONAL. By default HierarchicLayouter.ROUTE_POLYLINE is set.


getRoutingStyle

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

See Also:
HierarchicLayouter.setRoutingStyle(byte)

setLayoutStyle

public void setLayoutStyle(byte style)
Sets the layout style for this layouter. Possible values are HierarchicLayouter.POLYLINE, HierarchicLayouter.LINEAR_SEGMENTS, HierarchicLayouter.MEDIAN_SIMPLEX, HierarchicLayouter.SIMPLEX, HierarchicLayouter.PENDULUM, and HierarchicLayouter.TREE. The default is set to HierarchicLayouter.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 HierarchicLayouter.LAYERING_HIERARCHICAL_TIGHT_TREE is set.

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

getLayeringStrategy

public byte getLayeringStrategy()
Returns the currently set layering strategy. see @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 currently set 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 currently set 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. A 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


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, selfloops, 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, selfloops, same layer edges and bus connectors.

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

setRemoveFalseCrossings

public void setRemoveFalseCrossings(boolean b)
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()
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 hierarchich 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-2003,
yWorks GmbH.
All rights reserved.

2003