Search this API

y.layout
Class ParallelEdgeLayouter

java.lang.Object
  extended by y.layout.AbstractLayoutStage
      extended by y.layout.ParallelEdgeLayouter
All Implemented Interfaces:
Layouter, LayoutStage

public class ParallelEdgeLayouter
extends AbstractLayoutStage

A layout algorithm that routes parallel edges (edges that connect the same pair of nodes) of a graph.

A core layout algorithm can be specified for this class. In that case the performed layout process of this class is subdivided into four stages:

  1. Remove parallel edges from the input graph. If there are parallel edges between two nodes A and B than only one of these edges will remain in the graph. The remaining edge is called the leading edge and is the representative of the other edges.
  2. Invoke the core layouter on the now parallel edge free graph.
  3. Reinsert all formerly removed edges of the graph.
  4. Route the parallel edges such that they run in parallel to their leading edge which was routed by the core layouter.


Field Summary
protected  EdgeList hiddenEdges
          Holds the list of parallel edges that are hidden from the core layouter.
static Object LEADING_EDGE_DPKEY
          A DataProvider key that can be used to specify which parallel edge should be used as leading edge, i.e., as the edge whose layout is used to obtain the layout of the corresponding parallel edges.
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 layouter.
static Object SCOPE_DPKEY
          A DataProvider key that can be used to tell the stage whether edges should be included in or excluded from the calculation.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
ParallelEdgeLayouter()
          Creates a new instance of ParallelEdgeLayouter with no core layouter assigned.
ParallelEdgeLayouter(Layouter coreLayouter)
          Creates a new instance of ParallelEdgeLayouter for the given core layouter.
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Returns true iff the given graph can be laid out by this algorithm.
 void doLayout(LayoutGraph graph)
          Main layout routine that assigns new layout information to the given graph.
protected  void findAndHideParallelEdges(Graph graph)
          This method detects parallel edges of the given graph.
 double getAbsJoinEndDistance()
          Gets the absolute distance from the end point of the lines to the first parallel segments if end joining is enabled.
 double getLineDistance()
          Returns the distance between two adjacent paths that run in parallel.
 double getRelJoinEndDistance()
          Returns the relative distance from the end point of the lines to the first parallel segments if end joining is enabled.
 boolean isDirectedModeEnabled()
          Returns whether or not edges should be considered as directed.
 boolean isJoinEndsEnabled()
          Returns the state of the automatic end joining mechanism, i.e. if all lines should end at the same point.
 boolean isLeadingEdgeAdjustmentEnabled()
          Returns whether this layouter will adjust the leading edge if the number of edges is even.
 boolean isUsingAdaptiveLineDistances()
          Whether or not the line distances between parallel edges should be determined according to the nodes' bounds.
protected  void layoutParallelEdges(LayoutGraph graph, EdgeMap parallelEdges)
          This method assigns a layout to parallel edges.
 void setAbsJoinEndDistance(double absJoinEndDistance)
          Sets the absolute distance from the end point of the lines to the first parallel segments if end joining is enabled.
 void setDirectedModeEnabled(boolean directedModeEnabled)
          Sets whether or not edges should be considered as directed.
 void setJoinEndsEnabled(boolean joinEndsEnabled)
          Specifies whether or not to join end points of parallel edges.
 void setLeadingEdgeAdjustmentEnabled(boolean leadingEdgeAdjustmentEnabled)
          Specifies whether this layouter will adjust the leading edge if the number of edges is even.
 void setLineDistance(double distance)
          Sets the distance between two adjacent paths that run in parallel.
 void setRelJoinEndDistance(double relJoinEndDistance)
          Sets the relative distance from the end point of the lines to the first parallel segments if end joining is enabled.
 void setUsingAdaptiveLineDistances(boolean usingAdaptiveLineDistances)
          Whether or not the line distances between parallel edges should be determined according to the nodes' bounds.
 
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

SCOPE_DPKEY

public static final Object SCOPE_DPKEY
A DataProvider key that can be used to tell the stage whether edges should be included in or excluded from the calculation. For every Edge instance the provider should yield boolean values to indicate whether an edge should be laid out. If no data provider is registered for the given key, all edges wil be laid out.


LEADING_EDGE_DPKEY

public static final Object LEADING_EDGE_DPKEY
A DataProvider key that can be used to specify which parallel edge should be used as leading edge, i.e., as the edge whose layout is used to obtain the layout of the corresponding parallel edges. For every Edge instance the provider should yield boolean values to indicate whether an edge is a leading edge.


hiddenEdges

protected EdgeList hiddenEdges
Holds the list of parallel edges that are hidden from the core layouter.


parallelEdges

public EdgeMap parallelEdges
EdgeMap that associates a hidden edge with the unique parallel edge not hidden from the core layouter.


lineDistance

protected double lineDistance
Holds the line distance assigned between parallel edges.

Constructor Detail

ParallelEdgeLayouter

public ParallelEdgeLayouter(Layouter coreLayouter)
Creates a new instance of ParallelEdgeLayouter for the given core layouter.

See Also:
AbstractLayoutStage.setCoreLayouter(Layouter)

ParallelEdgeLayouter

public ParallelEdgeLayouter()
Creates a new instance of ParallelEdgeLayouter with no core layouter assigned.

Method Detail

isDirectedModeEnabled

public boolean isDirectedModeEnabled()
Returns whether or not edges should be considered as directed.

See Also:
setDirectedModeEnabled(boolean)

setDirectedModeEnabled

public void setDirectedModeEnabled(boolean directedModeEnabled)
Sets whether or not edges should be considered as directed. In directed mode only edges that have the same source and target node will be routed in parallel. In undirected mode, all edges connecting the same pair of edges will be routed in parallel. By default this feature is disabled.


isUsingAdaptiveLineDistances

public boolean isUsingAdaptiveLineDistances()
Whether or not the line distances between parallel edges should be determined according to the nodes' bounds.

Returns:
true if the line distances are determined according to the nodes' bounds.
See Also:
setUsingAdaptiveLineDistances(boolean)

setUsingAdaptiveLineDistances

public void setUsingAdaptiveLineDistances(boolean usingAdaptiveLineDistances)
Whether or not the line distances between parallel edges should be determined according to the nodes' bounds. If enabled, the line distances are chosen such that all parallel edges can be drawn straight-line and still connect to the nodes' bounds.

Parameters:
usingAdaptiveLineDistances - whether the line distance should be determined according to the nodes' bounds.

setLineDistance

public void setLineDistance(double distance)
Sets the distance between two adjacent paths that run in parallel. Note: if adaptive line distances are used (see setUsingAdaptiveLineDistances(boolean)) the real distance may be less than the given line distance.


getLineDistance

public double getLineDistance()
Returns the distance between two adjacent paths that run in parallel.


doLayout

public void doLayout(LayoutGraph graph)
Description copied from interface: Layouter
Main layout routine that assigns new layout information to the given graph.


canLayout

public boolean canLayout(LayoutGraph graph)
Description copied from interface: Layouter
Returns true iff the given graph can be laid out by this algorithm. Calling doLayout with the given graph as its argument will only success if this method returns true.


layoutParallelEdges

protected void layoutParallelEdges(LayoutGraph graph,
                                   EdgeMap parallelEdges)
This method assigns a layout to parallel edges. The layout for each parallel edge follows the layout of the one edge not being removed from the core layouter.


findAndHideParallelEdges

protected void findAndHideParallelEdges(Graph graph)
This method detects parallel edges of the given graph. From each set of parallel edges it hides all but one edge from the given graph.


isJoinEndsEnabled

public boolean isJoinEndsEnabled()
Returns the state of the automatic end joining mechanism, i.e. if all lines should end at the same point.

Returns:
Value of property joinEndsEnabled.

setJoinEndsEnabled

public void setJoinEndsEnabled(boolean joinEndsEnabled)
Specifies whether or not to join end points of parallel edges. If enabled all lines end at the same point. By default, this feature is disabled.

Parameters:
joinEndsEnabled - if joining of the ends should be enabled.

getAbsJoinEndDistance

public double getAbsJoinEndDistance()
Gets the absolute distance from the end point of the lines to the first parallel segments if end joining is enabled.

Returns:
the absolute length

setAbsJoinEndDistance

public void setAbsJoinEndDistance(double absJoinEndDistance)
Sets the absolute distance from the end point of the lines to the first parallel segments if end joining is enabled.

Parameters:
absJoinEndDistance - the new value.

getRelJoinEndDistance

public double getRelJoinEndDistance()
Returns the relative distance from the end point of the lines to the first parallel segments if end joining is enabled. The length is relative to the corresponding original segment's length.

Returns:
the relative length

setRelJoinEndDistance

public void setRelJoinEndDistance(double relJoinEndDistance)
Sets the relative distance from the end point of the lines to the first parallel segments if end joining is enabled. The length will be relative to the corresponding original segment's length.

Parameters:
relJoinEndDistance - the new relative value.

isLeadingEdgeAdjustmentEnabled

public boolean isLeadingEdgeAdjustmentEnabled()
Returns whether this layouter will adjust the leading edge if the number of edges is even.

Returns:
whether the adjustment is enabled.

setLeadingEdgeAdjustmentEnabled

public void setLeadingEdgeAdjustmentEnabled(boolean leadingEdgeAdjustmentEnabled)
Specifies whether this layouter will adjust the leading edge if the number of edges is even.

Parameters:
leadingEdgeAdjustmentEnabled - whether to enable the adjustment

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