Class SpringLayout<V,E>
- java.lang.Object
-
- edu.uci.ics.jung.algorithms.layout.AbstractLayout<V,E>
-
- edu.uci.ics.jung.algorithms.layout.SpringLayout<V,E>
-
- All Implemented Interfaces:
Layout<V,E>
,IterativeContext
,org.apache.commons.collections4.Transformer<V,java.awt.geom.Point2D>
- Direct Known Subclasses:
DAGLayout
,SpringLayout2
public class SpringLayout<V,E> extends AbstractLayout<V,E> implements IterativeContext
The SpringLayout package represents a visualization of a set of nodes. The SpringLayout, which is initialized with a Graph, assigns X/Y locations to each node. When calledrelax()
, the SpringLayout moves the visualization forward one step.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
SpringLayout.SpringDimensionChecker
Used for changing the size of the layout in response to a component's size.protected static class
SpringLayout.SpringVertexData
-
Field Summary
Fields Modifier and Type Field Description protected double
force_multiplier
protected org.apache.commons.collections4.Transformer<E,java.lang.Integer>
lengthFunction
protected int
repulsion_range_sq
protected java.util.Map<V,SpringLayout.SpringVertexData>
springVertexData
protected double
stretch
-
Fields inherited from class edu.uci.ics.jung.algorithms.layout.AbstractLayout
graph, initialized, locations, size
-
-
Constructor Summary
Constructors Constructor Description SpringLayout(edu.uci.ics.jung.graph.Graph<V,E> g)
Constructor for a SpringLayout for a raw graph with associated dimension--the input knows how big the graph is.SpringLayout(edu.uci.ics.jung.graph.Graph<V,E> g, org.apache.commons.collections4.Transformer<E,java.lang.Integer> length_function)
Constructor for a SpringLayout for a raw graph with associated component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
calculateRepulsion()
boolean
done()
For now, we pretend it never finishes.double
getForceMultiplier()
Returns the current value for the edge length force multiplier.int
getRepulsionRange()
Returns the current value for the node repulsion range.double
getStretch()
Returns the current value for the stretch parameter.void
initialize()
Initializes fields in the node that may not have been set during the constructor.boolean
isIncremental()
This one is an incremental visualizationprotected void
moveNodes()
protected void
relaxEdges()
void
reset()
No effect.void
setForceMultiplier(double force)
Sets the force multiplier for this instance.void
setRepulsionRange(int range)
Sets the node repulsion range (in drawing area units) for this instance.void
setSize(java.awt.Dimension size)
Sets the dimensions of the available space for layout tosize
.void
setStretch(double stretch)
Sets the stretch parameter for this instance.void
step()
Relaxation step.-
Methods inherited from class edu.uci.ics.jung.algorithms.layout.AbstractLayout
getGraph, getSize, getX, getY, isLocked, lock, lock, offsetVertex, setGraph, setInitializer, setLocation, setLocation, transform
-
-
-
-
Field Detail
-
stretch
protected double stretch
-
lengthFunction
protected org.apache.commons.collections4.Transformer<E,java.lang.Integer> lengthFunction
-
repulsion_range_sq
protected int repulsion_range_sq
-
force_multiplier
protected double force_multiplier
-
springVertexData
protected java.util.Map<V,SpringLayout.SpringVertexData> springVertexData
-
-
Constructor Detail
-
SpringLayout
public SpringLayout(edu.uci.ics.jung.graph.Graph<V,E> g)
Constructor for a SpringLayout for a raw graph with associated dimension--the input knows how big the graph is. Defaults to the unit length function.
-
SpringLayout
public SpringLayout(edu.uci.ics.jung.graph.Graph<V,E> g, org.apache.commons.collections4.Transformer<E,java.lang.Integer> length_function)
Constructor for a SpringLayout for a raw graph with associated component.- Parameters:
g
- theGraph
to lay outlength_function
- provides a length for each edge
-
-
Method Detail
-
getStretch
public double getStretch()
Returns the current value for the stretch parameter.- See Also:
setStretch(double)
-
setSize
public void setSize(java.awt.Dimension size)
Sets the dimensions of the available space for layout tosize
.
-
setStretch
public void setStretch(double stretch)
Sets the stretch parameter for this instance. This value specifies how much the degrees of an edge's incident vertices should influence how easily the endpoints of that edge can move (that is, that edge's tendency to change its length).
The default value is 0.70. Positive values less than 1 cause high-degree vertices to move less than low-degree vertices, and values > 1 cause high-degree vertices to move more than low-degree vertices. Negative values will have unpredictable and inconsistent results.
- Parameters:
stretch
-
-
getRepulsionRange
public int getRepulsionRange()
Returns the current value for the node repulsion range.- See Also:
setRepulsionRange(int)
-
setRepulsionRange
public void setRepulsionRange(int range)
Sets the node repulsion range (in drawing area units) for this instance. Outside this range, nodes do not repel each other. The default value is 100. Negative values are treated as their positive equivalents.- Parameters:
range
-
-
getForceMultiplier
public double getForceMultiplier()
Returns the current value for the edge length force multiplier.- See Also:
setForceMultiplier(double)
-
setForceMultiplier
public void setForceMultiplier(double force)
Sets the force multiplier for this instance. This value is used to specify how strongly an edge "wants" to be its default length (higher values indicate a greater attraction for the default length), which affects how much its endpoints move at each timestep. The default value is 1/3. A value of 0 turns off any attempt by the layout to cause edges to conform to the default length. Negative values cause long edges to get longer and short edges to get shorter; use at your own risk.
-
initialize
public void initialize()
Description copied from interface:Layout
Initializes fields in the node that may not have been set during the constructor. Must be called before the iterations begin.- Specified by:
initialize
in interfaceLayout<V,E>
-
step
public void step()
Relaxation step. Moves all nodes a smidge.- Specified by:
step
in interfaceIterativeContext
-
relaxEdges
protected void relaxEdges()
-
calculateRepulsion
protected void calculateRepulsion()
-
moveNodes
protected void moveNodes()
-
isIncremental
public boolean isIncremental()
This one is an incremental visualization
-
done
public boolean done()
For now, we pretend it never finishes.- Specified by:
done
in interfaceIterativeContext
-
-