Class DAGLayout<V,E>

All Implemented Interfaces:
com.google.common.base.Function<V,Point2D>, Layout<V,E>, IterativeContext, Function<V,Point2D>

public class DAGLayout<V,E> extends SpringLayout<V,E>
An implementation of Layout suitable for tree-like directed acyclic graphs. Parts of it will probably not terminate if the graph is cyclic! The layout will result in directed edges pointing generally upwards. Any vertices with no successors are considered to be level 0, and tend towards the top of the layout. Any vertex has a level one greater than the maximum level of all its successors.
Author:
John Yesberg
  • Constructor Details

    • DAGLayout

      public DAGLayout(Graph<V,E> g)
  • Method Details

    • setRoot

      public void setRoot()
      Calculates the level of each vertex in the graph. Level 0 is allocated to each vertex with no successors. Level n+1 is allocated to any vertex whose successors' maximum level is n.
    • setRoot

      public void setRoot(V v)
      Set vertex v to be level 0.
      Parameters:
      v - the vertex to set as root
    • propagateMinimumLevel

      public void propagateMinimumLevel(V v)
      A recursive method for allocating the level for each vertex. Ensures that all predecessors of v have a level which is at least one greater than the level of v.
      Parameters:
      v - the vertex whose minimum level is to be calculated
    • setSize

      public void setSize(Dimension size)
      Description copied from class: AbstractLayout
      When a visualization is resized, it presumably wants to fix the locations of the vertices and possibly to reinitialize its data. The current method calls initializeLocations followed by initialize_local.
      Specified by:
      setSize in interface Layout<V,E>
      Overrides:
      setSize in class SpringLayout<V,E>
      Parameters:
      size - the space to use to lay out this graph
    • initialize

      public void initialize()
      Had to override this one as well, to ensure that setRoot() is called.
      Specified by:
      initialize in interface Layout<V,E>
      Overrides:
      initialize in class SpringLayout<V,E>
    • moveNodes

      protected void moveNodes()
      Override the moveNodes() method from SpringLayout. The only change we need to make is to make sure that nodes don't float higher than the minY coordinate, as calculated by their minimumLevel.
      Overrides:
      moveNodes in class SpringLayout<V,E>
    • done

      public boolean done()
      Override incrementsAreDone so that we can eventually stop.
      Specified by:
      done in interface IterativeContext
      Overrides:
      done in class SpringLayout<V,E>
      Returns:
      false
    • setLocation

      public void setLocation(V picked, double x, double y)
      Override forceMove so that if someone moves a node, we can re-layout everything.
      Overrides:
      setLocation in class AbstractLayout<V,E>
      Parameters:
      picked - the vertex whose location is to be set
      x - the x coordinate of the location to set
      y - the y coordinate of the location to set
    • setLocation

      public void setLocation(V picked, Point2D p)
      Override forceMove so that if someone moves a node, we can re-layout everything.
      Specified by:
      setLocation in interface Layout<V,E>
      Overrides:
      setLocation in class AbstractLayout<V,E>
      Parameters:
      picked - the vertex whose location is to be set
      p - the location to set
    • relaxEdges

      protected void relaxEdges()
      Overridden relaxEdges. This one reduces the effect of edges between greatly different levels.
      Overrides:
      relaxEdges in class SpringLayout<V,E>