Search this API

y.layout.tree
Class LeftRightPlacer

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

public class LeftRightPlacer
extends AbstractRotatableNodePlacer

The LeftRightPlacer arranges the children in a subtree on the left and the right of a vertical bus.

Layout Style

The default settings generate a layout with a single vertical bus, where children are placed left and right of it. By adjusting the branch count, it is possible to generate multiple vertical buses (i.e. branches) that are placed next to each other, below the root node.


Default, single-branch layout


Layout with three branches

 
Your browser does not support SVG content.

Nested Class Summary
static class LeftRightPlacer.LeftRightDataProvider
          A special DataProvider that determines whether a given node is placed left or right of the parent node.
 
Nested classes/interfaces inherited from class y.layout.tree.AbstractRotatableNodePlacer
AbstractRotatableNodePlacer.Matrix, AbstractRotatableNodePlacer.RootAlignment
 
Field Summary
static java.lang.Object LEFT_RIGHT_DPKEY
          A DataProvider key for assigning nodes to the left or the right side of the bus If no LeftRightPlacer.LeftRightDataProvider is specified using this key, the nodes will be placed alternating from left to right.
 
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
LeftRightPlacer()
          Creates a new LeftRightPlacer instance with default settings.
LeftRightPlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
          Creates a new LeftRightPlacer instance using the given modification matrix.
 
Method Summary
 java.util.Comparator createComparator()
          Returns a Comparator for outgoing edges that considers the locations of the target nodes.
 Processor createProcessor(GenericTreeLayouter layouter, LayoutGraph graph, Node currentRoot)
          Creates a processor that distributes the child elements into multiple branches, if necessary.
protected  byte determineChildConnector(Node child)
          Determines a connector direction for the given child node.
 void determineChildConnectors(Node localRoot, DataMap connectorMap)
          Determines the direction of the child connectors according to which side of the bus the child is assigned.
 int getBranchCount()
          Returns the number of branches (buses) of the subtree layout.
 double getHorizontalDistance()
          Returns the horizontal distance between nodes or subtrees.
 double getVerticalDistance()
          Returns the vertical distance between nodes or subtrees.
 boolean isPlaceLastOnBottom()
          Returns whether or not the last child is placed centered, aligned with the bus and below the other child nodes.
protected  y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot, byte parentConnectorDirection)
          Places the subtree shapes of the children left and right of a common vertical bus.
 void setBranchCount(int branchCount)
          Specifies the number of branches (buses) of the subtree layout.
 void setHorizontalDistance(double distance)
          Specifies the horizontal distance between nodes or subtrees.
 void setPlaceLastOnBottom(boolean placeLastOnBottom)
          Specifies whether or not the last child is placed centered, aligned with the bus and below the other child nodes.
 void setSpacing(double spacing)
          Specifies a uniform horizontal and vertical spacing between subtrees.
 void setVerticalDistance(double distance)
          Specifies the vertical distance between nodes or subtrees.
 
Methods inherited from class y.layout.tree.AbstractRotatableNodePlacer
createFromSketchComparator, createRootNodeShape, createSubtreeShape, getModificationMatrix, getPortConstraint, getSourcePointAbs, getSpacing, placeSubtree, translateDirectionToModel, translateDirectionToReal, translatePoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEFT_RIGHT_DPKEY

public static final java.lang.Object LEFT_RIGHT_DPKEY
A DataProvider key for assigning nodes to the left or the right side of the bus

If no LeftRightPlacer.LeftRightDataProvider is specified using this key, the nodes will be placed alternating from left to right.

Constructor Detail

LeftRightPlacer

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


LeftRightPlacer

public LeftRightPlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
Creates a new LeftRightPlacer instance using the given modification matrix.

Parameters:
modificationMatrix - the transformation matrix for this AbstractRotatableNodePlacer
Throws:
java.lang.IllegalArgumentException - if the given transformation matrix is null
Method Detail

getHorizontalDistance

public double getHorizontalDistance()
Returns the horizontal distance between nodes or subtrees.

The distance needs to be non-negative.

Returns:
the non-negative horizontal distance
See Also:
setHorizontalDistance(double)

setHorizontalDistance

public void setHorizontalDistance(double distance)
Specifies the horizontal distance between nodes or subtrees.

The distance needs to be non-negative.

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

20

40

getVerticalDistance

public double getVerticalDistance()
Returns the vertical distance between nodes or subtrees.

The distance needs to be non-negative.

Returns:
the non-negative vertical distance
See Also:
setVerticalDistance(double)

setVerticalDistance

public void setVerticalDistance(double distance)
Specifies the vertical distance between nodes or subtrees.

The distance needs to be non-negative.

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

20

40

setSpacing

public void setSpacing(double spacing)
Specifies a uniform horizontal and vertical spacing between subtrees.

This method sets the given distance value for the horizontal spacing and for the vertical spacing.

Overrides:
setSpacing in class AbstractRotatableNodePlacer
Parameters:
spacing - the distance between subtrees
Throws:
java.lang.IllegalArgumentException - if the specified spacing value is negative
See Also:
setHorizontalDistance(double), setVerticalDistance(double)

getBranchCount

public int getBranchCount()
Returns the number of branches (buses) of the subtree layout.

A branch consists of a vertical bus where the child nodes are placed left and right of it. If the subtree handled by this NodePlacer consists of multiple branches, they are placed next to each other with the root node centered above them. Child nodes are equally distributed over the different available branches. The out-edge order is considered such that child subtrees are first assigned to the leftmost branch (e.g. if each branch contains four children, the first four children are in the first, leftmost branch, the second four children are in the second branch and so on).

 
The assignment of child nodes to the branch is solely based on the out-edge order of the edges from the root of the child nodes. Therefore, if nodes have a user-specified left/right side, the different branches may contain a different number of left and right nodes. By providing a customized out-edge order, this can be adjusted to fit more specific requirements.
Returns:
the number of branches of the subtree layout
See Also:
setBranchCount(int)

setBranchCount

public void setBranchCount(int branchCount)
Specifies the number of branches (buses) of the subtree layout.

A branch consists of a vertical bus where the child nodes are placed left and right of it. If the subtree handled by this NodePlacer consists of multiple branches, they are placed next to each other with the root node centered above them. Child nodes are equally distributed over the different available branches. The out-edge order is considered such that child subtrees are first assigned to the leftmost branch (e.g. if each branch contains four children, the first four children are in the first, leftmost branch, the second four children are in the second branch and so on).

 
The assignment of child nodes to the branch is solely based on the out-edge order of the edges from the root of the child nodes. Therefore, if nodes have a user-specified left/right side, the different branches may contain a different number of left and right nodes. By providing a customized out-edge order, this can be adjusted to fit more specific requirements.
Default Value:
The default value is 1. The layout consists of a single branch.
Parameters:
branchCount - the number of branches of the subtree layout
Throws:
java.lang.IllegalArgumentException - if the given branch count is smaller than 1
Sample Graphs:

Layout with a single branch consisting of 12 child nodes

Layout with three branches - each branch holds four child nodes

determineChildConnectors

public void determineChildConnectors(Node localRoot,
                                     DataMap connectorMap)
Determines the direction of the child connectors according to which side of the bus the child is assigned.

Children on the left will get a connector to the NodePlacer.DIRECTION_EAST. Children on the right will get one to the NodePlacer.DIRECTION_WEST. A connector to the NodePlacer.DIRECTION_NORTH is assigned for the bottom child.

Specified by:
determineChildConnectors in interface NodePlacer
Overrides:
determineChildConnectors in class AbstractRotatableNodePlacer
Parameters:
localRoot - the local root node
connectorMap - the map that must be used for storing the direction specifiers of the child nodes
See Also:
setPlaceLastOnBottom(boolean)

determineChildConnector

protected byte determineChildConnector(Node child)
Determines a connector direction for the given child node.

Since the connector directions are already determined by determineChildConnectors(Node, DataMap), this method doesn't need to be called.

Specified by:
determineChildConnector in class AbstractRotatableNodePlacer
Parameters:
child - the child node
Returns:
a direction specifier as defined in the NodePlacer interface
Throws:
java.lang.IllegalStateException - if this method is called

placeSubtree

protected y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot,
                                                         byte parentConnectorDirection)
Places the subtree shapes of the children left and right of a common vertical bus.

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

isPlaceLastOnBottom

public boolean isPlaceLastOnBottom()
Returns whether or not the last child is placed centered, aligned with the bus and below the other child nodes.

When enabled, the last child will always be centered independent of the number of siblings.

Returns:
true if the last child is separated, false otherwise
See Also:
setPlaceLastOnBottom(boolean)

setPlaceLastOnBottom

public void setPlaceLastOnBottom(boolean placeLastOnBottom)
Specifies whether or not the last child is placed centered, aligned with the bus and below the other child nodes.

When enabled, the last child will always be centered independent of the number of siblings.

Default Value:
The default value is true. The last child is centered below its siblings
Parameters:
placeLastOnBottom - true if the last child is separated, false otherwise
Sample Graphs:

false

true

createComparator

public java.util.Comparator createComparator()
Returns a Comparator for outgoing edges that considers the locations of the target nodes.

The Comparator applies the modification matrix of this LeftRightPlacer and then compares the y-coordinates of the target nodes.

Overrides:
createComparator in class AbstractRotatableNodePlacer
Returns:
the Comparator that compares outgoing edges according to the locations of their target nodes

createProcessor

public Processor createProcessor(GenericTreeLayouter layouter,
                                 LayoutGraph graph,
                                 Node currentRoot)
Creates a processor that distributes the child elements into multiple branches, if necessary.

The branch count defines whether or not the subtree layout will consist of multiple branches. If so, this method creates a processor to assign the children to the branches.

Specified by:
createProcessor in interface NodePlacer
Overrides:
createProcessor in class AbstractRotatableNodePlacer
Parameters:
layouter - the current GenericTreeLayouter instance
graph - the input graph
currentRoot - the root node handled by this NodePlacer
Returns:
the processor distributing children to multiple branches or null if only a single-branch layout is created

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