Search this API

y.layout.router
Class OrganicEdgeRouter

java.lang.Object
  extended by y.layout.router.OrganicEdgeRouter
All Implemented Interfaces:
Layouter, LayoutStage

public class OrganicEdgeRouter
extends Object
implements LayoutStage

This algorithm routes edges using an organic-like layout approach and style. It is implemented as a LayoutStage so that it can easily be appended to another stage, by setting the other stage as the core of this one. Note that this algorithm only works correctly if it is guaranteed that nodes are at least approximately twice as far away from each other as the minimal edge distance, which has been set for this algorithm. This can be achieved by using the createNodeEnlargementStage() layout stage in combination with a stage that removes node overlaps as the core of this layouter.

Here is a sample output of the router using as input a straight-line drawing created by SmartOrganicLayouter:



Field Summary
static Object ROUTE_EDGE_DPKEY
          Use this key to provide the algorithm with boolean values for each edge, specifying the ones which should be rerouted.
 
Fields inherited from interface y.layout.Layouter
EDGE_ID_DPKEY, NODE_ID_DPKEY, SELECTED_EDGES, SELECTED_NODES
 
Constructor Summary
OrganicEdgeRouter()
          Creates a new instance of OrganicEdgeRouter with an initial minimal distance of 10.
OrganicEdgeRouter(double minNodeDistance)
          Creates a new instance of OrganicEdgeRouter using the given initial minimal distance
 
Method Summary
 boolean canLayout(LayoutGraph graph)
          Returns true iff the given graph can be laid out by this algorithm.
protected  void checkGroupNodeSize(GraphLayout layout, Object node)
          This method throws an IllegalArgumentException if the width/height of the given group node object is zero.
protected  void checkNodeSize(GraphLayout layout, Object node)
          This method throws an IllegalArgumentException if the width/height of the given node object is zero.
 LayoutStage createNodeEnlargementStage()
          This will return a layout stage which can be given a core layouter, which itself should assure that the nodes do not overlap.
 void doLayout(LayoutGraph graph)
          Main layout routine that assigns new layout information to the given graph.
 Layouter getCoreLayouter()
          Returns the core layouter.
 double getMinimalDistance()
          Returns the minimal distance between nodes and non-incident edges.
 boolean isEdgeNodeOverlapAllowed()
          Returns whether or not edge-node overlaps are allowed.
 boolean isRoutingAll()
          Returns whether edges should be rerouted even if they do not obey all constraints initially.
 boolean isUsingBends()
          Returns whether given bend coordinates are taken into account when determining initial bend positions.
 void setCoreLayouter(Layouter l)
          Sets the core layouter.
 void setEdgeNodeOverlapAllowed(boolean edgeNodeOverlapAllowed)
          Enabling this option often leads to better results if the createNodeEnlargementStage() LayoutStage is not used (e.g. because the nodes are not allowed to move) and the distances between some nodes are small.
 void setMinimalDistance(double minimalDistance)
          Specifies the minimal distance the algorithm should guarantee between nodes and non-incident edges.
 void setRoutingAll(boolean routingAll)
          Specifies whether edges should be rerouted even if they do not obey all constraints initially.
 void setUsingBends(boolean usingBends)
          Specifies whether given bend coordinates are taken into account when determining initial bend positions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROUTE_EDGE_DPKEY

public static final Object ROUTE_EDGE_DPKEY
Use this key to provide the algorithm with boolean values for each edge, specifying the ones which should be rerouted.

Constructor Detail

OrganicEdgeRouter

public OrganicEdgeRouter()
Creates a new instance of OrganicEdgeRouter with an initial minimal distance of 10.


OrganicEdgeRouter

public OrganicEdgeRouter(double minNodeDistance)
Creates a new instance of OrganicEdgeRouter using the given initial minimal distance

Method Detail

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.

Specified by:
canLayout in interface Layouter

isEdgeNodeOverlapAllowed

public boolean isEdgeNodeOverlapAllowed()
Returns whether or not edge-node overlaps are allowed. Enabling this option often leads to better results if the createNodeEnlargementStage() LayoutStage is not used (e.g. because the nodes are not allowed to move) and the distances between some nodes are small. However enabling this option may produce edge-node overlaps. Furthermore, the minimal distance (set with setMinimalDistance(double) cannot always be maintained in that case.

Returns:
true if edge-node overlaps are allowed.
See Also:
setEdgeNodeOverlapAllowed(boolean), createNodeEnlargementStage(), setMinimalDistance(double)

setEdgeNodeOverlapAllowed

public void setEdgeNodeOverlapAllowed(boolean edgeNodeOverlapAllowed)
Enabling this option often leads to better results if the createNodeEnlargementStage() LayoutStage is not used (e.g. because the nodes are not allowed to move) and the distances between some nodes are small. However enabling this option may produce edge-node overlaps. Furthermore, the minimal distance (set with setMinimalDistance(double)) cannot always be maintained in that case.

Parameters:
edgeNodeOverlapAllowed - true if edge-node overlaps should be allowed.
See Also:
isEdgeNodeOverlapAllowed(), createNodeEnlargementStage(), setMinimalDistance(double)

doLayout

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

Specified by:
doLayout in interface Layouter

checkNodeSize

protected void checkNodeSize(GraphLayout layout,
                             Object node)
                      throws IllegalArgumentException
This method throws an IllegalArgumentException if the width/height of the given node object is zero. It is called by the doLayout(LayoutGraph) method for each node object in the input graph.

Throws:
IllegalArgumentException - thrown if the width/height of the node object is zero.
Parameters:
layout - a graph layout object.
node - the node object to test.
See Also:
checkGroupNodeSize(GraphLayout,Object)

checkGroupNodeSize

protected void checkGroupNodeSize(GraphLayout layout,
                                  Object node)
                           throws IllegalArgumentException
This method throws an IllegalArgumentException if the width/height of the given group node object is zero. It is called by the doLayout(LayoutGraph) method for each group node object in the input graph.

Throws:
IllegalArgumentException - thrown if the width/height of the group node object is zero.
Parameters:
layout - a graph layout object.
node - the group node object to test.
See Also:
checkNodeSize(GraphLayout,Object)

getCoreLayouter

public Layouter getCoreLayouter()
Returns the core layouter.

Specified by:
getCoreLayouter in interface LayoutStage

setCoreLayouter

public void setCoreLayouter(Layouter l)
Sets the core layouter.

Specified by:
setCoreLayouter in interface LayoutStage

getMinimalDistance

public double getMinimalDistance()
Returns the minimal distance between nodes and non-incident edges.


setMinimalDistance

public void setMinimalDistance(double minimalDistance)
Specifies the minimal distance the algorithm should guarantee between nodes and non-incident edges. Values should be larger than 10.


isUsingBends

public boolean isUsingBends()
Returns whether given bend coordinates are taken into account when determining initial bend positions.


setUsingBends

public void setUsingBends(boolean usingBends)
Specifies whether given bend coordinates are taken into account when determining initial bend positions.


isRoutingAll

public boolean isRoutingAll()
Returns whether edges should be rerouted even if they do not obey all constraints initially. This flag is initially set to false so that if edges that do not intersect with other nodes will not be rerouted by this algorithm.


setRoutingAll

public void setRoutingAll(boolean routingAll)
Specifies whether edges should be rerouted even if they do not obey all constraints initially. This flag is initially set to false so that if edges that do not intersect with other nodes will not be rerouted by this algorithm.


createNodeEnlargementStage

public LayoutStage createNodeEnlargementStage()
This will return a layout stage which can be given a core layouter, which itself should assure that the nodes do not overlap. This ensures that OrganicEdgeRouter has enough empty space for routing edges. This could for example look like the following snippet:
 RemoveOverlapsLayoutStage rmos = new RemoveOverlapsLayoutStage(0);
 LayoutStage nodeEnlarger = router.createNodeEnlargementStage();
 final CompositeLayoutStage cls = new CompositeLayoutStage();
 cls.appendStage(nodeEnlarger);
 cls.appendStage(new BendConverter());
 cls.appendStage(rmos);

 OrganicEdgeRouter oer = new OrganicEdgeRouter();
 oer.setCoreLayouter(cls);
 oer.doLayout(myGraph);
 


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