Search this API

y.layout.tree
Class DefaultPortAssignment

java.lang.Object
  extended by y.layout.tree.DefaultPortAssignment
All Implemented Interfaces:
PortAssignment

public class DefaultPortAssignment
extends java.lang.Object
implements PortAssignment

The DefaultPortAssignment provides some simple port assignment styles.

Ports are either centered on the node, distributed at one side of the node or placed considering PortConstraints.

 

Field Summary
static byte MODE_NONE
          A port assignment specifier which defines that all ports are reset to the center of their nodes.
static byte MODE_PORT_CONSTRAINTS
          A port assignment specifier that defines that PortConstraints are considered.
static byte MODE_PORT_DISTRIBUTED_EAST
          A port assignment specifier which defines that edges are distributed evenly at the eastern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_NORTH
          A port assignment specifier which defines that edges are distributed evenly at the northern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_SOUTH
          A port assignment specifier which defines that edges are distributed evenly at the southern side of their nodes.
static byte MODE_PORT_DISTRIBUTED_WEST
          A port assignment specifier which defines that edges are distributed evenly at the western side of their nodes.
 
Constructor Summary
DefaultPortAssignment()
          Creates a new DefaultPortAssignment instance with default settings.
DefaultPortAssignment(byte mode)
          Creates a new DefaultPortAssignment instance using the given port assignment mode.
DefaultPortAssignment(byte mode, double ratio)
          Creates a new DefaultPortAssignment instance using the given port assignment mode and ratio between the border and the ports and the gap between the ports themselves.
 
Method Summary
protected  void assignChildEdgeSourcePort(LayoutGraph graph, Node node, Edge edge, int index)
          Assigns relative coordinates to the source port of the outgoing edge to a child of the given node.
protected  void assignParentEdgeTargetPort(LayoutGraph graph, Node node, Edge edge)
          Assigns relative coordinates to the target port of the incoming edge from the parent of the given node.
 void assignPorts(LayoutGraph graph, Node node)
          Places the ports of edges connecting to the given node according to the port assignment mode.
 double getBorderGapToPortGapRatio()
          Returns the ratio of the border gap (distance between the outer ports to the node border) to the port gap (distance between adjacent ports).
 byte getMode()
          Returns the mode that describes how ports are placed.
protected  double getPortBorderGap(double sideLength, int edgeCount)
          Determines the distance between the outer ports and the border of the node.
protected  double getPortDistanceDelta(double sideLength, int edgeCount, double portBorderGap)
          Determines the distance between two adjacent ports.
protected  PortConstraint getSourcePortConstraint(LayoutGraph graph, Edge edge, int index)
          Retrieves the source PortConstraint for the given edge.
protected  PortConstraint getTargetPortConstraint(LayoutGraph graph, Edge edge)
          Retrieves the target PortConstraint for the given edge.
 boolean isReversedPortOrder()
          Returns whether or not the port assignment should reverse the order of the ports.
 void setBorderGapToPortGapRatio(double borderGapToPortGapRatio)
          Specifies the ratio of the border gap (distance between the outer ports to the node border) to the port gap (distance between adjacent ports).
 void setMode(byte mode)
          Specifies the mode that describes how ports are placed.
 void setReversedPortOrder(boolean reversedPortOrder)
          Specifies whether or not the port assignment should reverse the order of the ports.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_PORT_CONSTRAINTS

public static final byte MODE_PORT_CONSTRAINTS
A port assignment specifier that defines that PortConstraints are considered. Ports are placed using the following rules:

If edges with PortConstraints are grouped, all edges in the same group will use the port coordinates of the first edge in the group.

See Also:
PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Edges end at fixed port locations

MODE_PORT_DISTRIBUTED_NORTH

public static final byte MODE_PORT_DISTRIBUTED_NORTH
A port assignment specifier which defines that edges are distributed evenly at the northern side of their nodes.

Grouped edges will use the same port coordinate and will be considered as a single edge when calculating the distribution.

See Also:
PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Edge ports are distributed on the northern border of the node

MODE_PORT_DISTRIBUTED_SOUTH

public static final byte MODE_PORT_DISTRIBUTED_SOUTH
A port assignment specifier which defines that edges are distributed evenly at the southern side of their nodes.

Grouped edges will use the same port coordinate and will be considered as a single edge when calculating the distribution.

See Also:
PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Edge ports are distributed on the southern border of the node

MODE_PORT_DISTRIBUTED_EAST

public static final byte MODE_PORT_DISTRIBUTED_EAST
A port assignment specifier which defines that edges are distributed evenly at the eastern side of their nodes.

Grouped edges will use the same port coordinate and will be considered as a single edge when calculating the distribution.

See Also:
PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Edge ports are distributed on the eastern border of the node

MODE_PORT_DISTRIBUTED_WEST

public static final byte MODE_PORT_DISTRIBUTED_WEST
A port assignment specifier which defines that edges are distributed evenly at the western side of their nodes.

Grouped edges will use the same port coordinate and will be considered as a single edge when calculating the distribution.

See Also:
PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Edge ports are distributed on the western border of the node

MODE_NONE

public static final byte MODE_NONE
A port assignment specifier which defines that all ports are reset to the center of their nodes.

See Also:
Constant Field Values
Sample Graph:

All edges end at the center of the node
Constructor Detail

DefaultPortAssignment

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


DefaultPortAssignment

public DefaultPortAssignment(byte mode)
Creates a new DefaultPortAssignment instance using the given port assignment mode.

Parameters:
mode - one of the predefined port assignment specifiers
Throws:
java.lang.IllegalArgumentException - if an unknown mode is specified

DefaultPortAssignment

public DefaultPortAssignment(byte mode,
                             double ratio)
Creates a new DefaultPortAssignment instance using the given port assignment mode and ratio between the border and the ports and the gap between the ports themselves.

Parameters:
mode - one of the predefined port assignment specifiers
ratio - the ratio of the distance between outer ports and the border to the distance between any two ports
Throws:
java.lang.IllegalArgumentException - if an unknown mode is specified or if the specified ratio is negative
Method Detail

assignPorts

public void assignPorts(LayoutGraph graph,
                        Node node)
Places the ports of edges connecting to the given node according to the port assignment mode.

Specified by:
assignPorts in interface PortAssignment
Parameters:
graph - the input graph
node - the node whose adjacent edges' ports should be placed
See Also:
getMode()

assignParentEdgeTargetPort

protected void assignParentEdgeTargetPort(LayoutGraph graph,
                                          Node node,
                                          Edge edge)
Assigns relative coordinates to the target port of the incoming edge from the parent of the given node.

This method is called by assignPorts(LayoutGraph, Node) if the given node has a parent node. It may be overridden to assign a custom location to the target port of the incoming edge.

 
This implementation considers PortConstraints despite the port assignment mode.
Parameters:
graph - the input graph
node - the node
edge - the edge from the parent node
See Also:
EdgeLayout.setTargetPoint(YPoint)

assignChildEdgeSourcePort

protected void assignChildEdgeSourcePort(LayoutGraph graph,
                                         Node node,
                                         Edge edge,
                                         int index)
Assigns relative coordinates to the source port of the outgoing edge to a child of the given node.

This method is called by assignPorts(LayoutGraph, Node) for each outgoing edge of the given node. It may be overridden to assign a custom location to the source port of outgoing edges.

 
This implementation considers PortConstraints despite the port assignment mode.
Parameters:
graph - the input graph
node - the node
edge - the edge to the child node
index - the zero-based index of the child edge
See Also:
EdgeLayout.setSourcePoint(YPoint)

getPortBorderGap

protected double getPortBorderGap(double sideLength,
                                  int edgeCount)
Determines the distance between the outer ports and the border of the node.

This implementation calculates the gap according to the number of edges at one side of the node. It also includes the ratio between border gap and port gap.

This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) to calculate the location of the first port. It may be overridden to implement a different distribution of ports on the node's side.

Parameters:
sideLength - the width/height of the side
edgeCount - the number of edges that connect to this side
Returns:
the absolute gap to be used on both sides of the ports
See Also:
assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int), getBorderGapToPortGapRatio()

getPortDistanceDelta

protected double getPortDistanceDelta(double sideLength,
                                      int edgeCount,
                                      double portBorderGap)
Determines the distance between two adjacent ports.

This implementation calculates the gap according to the number of edges at one side of the node. The edges are distributed keeping the given gap to the border of the node.

This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) to calculate the distance between two ports. It may be overridden to implement a different distribution of ports on the node's side.

Parameters:
sideLength - the width/height of the side
edgeCount - the number of edges/ports that connect to this side
portBorderGap - the port border gap (i.e. calculated by getPortBorderGap(double, int))
Returns:
the absolute distance to be used between two adjacent ports
See Also:
assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int), getPortBorderGap(double, int)

getSourcePortConstraint

protected PortConstraint getSourcePortConstraint(LayoutGraph graph,
                                                 Edge edge,
                                                 int index)
Retrieves the source PortConstraint for the given edge.

This implementation accesses the DataProvider registered with PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY.

This method is called by assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int) in MODE_PORT_CONSTRAINTS.

Parameters:
graph - the input graph
edge - the edge
index - the index of the child that is the target of the given edge
Returns:
the source PortConstraint or null if no source PortConstraint is specified
See Also:
PortConstraint, PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, assignChildEdgeSourcePort(LayoutGraph, Node, Edge, int)

getTargetPortConstraint

protected PortConstraint getTargetPortConstraint(LayoutGraph graph,
                                                 Edge edge)
Retrieves the target PortConstraint for the given edge.

This implementation accesses the DataProvider registered with PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY.

This method is called by assignParentEdgeTargetPort(LayoutGraph, Node, Edge) in MODE_PORT_CONSTRAINTS.

Parameters:
graph - the input graph
edge - the edge
Returns:
the target PortConstraint or null if no target PortConstraint is specified
See Also:
PortConstraint, PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, assignParentEdgeTargetPort(LayoutGraph, Node, Edge)

getMode

public byte getMode()
Returns the mode that describes how ports are placed.

Returns:
one of the predefined port assignment specifiers
See Also:
setMode(byte)

setMode

public void setMode(byte mode)
Specifies the mode that describes how ports are placed.

Default Value:
The default value is MODE_NONE
Parameters:
mode - one of the predefined port assignment specifiers
Throws:
java.lang.IllegalArgumentException - if an unknown mode is specified

getBorderGapToPortGapRatio

public double getBorderGapToPortGapRatio()
Returns the ratio of the border gap (distance between the outer ports to the node border) to the port gap (distance between adjacent ports).

The ratio must have a positive value. When the ratio is 0 the ports will be distributed along the whole side of the node without a gap between the last port and the corner.

 
This setting only affects distributed port assignments (e.g. MODE_PORT_DISTRIBUTED_NORTH).
Returns:
the ratio of the border gap (gap between ports and border) to the port gap (gap between two ports)
See Also:
setBorderGapToPortGapRatio(double)

setBorderGapToPortGapRatio

public void setBorderGapToPortGapRatio(double borderGapToPortGapRatio)
Specifies the ratio of the border gap (distance between the outer ports to the node border) to the port gap (distance between adjacent ports).

The ratio must have a positive value. When the ratio is 0 the ports will be distributed along the whole side of the node without a gap between the last port and the corner.

 
This setting only affects distributed port assignments (e.g. MODE_PORT_DISTRIBUTED_NORTH).
Default Value:
The default value is 0.5.
Parameters:
borderGapToPortGapRatio - the ratio of the border gap (gap between ports and border) to the port gap (gap between two ports)
Throws:
java.lang.IllegalArgumentException - if the specified ratio is negative
Sample Graphs:

0.5

1

isReversedPortOrder

public boolean isReversedPortOrder()
Returns whether or not the port assignment should reverse the order of the ports.

The normal order is from left to right and from top to bottom. It will be reversed if this option is enabled.

 
This setting only affects distributed port assignment (e.g. MODE_PORT_DISTRIBUTED_NORTH).
Returns:
true if the order of the ports are reversed, false otherwise
See Also:
setReversedPortOrder(boolean)

setReversedPortOrder

public void setReversedPortOrder(boolean reversedPortOrder)
Specifies whether or not the port assignment should reverse the order of the ports.

The normal order is from left to right and from top to bottom. It will be reversed if this option is enabled.

 
This setting only affects distributed port assignment (e.g. MODE_PORT_DISTRIBUTED_NORTH).
Default Value:
The default value is false. The normal order is used for the ports.
Parameters:
reversedPortOrder - true if the order of the ports should be reversed, false otherwise
Sample Graphs:

false

true

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