info.aduna.linkmap.layout
Class SpringLayoutManager

java.lang.Object
  extended by info.aduna.linkmap.layout.GraphLayoutManager
      extended by info.aduna.linkmap.layout.IteratingLayoutManager
          extended by info.aduna.linkmap.layout.SpringLayoutManager
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
AdaptiveSpringLayoutManager

public class SpringLayoutManager
extends IteratingLayoutManager

SpringLayoutManager is an IteratingLayoutManager that implements the "spring embedder" algorithm: it simulates a physical model of Vertices that repel each other like electrically charged particles, with the Edges between them acting like springs that hold them together. When used with carefully tested parameters - the spring embedder algorithm is quite sensitive when it comes to layout parameters, with regard to speed, quality and ability to reach an equilibrium -, SpringLayoutManager can calculate an aesthetically pleasing and almost organic layout for a Graph.

SpringLayoutManager assumes that the graph (or the part of it) for which it is calculating a layout, is connected, i.e. that there is a path between every pair of vertices in the graph (ignoring directionality). It is able to calculate the layout of non-connected graphs, but it will never stabilize in such a case (or only after a very large number of iterations): the various subgraphs will repel each other with absolutely no forces between them trying to hold them together. In order to calculate a reasonable layout for such a graph, SpringLayoutManager can be used in conjunction with SubgraphRelocationManager. The SpringLayoutManager is then used as a GraphLayoutManager for every connected subgraph, which are combined into one dense rectangular graph structure by the SubgraphRelocationManager.

During the design and implementation of this class, care has been taken to produce an API which allows for extreme customization through method overriding. This means that SpringLayoutManager can be tuned into the extreme for a specific kind of Graph rather easily. See the documentation of the methods for more information on this matter.


Nested Class Summary
static class SpringLayoutManager.EdgeAttribute
           
static class SpringLayoutManager.VertexAttribute
           
 
Field Summary
static double DEFAULT_ADAPTATION
          The default value of the adaptation parameter.
static double DEFAULT_ATTRACTION
          The default value of the attraction parameter.
static double DEFAULT_AVERAGE_MOVEMENT_THRESHOLD
          The default value of the average movement threshold.
static double DEFAULT_CHARGE
          The default charge of a vertex.
static double DEFAULT_MASS
          The default mass of a vertex.
static double DEFAULT_MAXIMUM_ALLOWED_MOVEMENT
          The default value of the maximum allowed movement parameter.
static double DEFAULT_MAXIMUM_OBSERVED_MOVEMENT_THRESHOLD
          The default value of the maximum observed movement threshold.
static double DEFAULT_MOMENTUM
          The default value of the momentum parameter.
static double DEFAULT_REPULSION
          The default value of the repulsion parameter.
static double DEFAULT_SPRING_CONSTANT
          The default spring constant of an edge.
static double DEFAULT_SPRING_LENGTH
          The default spring length of an edge.
static int DEFAULT_TRANSLATION_INTERVAL
          The default value of the translation interval parameter.
 
Fields inherited from class info.aduna.linkmap.layout.IteratingLayoutManager
UNDEFINED_MAX_ITERATION
 
Constructor Summary
SpringLayoutManager()
          Create a new SpringLayoutManager which will calculate the layout for a (yet unspecified) Graph.
 
Method Summary
 SpringLayoutManager.EdgeAttribute createEdgeAttribute(Edge edge)
          Creates a new EdgeAttribute for the specified Edge.
 LayoutConverter createLayoutConverter()
          Returns a LayoutConverter that allows the rendering mechanism to retrieve and adapt the layout of a graph, while abstracting from the specified GraphLayoutManager implementation that is used.
 SpringLayoutManager.VertexAttribute createVertexAttribute(Vertex vertex)
          Creates a new VertexAttribute for the specified Vertex.
 void doLayout()
          Calculates a layout for the Graph registered in this SpringLayoutManager.
 void doLayout(Collection<SpringLayoutManager.VertexAttribute> vertexAttributes, Collection<SpringLayoutManager.EdgeAttribute> edgeAttributes)
          Calculates a layout for a Graph represented by the specified Lists of VertexAttributes and EdgeAttributes.
 void doLayout(SpringLayoutManager.VertexAttribute[] vertexAttributes, SpringLayoutManager.EdgeAttribute[] edgeAttributes)
          Calculates a layout for a Graph represented by the specified arrays of VertexAttributes and EdgeAttributes.
 double getAdaptation()
           
 double getAttraction()
           
 double getAverageMovementThreshold()
           
 double getCharge()
           
 ArrayList<SpringLayoutManager.EdgeAttribute> getEdgeAttributes(Collection<Edge> edges)
          Returns an ArrayList containing all EdgeAttributes occuring in the specified Graph.
 double getMass()
           
 double getMaximumAllowedMovement()
           
 double getMaximumObservedMovement()
           
 double getMaximumObservedMovementThreshold()
           
 double getMomentum()
           
 double getRepulsion()
           
 double getSpringConstant()
           
 double getSpringLength()
           
 double getSummedMovement()
           
 int getTranslationInterval()
           
 ArrayList<SpringLayoutManager.VertexAttribute> getVertexAttributes(Collection<Vertex> vertices)
          Returns an ArrayList containing all VertexAttributes occuring in the specified Graph.
 void initialize(Graph graph)
          Makes sure all Vertices and Edges in the specified Graph have layout attributes.
 void initLayoutParameters()
          Initializes the layout parameters of this SpringLayoutManager.
 void initThresholds()
          Initializes the quality thresholds of this SpringLayoutManager.
 boolean isAverageMovementThresholdEnabled()
          Returns whether averageMovementThreshold is greater than or equal to zero.
 boolean isMaximumObservedMovementThresholdEnabled()
          Returns whether maximumObservedMovementThreshold is greater than or equal to zero.
 void move(SpringLayoutManager.VertexAttribute attribute)
          Moves a Vertex represented by the specified VertexAttribute.
 void randomizeCoordinates(Graph graph, long seed)
          Gives the Vertices in the specified Graph a random position in the area of the rectange (0, 0, 500, 500).
 void reset(SpringLayoutManager.EdgeAttribute attribute)
          Resets the properties of the specified EdgeAttribute to its initial values.
 void reset(SpringLayoutManager.VertexAttribute attribute)
          Resets the properties of the specified VertexAttribute to its initial values.
 void resetAttributes()
          Sets the properties of all layout attributes inside the current Graph to their initial values.
 void resetAttributes(Graph graph)
          Sets the properties of all layout attributes of the specified Graph to their initial values.
 void setAdaptation(double adaptation)
           
 void setAttraction(double attraction)
           
 void setAverageMovementThreshold(double averageMovementThreshold)
           
 void setCharge(double charge)
          Set the value of the standard vertex charge.
 void setEdgeAttribute(Edge edge)
          Checks whether the specified Edge already has a layout attribute and, if not, installs one.
 void setMass(double mass)
          Set the value of the standard vertex mass.
 void setMaximumAllowedMovement(double maximumAllowedMovement)
           
 void setMaximumObservedMovement(double maximumObservedMovement)
           
 void setMaximumObservedMovementThreshold(double maximumObservedMovementThreshold)
           
 void setMomentum(double momentum)
           
 void setRepulsion(double repulsion)
           
 void setSpringConstant(double constant)
          Set the value of the standard spring constant.
 void setSpringLength(double length)
          Set the value of the standard spring length.
 void setSummedMovement(double summedMovement)
           
 void setTranslationInterval(int translationInterval)
          Sets the translation interval.
 void setVertexAttribute(Vertex vertex)
          Checks whether the specified Vertex already has a layout attribute and, if not, installs one.
 
Methods inherited from class info.aduna.linkmap.layout.IteratingLayoutManager
continueLayout, getIteration, getMaxIteration, handlePauseLayout, increaseIteration, isMaxIterationReached, pauseLayout, pauseLayoutRequested, setIteration, setMaxIteration, setPauseLayout, setStopLayout, stopLayout, stopLayoutRequested
 
Methods inherited from class info.aduna.linkmap.layout.GraphLayoutManager
getGraph, run, setGraph
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MASS

public static final double DEFAULT_MASS
The default mass of a vertex.

See Also:
Constant Field Values

DEFAULT_CHARGE

public static final double DEFAULT_CHARGE
The default charge of a vertex.

See Also:
Constant Field Values

DEFAULT_SPRING_LENGTH

public static final double DEFAULT_SPRING_LENGTH
The default spring length of an edge.

See Also:
Constant Field Values

DEFAULT_SPRING_CONSTANT

public static final double DEFAULT_SPRING_CONSTANT
The default spring constant of an edge.

See Also:
Constant Field Values

DEFAULT_REPULSION

public static final double DEFAULT_REPULSION
The default value of the repulsion parameter.

See Also:
Constant Field Values

DEFAULT_ATTRACTION

public static final double DEFAULT_ATTRACTION
The default value of the attraction parameter.

See Also:
Constant Field Values

DEFAULT_ADAPTATION

public static final double DEFAULT_ADAPTATION
The default value of the adaptation parameter.

See Also:
Constant Field Values

DEFAULT_TRANSLATION_INTERVAL

public static final int DEFAULT_TRANSLATION_INTERVAL
The default value of the translation interval parameter.

See Also:
Constant Field Values

DEFAULT_MOMENTUM

public static final double DEFAULT_MOMENTUM
The default value of the momentum parameter.

See Also:
Constant Field Values

DEFAULT_MAXIMUM_ALLOWED_MOVEMENT

public static final double DEFAULT_MAXIMUM_ALLOWED_MOVEMENT
The default value of the maximum allowed movement parameter.

See Also:
Constant Field Values

DEFAULT_AVERAGE_MOVEMENT_THRESHOLD

public static final double DEFAULT_AVERAGE_MOVEMENT_THRESHOLD
The default value of the average movement threshold.

See Also:
Constant Field Values

DEFAULT_MAXIMUM_OBSERVED_MOVEMENT_THRESHOLD

public static final double DEFAULT_MAXIMUM_OBSERVED_MOVEMENT_THRESHOLD
The default value of the maximum observed movement threshold.

See Also:
Constant Field Values
Constructor Detail

SpringLayoutManager

public SpringLayoutManager()
Create a new SpringLayoutManager which will calculate the layout for a (yet unspecified) Graph.

Method Detail

initLayoutParameters

public void initLayoutParameters()
Initializes the layout parameters of this SpringLayoutManager.


initThresholds

public void initThresholds()
Initializes the quality thresholds of this SpringLayoutManager.


setRepulsion

public void setRepulsion(double repulsion)

getRepulsion

public double getRepulsion()

setAttraction

public void setAttraction(double attraction)

getAttraction

public double getAttraction()

setAdaptation

public void setAdaptation(double adaptation)

getAdaptation

public double getAdaptation()

setTranslationInterval

public void setTranslationInterval(int translationInterval)
Sets the translation interval. A translation interval less than zero is allowed: it means that no translation will be done during the iterations, only a single translation is done at the end of the algorithm.


getTranslationInterval

public int getTranslationInterval()

setMomentum

public void setMomentum(double momentum)

getMomentum

public double getMomentum()

setMaximumAllowedMovement

public void setMaximumAllowedMovement(double maximumAllowedMovement)

getMaximumAllowedMovement

public double getMaximumAllowedMovement()

setMass

public void setMass(double mass)
Set the value of the standard vertex mass. This should be a value greater than zero. New vertices will have this mass as layout property. Existing vertices are not updated, for this you need to invoke resetAttributes.


getMass

public double getMass()

setCharge

public void setCharge(double charge)
Set the value of the standard vertex charge. This should be a value greater than or equal to zero. New vertices will have this charge as layout property. Existing vertices are not updated, for this you need to invoke resetAttributes.


getCharge

public double getCharge()

setSpringConstant

public void setSpringConstant(double constant)
Set the value of the standard spring constant. This should be a value greater than or equal to zero. New Edges will have this spring constant as layout property. Existing Edges are not updated, for this you need to invoke resetAttributes.


getSpringConstant

public double getSpringConstant()

setSpringLength

public void setSpringLength(double length)
Set the value of the standard spring length. This should be a value greater than or equal to zero. New edges will have this spring length as layout property. Older edges are not updated, for this you need to invoke resetAttributes.


getSpringLength

public double getSpringLength()

setSummedMovement

public void setSummedMovement(double summedMovement)

getSummedMovement

public double getSummedMovement()

setMaximumObservedMovement

public void setMaximumObservedMovement(double maximumObservedMovement)

getMaximumObservedMovement

public double getMaximumObservedMovement()

setAverageMovementThreshold

public void setAverageMovementThreshold(double averageMovementThreshold)

getAverageMovementThreshold

public double getAverageMovementThreshold()

isAverageMovementThresholdEnabled

public boolean isAverageMovementThresholdEnabled()
Returns whether averageMovementThreshold is greater than or equal to zero.


setMaximumObservedMovementThreshold

public void setMaximumObservedMovementThreshold(double maximumObservedMovementThreshold)

getMaximumObservedMovementThreshold

public double getMaximumObservedMovementThreshold()

isMaximumObservedMovementThresholdEnabled

public boolean isMaximumObservedMovementThresholdEnabled()
Returns whether maximumObservedMovementThreshold is greater than or equal to zero.


initialize

public void initialize(Graph graph)
Makes sure all Vertices and Edges in the specified Graph have layout attributes. Note that the newly created vertex attributes will probably need to have their coordinates randomized, this is not done in this method.

Specified by:
initialize in class GraphLayoutManager

setVertexAttribute

public void setVertexAttribute(Vertex vertex)
Checks whether the specified Vertex already has a layout attribute and, if not, installs one. The newly created layout attribute is initialized using the reset method, but their coordinates are not yet randomized.


setEdgeAttribute

public void setEdgeAttribute(Edge edge)
Checks whether the specified Edge already has a layout attribute and, if not, installs one. The newly created layout attributes are initialized using the appropriate reset method.


createVertexAttribute

public SpringLayoutManager.VertexAttribute createVertexAttribute(Vertex vertex)
Creates a new VertexAttribute for the specified Vertex. The VertexAttribute still needs to be set on the Vertex. Its properties are not yet initialized.


createEdgeAttribute

public SpringLayoutManager.EdgeAttribute createEdgeAttribute(Edge edge)
Creates a new EdgeAttribute for the specified Edge. The SpringEdgeAttribute still needs to be set on the Edge. Its properties are not yet initialized.


randomizeCoordinates

public void randomizeCoordinates(Graph graph,
                                 long seed)
Gives the Vertices in the specified Graph a random position in the area of the rectange (0, 0, 500, 500). The Random object used for generating the random numbers will use the specified seed.


resetAttributes

public void resetAttributes()
Sets the properties of all layout attributes inside the current Graph to their initial values. This invokes the resetAttributes method with the current Graph.


resetAttributes

public void resetAttributes(Graph graph)
Sets the properties of all layout attributes of the specified Graph to their initial values. For this it uses the three available reset methods.


reset

public void reset(SpringLayoutManager.VertexAttribute attribute)
Resets the properties of the specified VertexAttribute to its initial values. This copies the global mass and charge properties into the VertexAttribute and sets the various force properties to zero.


reset

public void reset(SpringLayoutManager.EdgeAttribute attribute)
Resets the properties of the specified EdgeAttribute to its initial values. This copies the global spring constant and length properties into the EdgeAttribute.


doLayout

public void doLayout()
Calculates a layout for the Graph registered in this SpringLayoutManager.

Specified by:
doLayout in class GraphLayoutManager

doLayout

public void doLayout(Collection<SpringLayoutManager.VertexAttribute> vertexAttributes,
                     Collection<SpringLayoutManager.EdgeAttribute> edgeAttributes)
Calculates a layout for a Graph represented by the specified Lists of VertexAttributes and EdgeAttributes.


doLayout

public void doLayout(SpringLayoutManager.VertexAttribute[] vertexAttributes,
                     SpringLayoutManager.EdgeAttribute[] edgeAttributes)
Calculates a layout for a Graph represented by the specified arrays of VertexAttributes and EdgeAttributes.


move

public void move(SpringLayoutManager.VertexAttribute attribute)
Moves a Vertex represented by the specified VertexAttribute. The actual movement is determined in the first place by the forces acting on it and the adaptation (in the simplest case, actual movement equals these forces multiplied by the adaptation), but are also influenced by the maximum allowed movement and the momentum.


createLayoutConverter

public LayoutConverter createLayoutConverter()
Description copied from class: GraphLayoutManager
Returns a LayoutConverter that allows the rendering mechanism to retrieve and adapt the layout of a graph, while abstracting from the specified GraphLayoutManager implementation that is used.

Specified by:
createLayoutConverter in class GraphLayoutManager

getVertexAttributes

public ArrayList<SpringLayoutManager.VertexAttribute> getVertexAttributes(Collection<Vertex> vertices)
Returns an ArrayList containing all VertexAttributes occuring in the specified Graph.


getEdgeAttributes

public ArrayList<SpringLayoutManager.EdgeAttribute> getEdgeAttributes(Collection<Edge> edges)
Returns an ArrayList containing all EdgeAttributes occuring in the specified Graph.



Copyright © 1997-2008 Aduna. All Rights Reserved.