Search this API

y.layout.tree
Class GridNodePlacer

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

public class GridNodePlacer
extends AbstractRotatableNodePlacer

The GridNodePlacer arranges the shapes of the children of a local root in a grid.

Layout Style

The grid consists of a number of rows. The subtrees are assigned to the rows using a DataProvider that is registered with the graph with GRID_DPKEY. If there is no row mapping provided, all subtrees are assigned to a single row. Furthermore, if property setAutomaticRowAssignmentEnabled(boolean) is enabled, the row assignment is made automatically - the produced grid will be square-like with respect to the child count, ignoring actual subtree sizes. For example, if there are nine children, a grid with three rows is generated.

The edges from the children to the local root are routed in a bus-like way. The placement of the bus can be configured using the property setBusPlacement(int). The alignment of the root node can be configured using #setRootAlignment(RootAlignment). To align the root node with the bus, use BUS_ALIGNED. A bus-aligned root in conjunction with BUS_PLACEMENT_CENTER produces a symmetric grid with the bus and root aligned in the middle.


Child nodes in a grid with three rows, with a bus-aligned root and the bus placed in the center


Child nodes placed in a grid using three rows and four columns where the root alignment and bus placement are leading.

 

Nested Class Summary
 
Nested classes/interfaces inherited from class y.layout.tree.AbstractRotatableNodePlacer
AbstractRotatableNodePlacer.Matrix, AbstractRotatableNodePlacer.RootAlignment
 
Field Summary
static AbstractRotatableNodePlacer.RootAlignment BUS_ALIGNED
          Horizontal RootAlignment with the bus of the grid so that the position of the root depends on the selected bus placement.
static int BUS_PLACEMENT_CENTER
          A bus placement that places the bus that connects the child nodes in the center of the child subtrees.
static int BUS_PLACEMENT_LEADING
          A bus placement that places the bus that connects the child nodes in a leading way, left of the child subtrees.
static int BUS_PLACEMENT_TRAILING
          A bus placement that places the bus that connects the child nodes in a trailing way, right of the child subtrees.
static java.lang.Object GRID_DPKEY
          A DataProvider key for assigning nodes to the rows in the grid If no DataProvider is registered with this key, all nodes will be placed in the same row.
 
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
GridNodePlacer()
          Creates a new GridNodePlacer with default settings.
GridNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
          Creates a new GridNodePlacer instance whose direction is specified by the given modification matrix.
GridNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix, AbstractRotatableNodePlacer.RootAlignment rootAlignment)
          Creates a new GridNodePlacer instance with the given modification matrix and root alignment.
 
Method Summary
 java.util.Comparator createFromSketchComparator()
          Creates a Comparator that sorts the outgoing edges according to the rows and x-coordinates of their target nodes.
protected  byte determineChildConnector(Node child)
          Returns NodePlacer.DIRECTION_NORTH for every given child node.
 int getBusPlacement()
          Returns the placement of the bus with respect to the child node grid.
 AbstractRotatableNodePlacer.RootAlignment getRootAlignment()
          Returns the RootAlginment that defines how the root node is aligned with its children and their shapes.
 boolean isAutomaticRowAssignmentEnabled()
          Returns whether or not the nodes are automatically assigned to the rows of the grid.
protected  y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot, byte parentConnectorDirection)
          Places the children of a local root node in a grid.
 void setAutomaticRowAssignmentEnabled(boolean automaticRowAssignmentEnabled)
          Specifies whether or not the nodes are automatically assigned to the rows of the grid.
 void setBusPlacement(int busPlacement)
          Specifies the placement of the bus with respect to the child node grid.
 void setRootAlignment(AbstractRotatableNodePlacer.RootAlignment rootAlignment)
          Specifies the RootAlginment that defines how the root node is aligned with its children and their shapes.
 
Methods inherited from class y.layout.tree.AbstractRotatableNodePlacer
createComparator, createProcessor, 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

GRID_DPKEY

public static final java.lang.Object GRID_DPKEY
A DataProvider key for assigning nodes to the rows in the grid

If no DataProvider is registered with this key, all nodes will be placed in the same row.


BUS_PLACEMENT_LEADING

public static final int BUS_PLACEMENT_LEADING
A bus placement that places the bus that connects the child nodes in a leading way, left of the child subtrees.

See Also:
Constant Field Values
Sample Graph:

The bus is placed leading, left of the children

BUS_PLACEMENT_TRAILING

public static final int BUS_PLACEMENT_TRAILING
A bus placement that places the bus that connects the child nodes in a trailing way, right of the child subtrees.

See Also:
Constant Field Values
Sample Graph:

The bus is placed trailing, right of the children

BUS_PLACEMENT_CENTER

public static final int BUS_PLACEMENT_CENTER
A bus placement that places the bus that connects the child nodes in the center of the child subtrees.

For a row with n > 1 children, the bus segment is placed after the (n/2)th child. If a row consists of a single child, it is placed right of the bus.

See Also:
Constant Field Values
Sample Graph:

The bus is placed in the center

BUS_ALIGNED

public static final AbstractRotatableNodePlacer.RootAlignment BUS_ALIGNED
Horizontal RootAlignment with the bus of the grid so that the position of the root depends on the selected bus placement.

The root node is simply center-aligned with the bus of the subtree grid created by GridNodePlacer. The given shapes of the children and the spacing are not considered in any way.

 
This alignment is only intended for usage with GridNodePlacer.
Constructor Detail

GridNodePlacer

public GridNodePlacer()
Creates a new GridNodePlacer with default settings.


GridNodePlacer

public GridNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
Creates a new GridNodePlacer instance whose direction is specified by the given modification matrix.

Parameters:
modificationMatrix - the transformation matrix for this AbstractRotatableNodePlacer

GridNodePlacer

public GridNodePlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix,
                      AbstractRotatableNodePlacer.RootAlignment rootAlignment)
Creates a new GridNodePlacer instance with the given modification matrix and root alignment.

Parameters:
modificationMatrix - the transformation matrix for this AbstractRotatableNodePlacer
rootAlignment - the alignment of the local root with its subtrees
Method Detail

getBusPlacement

public int getBusPlacement()
Returns the placement of the bus with respect to the child node grid.

Returns:
one of the predefined bus placements
See Also:
setBusPlacement(int)

setBusPlacement

public void setBusPlacement(int busPlacement)
Specifies the placement of the bus with respect to the child node grid.

Default Value:
The default value is BUS_PLACEMENT_LEADING. The bus is placed leading, left of the grid structure.
Parameters:
busPlacement - one of the predefined bus placements
Throws:
java.lang.IllegalArgumentException - if the given bus placement is unknown

isAutomaticRowAssignmentEnabled

public boolean isAutomaticRowAssignmentEnabled()
Returns whether or not the nodes are automatically assigned to the rows of the grid.

If enabled, the nodes are assigned to rows automatically. User-specified row indices are ignored. The grid will be square-like with respect to the child count, ignoring actual subtree sizes. For example, if there are nine children, a grid with three rows - each row containing three nodes - is generated.

 
If this feature is enabled, the from-sketch order is ignored.
Returns:
true if nodes are automatically assigned to rows, false otherwise
See Also:
setAutomaticRowAssignmentEnabled(boolean)

setAutomaticRowAssignmentEnabled

public void setAutomaticRowAssignmentEnabled(boolean automaticRowAssignmentEnabled)
Specifies whether or not the nodes are automatically assigned to the rows of the grid.

If enabled, the nodes are assigned to rows automatically. User-specified row indices are ignored. The grid will be square-like with respect to the child count, ignoring actual subtree sizes. For example, if there are nine children, a grid with three rows - each row containing three nodes - is generated.

 
If this feature is enabled, the from-sketch order is ignored.
Default Value:
The default value is false. The rows are user-specified.
Parameters:
automaticRowAssignmentEnabled - true if nodes should be automatically assigned to rows, false otherwise

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 a local root node in a grid.

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

createFromSketchComparator

public java.util.Comparator createFromSketchComparator()
Creates a Comparator that sorts the outgoing edges according to the rows and x-coordinates of their target nodes.

Edges that connect to nodes in different rows are ordered by the row index. If two edges connect to the same row, they are sorted by the x-coordinates of their target nodes.

Specified by:
createFromSketchComparator in interface FromSketchNodePlacer
Overrides:
createFromSketchComparator in class AbstractRotatableNodePlacer
 
If the rows are automatically assigned, the created from-sketch Comparator does not have an effect.
Returns:
a Comparator that orders edges lexicographically by row and x-coordinates of their target nodes
See Also:
GRID_DPKEY

getRootAlignment

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

Returns:
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 BUS_ALIGNED
Parameters:
rootAlignment - the AbstractRotatableNodePlacer.RootAlignment instance specifying the location relative to the subtrees

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