public class DefaultPortAssignment extends Object implements IPortAssignment
DefaultPortAssignment
implements the default port assignment strategy.
Ports are either placed at the center
or get distributed
at the sides of the node.
If PortConstraint
s are specified, the strong PortConstraint
s are handled separately and keep their
initial location relative to the node while weak
PortConstraint
s 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.
Constructor and Description |
---|
DefaultPortAssignment()
Creates a new
DefaultPortAssignment with default settings. |
DefaultPortAssignment(PortAssignmentMode mode)
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. |
DefaultPortAssignment(PortAssignmentMode 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. |
Modifier and Type | Method and Description |
---|---|
void |
assignPorts(LayoutGraph graph,
Node node)
Places the ports of edges connecting to the given node according to the
port assignment mode . |
double |
getBorderGapToPortGapRatio()
Gets the ratio of the border gap (distance between the outer ports and the node border) to the port gap
(distance between adjacent ports).
|
ForkStyle |
getForkStyle()
Gets the fork style which influences the port assignment.
|
PortAssignmentMode |
getMode()
Gets 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 value)
Sets 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(ForkStyle value)
Sets the fork style which influences the port assignment.
|
void |
setMode(PortAssignmentMode value)
Sets the mode that describes how ports are placed.
|
public DefaultPortAssignment()
DefaultPortAssignment
with default settings.public DefaultPortAssignment(PortAssignmentMode mode)
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.IllegalArgumentException
- if the given mode is unknown or the given ratio is negativemode
- one of the predefined port assignment modespublic DefaultPortAssignment(PortAssignmentMode mode, double ratio)
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.IllegalArgumentException
- if the given mode is unknown or the given ratio is negativemode
- one of the predefined port assignment modesratio
- the ratio of the distance between outer ports and the border to the distance between any two portspublic void assignPorts(LayoutGraph graph, Node node)
port assignment mode
.assignPorts
in interface IPortAssignment
graph
- the input graphnode
- the node whose adjacent edges' ports should be placedgetMode()
public double getBorderGapToPortGapRatio()
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.
IllegalArgumentException
- if the specified ratio is negativedistributed
port assignment.setBorderGapToPortGapRatio(double)
public ForkStyle getForkStyle()
If the fork style is set to
ForkStyle.OUTSIDE_NODE
, edges without port constraints will be assigned in flow direction.
If the fork style is set to
ForkStyle.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.
IllegalArgumentException
- if the specified fork style is unknownForkStyle.OUTSIDE_NODE
setForkStyle(ForkStyle)
public PortAssignmentMode getMode()
IllegalArgumentException
- if an unknown mode is specifiedPortAssignmentMode.CENTER
setMode(PortAssignmentMode)
protected double getPortBorderGap(double sideLength, int edgeCount)
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.
sideLength
- the width/height of the sideedgeCount
- the number of edges that connect to this sideassignPorts(LayoutGraph, Node)
,
getBorderGapToPortGapRatio()
protected double getPortDistanceDelta(double sideLength, int edgeCount, double portBorderGap)
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.
sideLength
- the width/height of the sideedgeCount
- the number of edges/ports that connect to this sideportBorderGap
- the port border gap (i.e. calculated by getPortBorderGap(double, int)
)assignPorts(LayoutGraph, Node)
,
getPortBorderGap(double, int)
public void setBorderGapToPortGapRatio(double value)
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.
IllegalArgumentException
- if the specified ratio is negativedistributed
port assignment.value
- the ratio of the border gap (gap between ports and border) to the port gap (gap between two ports)getBorderGapToPortGapRatio()
public void setForkStyle(ForkStyle value)
If the fork style is set to
ForkStyle.OUTSIDE_NODE
, edges without port constraints will be assigned in flow direction.
If the fork style is set to
ForkStyle.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.
IllegalArgumentException
- if the specified fork style is unknownForkStyle.OUTSIDE_NODE
value
- one of the predefined fork stylesgetForkStyle()
public void setMode(PortAssignmentMode value)
IllegalArgumentException
- if an unknown mode is specifiedPortAssignmentMode.CENTER
value
- one of the predefined port assignment modesgetMode()