Search this API

y.layout.tree
Class AssistantPlacer

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

public class AssistantPlacer
extends AbstractRotatableNodePlacer

The AssistantPlacer places nodes that are marked as assistants left and right of their parents and all other nodes below the assistant nodes.

Layout Style


Assistants are marked

Concept

This NodePlacer delegates the placement of all assistant nodes to an instance of LeftRightPlacer. The non-assistant nodes are handled by another node placer. To be able to do this, AssistantPlacer uses a Processor which prepares the graph for node placing.

A DataProvider that is registered using ASSISTANT_DPKEY returns true for assistant nodes and false for all other nodes.

 
This node placer produces the best results when using a PortAssignment that starts all edges at the same port. If the ports are distributed along the border, edge crossings may occur.
 

Nested Class Summary
 
Nested classes/interfaces inherited from class y.layout.tree.AbstractRotatableNodePlacer
AbstractRotatableNodePlacer.Matrix, AbstractRotatableNodePlacer.RootAlignment
 
Field Summary
static java.lang.Object ASSISTANT_DPKEY
          A DataProvider key for marking which nodes are placed as assistants
 
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
AssistantPlacer()
          Creates a new AssistantPlacer instance with default settings.
AssistantPlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
          Creates a new AssistantPlacer instance that uses the transformation defined by the given matrix.
 
Method Summary
 java.util.Comparator createComparator()
          Delegates the creation of from-sketch comparators to the two NodePlacers handling assistant and non-assistant nodes.
static java.util.Comparator createCompoundComparator(java.util.Comparator assistantComparator, java.util.Comparator childComparator)
          Creates a Comparator that compares outgoing edges connecting to assistant nodes and edges connecting to non-assistant nodes separately.
 Processor createProcessor(GenericTreeLayouter layouter, LayoutGraph graph, Node currentRoot)
          Creates a Processor that prepares the graph for placing assistant node.
protected  byte determineChildConnector(Node child)
          Determines a connector direction for the given child node.
 void determineChildConnectors(Node localRoot, DataMap connectorMap)
          Delegates the calculation of the child connectors to the LeftRightPlacer which arranges the assistant nodes.
 NodePlacer getChildNodePlacer()
          Returns the NodePlacer instance that places the non-assistant children.
protected  GenericTreeLayouter.SubtreeShape getNodeShape(Node node)
          Returns the GenericTreeLayouter.SubtreeShape for the given node.
 double getSpacing()
          Returns the spacing between subtrees for the delegate NodePlacer.
 GenericTreeLayouter.SubtreeShape placeSubtree(DataProvider nodeShapeProvider, DataProvider subtreeShapeProvider, LayoutGraph graph, Node localRoot, byte parentConnectorDirection)
          Delegates the arrangement of GenericTreeLayouter.SubtreeShapes to an instance of LeftRightPlacer.
protected  y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot, byte parentConnectorDirection)
          Arranges the local root relative to the subtree shape of its children.
 void setChildNodePlacer(NodePlacer childNodePlacer)
          Specifies the NodePlacer instance that places the non-assistant children.
 void setSpacing(double spacing)
          Specifies the spacing between subtrees for the delegate NodePlacer.
 
Methods inherited from class y.layout.tree.AbstractRotatableNodePlacer
createFromSketchComparator, createRootNodeShape, createSubtreeShape, getModificationMatrix, getPortConstraint, getSourcePointAbs, translateDirectionToModel, translateDirectionToReal, translatePoint
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASSISTANT_DPKEY

public static final java.lang.Object ASSISTANT_DPKEY
A DataProvider key for marking which nodes are placed as assistants

Constructor Detail

AssistantPlacer

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


AssistantPlacer

public AssistantPlacer(AbstractRotatableNodePlacer.Matrix modificationMatrix)
Creates a new AssistantPlacer instance that uses the transformation defined by the given matrix.

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

determineChildConnector

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

Specified by:
determineChildConnector in class AbstractRotatableNodePlacer
 
This method should not be called! Finding the directions for the connectors is delegated to the NodePlacer for the assistant nodes by determineChildConnectors(Node, DataMap).
Parameters:
child - the child node
Returns:
a direction specifier as defined in the NodePlacer interface
Throws:
java.lang.IllegalStateException - if this method is called

determineChildConnectors

public void determineChildConnectors(Node localRoot,
                                     DataMap connectorMap)
Delegates the calculation of the child connectors to the LeftRightPlacer which arranges the assistant nodes.

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:
AbstractRotatableNodePlacer.determineChildConnector(Node)

getNodeShape

protected GenericTreeLayouter.SubtreeShape getNodeShape(Node node)
Returns the GenericTreeLayouter.SubtreeShape for the given node.

This is a convenience method that retrieves a GenericTreeLayouter.SubtreeShape for a single node from the corresponding DataProvider.

This method is used in placeSubtree(Node, byte) for retrieving the GenericTreeLayouter.SubtreeShapes for the local root nodes. It may be overridden to return a custom implementation of GenericTreeLayouter.SubtreeShape.

 
This method can first be called during the execution of placeSubtree(Node, byte). Otherwise, the DataProvider for querying results will not have been initialized yet.
Parameters:
node - the node
Returns:
the GenericTreeLayouter.SubtreeShape for the given node

createProcessor

public Processor createProcessor(GenericTreeLayouter layouter,
                                 LayoutGraph graph,
                                 Node currentRoot)
Creates a Processor that prepares the graph for placing assistant node.

The pre-processing step adds a dummy node as a child to the current root and changes all edges of non-assistant children such that they start at this dummy node. That way, AssistantPlacer is able to delegate the assistant nodes to a NodePlacer different from the one used for placing non-assistant nodes. The child node placer is assigned to the dummy node. So the non-assistant children are placed by this delegate placer.

All changes will be cleaned up during the post-processing step.

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 instance that prepares the graph for AssistantPlacer, or null if the out-degree of the given root node is zero

setSpacing

public void setSpacing(double spacing)
Specifies the spacing between subtrees for the delegate NodePlacer.

The spacing needs to be non-negative.

Overrides:
setSpacing in class AbstractRotatableNodePlacer
Default Value:
The default value is 20.
Parameters:
spacing - the distance between subtrees
Throws:
java.lang.IllegalArgumentException - if the given spacing is negative
Sample Graphs:

Spacing 20 using SimpleNodePlacer

Spacing 50 using SimpleNodePlacer

getSpacing

public double getSpacing()
Returns the spacing between subtrees for the delegate NodePlacer.

The spacing needs to be non-negative.

Overrides:
getSpacing in class AbstractRotatableNodePlacer
Returns:
the distance between subtrees
See Also:
setSpacing(double)

placeSubtree

public GenericTreeLayouter.SubtreeShape placeSubtree(DataProvider nodeShapeProvider,
                                                     DataProvider subtreeShapeProvider,
                                                     LayoutGraph graph,
                                                     Node localRoot,
                                                     byte parentConnectorDirection)
Delegates the arrangement of GenericTreeLayouter.SubtreeShapes to an instance of LeftRightPlacer.

The LeftRightPlacer places all assistant nodes left and right of the local root node. The GenericTreeLayouter.SubtreeShape associated with the dummy node which contains GenericTreeLayouter.SubtreeShapes of the non-assistant nodes is placed below the assistant nodes, center-aligned with respect to the local root node.

Specified by:
placeSubtree in interface NodePlacer
Overrides:
placeSubtree in class AbstractRotatableNodePlacer
Parameters:
nodeShapeProvider - the DataProvider for obtaining an initial shape of the root node
subtreeShapeProvider - the DataProvider for accessing the pre-calculated shapes of the subtrees
graph - the input graph
localRoot - the root of the subtree that should be arranged by this method
parentConnectorDirection - the direction specifier for the connector of the local root node to its parent node
Returns:
the merged GenericTreeLayouter.SubtreeShape containing the local root and all assistant nodes and non-assistant nodes
See Also:
AbstractRotatableNodePlacer.placeSubtree(Node, byte)

placeSubtree

protected y.layout.tree.SubtreeShapeRotated placeSubtree(Node localRoot,
                                                         byte parentConnectorDirection)
Arranges the local root relative to the subtree shape of its children.

Specified by:
placeSubtree in class AbstractRotatableNodePlacer
 
This method should not be called! Placing subtrees is delegated to the NodePlacer for the assistant nodes and the placer for non-assistant nodes by method placeSubtree(DataProvider, DataProvider, LayoutGraph, Node, byte).
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
Throws:
java.lang.IllegalStateException - if this method is called

setChildNodePlacer

public void setChildNodePlacer(NodePlacer childNodePlacer)
Specifies the NodePlacer instance that places the non-assistant children.

These non-assistant child nodes will be placed below the assistant child nodes and are arranged by the given NodePlacer. Non-assistant child nodes are the ones that are not marked in the DataProvider registered with ASSISTANT_DPKEY.

 
Using CompactNodePlacer as placer for non-assistant children is not supported. Instead, CompactNodePlacer itself allows to define assistant nodes and in that case places sub-trees using the same style as AssistantPlacer does.
Default Value:
The default value is SimpleNodePlacer. A SimpleNodePlacer with centered local roots is used.
Parameters:
childNodePlacer - the child node placer for the non-assistant children
Throws:
java.lang.IllegalArgumentException - if the given child placer is null or an instance of class CompactNodePlacer.
See Also:
ASSISTANT_DPKEY

getChildNodePlacer

public NodePlacer getChildNodePlacer()
Returns the NodePlacer instance that places the non-assistant children.

These non-assistant child nodes will be placed below the assistant child nodes and are arranged by the given NodePlacer. Non-assistant child nodes are the ones that are not marked in the DataProvider registered with ASSISTANT_DPKEY.

 
Using CompactNodePlacer as placer for non-assistant children is not supported. Instead, CompactNodePlacer itself allows to define assistant nodes and in that case places sub-trees using the same style as AssistantPlacer does.
Returns:
the child node placer for the non-assistant children
See Also:
setChildNodePlacer(NodePlacer), ASSISTANT_DPKEY

createComparator

public java.util.Comparator createComparator()
Delegates the creation of from-sketch comparators to the two NodePlacers handling assistant and non-assistant nodes.

The from-sketch Comparators are combined into a compound comparator. The one for the edges connecting to assistant nodes is retrieved from a LeftRightPlacer while the other one is provided by the child placer.

Overrides:
createComparator in class AbstractRotatableNodePlacer
Returns:
the Comparator to compare edges, considering the initial locations of their target nodes
See Also:
setChildNodePlacer(NodePlacer), createCompoundComparator(Comparator, Comparator), FromSketchNodePlacer.createFromSketchComparator()

createCompoundComparator

public static java.util.Comparator createCompoundComparator(java.util.Comparator assistantComparator,
                                                            java.util.Comparator childComparator)
Creates a Comparator that compares outgoing edges connecting to assistant nodes and edges connecting to non-assistant nodes separately.

Parameters:
assistantComparator - the Comparator for edges connecting to assistant nodes
childComparator - the Comparator for edges connecting to non-assistant nodes
Returns:
a Comparator that compares edges to assistant nodes separately from edges to non-assistant nodes

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