Class ForceArrangement
- All Implemented Interfaces:
GraphArrangement
An organic arrangement for networks: edges pull like springs and every node pushes every other away, until the graph settles.
This is Fruchterman and Reingold's method with a cooling schedule. Repulsion is summed through a Barnes-Hut quadtree, so a step costs n log n rather than n squared, and a graph of thousands of nodes settles in well under a second.
arrange runs every iteration at once. A view that animates the graph
settling, or keeps it live while the user drags a node, calls start and
then step once a frame instead. Starting positions come from the model, so
a graph that was laid out before moves only as much as its changes need;
nodes that are all at one point are first spread on a circle. The run is
deterministic: the same graph gives the same picture.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarrange(GraphModel model) Computes a position for every node, and a route for edges the arrangement bends.doubleThe length an edge settles at, in world units, between node centres.intHow many stepsarrangeruns, 300 by default.voidHolds a node at a centre position for the next steps; the view calls it while the user drags the node.voidreheat(int steps) Keeps the run going for more steps, for instance while a node is dragged, at a temperature that lets the graph follow.voidPushes apart nodes that still overlap once the forces have settled, along the axis where they overlap least.result()The positions the run has reached.voidsetIdealLength(double idealLength) Sets the edge length.voidsetIterations(int iterations) Sets the number of steps.voidstart(GraphModel model) Prepares a stepwise run from the model's current positions.booleanstep()Moves every node one step towards rest.
-
Constructor Details
-
ForceArrangement
public ForceArrangement()
-
-
Method Details
-
getIdealLength
public double getIdealLength()The length an edge settles at, in world units, between node centres. -
setIdealLength
public void setIdealLength(double idealLength) Sets the edge length. -
getIterations
public int getIterations()How many stepsarrangeruns, 300 by default. -
setIterations
public void setIterations(int iterations) Sets the number of steps. -
arrange
Description copied from interface:GraphArrangementComputes a position for every node, and a route for edges the arrangement bends.- Specified by:
arrangein interfaceGraphArrangement
-
start
Prepares a stepwise run from the model's current positions. -
step
public boolean step()Moves every node one step towards rest.
Returns
false once the run has finished
-
reheat
public void reheat(int steps) Keeps the run going for more steps, for instance while a node is dragged, at a temperature that lets the graph follow. -
hold
Holds a node at a centre position for the next steps; the view calls it while the user drags the node. -
result
The positions the run has reached. -
removeOverlaps
public void removeOverlaps()Pushes apart nodes that still overlap once the forces have settled, along the axis where they overlap least. Neighbours are found through a grid of cells as large as the largest node, so a pass is linear.
-