Class JGraphFastOrganicLayout
java.lang.Object
com.jgraph.layout.organic.JGraphFastOrganicLayout
- All Implemented Interfaces:
JGraphLayout, JGraphLayout.Stoppable
- Direct Known Subclasses:
JGraphFRLayout
This layout is an implementation of "Graph Drawing by Force-Directed
Placement" by Fruchterman and Reingold (1991). FR layouts are a variation on
the basic Eades et al Spring Embedded layout. The paper states that
"distributing vertices evenly, making edge lengths uniform, and reflecting
symmetry" are its target aims. The variation from the basic embedded is that
the attractive force is proportional to the square of the spring length, the
natural spring length being zero and the repulsive force is linear with the
distance between the nodes. FR layouts are better suited to well connected
graphs.
The computational effort per iteration is quadratic, O(|N|^2+|E|). This is due to the way all nodes calculate repulsion from all others. The three user variables are
The computational effort per iteration is quadratic, O(|N|^2+|E|). This is due to the way all nodes calculate repulsion from all others. The three user variables are
forceConstant,initialTemp and
maxIteration.forceConstant is the constant k
in the paper and affects the radius around each node around which other nodes
would be in equilibrium. initialTemp sets the start
temperature of the layout, lower values limit the displacement of each node
on each iteration. maxIteration sets the total number of
iterations of the layout that occur.-
Nested Class Summary
Nested classes/interfaces inherited from interface JGraphLayout
JGraphLayout.Stoppable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[][]An array of locally stored co-ordinate positions for the verticesprotected double[]An array of locally stored X co-ordinate displacements for the verticesprotected double[]An array of locally stored Y co-ordinate displacements for the verticesprotected doubleThe force constant by which the attractive forces are divided and the replusive forces are multiple by the square of.protected doubleCache offorceConstant^2 for performanceprotected doubleStart value of temperatureprotected boolean[]Local copy of isMoveableprotected intCurrent iteration countprotected intTotal number of iterations to run the layout thoughprotected doubleprevents from dividing with zeroprotected doublecached version ofminDistanceLimitsquaredprotected int[][]Local copy of cell neighboursprotected JGraphLayoutProgressAn object to monitor and control progress.protected double[]The approximate radius of each cell, nodes onlyprotected double[]The approximate radius squared of each cell, nodes onlyprotected doubleTemperature to limit displacement at later stages of layoutprotected Object[]An array of all vertices to be laid outFields inherited from interface JGraphLayout
VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalculates the attractive forces between all laid out nodes linked by edgesvoidTakes the displacements calculated for each cell and applies them to the local cache of cell positions.voidCalculates the repulsive forces between all laid out nodesdoubledoubleintReturns the progress object that represents the progress of the current layout run.voidrun(JGraphFacade graph) Executes the Fruchterman-Reingold layout using the graph description from the specified facadevoidsetForceConstant(double forceConstant) voidsetInitialTemp(double initialTemp) voidsetMaxIterations(int maxIterations) toString()ReturnsFast Organic, the name of this algorithm.
-
Field Details
-
forceConstant
protected double forceConstantThe force constant by which the attractive forces are divided and the replusive forces are multiple by the square of. The value equates to the average radius there is of free space around each node. -
forceConstantSquared
protected double forceConstantSquaredCache offorceConstant^2 for performance -
temperature
protected double temperatureTemperature to limit displacement at later stages of layout -
initialTemp
protected double initialTempStart value of temperature -
iteration
protected int iterationCurrent iteration count -
maxIterations
protected int maxIterationsTotal number of iterations to run the layout though -
vertexArray
An array of all vertices to be laid out -
dispX
protected double[] dispXAn array of locally stored X co-ordinate displacements for the vertices -
dispY
protected double[] dispYAn array of locally stored Y co-ordinate displacements for the vertices -
cellLocation
protected double[][] cellLocationAn array of locally stored co-ordinate positions for the vertices -
radius
protected double[] radiusThe approximate radius of each cell, nodes only -
radiusSquared
protected double[] radiusSquaredThe approximate radius squared of each cell, nodes only -
isMoveable
protected boolean[] isMoveableLocal copy of isMoveable -
neighbours
protected int[][] neighboursLocal copy of cell neighbours -
progress
An object to monitor and control progress. -
minDistanceLimit
protected double minDistanceLimitprevents from dividing with zero -
minDistanceLimitSquared
protected double minDistanceLimitSquaredcached version ofminDistanceLimitsquared
-
-
Constructor Details
-
JGraphFastOrganicLayout
public JGraphFastOrganicLayout()
-
-
Method Details
-
getProgress
Description copied from interface:JGraphLayout.StoppableReturns the progress object that represents the progress of the current layout run. Once created, this instance should not be replaced during a layout run. For new runs you should use the reset method on the progress. Consequently, the max progress is only valid after the run method has been invoked, which means you should use a listener if you spawn a new thread.By convention, the layout must check the isStopped method in its inner-most loops and return immediately if the method returns
true.- Specified by:
getProgressin interfaceJGraphLayout.Stoppable- Returns:
- Returns the progress.
-
run
Executes the Fruchterman-Reingold layout using the graph description from the specified facade- Specified by:
runin interfaceJGraphLayout- Parameters:
graph- the facade describing the graph to be acted upon
-
calcPositions
public void calcPositions()Takes the displacements calculated for each cell and applies them to the local cache of cell positions. Limits the displacement to the current temperature. -
calcAttraction
public void calcAttraction()Calculates the attractive forces between all laid out nodes linked by edges -
calcRepulsion
public void calcRepulsion()Calculates the repulsive forces between all laid out nodes -
getForceConstant
public double getForceConstant()- Returns:
- Returns the forceConstant.
-
setForceConstant
public void setForceConstant(double forceConstant) - Parameters:
forceConstant- The forceConstant to set.
-
getMaxIterations
public int getMaxIterations()- Returns:
- Returns the maxIterations.
-
setMaxIterations
public void setMaxIterations(int maxIterations) - Parameters:
maxIterations- The maxIterations to set.
-
getInitialTemp
public double getInitialTemp()- Returns:
- Returns the initialTemp.
-
setInitialTemp
public void setInitialTemp(double initialTemp) - Parameters:
initialTemp- The initialTemp to set.
-
toString
-