Search this API

y.layout.tree
Class ARNodePlacer

java.lang.Object
  extended by y.layout.tree.AbstractNodePlacer
      extended by y.layout.tree.ARNodePlacer
All Implemented Interfaces:
java.lang.Cloneable, FromSketchNodePlacer, NodePlacer

public class ARNodePlacer
extends AbstractNodePlacer
implements FromSketchNodePlacer

This NodePlacer places the subtrees such that the overall aspect ratio of the arranged subtree will be close to a preferred aspect ratio.

Layout Style

The aspect ratio describes the relation between width and height of the subtree. To achieve the desired aspect ratio, this NodePlacer divides the child GenericTreeLayouter.SubtreeShapes into as much rows as needed. The edges are either routed along the rows or along the columns.


Aspect ratio 1


Aspect ratio 0.5


Aspect ratio 2

 

Field Summary
static byte FILL_STYLE_CENTERED
          Style specifier which defines that rows/columns are aligned with their center.
static byte FILL_STYLE_JUSTIFY
          Style specifier which defines that rows/columns are justified to have the same width/height.
static byte FILL_STYLE_LEADING
          Style specifier which defines that rows/columns are aligned with their leading side.
static byte FILL_STYLE_TRAILING
          Style specifier which defines that rows/columns are aligned with their trailing side.
 
Fields inherited from class y.layout.tree.AbstractNodePlacer
graph
 
Fields inherited from interface y.layout.tree.NodePlacer
DIRECTION_ANY, DIRECTION_EAST, DIRECTION_NONE, DIRECTION_NORTH, DIRECTION_SOUTH, DIRECTION_WEST
 
Constructor Summary
ARNodePlacer()
          Creates a new instance of ARNodePlacer with default settings.
ARNodePlacer(boolean horizontal, double aspectRatio, byte fillStyle, double horizontalDistance, double verticalDistance)
          Creates a new instance of ARNodePlacer with given settings.
 
Method Summary
 java.util.Comparator createFromSketchComparator()
          Creates an edge Comparator which takes the initial coordinates of the nodes into account.
protected  byte determineChildConnector(Node child)
          Determines a connector direction for the given child node depending on whether or not the child nodes are arranged horizontally.
 double getAspectRatio()
          Returns the preferred aspect ratio (width/height) for the subtrees.
 byte getFillStyle()
          Returns how rows/columns are aligned with each other.
 double getHorizontalDistance()
          Returns the horizontal distance between the GenericTreeLayouter.SubtreeShapes.
 double getVerticalDistance()
          Returns the vertical distance between the GenericTreeLayouter.SubtreeShapes.
 boolean isHorizontal()
          Returns whether child nodes are distributed in horizontal rows or vertical columns.
protected  GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot, byte parentConnectorDirection)
          Arranges the SubtreeShapes of children of the local root node in rows or columns that fit the specified aspect ratio.
 void setAspectRatio(double aspectRatio)
          Specifies the preferred aspect ratio (width/height) for the subtrees.
 void setFillStyle(byte fillStyle)
          Specifies how rows/columns are aligned with each other.
 void setHorizontal(boolean horizontal)
          Specifies whether child nodes are distributed in horizontal rows or vertical columns.
 void setHorizontalDistance(double horizontalDistance)
          Specifies the horizontal distance between the GenericTreeLayouter.SubtreeShapes.
 void setVerticalDistance(double verticalDistance)
          Specifies the vertical distance between the GenericTreeLayouter.SubtreeShapes.
 
Methods inherited from class y.layout.tree.AbstractNodePlacer
clone, createProcessor, determineChildConnectors, getNodeShape, getSubtreeShape, placeSubtree
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface y.layout.tree.NodePlacer
createProcessor, determineChildConnectors, placeSubtree
 

Field Detail

FILL_STYLE_LEADING

public static final byte FILL_STYLE_LEADING
Style specifier which defines that rows/columns are aligned with their leading side.

See Also:
setFillStyle(byte), Constant Field Values
Sample Graph:

Left-aligned rows

FILL_STYLE_CENTERED

public static final byte FILL_STYLE_CENTERED
Style specifier which defines that rows/columns are aligned with their center.

See Also:
setFillStyle(byte), Constant Field Values
Sample Graph:

Centered rows

FILL_STYLE_JUSTIFY

public static final byte FILL_STYLE_JUSTIFY
Style specifier which defines that rows/columns are justified to have the same width/height.

See Also:
setFillStyle(byte), Constant Field Values
Sample Graph:

Justified rows

FILL_STYLE_TRAILING

public static final byte FILL_STYLE_TRAILING
Style specifier which defines that rows/columns are aligned with their trailing side.

See Also:
setFillStyle(byte), Constant Field Values
Sample Graph:

Right-aligned rows
Constructor Detail

ARNodePlacer

public ARNodePlacer()
Creates a new instance of ARNodePlacer with default settings.


ARNodePlacer

public ARNodePlacer(boolean horizontal,
                    double aspectRatio,
                    byte fillStyle,
                    double horizontalDistance,
                    double verticalDistance)
Creates a new instance of ARNodePlacer with given settings.

Parameters:
horizontal - true for horizontal row mode, false for vertical row mode
horizontalDistance - horizontal distance between adjacent elements
verticalDistance - vertical distance between adjacent elements
aspectRatio - the aspectRatio for the subtree
fillStyle - a fill style constant describing the node distribution
Throws:
java.lang.IllegalArgumentException - if the specified aspect ratio is 0 or negative or if an unknown fill style is specified or if the horizontal/vertical distance is negative
Method Detail

determineChildConnector

protected byte determineChildConnector(Node child)
Determines a connector direction for the given child node depending on whether or not the child nodes are arranged horizontally.

If the child nodes are distributed horizontally, the edge should connect north, otherwise it should connect west.

Specified by:
determineChildConnector in class AbstractNodePlacer
Parameters:
child - the child node
Returns:
NodePlacer.DIRECTION_NORTH if nodes are placed in rows, NodePlacer.DIRECTION_WEST otherwise

placeSubtree

protected GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot,
                                                        byte parentConnectorDirection)
Arranges the SubtreeShapes of children of the local root node in rows or columns that fit the specified aspect ratio.

Specified by:
placeSubtree in class AbstractNodePlacer
Parameters:
localRoot - the local root node
parentConnectorDirection - the direction of the connector
Returns:
the GenericTreeLayouter.SubtreeShape containing the local root and all its subtrees

isHorizontal

public boolean isHorizontal()
Returns whether child nodes are distributed in horizontal rows or vertical columns.

Returns:
true for horizontal rows, false for vertical columns
See Also:
setHorizontal(boolean)

setHorizontal

public void setHorizontal(boolean horizontal)
Specifies whether child nodes are distributed in horizontal rows or vertical columns.

Default Value:
The default value is false. The child nodes are placed in vertical columns.
Parameters:
horizontal - true for horizontal rows, false for vertical columns
Sample Graphs:

false

true

getVerticalDistance

public double getVerticalDistance()
Returns the vertical distance between the GenericTreeLayouter.SubtreeShapes. The nodes will be placed below each other, keeping this distance.

The distance needs to be non-negative.

Returns:
the vertical distance between elements
See Also:
setVerticalDistance(double)

setVerticalDistance

public void setVerticalDistance(double verticalDistance)
Specifies the vertical distance between the GenericTreeLayouter.SubtreeShapes. The nodes will be placed below each other, keeping this distance.

The distance needs to be non-negative.

Default Value:
The default value is 40.
Parameters:
verticalDistance - the vertical distance between elements
Throws:
java.lang.IllegalArgumentException - if the specified distance is negative
Sample Graphs:

40

80

getHorizontalDistance

public double getHorizontalDistance()
Returns the horizontal distance between the GenericTreeLayouter.SubtreeShapes. The nodes will be placed next to each other, keeping this distance.

The distance needs to be non-negative.

Returns:
the horizontal distance between elements
See Also:
setHorizontalDistance(double)

setHorizontalDistance

public void setHorizontalDistance(double horizontalDistance)
Specifies the horizontal distance between the GenericTreeLayouter.SubtreeShapes. The nodes will be placed next to each other, keeping this distance.

The distance needs to be non-negative.

Default Value:
The default value is 40.
Parameters:
horizontalDistance - the horizontal distance between elements
Throws:
java.lang.IllegalArgumentException - if the specified distance is negative
Sample Graphs:

40

80

getAspectRatio

public double getAspectRatio()
Returns the preferred aspect ratio (width/height) for the subtrees. This ratio determines among how many rows/columns the nodes will be distributed.

The aspect ratio needs to be positive.

Returns:
the preferred ratio between width and height
See Also:
setAspectRatio(double)

setAspectRatio

public void setAspectRatio(double aspectRatio)
Specifies the preferred aspect ratio (width/height) for the subtrees. This ratio determines among how many rows/columns the nodes will be distributed.

The aspect ratio needs to be positive.

Default Value:
The default value is 1.
Parameters:
aspectRatio - the preferred ratio between width and height
Throws:
java.lang.IllegalArgumentException - if the specified aspect ratio is 0 or negative
Sample Graphs:

0.5

2

getFillStyle

public byte getFillStyle()
Returns how rows/columns are aligned with each other.

Returns:
one of the predefined fill styles
See Also:
setFillStyle(byte)

setFillStyle

public void setFillStyle(byte fillStyle)
Specifies how rows/columns are aligned with each other.

Default Value:
The default value is FILL_STYLE_LEADING
Parameters:
fillStyle - one of the predefined fill styles
Throws:
java.lang.IllegalArgumentException - if an unknown fill style is specified

createFromSketchComparator

public java.util.Comparator createFromSketchComparator()
Creates an edge Comparator which takes the initial coordinates of the nodes into account.

This Comparator defines the order of the outgoing edges of a node before the actual placement of the node's subtree is calculated. It also considers whether or not the rows are placed horiontally.

Specified by:
createFromSketchComparator in interface FromSketchNodePlacer
Returns:
the Comparator for the edges

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