com.jgraph.layout.graph

Class JGraphSpringLayout

public class JGraphSpringLayout extends Object implements JGraphLayout, JGraphLayout.Stoppable

Deprecated: use JGraphFastOrganicLayout instead

A basic Spring Embedded Layout Algorithm. Edges on the graph represent spring. All the springs have a natural length, measured in the same units as the screen co-ordination system, which they attempt to achieve constantly. If the spring is shorter than its natural length it extends, pushing the nodes are either end of the edge apart. If the spring is longer than its natural length it contracts, pulling the nodes at either end of the edge together. The force exerted by the spring is proportional to different between its current length and its natural length. A force multiple is also applied indicating the "strength" of the spring. In addition, all nodes repel each other with a force inversely proportional to the distance between each other. The repelling force is mutliplied by a replusive force factor. The whole affect is to cause nodes to space out fairly evenly but for nodes linked by edges ( springs ) to cluster together
Field Summary
protected double[]cellLocationX
An array of locally stored X co-ordinate positions for the vertices
protected double[]cellLocationY
An array of locally stored Y co-ordinate positions for the vertices
protected Mapdisplacement
Stores the temporary positions of each cell during the layout
protected double[]dispX
An array of locally stored X co-ordinate displacements for the vertices
protected double[]dispY
An array of locally stored Y co-ordinate displacements for the vertices
protected boolean[]isMoveable
Local copy of isMoveable
protected intiteration
current iteration number
protected intmaxIterations
total number of iterations to step through when running
protected int[][]neighbours
Local copy of cell neighbours
protected JGraphLayoutProgressprogress
An object to monitor and control progress.
protected doublereplusiveForce
The multiple by which the force replusive each pair of nodes scaled by Increase to make nodes force further apart
protected doublespringForce
The multiple of force applied to the attraction of springs
protected doublespringLength
The natural length of the spring (edge) whereby it imparts no force on either connected node
protected Object[]vertexArray
An array of all vertices to be laid out
Constructor Summary
JGraphSpringLayout()
Creates a new layout of 50 iterations
JGraphSpringLayout(int iterations)
Creates a new spring layout to be executed over the specified number of iterations
Method Summary
protected voidattract()
Calculates an attractive force between the cells connected by the specified edge
intgetMaxIterations()
JGraphLayoutProgressgetProgress()
doublegetReplusiveForce()
doublegetSpringForce()
doublegetSpringLength()
protected voidreposition(JGraphFacade graph)
repositions the specified cells using the positioning data obtained through repulse and attract phases
protected voidrepulse()
Calculates a repulsion force between the specified cells and stores the cumulative displacement applied to each cell
voidrun(JGraphFacade graph)
Executes the spring layout of the specified facade data
voidsetMaxIterations(int iterations)
voidsetReplusiveForce(double replusiveForce)
voidsetSpringForce(double springForce)
voidsetSpringLength(double springLength)
StringtoString()
Returns Spring, the name of this algorithm.

Field Detail

cellLocationX

protected double[] cellLocationX
An array of locally stored X co-ordinate positions for the vertices

cellLocationY

protected double[] cellLocationY
An array of locally stored Y co-ordinate positions for the vertices

displacement

protected transient Map displacement
Stores the temporary positions of each cell during the layout

dispX

protected double[] dispX
An array of locally stored X co-ordinate displacements for the vertices

dispY

protected double[] dispY
An array of locally stored Y co-ordinate displacements for the vertices

isMoveable

protected boolean[] isMoveable
Local copy of isMoveable

iteration

protected int iteration
current iteration number

maxIterations

protected int maxIterations
total number of iterations to step through when running

neighbours

protected int[][] neighbours
Local copy of cell neighbours

progress

protected JGraphLayoutProgress progress
An object to monitor and control progress.

replusiveForce

protected double replusiveForce
The multiple by which the force replusive each pair of nodes scaled by Increase to make nodes force further apart

springForce

protected double springForce
The multiple of force applied to the attraction of springs

springLength

protected double springLength
The natural length of the spring (edge) whereby it imparts no force on either connected node

vertexArray

protected Object[] vertexArray
An array of all vertices to be laid out

Constructor Detail

JGraphSpringLayout

public JGraphSpringLayout()
Creates a new layout of 50 iterations

JGraphSpringLayout

public JGraphSpringLayout(int iterations)
Creates a new spring layout to be executed over the specified number of iterations

Parameters: iterations the number of layout iterations to execute

Method Detail

attract

protected void attract()
Calculates an attractive force between the cells connected by the specified edge

getMaxIterations

public int getMaxIterations()

Returns: Returns the total number of iterations.

getProgress

public JGraphLayoutProgress getProgress()

Returns: Returns the progress.

getReplusiveForce

public double getReplusiveForce()

Returns: Returns the replusiveForce.

getSpringForce

public double getSpringForce()

Returns: Returns the springForce.

getSpringLength

public double getSpringLength()

Returns: Returns the springLength.

reposition

protected void reposition(JGraphFacade graph)
repositions the specified cells using the positioning data obtained through repulse and attract phases

Parameters: graph the description of the graph to be laid out

repulse

protected void repulse()
Calculates a repulsion force between the specified cells and stores the cumulative displacement applied to each cell

run

public void run(JGraphFacade graph)
Executes the spring layout of the specified facade data

Parameters: graph the description of the graph to be acted upon

setMaxIterations

public void setMaxIterations(int iterations)

Parameters: iterations the value to set maxIterations to

setReplusiveForce

public void setReplusiveForce(double replusiveForce)

Parameters: replusiveForce The replusiveForce to set.

setSpringForce

public void setSpringForce(double springForce)

Parameters: springForce The springForce to set.

setSpringLength

public void setSpringLength(double springLength)

Parameters: springLength The springLength to set.

toString

public String toString()
Returns Spring, the name of this algorithm.
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.