public class DefaultNodePlacer extends AbstractNodePlacer implements IFromSketchNodePlacer, ICloneable
DefaultNodePlacer is the default implementation of interface INodePlacer.
Each layer in the tree uses different configurations of DefaultNodePlacer
TreeLayout.SubtreeShapes can be arranged in each main direction specified in
ChildPlacement. That way, the subtrees of the same graph can have
different directions.
This node placer aligns the local root node according to a chosen alignment.
There are various routing styles that result in different edge routes.
graph| Constructor and Description |
|---|
DefaultNodePlacer()
Creates a new
DefaultNodePlacer instance with default settings. |
DefaultNodePlacer(ChildPlacement childPlacement,
double verticalDistance,
double horizontalDistance)
Creates a new
DefaultNodePlacer instance with customized
child placement, vertical and
horizontal distance. |
DefaultNodePlacer(ChildPlacement childPlacement,
RootAlignment rootAlignment,
double verticalDistance,
double horizontalDistance)
Creates a new
DefaultNodePlacer instance with customized
child placement, root alignment,
vertical and horizontal distance. |
DefaultNodePlacer(ChildPlacement childPlacement,
RootAlignment rootAlignment,
RoutingStyle routingStyle,
double verticalDistance,
double horizontalDistance)
Creates a new
DefaultNodePlacer instance with customized
child placement, root alignment,
routing style, vertical and
horizontal distance. |
DefaultNodePlacer(ChildPlacement childPlacement,
RootAlignment rootAlignment,
RoutingStyle routingStyle,
double verticalDistance,
double horizontalDistance,
double minFirstSegmentLength,
double minLastSegmentLength,
double minSlope,
double minSlopeHeight)
Creates a new
DefaultNodePlacer instance with custom settings. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
calculateParentConnector(LayoutGraph graph,
Node localRoot,
INodeLayout rootLayout,
TreeLayout.SubtreeShape subtreeShape,
Edge parentEdge,
IEdgeLayout parentEdgeLayout,
byte direction)
Calculates the bends for the connector to the parent node.
|
protected void |
calculateSlopedSourceEdgeLayout(INodeLayout rootLayout,
TreeLayout.SubtreeShape childShape,
Edge edge,
double childForkCoordinate,
double rootForkCoordinate)
Calculates the routing of the source side of the edge to the given child node.
|
protected void |
calculateSourceEdgeLayout(INodeLayout rootLayout,
TreeLayout.SubtreeShape childShape,
Edge edge)
Calculates the routing of the source side of the edge to the given child node.
|
protected void |
calculateTargetEdgeLayout(INodeLayout rootLayout,
TreeLayout.SubtreeShape childShape,
Edge edge)
Calculates the routing of the target side of the edge to the given child node.
|
Comparator<Object> |
createComparator()
Creates a
Comparator for outgoing edges which takes the initial coordinates of the edges' targets into account. |
Comparator<Object> |
createFromSketchComparator()
Delegates to
createComparator(). |
protected ParentConnectorDirection |
determineChildConnector(Node child)
Determines a connector direction for the given child node depending on the selected
child placement. |
ChildPlacement |
getChildPlacement()
Gets the direction in which the child nodes are placed with respect to their parent node.
|
double |
getHorizontalDistance()
Gets the horizontal distance between nodes or
TreeLayout.SubtreeShapes. |
double |
getMinimumFirstSegmentLength()
Gets the minimum length for the first segment of an edge.
|
double |
getMinimumLastSegmentLength()
Gets the minimum length for the last segment of an edge.
|
double |
getMinimumSlope()
Gets the minimum slope of the edge segments.
|
double |
getMinimumSlopeHeight()
Gets the minimum height for sloped edge segments.
|
RootAlignment |
getRootAlignment()
Gets how the root node is aligned with its children and their
TreeLayout.SubtreeShapes. |
RoutingStyle |
getRoutingStyle()
Gets the style in which edge paths are routed.
|
double |
getVerticalAlignment()
Gets the relative vertical alignment of nodes with the same parent.
|
double |
getVerticalDistance()
Gets the vertical distance between nodes or
TreeLayout.SubtreeShapes. |
protected TreeLayout.SubtreeShape |
placeSubtree(Node localRoot,
ParentConnectorDirection parentConnectorDirection)
Arranges the root node and its children.
|
void |
setChildPlacement(ChildPlacement value)
Sets the direction in which the child nodes are placed with respect to their parent node.
|
void |
setHorizontalDistance(double value)
Sets the horizontal distance between nodes or
TreeLayout.SubtreeShapes. |
void |
setMinimumFirstSegmentLength(double value)
Sets the minimum length for the first segment of an edge.
|
void |
setMinimumLastSegmentLength(double value)
Sets the minimum length for the last segment of an edge.
|
void |
setMinimumSlope(double value)
Sets the minimum slope of the edge segments.
|
void |
setMinimumSlopeHeight(double value)
Sets the minimum height for sloped edge segments.
|
void |
setRootAlignment(RootAlignment value)
Sets how the root node is aligned with its children and their
TreeLayout.SubtreeShapes. |
void |
setRoutingStyle(RoutingStyle value)
Sets the style in which edge paths are routed.
|
void |
setVerticalAlignment(double value)
Sets the relative vertical alignment of nodes with the same parent.
|
void |
setVerticalDistance(double value)
Sets the vertical distance between nodes or
TreeLayout.SubtreeShapes. |
clone, createProcessor, determineChildConnectors, getNodeShape, getSubtreeShape, placeSubtreeequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateProcessor, determineChildConnectors, placeSubtreeclonepublic DefaultNodePlacer()
DefaultNodePlacer instance with default settings.public DefaultNodePlacer(ChildPlacement childPlacement, double verticalDistance, double horizontalDistance)
DefaultNodePlacer instance with customized
child placement, vertical and
horizontal distance.IllegalArgumentException - if the placement specifier is unknown or if the horizontal/vertical distance is negativechildPlacement - the child placement specifier describing the style of the arrangementverticalDistance - the vertical distance between the TreeLayout.SubtreeShapeshorizontalDistance - the horizontal distance between the TreeLayout.SubtreeShapessetChildPlacement(ChildPlacement),
setVerticalDistance(double),
setHorizontalDistance(double)public DefaultNodePlacer(ChildPlacement childPlacement, RootAlignment rootAlignment, double verticalDistance, double horizontalDistance)
DefaultNodePlacer instance with customized
child placement, root alignment,
vertical and horizontal distance.IllegalArgumentException - if the placement specifier or the root alignment specifier is unknown or if the horizontal/vertical distance is
negativechildPlacement - the child placement specifier describing the style of the arrangementrootAlignment - the alignment specifier describing how the root node is aligned with its child nodesverticalDistance - the vertical distance between the TreeLayout.SubtreeShapeshorizontalDistance - the horizontal distance between the TreeLayout.SubtreeShapessetChildPlacement(ChildPlacement),
setRootAlignment(RootAlignment),
setVerticalDistance(double),
setHorizontalDistance(double)public DefaultNodePlacer(ChildPlacement childPlacement, RootAlignment rootAlignment, RoutingStyle routingStyle, double verticalDistance, double horizontalDistance)
DefaultNodePlacer instance with customized
child placement, root alignment,
routing style, vertical and
horizontal distance.IllegalArgumentException - if the placement specifier or the root alignment or the routing style is unknown or if the horizontal/vertical distance
is negativechildPlacement - the child placement specifier describing the style of the arrangementrootAlignment - the alignment specifier describing how the root node is aligned with its child nodesroutingStyle - the routing style specifierverticalDistance - the vertical distance between the TreeLayout.SubtreeShapeshorizontalDistance - the horizontal distance between the TreeLayout.SubtreeShapessetChildPlacement(ChildPlacement),
setRootAlignment(RootAlignment),
setRoutingStyle(RoutingStyle),
setVerticalDistance(double),
setHorizontalDistance(double)public DefaultNodePlacer(ChildPlacement childPlacement, RootAlignment rootAlignment, RoutingStyle routingStyle, double verticalDistance, double horizontalDistance, double minFirstSegmentLength, double minLastSegmentLength, double minSlope, double minSlopeHeight)
DefaultNodePlacer instance with custom settings.IllegalArgumentException - if the placement specifier or the root alignment or the routing style is unknown or if the horizontal/vertical distance
or the minimum first/last segment length or the minimum slope or the minimum vertical height is negativechildPlacement - the child placement specifier describing the style of the arrangementrootAlignment - the alignment specifier describing how the root node is aligned with its child nodesroutingStyle - the routing style specifierverticalDistance - the vertical distance between the TreeLayout.SubtreeShapeshorizontalDistance - the horizontal distance between the TreeLayout.SubtreeShapesminFirstSegmentLength - the minimum length of the first edge segment (connected to the root node)minLastSegmentLength - the minimum length of the last edge segment (connected to the child node)minSlope - the minimum slope between the root node and the TreeLayout.SubtreeShapesminSlopeHeight - the minimum vertical height of sloped edge segmentssetChildPlacement(ChildPlacement),
setRootAlignment(RootAlignment),
setRoutingStyle(RoutingStyle),
setVerticalDistance(double),
setHorizontalDistance(double),
setMinimumFirstSegmentLength(double),
setMinimumLastSegmentLength(double),
setMinimumSlope(double),
setMinimumSlopeHeight(double)protected void calculateParentConnector(LayoutGraph graph, Node localRoot, INodeLayout rootLayout, TreeLayout.SubtreeShape subtreeShape, Edge parentEdge, IEdgeLayout parentEdgeLayout, byte direction)
This implementation adds bends to the connector for edges that route the edges around the child node in case there are
PortConstraints that conflict with the direction of the child placement.
This method is called in placeSubtree(Node, ParentConnectorDirection) to route the edges after the
TreeLayout.SubtreeShapes are arranged. It may be overridden to customize the routing style.
graph - the input graphlocalRoot - the local root node whose connector is calculated and stored in the given subtree shaperootLayout - the INodeLayout of the root nodesubtreeShape - the shape of the whole subtree of the local rootparentEdge - the incoming edge of the local root node that will be the connector for the given subtree shapeparentEdgeLayout - the current IEdgeLayout of the connector edgedirection - the direction specifier as defined in the INodePlacer interface which should be
used for the connectorAbstractNodePlacer.determineChildConnectors(Node, com.yworks.yfiles.algorithms.IDataMap)protected void calculateSlopedSourceEdgeLayout(INodeLayout rootLayout, TreeLayout.SubtreeShape childShape, Edge edge, double childForkCoordinate, double rootForkCoordinate)
This method delegates to calculateSourceEdgeLayout(INodeLayout, TreeLayout.SubtreeShape, Edge) if the routing style
is not RoutingStyle.FORK. It may be overridden to implement a custom routing style.
rootLayout - the INodeLayout of the local root nodechildShape - the TreeLayout.SubtreeShape instance of the corresponding child's subtreeedge - the edgerootForkCoordinate - the y-coordinate of the first bend of the edge if the placement is horizontal, the x-coordinate otherwisechildForkCoordinate - the y-coordinate of the second (= last) bend of the edge if the placement is horizontal, the x-coordinate otherwiseprotected void calculateSourceEdgeLayout(INodeLayout rootLayout, TreeLayout.SubtreeShape childShape, Edge edge)
This implementation adds bends to the IEdgeLayout of the given edge according to the specified routing style
and child placement. It also updates the target points in the
TreeLayout.SubtreeShape.
This method is called by calculateSlopedSourceEdgeLayout(INodeLayout, TreeLayout.SubtreeShape, Edge, double, double)
to route the edges. It may be overridden to implement a custom edge routing style.
rootLayout - the INodeLayout of the local root nodechildShape - the TreeLayout.SubtreeShape of the child's subtree that is connected through the given edgeedge - the edgeprotected void calculateTargetEdgeLayout(INodeLayout rootLayout, TreeLayout.SubtreeShape childShape, Edge edge)
This implementation just resets the current IEdgeLayout.
This method is called by placeSubtree(Node, ParentConnectorDirection) after the shapes
of the local root's children are placed. It may be overridden to add some target points
to the edge.
rootLayout - the INodeLayout of the local root nodechildShape - the TreeLayout.SubtreeShape of the child's subtree that is connected through the given edgeedge - the edgepublic Comparator<Object> createComparator()
Comparator for outgoing edges which takes the initial coordinates of the edges' targets into account.
Child nodes are sorted in a way that the layout will resemble the current arrangement of the nodes. This is especially useful for interactive or incremental layout calculation.
Comparator that considers the initial coordinates of the nodespublic Comparator<Object> createFromSketchComparator()
createComparator().createFromSketchComparator in interface IFromSketchNodePlacerComparatorcreateComparator()protected ParentConnectorDirection determineChildConnector(Node child)
child placement.
If the child nodes are placed below the root node, the edge should connect
north. If they are placed above the
root node it should connect
south. The vertical placements are handled analogous.
determineChildConnector in class AbstractNodePlacerchild - the child nodechild placementgetChildPlacement()public ChildPlacement getChildPlacement()
Subtrees can be placed below, above, left or right of their roots.
IllegalArgumentException - if an unknown placement specifier is setChildPlacement.HORIZONTAL_DOWNWARDsetChildPlacement(ChildPlacement)public double getHorizontalDistance()
TreeLayout.SubtreeShapes.
The distance needs to be non-negative.
IllegalArgumentException - if the specified distance is negativesetHorizontalDistance(double)public double getMinimumFirstSegmentLength()
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.
IllegalArgumentException - if the minimum segment length is negativesetMinimumFirstSegmentLength(double)public double getMinimumLastSegmentLength()
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.
IllegalArgumentException - if the minimum segment length is negativesetMinimumLastSegmentLength(double)public double getMinimumSlope()
These sloped segments are between the vertical first and last segment of the edge.
The segments may become steeper but they will have at least the specified slope. Negative minimum slopes can lead to edge routes looking like spider legs.
vertical distance slope segments can have.setMinimumSlopeHeight(double),
setMinimumSlope(double)public double getMinimumSlopeHeight()
These sloped segments are between the vertical first and last segment of the edge.
The segments may become steeper to reach the specified height.
MinimumSlope minimum slope} segments can have.setMinimumSlope(double),
setMinimumSlopeHeight(double)public RootAlignment getRootAlignment()
TreeLayout.SubtreeShapes.IllegalArgumentException - if an unknown root alignment specifier is setRootAlignment.CENTERsetRootAlignment(RootAlignment)public RoutingStyle getRoutingStyle()
IllegalArgumentException - if the specified routing style is unknownRoutingStyle.FORKsetRoutingStyle(RoutingStyle)public double getVerticalAlignment()
All values between 0 and 1 result in a valid alignment.
0 - nodes are top-aligned0.5 - nodes are center-aligned1 - nodes are bottom-aligned
Values outside the interval [0,1] will result in a more compact node placement with unaligned nodes.
setVerticalAlignment(double)public double getVerticalDistance()
TreeLayout.SubtreeShapes.
The distance needs to be non-negative.
IllegalArgumentException - if the specified distance is negativesetVerticalDistance(double)protected TreeLayout.SubtreeShape placeSubtree(Node localRoot, ParentConnectorDirection parentConnectorDirection)
placeSubtree in class AbstractNodePlacerlocalRoot - the local root nodeparentConnectorDirection - the direction of the connectorTreeLayout.SubtreeShape containing the local root and all its subtreespublic void setChildPlacement(ChildPlacement value)
Subtrees can be placed below, above, left or right of their roots.
IllegalArgumentException - if an unknown placement specifier is setChildPlacement.HORIZONTAL_DOWNWARDvalue - one of the valid placement specifiersgetChildPlacement()public void setHorizontalDistance(double value)
TreeLayout.SubtreeShapes.
The distance needs to be non-negative.
IllegalArgumentException - if the specified distance is negativevalue - the non-negative horizontal distancegetHorizontalDistance()public void setMinimumFirstSegmentLength(double value)
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.
IllegalArgumentException - if the minimum segment length is negativevalue - the non-negative minimum segment lengthgetMinimumFirstSegmentLength()public void setMinimumLastSegmentLength(double value)
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.
IllegalArgumentException - if the minimum segment length is negativevalue - the non-negative minimum segment lengthgetMinimumLastSegmentLength()public void setMinimumSlope(double value)
These sloped segments are between the vertical first and last segment of the edge.
The segments may become steeper but they will have at least the specified slope. Negative minimum slopes can lead to edge routes looking like spider legs.
vertical distance slope segments can have.value - the minimum slopesetMinimumSlopeHeight(double),
getMinimumSlope()public void setMinimumSlopeHeight(double value)
These sloped segments are between the vertical first and last segment of the edge.
The segments may become steeper to reach the specified height.
MinimumSlope minimum slope} segments can have.value - the minimum height for sloped segmentssetMinimumSlope(double),
getMinimumSlopeHeight()public void setRootAlignment(RootAlignment value)
TreeLayout.SubtreeShapes.IllegalArgumentException - if an unknown root alignment specifier is setRootAlignment.CENTERvalue - one of the valid root alignment specifiersgetRootAlignment()public void setRoutingStyle(RoutingStyle value)
IllegalArgumentException - if the specified routing style is unknownRoutingStyle.FORKvalue - the routing style specifiergetRoutingStyle()public void setVerticalAlignment(double value)
All values between 0 and 1 result in a valid alignment.
0 - nodes are top-aligned0.5 - nodes are center-aligned1 - nodes are bottom-aligned
Values outside the interval [0,1] will result in a more compact node placement with unaligned nodes.
value - the relative vertical alignment of nodes that have the same parent nodegetVerticalAlignment()public void setVerticalDistance(double value)
TreeLayout.SubtreeShapes.
The distance needs to be non-negative.
IllegalArgumentException - if the specified distance is negativevalue - the non-negative vertical distancegetVerticalDistance()