Search this API

y.layout.seriesparallel
Class DefaultPortAssignment

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

public class DefaultPortAssignment
extends java.lang.Object
implements PortAssignment

DefaultPortAssignment implements the default port assignment strategy. Ports are either placed at the center or get distributed at the sides of the node.

If PortConstraints are specified, the strong PortConstraints are handled separately and keep their initial location relative to the node while weak PortConstraints just influence on which side of the node the port is placed.

If there are edge groups specified, the edges which belong to the same group get the same port locations.

See Also:
PortConstraint, PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY
 

Field Summary
static byte FORK_STYLE_AT_NODE
          Fork style specifier that defines that the edges will fork on a node.
static byte FORK_STYLE_OUTSIDE_NODE
          Fork style specifier that defines that the edges will fork outside a node.
static byte PORT_ASSIGNMENT_MODE_CENTER
          A port assignment specifier which defines that all ports are reset to the center of their nodes.
static byte PORT_ASSIGNMENT_MODE_DISTRIBUTED
          A port assignment specifier which defines that the ports of incoming and outgoing edges are distributed evenly at the side of their nodes.
 
Constructor Summary
DefaultPortAssignment()
          Creates a new DefaultPortAssignment 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 mode and a given value for the ratio of the gap between the border and the ports to the gap between the ports themselves.
 
Method Summary
 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 and the node border) to the port gap (distance between adjacent ports).
 byte getForkStyle()
          Returns the fork style which influences the port assignment.
 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.
 void setBorderGapToPortGapRatio(double borderGapToPortGapRatio)
          Specifies the ratio of the border gap (distance between the outer ports and the node border) to the port gap (distance between adjacent ports).
 void setForkStyle(byte forkStyle)
          Specifies the fork style which influences the port assignment.
 void setMode(byte mode)
          Specifies the mode that describes how ports are placed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT_ASSIGNMENT_MODE_CENTER

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

 
Ports that are restricted by strong PortConstraints are excluded. They will keep their current locations on the node.
See Also:
PortConstraint, Constant Field Values
Sample Graph:

Centered ports

PORT_ASSIGNMENT_MODE_DISTRIBUTED

public static final byte PORT_ASSIGNMENT_MODE_DISTRIBUTED
A port assignment specifier which defines that the ports of incoming and outgoing edges are distributed evenly at the side of their nodes.

The source ports of edges without PortConstraints will be distributed at the sides of their source and target nodes. Edges with weak PortConstraints are distributed at the side of the nodes which is specified in the PortConstraint.

Grouped edges will get the same port location.

 
Ports that are restricted by strong PortConstraints are excluded. They will keep their current locations on the node.
See Also:
PortConstraint, PortConstraintKeys.SOURCE_GROUPID_KEY, PortConstraintKeys.TARGET_GROUPID_KEY, Constant Field Values
Sample Graph:

Distributed Ports

FORK_STYLE_OUTSIDE_NODE

public static final byte FORK_STYLE_OUTSIDE_NODE
Fork style specifier that defines that the edges will fork outside a node. Edges leave/enter the nodes south/north and bend between their source and target.

See Also:
Constant Field Values
Sample Graph:

Fork outside node

FORK_STYLE_AT_NODE

public static final byte FORK_STYLE_AT_NODE
Fork style specifier that defines that the edges will fork on a node. Edges leave/enter the nodes south/north if they are straight (no bends) or east and west of the node.

 
If this fork style is set and the routing style is set to SeriesParallelLayouter.ROUTING_STYLE_POLYLINE, the integrated edge labeling may place labels far away from the associated edges.
See Also:
Constant Field Values
Sample Graph:

Fork inside node
Constructor Detail

DefaultPortAssignment

public DefaultPortAssignment()
Creates a new DefaultPortAssignment 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 modes
Throws:
java.lang.IllegalArgumentException - if the given mode is unknown

DefaultPortAssignment

public DefaultPortAssignment(byte mode,
                             double ratio)
Creates a new DefaultPortAssignment instance using the given mode and a given value for the ratio of the gap between the border and the ports to the gap between the ports themselves.

Parameters:
mode - one of the predefined port assignment modes
ratio - the ratio of the distance between outer ports and the border to the distance between any two ports
Throws:
java.lang.IllegalArgumentException - if the given mode is unknown or the given 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()

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 assignPorts(LayoutGraph, Node) 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:
assignPorts(LayoutGraph, Node), 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 assignPorts(LayoutGraph, Node) 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:
assignPorts(LayoutGraph, Node), getPortBorderGap(double, int)

getMode

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

Returns:
one of the predefined port assignment modes
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 PORT_ASSIGNMENT_MODE_CENTER
Parameters:
mode - one of the predefined port assignment modes
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 and the node border) to the port gap (distance between adjacent ports).

The ratio must have a positive value. If 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 the distributed port assignment.
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 and the node border) to the port gap (distance between adjacent ports).

The ratio must have a positive value. If 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 the distributed port assignment.
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

getForkStyle

public byte getForkStyle()
Returns the fork style which influences the port assignment.

If the fork style is set to FORK_STYLE_OUTSIDE_NODE, edges without port constraints will be assigned in flow direction.

If the fork style is set to FORK_STYLE_AT_NODE, the ports of edges in flow direction also get distributed to the sides unless they are without bends. Due to large minimum first/last segment lengths edges may overlap.

Returns:
one of the predefined fork styles
See Also:
setForkStyle(byte)

setForkStyle

public void setForkStyle(byte forkStyle)
Specifies the fork style which influences the port assignment.

If the fork style is set to FORK_STYLE_OUTSIDE_NODE, edges without port constraints will be assigned in flow direction.

If the fork style is set to FORK_STYLE_AT_NODE, the ports of edges in flow direction also get distributed to the sides unless they are without bends. Due to large minimum first/last segment lengths edges may overlap.

Default Value:
The default value is FORK_STYLE_OUTSIDE_NODE
Parameters:
forkStyle - one of the predefined fork styles
Throws:
java.lang.IllegalArgumentException - if the specified fork style is unknown

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