Search this API

y.layout.tree
Class LayeredNodePlacer

java.lang.Object
  extended by y.layout.tree.AbstractRotatableNodePlacer
      extended by y.layout.tree.LayeredNodePlacer
All Implemented Interfaces:
FromSketchNodePlacer, NodePlacer

public class LayeredNodePlacer
extends AbstractRotatableNodePlacer

A LayeredNodePlacer arranges the nodes of a subtree respecting layers.

Layout Style

Nodes that have the same depth in the tree will be placed in the same horizontal layer. They will be vertically aligned.

 
Changing the orientation within the LayeredNodePlacer is strongly discouraged because it causes problems with the layering.
 

Nested Class Summary
 
Nested classes/interfaces inherited from class y.layout.tree.AbstractRotatableNodePlacer
AbstractRotatableNodePlacer.Matrix, AbstractRotatableNodePlacer.RootAlignment
 
Field Summary
static int ORTHOGONAL_STYLE
          Routing style specifier which defines that edges are routed in an orthogonal, bus-like fashion.
static int PLAIN_STYLE
          Routing style specifier which defines that edges consist of one straight segment.
 
Fields inherited from class y.layout.tree.AbstractRotatableNodePlacer
createdChildren, graph, modificationMatrix, nodeShapeProvider, spacing, subtreeShapeProvider
 
Fields inherited from interface y.layout.tree.NodePlacer
DIRECTION_ANY, DIRECTION_EAST, DIRECTION_NONE, DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_WEST
 
Constructor Summary
LayeredNodePlacer()
          Creates a new LayeredNodePlacer instance with the default settings.
LayeredNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix, java.lang.Object id)
          Creates a new LayeredNodePlacer instance whose direction is specified by the given modification matrix.
 
Method Summary
 Processor createProcessor(GenericTreeLayouter layouter, LayoutGraph graph, Node currentRoot)
          Creates a Processor that distributes the nodes over the layers.
protected  byte determineChildConnector(Node child)
          Returns NodePlacer.DIRECTION_NORTH for every given child node.
 double getBusAlignment()
          Returns the vertical bus alignment for orthogonally routed edges.
 java.lang.Object getId()
          Returns the ID of this LayeredNodePlacer.
 double getLayerSpacing()
          Returns the distance between two adjacent layers.
 AbstractRotatableNodePlacer.RootAlignment getRootAlignment()
          Returns the RootAlginment that defines how the root node is aligned with its children and their shapes.
 int getRoutingStyle()
          Returns the routing style for the edges in the subtree.
 double getVerticalAlignment()
          Returns the relative vertical alignment of nodes within their respective layers.
 boolean isDendrogramStyleEnabled()
          Returns whether or not the layering is done dendrogram-like.
 boolean isPolylineLabelingEnabled()
          Returns whether or not straight edges are extended to avoid label overlaps.
protected  y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot, byte parentConnectorDirection)
          Places the children of local root in layers.
 void setBusAlignment(double busAlignment)
          Specifies the vertical bus alignment for orthogonally routed edges.
 void setDendrogramStyleEnabled(boolean enabled)
          Specifies whether or not the layering is done dendrogram-like.
 void setLayerSpacing(double layerSpacing)
          Specifies the distance between two adjacent layers.
 void setPolylineLabelingEnabled(boolean polylineLabelingEnabled)
          Specifies whether or not straight edges are extended to avoid label overlaps.
 void setRootAlignment(AbstractRotatableNodePlacer.RootAlignment rootAlignment)
          Specifies the RootAlginment that defines how the root node is aligned with its children and their shapes.
 void setRoutingStyle(int routingStyle)
          Specifies the routing style for the edges in the subtree.
 void setVerticalAlignment(double verticalAlignment)
          Specifies the relative vertical alignment of nodes within their respective layers.
 
Methods inherited from class y.layout.tree.AbstractRotatableNodePlacer
createComparator, createFromSketchComparator, createRootNodeShape, createSubtreeShape, determineChildConnectors, getModificationMatrix, getPortConstraint, getSourcePointAbs, getSpacing, placeSubtree, setSpacing, translateDirectionToModel, translateDirectionToReal, translatePoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLAIN_STYLE

public static final int PLAIN_STYLE
Routing style specifier which defines that edges consist of one straight segment.

 
It is possible that edges overlap with nodes, depending on their size and vertical alignment. If node labels are considered, there might also be edge overlaps with node labels that are placed above the according node.
See Also:
setRoutingStyle(int), Constant Field Values
Sample Graph:

ORTHOGONAL_STYLE

public static final int ORTHOGONAL_STYLE
Routing style specifier which defines that edges are routed in an orthogonal, bus-like fashion.

See Also:
setRoutingStyle(int), Constant Field Values
Sample Graph:
Constructor Detail

LayeredNodePlacer

public LayeredNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix,
                         java.lang.Object id)
Creates a new LayeredNodePlacer instance whose direction is specified by the given modification matrix.

The given ID identifies different LayeredNodePlacer instances that share the same layer heights.

Parameters:
modificationMatrix - the transformation matrix for this AbstractRotatableNodePlacer
id - the LayeredNodePlacer ID
Throws:
java.lang.IllegalArgumentException - if the given transformation matrix or id is null

LayeredNodePlacer

public LayeredNodePlacer()
Creates a new LayeredNodePlacer instance with the default settings.

Method Detail

isDendrogramStyleEnabled

public boolean isDendrogramStyleEnabled()
Returns whether or not the layering is done dendrogram-like.

When enabled, leaves are placed in the same layer and remaining tree nodes are assigned to a layer as close to their children as possible.

Returns:
true if the graph is layered as a dendrogram, false otherwise
See Also:
setDendrogramStyleEnabled(boolean)

setDendrogramStyleEnabled

public void setDendrogramStyleEnabled(boolean enabled)
Specifies whether or not the layering is done dendrogram-like.

When enabled, leaves are placed in the same layer and remaining tree nodes are assigned to a layer as close to their children as possible.

Default Value:
The default value is false. The nodes are assigned to the topmost layer.
Parameters:
enabled - true if the graph is layered as a dendrogram, false otherwise
Sample Graphs:

false

true

determineChildConnector

protected byte determineChildConnector(Node child)
Returns NodePlacer.DIRECTION_NORTH for every given child node. Edges always connect to the top of the child nodes.

Specified by:
determineChildConnector in class AbstractRotatableNodePlacer
Parameters:
child - the child node
Returns:
NodePlacer.DIRECTION_NORTH

placeSubtree

protected y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot,
                                                         byte parentConnectorDirection)
Places the children of local root in layers.

Specified by:
placeSubtree in class AbstractRotatableNodePlacer
Parameters:
localRoot - the local root node
parentConnectorDirection - the direction specifier for the connector of the local root node to its parent node
Returns:
the merged subtree shape that contains the local root node and all its children

createProcessor

public Processor createProcessor(GenericTreeLayouter layouter,
                                 LayoutGraph graph,
                                 Node currentRoot)
Creates a Processor that distributes the nodes over the layers.

The Processor is chosen depending on the layout style.

Specified by:
createProcessor in interface NodePlacer
Overrides:
createProcessor in class AbstractRotatableNodePlacer
Parameters:
graph - the input graph
currentRoot - the current root node for this node placer
layouter - the current GenericTreeLayouter instance
Returns:
the Processor or null if the layer information is already assigned to the current root
See Also:
setDendrogramStyleEnabled(boolean)

getRootAlignment

public AbstractRotatableNodePlacer.RootAlignment getRootAlignment()
Returns the RootAlginment that defines how the root node is aligned with its children and their shapes.

Returns:
the AbstractRotatableNodePlacer.RootAlignment instance specifying the location relative to the subtrees
See Also:
setRootAlignment(AbstractRotatableNodePlacer.RootAlignment)

setRootAlignment

public void setRootAlignment(AbstractRotatableNodePlacer.RootAlignment rootAlignment)
Specifies the RootAlginment that defines how the root node is aligned with its children and their shapes.

Default Value:
The default value is AbstractRotatableNodePlacer.RootAlignment.CENTER_OVER_CHILDREN
Parameters:
rootAlignment - the AbstractRotatableNodePlacer.RootAlignment instance specifying the location relative to the subtrees
Throws:
java.lang.IllegalArgumentException - if the given root alignment is null

getVerticalAlignment

public double getVerticalAlignment()
Returns the relative vertical alignment of nodes within their respective layers.

A value of 0 means that nodes are top-aligned; a value of 0.5 means that nodes are center-aligned; a value of 1 means that nodes are bottom-aligned;

Values for a valid vertical alignment are in the range [0..1].

Returns:
the vertical alignment of nodes within their layers
See Also:
setVerticalAlignment(double)

setVerticalAlignment

public void setVerticalAlignment(double verticalAlignment)
Specifies the relative vertical alignment of nodes within their respective layers.

A value of 0 means that nodes are top-aligned; a value of 0.5 means that nodes are center-aligned; a value of 1 means that nodes are bottom-aligned;

Values for a valid vertical alignment are in the range [0..1].

Default Value:
The default value is 0.5. Nodes are center aligned.
Parameters:
verticalAlignment - the vertical alignment of nodes within their layers
Throws:
java.lang.IllegalArgumentException - if the specified alignment is outside [0..1]
Sample Graphs:

0

0.5

1

getId

public java.lang.Object getId()
Returns the ID of this LayeredNodePlacer.

The ID is used for identifying LayeredNodePlacers that share information about the layer height. Using different IDs allows aligned layouts within different subtrees.

Returns:
the ID of this node placer

getLayerSpacing

public double getLayerSpacing()
Returns the distance between two adjacent layers.

The spacing needs to be non-negative.

Returns:
the spacing between two layers
See Also:
setLayerSpacing(double)

setLayerSpacing

public void setLayerSpacing(double layerSpacing)
Specifies the distance between two adjacent layers.

The spacing needs to be non-negative.

Default Value:
The default value is 40.
Parameters:
layerSpacing - the spacing between two layers
Throws:
java.lang.IllegalArgumentException - if the specified spacing is negative
Sample Graphs:

40

80

setRoutingStyle

public void setRoutingStyle(int routingStyle)
Specifies the routing style for the edges in the subtree.

Default Value:
The default value is PLAIN_STYLE
Parameters:
routingStyle - one of the predefined edge routing styles
Throws:
java.lang.IllegalArgumentException - if the specified routing style specifier is unknown

getRoutingStyle

public int getRoutingStyle()
Returns the routing style for the edges in the subtree.

Returns:
one of the predefined edge routing styles
See Also:
setRoutingStyle(int)

getBusAlignment

public double getBusAlignment()
Returns the vertical bus alignment for orthogonally routed edges.

The bus alignment determines the relative position of an edge bus in between two subsequent layers of nodes.

Values for a valid vertical alignment are in the range [0..1], such that:

 
Bus alignment only applies if the routing style is set to ORTHOGONAL_STYLE.
Returns:
the relative bus alignment
See Also:
setBusAlignment(double)

setBusAlignment

public void setBusAlignment(double busAlignment)
Specifies the vertical bus alignment for orthogonally routed edges.

The bus alignment determines the relative position of an edge bus in between two subsequent layers of nodes.

Values for a valid vertical alignment are in the range [0..1], such that:

 
Bus alignment only applies if the routing style is set to ORTHOGONAL_STYLE.
Default Value:
The default value is 0.5.
Parameters:
busAlignment - the relative bus alignment
Throws:
java.lang.IllegalArgumentException - if the specified alignment is outside [0..1]
Sample Graphs:

0.3

0.5

0.7

isPolylineLabelingEnabled

public boolean isPolylineLabelingEnabled()
Returns whether or not straight edges are extended to avoid label overlaps.

If enabled, polyline connectors between the parent and its children are added to the according subtree shape. Node or edge labels will not be crossed.

 
Polyline labeling only has an effect if the routing style is PLAIN_STYLE.
Returns:
true if polyline connectors are added, false otherwise
See Also:
setPolylineLabelingEnabled(boolean)

setPolylineLabelingEnabled

public void setPolylineLabelingEnabled(boolean polylineLabelingEnabled)
Specifies whether or not straight edges are extended to avoid label overlaps.

If enabled, polyline connectors between the parent and its children are added to the according subtree shape. Node or edge labels will not be crossed.

 
Polyline labeling only has an effect if the routing style is PLAIN_STYLE.
Default Value:
The default value is false. Edges are only routed straight.
Parameters:
polylineLabelingEnabled - true if polyline connectors should be added, false otherwise
Sample Graphs:

false

true

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