Apply this force, optionally observing the specified alpha. Typically, the force is applied to the array of nodes previously passed to force.initialize, however, some forces may apply to a subset of nodes, or behave differently. For example, d3.forceLink applies to the source and target of each link.
The first generic refers to the type of data for a node. The second generic refers to the type of data for a link.
Return the current distance accessor, which defaults to implying a default distance of 30.
Set the distance accessor to use the specified constant number for all links, re-evaluates the distance accessor for each link, and returns this force.
The constant is internally wrapped into a distance accessor function.
The distance accessor is invoked for each link, being passed the link, its zero-based index and the complete array of links. The resulting number is then stored internally, such that the distance of each link is only recomputed when the force is initialized or when this method is called with a new distance, and not on every application of the force.
The constant distance to be used for all links.
Set the distance accessor to use the specified function, re-evaluates the distance accessor for each link, and returns this force.
The distance accessor is invoked for each link, being passed the link, its zero-based index and the complete array of links. The resulting number is then stored internally, such that the distance of each link is only recomputed when the force is initialized or when this method is called with a new distance, and not on every application of the force.
A distance accessor function which is invoked for each link being passed the link, its zero-based index and the complete array of links. It returns the distance.
Return the current node id accessor, which defaults to the numeric node.index.
Set the node id accessor to the specified function and return this force.
The default id accessor allows each link’s source and target to be specified as a zero-based index into the nodes array.
The id accessor is invoked for each node whenever the force is initialized, as when the nodes or links change, being passed the node, the zero-based index of the node in the node array, and the node array.
A node id accessor function which is invoked for each node in the simulation, being passed the node, the zero-based index of the node in the node array, and the node array. It returns a string to represent the node id which can be used for matching link source and link target strings during the ForceLink initialization.
Assign the array of nodes to this force. This method is called when a force is bound to a simulation via simulation.force and when the simulation’s nodes change via simulation.nodes.
A force may perform necessary work during initialization, such as evaluating per-node parameters, to avoid repeatedly performing work during each application of the force.
Return the current iteration count which defaults to 1.
Sets the number of iterations per application to the specified number and return this force.
Increasing the number of iterations greatly increases the rigidity of the constraint and is useful for complex structures such as lattices, but also increases the runtime cost to evaluate the force.
Number of iterations.
Return the current array of links, which defaults to the empty array.
Set the array of links associated with this force, recompute the distance and strength parameters for each link, and return this force.
Each link is an object with the following properties:
For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references; see link.id. If the specified array of links is modified, such as when links are added to or removed from the simulation, this method must be called again with the new (or changed) array to notify the force of the change; the force does not make a defensive copy of the specified array.
An array of link data.
Return the current strength accessor. For details regarding the default behavior see: https://github.com/d3/d3-force#link_strength
Set the strenght accessor to use the specified constant number for all links, re-evaluates the strength accessor for each link, and returns this force.
The constant is internally wrapped into a strength accessor function.
The strength accessor is invoked for each link, being passed the link, its zero-based index and the complete array of links. The resulting number is then stored internally, such that the strength of each link is only recomputed when the force is initialized or when this method is called with a new strength, and not on every application of the force.
The constant strength to be used for all links.
Set the strenght accessor to use the specified function, re-evaluates the strength accessor for each link, and returns this force.
The strength accessor is invoked for each link, being passed the link, its zero-based index and the complete array of links. The resulting number is then stored internally, such that the strength of each link is only recomputed when the force is initialized or when this method is called with a new strength, and not on every application of the force.
A distance accessor function which is invoked for each link being passed the link, its zero-based index and the complete array of links. It returns the strength.
Generated using TypeDoc
The link force pushes linked nodes together or apart according to the desired link distance. The strength of the force is proportional to the difference between the linked nodes’ distance and the target distance, similar to a spring force.
The first generic refers to the type of data for a node. The second generic refers to the type of data for a link.