
Search this API  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object y.layout.AbstractLayoutStage y.layout.ParallelEdgeLayouter
public class ParallelEdgeLayouter
ParallelEdgeLayouter
is a LayoutStage
that routes parallel edges which connect the same pair of nodes
in a graph.
The edge paths of parallel edges consist of parallel segments. At the end points, the edges can either still be
parallel or joined in one point
.
The master edge determining the routing is highlighted
ParallelEdgeLayouter
performs four basic steps:
core layout algorithm
on the graph without parallel edges
ParallelEdgeLayouter
can either be used as a LayoutStage
wrapping a
layout algorithm
which cannot handle parallel edges. Then it will hide the parallel edges from
this core layout algorithm
and take over the routing of them.
If no core layout algorithm
is specified, ParallelEdgeLayouter
can work alone.
It will route only the parallel edges and keep the remaining graph unchanged.
Note that, since the parallel edges' paths are parallel to the path of the associated master edge,
the master edge should always have a suitable route before calling the ParallelEdgeLayouter
.
To find out which edges this stage routed, a DataAcceptor
can be registered with the graph with
key ROUTED_PARALLEL_EDGES_DPKEY
. Parallel edges that were hidden during the core layout and
then routed by this stage are marked. Leading edges are not marked. This may be convenient if
parallel edges require further consideration, e.g., to place labels their labels (the core layout
could not do that because they were hidden).
Parallel edges can either be all edges between the same two nodes, ignoring the direction, or edges are
only considered parallel if they share the same source node and target node. Hence, they share the same
direction
.
To make sure that the ports of all parallel edges are on the end nodes, the first and last segments can be
joined
. However, these segments won't be parallel.
There are two ways to define the distance between two parallel edges. First, an absolute distance can be
defined
. Parallel segments will keep this distance. Second, the distance can be
determined relative to the node bounds
. Depending on the size of
the nodes and the number of parallel edges between them, the distance between parallel edges is adjusted. This will
keep the edges straight in most cases.
It is possible to select custom master edges
. All edges that are parallel to the
selected edges will be temporarily removed.
core layout algorithm
or by any other method that ensures that the input graph already has suitable routes (e.g., by
calling LayoutTool.resetPaths(LayoutGraph)
) before applying the ParallelEdgeLayouter
if the edges should receive straightline routes).Field Summary  

protected EdgeList 
hiddenEdges
Holds the list of parallel edges that are hidden from the core layout algorithm . 
static java.lang.Object 
LEADING_EDGE_DPKEY
A DataProvider key for specifying the master edges
Marked edges won't be removed for the core layout algorithm . 
protected double 
lineDistance
Holds the line distance assigned between parallel edges. 
EdgeMap 
parallelEdges
EdgeMap that associates a hidden edge with the unique parallel edge not hidden from the
core layout algorithm . 
static java.lang.Object 
ROUTED_PARALLEL_EDGES_DPKEY
A DataAcceptor key for publishing the parallel edges that were routed and not treated as leading edges
In the DataAcceptor registered with the graph with this key all parallel edges which are
no leading (master) edges are marked. 
static java.lang.Object 
SCOPE_DPKEY
A DataProvider key for marking edges that will be routed

Fields inherited from interface y.layout.Layouter 

EDGE_ID_DPKEY, NODE_ID_DPKEY, NODE_TYPE_DPKEY, SELECTED_EDGES, SELECTED_NODES 
Constructor Summary  

ParallelEdgeLayouter()
Creates a new ParallelEdgeLayouter instance with default settings. 

ParallelEdgeLayouter(Layouter coreLayouter)
Creates a new ParallelEdgeLayouter instance using the given
core layout algorithm . 
Method Summary  

boolean 
canLayout(LayoutGraph graph)
Accepts all graphs that can be handled by the core layout algorithm after removing all
parallel edges. 
void 
doLayout(LayoutGraph graph)
Delegates the arrangement of nodes and edges to the core layout algorithm and routes
the parallel edges. 
protected void 
findAndHideParallelEdges(Graph graph)
Hides all parallel edges leaving a master edge in the graph. 
double 
getAbsJoinEndDistance()
Returns the absolute distance from the end point of the joined lines to the first parallel segments. 
double 
getLineDistance()
Returns the distance between two adjacent edge paths that run in parallel. 
double 
getRelJoinEndDistance()
Returns the relative distance from the end point of the joined lines to the first parallel segments. 
boolean 
isDirectedModeEnabled()
Returns whether or not the direction of edges should be considered. 
boolean 
isJoinEndsEnabled()
Returns whether or not to join end points of parallel edges. 
boolean 
isLeadingEdgeAdjustmentEnabled()
Returns whether or not to adjust the leading edge to obtain more symmetric results. 
boolean 
isUsingAdaptiveLineDistances()
Returns whether or not the distances between parallel edges should be determined automatically according to the sizes of their source and target nodes. 
protected void 
layoutParallelEdges(LayoutGraph graph,
EdgeMap parallelEdges)
Assigns a layout to all parallel edges. 
void 
setAbsJoinEndDistance(double absJoinEndDistance)
Specifies the absolute distance from the end point of the joined lines to the first parallel segments. 
void 
setDirectedModeEnabled(boolean directedModeEnabled)
Specifies whether or not the direction of edges should be considered. 
void 
setJoinEndsEnabled(boolean joinEndsEnabled)
Specifies whether or not to join end points of parallel edges. 
void 
setLeadingEdgeAdjustmentEnabled(boolean leadingEdgeAdjustmentEnabled)
Specifies whether or not to adjust the leading edge to obtain more symmetric results. 
void 
setLineDistance(double distance)
Specifies the distance between two adjacent edge paths that run in parallel. 
void 
setRelJoinEndDistance(double relJoinEndDistance)
Specifies the relative distance from the end point of the joined lines to the first parallel segments. 
void 
setUsingAdaptiveLineDistances(boolean usingAdaptiveLineDistances)
Specifies whether or not the distances between parallel edges should be determined automatically according to the sizes of their source and target nodes. 
Methods inherited from class y.layout.AbstractLayoutStage 

canLayoutCore, doLayoutCore, getCoreLayouter, setCoreLayouter 
Methods inherited from class java.lang.Object 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 

public static final java.lang.Object SCOPE_DPKEY
DataProvider
key for marking edges that will be routed
DataProvider
is registered with the given key, all edges will be routed.public static final java.lang.Object LEADING_EDGE_DPKEY
DataProvider
key for specifying the master edges
Marked edges won't be removed for the core layout algorithm
. All edges parallel to
the master edges will get parallel paths.
If no leading edge is specified for a bundle of parallel edges, it will be determined automatically. If there is more than one leading edge, the first one is chosen.
public static final java.lang.Object ROUTED_PARALLEL_EDGES_DPKEY
DataAcceptor
key for publishing the parallel edges that were routed and not treated as leading edges
In the DataAcceptor
registered with the graph with this key all parallel edges which are
no leading (master) edges are marked. This way, it is easily possible to determine the set of edges that
were hidden during the core layout
.
Knowing which parallel edges were identified and hidden during the core layout can be a valuable information
for use cases where it is required to handle such edges specifically.
A frequent scenario is, for example, the requirement to place edge labels of these edges. The core layout
is not able to do so, because parallel edges are hidden. A generic labeling algorithm where only the
labels of the parallel edges are affected and placed can now easily be applied (see
AbstractLabelingAlgorithm.setSelection(Object)
.
ParallelEdgeLayouter
runs as part of a CanonicMultiStageLayouter
, stages
like the labeling
which run after this stage can
already use the information published with the data acceptor registered with this key. This way the
the labeling stage can, for example, handle labels of nonleading, parallel edges in a specific way.LEADING_EDGE_DPKEY
protected EdgeList hiddenEdges
core layout algorithm
.
public EdgeMap parallelEdges
EdgeMap
that associates a hidden edge with the unique parallel edge not hidden from the
core layout algorithm
.
protected double lineDistance
Constructor Detail 

public ParallelEdgeLayouter(Layouter coreLayouter)
ParallelEdgeLayouter
instance using the given
core layout algorithm
.
coreLayouter
 the core layout routineAbstractLayoutStage.setCoreLayouter(Layouter)
public ParallelEdgeLayouter()
ParallelEdgeLayouter
instance with default settings.
Method Detail 

public boolean isDirectedModeEnabled()
In directed mode, only edges that share the same source and target node will be routed in parallel. Edges that connect to the same nodes but in different directions won't be considered parallel.
In undirected mode, all edges connecting the same pair of nodes will be routed in parallel.
true
if the direction of parallel edges must be the same, false
otherwisepublic void setDirectedModeEnabled(boolean directedModeEnabled)
In directed mode, only edges that share the same source and target node will be routed in parallel. Edges that connect to the same nodes but in different directions won't be considered parallel.
In undirected mode, all edges connecting the same pair of nodes will be routed in parallel.
public boolean isUsingAdaptiveLineDistances()
If enabled, the distances between edges are chosen such that all parallel edges can be drawn as straight lines and still connect to the nodes' bounds.
true
if the distances are determined according to the nodes' bounds, false
otherwisesetUsingAdaptiveLineDistances(boolean)
,
setLineDistance(double)
public void setUsingAdaptiveLineDistances(boolean usingAdaptiveLineDistances)
If enabled, the distances between edges are chosen such that all parallel edges can be drawn as straight lines and still connect to the nodes' bounds.
usingAdaptiveLineDistances
 true
if the distances should be determined according to the nodes'
bounds, false
otherwisesetLineDistance(double)
false  true 
public void setLineDistance(double distance)
The distance needs to be nonnegative.
adaptive line distances
are used, the resulting distance
may be less than the specified distance.distance
 the distance between two parallel edges
java.lang.IllegalArgumentException
 if the specified distance is less than 0
setUsingAdaptiveLineDistances(boolean)
10  20 
public double getLineDistance()
The distance needs to be nonnegative.
adaptive line distances
are used, the resulting distance
may be less than the specified distance.setLineDistance(double)
,
setUsingAdaptiveLineDistances(boolean)
public void doLayout(LayoutGraph graph)
core layout algorithm
and routes
the parallel edges.
graph
 the input graphLayouter.canLayout(LayoutGraph)
public boolean canLayout(LayoutGraph graph)
core layout algorithm
after removing all
parallel edges.
If there is no core layout algorithm
, all graphs are accepted.
graph
 the input graph
true
if there is no core layout algorithm or the core layout algorithm accepts the graph,
false
otherwiseLayouter.doLayout(LayoutGraph)
protected void layoutParallelEdges(LayoutGraph graph, EdgeMap parallelEdges)
The layout for each parallel edge follows the layout of the master edge which was not removed from the
core layout algorithm
.
This method is called when the core layout algorithm
is finished. It may be overridden
to introduce a custom routing for parallel edges.
graph
 the graph after the core layoutparallelEdges
 the map that provides all parallel edges for each master edgesetJoinEndsEnabled(boolean)
,
setUsingAdaptiveLineDistances(boolean)
,
setLeadingEdgeAdjustmentEnabled(boolean)
protected void findAndHideParallelEdges(Graph graph)
ParallelEdgeLayouter
detects parallel edges of the given graph. From each set of parallel edges it hides
all but one edge from the given graph.
This method is called before invoking the core layout algorithm
. It may be overridden
to change the selection of leading edges. Hidden edges should be stored in hiddenEdges
to enable unhiding
later on.
graph
 the input graphsetDirectedModeEnabled(boolean)
,
SCOPE_DPKEY
public boolean isJoinEndsEnabled()
If enabled, all edges end with nonparallel segments that connect at the same point to the node. Otherwise, all segments of the edges are parallel. In this case, some edges may not connect to the nodes' bounds.
true
if edges are joined at the ends, false
otherwisesetJoinEndsEnabled(boolean)
,
setAbsJoinEndDistance(double)
,
setRelJoinEndDistance(double)
public void setJoinEndsEnabled(boolean joinEndsEnabled)
If enabled, all edges end with nonparallel segments that connect at the same point to the node. Otherwise, all segments of the edges are parallel. In this case, some edges may not connect to the nodes' bounds.
public double getAbsJoinEndDistance()
The absolute distance needs to be nonnegative.
joined
.setAbsJoinEndDistance(double)
,
setJoinEndsEnabled(boolean)
,
setRelJoinEndDistance(double)
public void setAbsJoinEndDistance(double absJoinEndDistance)
The absolute distance needs to be nonnegative.
joined
.absJoinEndDistance
 the absolute distance from the end point to the first/last bend of parallel edges
java.lang.IllegalArgumentException
 if the specified distance is negativesetJoinEndsEnabled(boolean)
,
setRelJoinEndDistance(double)
20  10 
public double getRelJoinEndDistance()
The length is relative to the corresponding original segment's length. It needs to have a value in the
interval [0,1]
.
joined
.setRelJoinEndDistance(double)
,
setJoinEndsEnabled(boolean)
,
setAbsJoinEndDistance(double)
public void setRelJoinEndDistance(double relJoinEndDistance)
The length is relative to the corresponding original segment's length. It needs to have a value in the
interval [0,1]
.
joined
.relJoinEndDistance
 the relative distance from the end point to the first/last bend of parallel edges
java.lang.IllegalArgumentException
 if the specified relative distance is less than 0
or greater than
1
setJoinEndsEnabled(boolean)
,
setAbsJoinEndDistance(double)
0.1  0.4 
public boolean isLeadingEdgeAdjustmentEnabled()
true
if the leading edge is adjusted, false
otherwisesetLeadingEdgeAdjustmentEnabled(boolean)
public void setLeadingEdgeAdjustmentEnabled(boolean leadingEdgeAdjustmentEnabled)

© Copyright 20002022, yWorks GmbH. All rights reserved. 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 