Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ForceArrangement

  1. Object
  2. ForceArrangement

ImplementsGraphArrangement

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.

Constructors

public ForceArrangement()

Methods

public double getIdealLength()The length an edge settles at, in world units, between node centres.
public void setIdealLength(double idealLength)Sets the edge length.
public int getIterations()How many steps arrange runs, 300 by default.
public void setIterations(int iterations)Sets the number of steps.
public ArrangementResult arrange(GraphModel model)Computes a position for every node, and a route for edges the arrangement bends.
public void start(GraphModel model)Prepares a stepwise run from the model’s current positions.
public boolean step()Moves every node one step towards rest.
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.
public void hold(String nodeId, double centerX, double centerY)Holds a node at a centre position for the next steps; the view calls it while the user drags the node.
public ArrangementResult result()The positions the run has reached.
public void removeOverlaps()Pushes apart nodes that still overlap once the forces have settled, along the axis where they overlap least.

Inherited methods

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 steps arrange runs, 300 by default.

setIterations

public void setIterations(int iterations)
Sets the number of steps.

arrange

public ArrangementResult arrange(GraphModel model)
Computes a position for every node, and a route for edges the arrangement bends.

start

public void start(GraphModel model)
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

public void hold(String nodeId, double centerX, double centerY)
Holds a node at a centre position for the next steps; the view calls it while the user drags the node.

result

public ArrangementResult 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.