Search this API

y.layout.tree
Class CompactNodePlacer

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

public class CompactNodePlacer
extends AbstractNodePlacer

The CompactNodePlacer produces a compact placement of the children.

Layout Style

This NodePlacer uses a dynamic optimization approach that chooses a placement strategy of the children of the associated local root such that the overall result is compact with respect to a specified aspect ratio. The set of applied strategies is predefined and cannot be customized. A node can either be a normal tree node or an assistant node, in which case the AssistantPlacer is chosen automatically (i.e., you shouldn't explicitly map nodes to instances of AssistantPlacer but mark them by means of key AssistantPlacer.ASSISTANT_DPKEY).


All nodes are associated with an instance of CompactNodePlacer which yields a compact overall layout using different placement strategies.

 
This placer always produces orthogonal edge routes and doesn't support port constraints, port candidates and critical edges.
 

Field Summary
static java.lang.Object STRATEGY_MEMENTO_DPKEY
          A DataAcceptor key for storing/restoring the placement strategy of the children of nodes.
 
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
CompactNodePlacer()
          Creates a new CompactNodePlacer instance with default settings.
 
Method Summary
 Processor createProcessor(GenericTreeLayouter layouter, LayoutGraph graph, Node currentRoot)
          Creates a Processor.
protected  byte determineChildConnector(Node child)
          Determines a connector direction for the given child node.
 void determineChildConnectors(Node localRoot, DataMap connectorMap)
          Provides the direction of the connector to the SubtreeShape for each child node.
 double getHorizontalDistance()
          Returns the horizontal distance between nodes or subtrees.
 double getMinimumFirstSegmentLength()
          Returns the minimum length for the first segment of an edge.
 double getMinimumLastSegmentLength()
          Returns the minimum length for the last segment of an edge.
 double getPreferredAspectRatio()
          Returns the preferred aspect ratio (width/height) for the subtrees.
 double getVerticalDistance()
          Returns the vertical distance between nodes or subtrees.
protected  GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot, byte parentConnectorDirection)
          Arranges the local root relative to the GenericTreeLayouter.SubtreeShape of its children.
 void setHorizontalDistance(double distance)
          Specifies the horizontal distance between nodes or subtrees.
 void setMinimumFirstSegmentLength(double minFirstSegmentLength)
          Specifies the minimum length for the first segment of an edge.
 void setMinimumLastSegmentLength(double minLastSegmentLength)
          Specifies the minimum length for the last segment of an edge.
 void setPreferredAspectRatio(double aspectRatio)
          Specifies the preferred aspect ratio (width/height) for the subtrees.
 void setVerticalDistance(double distance)
          Specifies the vertical distance between nodes or subtrees.
 
Methods inherited from class y.layout.tree.AbstractNodePlacer
clone, getNodeShape, getSubtreeShape, placeSubtree
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STRATEGY_MEMENTO_DPKEY

public static final java.lang.Object STRATEGY_MEMENTO_DPKEY
A DataAcceptor key for storing/restoring the placement strategy of the children of nodes.

Even for small changes/updates in the graph structure, the results produced by the CompactNodePlacer may differ significantly. If a DataAcceptor is registered with this key, the layout algorithm stores the applied placement strategy for the nodes' children and keeps it in subsequent layout runs.

 
Adding new nodes may still change the result because some strategies can only be applied to specific subtrees, e.g., the LeftRightPlacer-like strategy is only applied to nodes where all children are leaf nodes.
Constructor Detail

CompactNodePlacer

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

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

determineChildConnector

protected byte determineChildConnector(Node child)
Description copied from class: AbstractNodePlacer
Determines a connector direction for the given child node.

This method is used in AbstractNodePlacer.determineChildConnectors(Node, DataMap) and must be implemented by subclasses.

Specified by:
determineChildConnector in class AbstractNodePlacer
Parameters:
child - the child node
Returns:
a direction specifier as defined in the NodePlacer interface

determineChildConnectors

public void determineChildConnectors(Node localRoot,
                                     DataMap connectorMap)
Description copied from class: AbstractNodePlacer
Provides the direction of the connector to the SubtreeShape for each child node.

This implementation uses AbstractNodePlacer.determineChildConnector(Node) to retrieve the direction for the connectors.

Specified by:
determineChildConnectors in interface NodePlacer
Overrides:
determineChildConnectors in class AbstractNodePlacer
Parameters:
localRoot - the local root node
connectorMap - the map that must be used for storing the direction specifiers of the child nodes

placeSubtree

protected GenericTreeLayouter.SubtreeShape placeSubtree(Node localRoot,
                                                        byte parentConnectorDirection)
Description copied from class: AbstractNodePlacer
Arranges the local root relative to the GenericTreeLayouter.SubtreeShape of its children.

This is the main method that must be implemented by subclasses. It is called by AbstractNodePlacer.placeSubtree(DataProvider, DataProvider, LayoutGraph, Node, byte).

Specified by:
placeSubtree in class AbstractNodePlacer
Parameters:
localRoot - the local root node
parentConnectorDirection - the direction of the connector
Returns:
a GenericTreeLayouter.SubtreeShape instance that describes the shape of the whole subtree rooted at the given local root

createProcessor

public Processor createProcessor(GenericTreeLayouter layouter,
                                 LayoutGraph graph,
                                 Node currentRoot)
Creates a Processor.

Specified by:
createProcessor in interface NodePlacer
Overrides:
createProcessor in class AbstractNodePlacer
Parameters:
layouter - the current GenericTreeLayouter instance
graph - the input graph
currentRoot - the root node handled by this NodePlacer
Returns:
a Processor instance or null

getPreferredAspectRatio

public double getPreferredAspectRatio()
Returns the preferred aspect ratio (width/height) for the subtrees.

The aspect ratio needs to be non-negative.

 
The aspect ratio is only considered for nodes associated with a CompactNodePlacer and without a parent associated with such a placer.
Returns:
the preferred ratio between width and height

setPreferredAspectRatio

public void setPreferredAspectRatio(double aspectRatio)
Specifies the preferred aspect ratio (width/height) for the subtrees.

The aspect ratio needs to be non-negative.

 
The aspect ratio is only considered for nodes associated with a CompactNodePlacer and without a parent associated with such a placer.
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 negative

setMinimumFirstSegmentLength

public void setMinimumFirstSegmentLength(double minFirstSegmentLength)
Specifies the minimum length for the first segment of an edge.

During layout calculation, the edges of the tree are directed. Hence, the first segment is always the segment that is attached to the source, which is the local root node.

The length needs to be non-negative.

Default Value:
The default value is 20.
Parameters:
minFirstSegmentLength - the non-negative minimum segment length
Throws:
java.lang.IllegalArgumentException - if the minimum segment length is negative
Sample Graphs:

15

30

getMinimumFirstSegmentLength

public double getMinimumFirstSegmentLength()
Returns the minimum length for the first segment of an edge.

During layout calculation, the edges of the tree are directed. Hence, the first segment is always the segment that is attached to the source, which is the local root node.

The length needs to be non-negative.

Returns:
the non-negative minimum segment length
See Also:
setMinimumFirstSegmentLength(double)

setMinimumLastSegmentLength

public void setMinimumLastSegmentLength(double minLastSegmentLength)
Specifies the minimum length for the last segment of an edge.

During layout calculation, the edges of the tree are directed. Hence, the last segment is always the segment that is attached to the target, which is a child node.

The length needs to be non-negative.

Default Value:
The default value is 20.
Parameters:
minLastSegmentLength - the non-negative minimum segment length
Throws:
java.lang.IllegalArgumentException - if the minimum segment length is negative
Sample Graphs:

15

30

getMinimumLastSegmentLength

public double getMinimumLastSegmentLength()
Returns the minimum length for the last segment of an edge.

During layout calculation, the edges of the tree are directed. Hence, the last segment is always the segment that is attached to the target, which is a child node.

The length needs to be non-negative.

Returns:
the non-negative minimum segment length
See Also:
setMinimumLastSegmentLength(double)

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