Search this API

y.layout.hierarchic.incremental
Class DefaultPortAllocator

java.lang.Object
  extended by y.layout.hierarchic.incremental.DefaultPortAllocator
All Implemented Interfaces:
PortAllocator

public class DefaultPortAllocator
extends java.lang.Object
implements PortAllocator

This class is a default PortAllocator implementation.

It is used by HierarchicLayouter after the sequencing phase.

 

Constructor Summary
DefaultPortAllocator()
          Creates a new instance of DefaultPortAllocator with default settings.
 
Method Summary
 void assignPorts(LayoutGraph graph, Layers layers, LayoutDataProvider ldp, ItemFactory itemFactory)
          Assigns source and target port coordinates to each edge of the graph.
 double getDefaultPortBorderGapRatio()
          Returns the border gap ratio for the default port.
protected  double getPortBorderGap(LayoutGraph graph, LayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount)
          Callback method used for determining the port border gap for each node and side.
protected  double getPortBorderGapRatio(LayoutGraph graph, LayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount)
          Callback method used for determining the port border gap ratio.
protected  double getPortDistanceDelta(LayoutGraph graph, LayoutDataProvider ldp, Node node, int sideIndex, double sideLength, int edgeCount, double portBorderGap)
          Callback method used for determining the distance between two adjacent ports.
 boolean isFixedPortConsiderationEnabled()
          Returns whether or not this PortAllocator considers edges with strong PortConstraints or fixed PortCandidate.
 void setDefaultPortBorderGapRatio(double defaultPortBorderGapRatio)
          Specifies the border gap ratio for the default port.
 void setFixedPortConsiderationEnabled(boolean considerStrongPorts)
          Specifies whether or not this PortAllocator considers edges with strong PortConstraints or fixed PortCandidate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultPortAllocator

public DefaultPortAllocator()
Creates a new instance of DefaultPortAllocator with default settings.

See Also:
setDefaultPortBorderGapRatio(double)
Method Detail

isFixedPortConsiderationEnabled

public boolean isFixedPortConsiderationEnabled()
Returns whether or not this PortAllocator considers edges with strong PortConstraints or fixed PortCandidate.

If these edges are ignored, the ports of the other edges are uniformly distributed on the sides of the nodes which may lead to intersections with the ignored edges. On the other hand, if these edges are considered, the port assignment of the other edges may no longer be uniform.

Returns:
true if the port allocator takes edges with strong/fixed ports into account, false otherwise
See Also:
setFixedPortConsiderationEnabled(boolean)

setFixedPortConsiderationEnabled

public void setFixedPortConsiderationEnabled(boolean considerStrongPorts)
Specifies whether or not this PortAllocator considers edges with strong PortConstraints or fixed PortCandidate.

If these edges are ignored, the ports of the other edges are uniformly distributed on the sides of the nodes which may lead to intersections with the ignored edges. On the other hand, if these edges are considered, the port assignment of the other edges may no longer be uniform.

Default Value:
The default value is true. Edges with strong/fixed ports are considered.
Parameters:
considerStrongPorts - true if the port allocator should take edges with strong/fixed ports into account, false otherwise

assignPorts

public void assignPorts(LayoutGraph graph,
                        Layers layers,
                        LayoutDataProvider ldp,
                        ItemFactory itemFactory)
Assigns source and target port coordinates to each edge of the graph.

This method assigns:

This method is called by HierarchicLayouter after the sequencing phase.

Specified by:
assignPorts in interface PortAllocator
Parameters:
graph - the input graph
layers - the given Layers instance containing the layering structure
ldp - the LayoutDataProvider containing information about the nodes and edges of the graph
itemFactory - the ItemFactory used for creating and destroying helper structures

getPortBorderGap

protected double getPortBorderGap(LayoutGraph graph,
                                  LayoutDataProvider ldp,
                                  Node node,
                                  int sideIndex,
                                  double sideLength,
                                  int edgeCount)
Callback method used for determining the port border gap for each node and side.

It may be overridden for a custom calculation of port border gap on a given node.

Parameters:
graph - the input graph
ldp - the LayoutDataProvider containing information about the nodes and edges of the graph
node - the given node
sideIndex - the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)
sideLength - the width/height of the side
edgeCount - the number of edges/ports that connect to this side
Returns:
the absolute gap on both sides of the ports
See Also:
getPortDistanceDelta(LayoutGraph, LayoutDataProvider, Node, int, double, int, double)

getPortDistanceDelta

protected double getPortDistanceDelta(LayoutGraph graph,
                                      LayoutDataProvider ldp,
                                      Node node,
                                      int sideIndex,
                                      double sideLength,
                                      int edgeCount,
                                      double portBorderGap)
Callback method used for determining the distance between two adjacent ports.

It may be overridden for a custom calculation of the distance between two adjacent ports..

Parameters:
graph - the input graph
ldp - the LayoutDataProvider containing information about the nodes and edges of the graph
node - the given node
sideIndex - the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)
sideLength - the width/height of the side
edgeCount - the number of edges/ports that connect to this side
portBorderGap - the previously calculated port border gap
Returns:
the absolute distance between two adjacent ports

getPortBorderGapRatio

protected double getPortBorderGapRatio(LayoutGraph graph,
                                       LayoutDataProvider ldp,
                                       Node node,
                                       int sideIndex,
                                       double sideLength,
                                       int edgeCount)
Callback method used for determining the port border gap ratio.

See setDefaultPortBorderGapRatio(double) for an explanation.

It may be overridden for a custom calculation of port border gap ratio on a given node.

 
If there exists a NodeLayoutDescriptor instance registered for the given node, this implementation returns the same value as NodeLayoutDescriptor.getPortBorderGapRatio(int). Else, returns the same value as getDefaultPortBorderGapRatio().
Parameters:
graph - the input graph
ldp - the LayoutDataProvider containing information about the nodes and edges of the graph
node - the given node
sideIndex - the zero-based (top is 0) clock-wise index of the side of the node (for top-to-bottom layouts)
sideLength - the width/height of the side
edgeCount - the number of edges/ports that connect to this side
Returns:
the border gap ratio

getDefaultPortBorderGapRatio

public double getDefaultPortBorderGapRatio()
Returns the border gap ratio for the default port.

This ratio determines the gap between a corner of the node and the first assigned port.

The ratio should be greater than 0.

A value of 0.0d results in ports being placed directly on the corner of the node (if there is more than one port).

A value of 0.5d results in ports being distributed along the side of the node so that the distance between the corner of the node and the first port is half as wide as the distance between two adjacent ports.

A value of Double.POSITIVE_INFINITY results in all ports being centered at the side in one point.

Returns:
the border gap ratio
See Also:
setDefaultPortBorderGapRatio(double)

setDefaultPortBorderGapRatio

public void setDefaultPortBorderGapRatio(double defaultPortBorderGapRatio)
Specifies the border gap ratio for the default port.

This ratio determines the gap between a corner of the node and the first assigned port.

The ratio should be greater than 0.

A value of 0.0d results in ports being placed directly on the corner of the node (if there is more than one port).

A value of 0.5d results in ports being distributed along the side of the node so that the distance between the corner of the node and the first port is half as wide as the distance between two adjacent ports.

A value of Double.POSITIVE_INFINITY results in all ports being centered at the side in one point.

Default Value:
The default value is 0.5d. Ports are distributed along the side of the node.
Parameters:
defaultPortBorderGapRatio - the given border gap ratio
Throws:
java.lang.IllegalArgumentException - if the given ratio is negative
Sample Graphs:

Port border gap ratio 0.0d - node 1 has port constraint PortConstraint.SOUTH while nodes 2,3,4 have port constraints PortConstraint.NORTH.

Port border gap ratio 0.5d - node 1 has port constraint PortConstraint.SOUTH while nodes 2,3,4 have port constraints PortConstraint.NORTH.

Port border gap ratio Double.POSITIVE_INFINITY - node 1 has port constraint PortConstraint.SOUTH while nodes 2,3,4 have port constraints PortConstraint.NORTH.

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