samples.preview_new_graphdraw.iterablelayouts
Class KKLayout

java.lang.Object
  extended by samples.preview_new_graphdraw.iter.IterableLayout
      extended by samples.preview_new_graphdraw.iterablelayouts.KKLayout
All Implemented Interfaces:
LayoutEmitter

public class KKLayout
extends IterableLayout

Implements the Kamada-Kawai algorithm for node layout. Does not respect filter calls, and sometimes crashes when the view changes to it.

Author:
Masanori Harada
See Also:
"Tomihisa Kamada and Satoru Kawai: An algorithm for drawing general indirect graphs. Information Processing Letters 31(1):7-15, 1989", "Tomihisa Kamada: On visualization of abstract objects and relations. Ph.D. dissertation, Dept. of Information Science, Univ. of Tokyo, Dec. 1988."

Field Summary
protected  double diameter
          The diameter of the visible graph.
protected  double energy
           
protected  double energyDelta
           
protected static String LAYOUT_INDEX_KEY
           
 double THRESHOLD
           
protected  UnweightedShortestPath unweightedShortestPaths
          Stores graph distances between vertices of the visible graph
protected  Set vertices
           
 
Fields inherited from class samples.preview_new_graphdraw.iter.IterableLayout
currentLayout, returnableLayout
 
Constructor Summary
KKLayout()
           
KKLayout(double thresh)
           
 
Method Summary
 void adjustForGravity(Set vertices)
          Shift all vertices so that the center of gravity is located at the center of the screen.
 void calculate()
          Transforms currentLayout according to current layout algorithm.
 boolean getAdjustForGravity()
          Returns true if gravity point adjusting is enabled.
protected  double getDistance(Vertex v1, Vertex v2)
          Gets a distance (a length of the shortest path) between the specified vertices.
 boolean getExchangeVertices()
          Returns true if the local minimum escape technique by exchanging vertices is enabled.
 void initializeLocationsFromLayout(EmittedLayout sla)
          Starts up this layout based on a previous layout.
 boolean isFinite()
          Says whether this algorthms' iterations will ever end.
 boolean iterationsAreDone()
          Gives the outlining algorithm a sense of how long to run.
 void setAdjustForGravity(boolean on)
          Enable or disable gravity point adjusting.
 void setExchangeVertices(boolean on)
          Enable or disable the local minimum escape technique by exchanging vertices.
 
Methods inherited from class samples.preview_new_graphdraw.iter.IterableLayout
advance, emit, getScreenSize, getVisEdge, getVisVertex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unweightedShortestPaths

protected UnweightedShortestPath unweightedShortestPaths
Stores graph distances between vertices of the visible graph


diameter

protected double diameter
The diameter of the visible graph. In other words, length of the longest shortest path between any two vertices of the visible graph.


LAYOUT_INDEX_KEY

protected static final String LAYOUT_INDEX_KEY
See Also:
Constant Field Values

vertices

protected Set vertices

energy

protected double energy

energyDelta

protected double energyDelta

THRESHOLD

public final double THRESHOLD
Constructor Detail

KKLayout

public KKLayout()

KKLayout

public KKLayout(double thresh)
Method Detail

initializeLocationsFromLayout

public void initializeLocationsFromLayout(EmittedLayout sla)
Description copied from class: IterableLayout
Starts up this layout based on a previous layout. It is reasonable to assume that this method will be called only once. After this method is complete, a CURRENT LAYOUT should be defined with the current states of the vertices, and a RETURNABLE LAYOUT should be defined for emit() to return. In general, emit() will just return this copy of the layout stored in returnableLayout, so this method and advance() are both respon sible for advancing correctly.

Overrides:
initializeLocationsFromLayout in class IterableLayout

getDistance

protected double getDistance(Vertex v1,
                             Vertex v2)
Gets a distance (a length of the shortest path) between the specified vertices. Returned value is used for computing the strength of an embedded spring. You may override this method to visualize a graph with weighted edges.

The original Kamada-Kawai algorithm requires a connected graph. That is, pathes must be exist between every pair of vertices in the graph. To visualize a non-connected graph, this method returns (diameter + 1) for vertices that are not connected.

The default implementation is as follows:

  int dist = unweightedShortestPaths.getShortestPath(v1, v2);
  if (dist < 0)
      return diameter + 1;
  else
      return dist;
 


calculate

public void calculate()
Description copied from class: IterableLayout
Transforms currentLayout according to current layout algorithm. This may change the state of the currentLayout object.

Specified by:
calculate in class IterableLayout

adjustForGravity

public void adjustForGravity(Set vertices)
Shift all vertices so that the center of gravity is located at the center of the screen.


setAdjustForGravity

public void setAdjustForGravity(boolean on)
Enable or disable gravity point adjusting.


getAdjustForGravity

public boolean getAdjustForGravity()
Returns true if gravity point adjusting is enabled.


setExchangeVertices

public void setExchangeVertices(boolean on)
Enable or disable the local minimum escape technique by exchanging vertices.


getExchangeVertices

public boolean getExchangeVertices()
Returns true if the local minimum escape technique by exchanging vertices is enabled.


iterationsAreDone

public boolean iterationsAreDone()
Description copied from class: IterableLayout
Gives the outlining algorithm a sense of how long to run. The algorithm is responsible for setting its own thresholds. Note that this should return a meaningful value (probably "false") even before initialize has been called.

Specified by:
iterationsAreDone in class IterableLayout
See Also:
IterableLayout.iterationsAreDone()

isFinite

public boolean isFinite()
Description copied from class: IterableLayout
Says whether this algorthms' iterations will ever end. (If not, there's no real use to waiting.)

Specified by:
isFinite in class IterableLayout
See Also:
IterableLayout.isFinite()