Class pv.Layout.Force
Extends
pv.Layout.Network.
Implements force-directed network layout as a node-link diagram. This
layout uses the Fruchterman-Reingold algorithm, which applies an attractive
spring force between neighboring nodes, and a repulsive electrical charge
force between all nodes. An additional drag force improves stability of the
simulation. See pv.Force.spring, pv.Force.drag and {@link
pv.Force.charge} for more details; note that the n-body charge force is
approximated using the Barnes-Hut algorithm.
This layout is implemented on top of pv.Simulation, which can be used directly for more control over simulation parameters. The simulation uses Position Verlet integration, which does not compute velocities explicitly, but allows for easy geometric constraints, such as bounding the nodes within the layout panel. Many of the configuration properties supported by this layout are simply passed through to the underlying forces and constraints of the simulation.
Force layouts are typically interactive. The gradual movement of the nodes as they stabilize to a local stress minimum can help reveal the structure of the network, as can pv.Behavior.drag, which allows the user to pick up nodes and reposition them while the physics simulation continues. This layout can also be used with pan & zoom behaviors for interaction.
To facilitate interaction, this layout by default automatically re-renders using a setInterval every 42 milliseconds. This can be disabled via the iterations property, which if non-null specifies the number of simulation iterations to run before the force-directed layout is finalized. Be careful not to use too high an iteration count, as this can lead to an annoying delay on page load.
As with other network layouts, the network data can be updated
dynamically, provided the property cache is reset. See
pv.Layout.Network for details. New nodes are initialized with random
positions near the center. Alternatively, positions can be specified manually
by setting the x and y attributes on nodes.
Defined in: Force.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Constructs a new, empty force-directed layout.
|
Field Attributes | Field Name and Description |
---|---|
The bound parameter; true if nodes should be constrained within the layout
panel.
|
|
The charge constant, which should be a negative number.
|
|
The maximum distance at which charge forces are applied.
|
|
The minimum distance at which charge forces are applied.
|
|
The Barnes-Hut approximation factor.
|
|
Default properties for force-directed layouts.
|
|
The drag constant, in the range [0,1].
|
|
The number of simulation iterations to run, or null if this layout is
interactive.
|
|
The spring constant, which should be a positive number.
|
|
The spring damping factor, in the range [0,1].
|
|
The spring rest length.
|
- Fields borrowed from class pv.Layout.Network:
- label, link, node
- Fields borrowed from class pv.Panel:
- canvas, children, overflow, transform
- Fields borrowed from class pv.Bar:
- fillStyle, height, lineWidth, strokeStyle, width
- Fields borrowed from class pv.Mark:
- bottom, childIndex, cursor, data, events, index, left, parent, proto, reverse, right, root, scale, title, top, type, visible
- Methods borrowed from class pv.Layout.Network:
- reset
- Methods borrowed from class pv.Panel:
- add, anchor
- Methods borrowed from class pv.Mark:
- anchorTarget, def, event, extend, margin, mouse, render
- See:
- "Graph Drawing by Force-directed Placement" by T. Fruchterman & E. Reingold, Software--Practice & Experience, November 1991.
Note that if this layout is used in conjunction with pan & zoom behaviors, those behaviors should have their bound parameter set to the same value.
In rare cases, two particles can become stuck on top of each other, as a minimum distance threshold will prevent the charge force from repelling them. However, this occurs very rarely because other forces and momentum typically cause the particles to become separated again, at which point the repulsive charge force kicks in.
The spring tension is automatically normalized using the inverse square root of the maximum link degree of attached nodes.
The spring damping is automatically normalized using the inverse square root of the maximum link degree of attached nodes.