WebCola
Options
All
  • Public
  • Public/Protected
  • All
Menu

The many-body (or n-body) force applies mutually amongst all nodes. It can be used to simulate gravity (attraction) if the strength is positive, or electrostatic charge (repulsion) if the strength is negative. This implementation uses quadtrees and the Barnes–Hut approximation to greatly improve performance; the accuracy can be customized using the theta parameter.

Unlike links, which only affect two linked nodes, the charge force is global: every node affects every other node, even if they are on disconnected subgraphs.

The generic refers to the type of data for a node.

Type parameters

Hierarchy

  • Force<NodeDatum, any>
    • ForceManyBody

Callable

  • __call(alpha: number): void
  • 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.

    Unlike links, which only affect two linked nodes, the charge force is global: every node affects every other node, even if they are on disconnected subgraphs.

    The generic refers to the type of data for a node.

    Parameters

    • alpha: number

    Returns void

Index

Methods

distanceMax

  • distanceMax(): number
  • distanceMax(distance: number)
  • Returns the current maximum distance over which this force is considered, which defaults to infinity.

    Returns number

  • Sets the maximum distance between nodes over which this force is considered.

    Specifying a finite maximum distance improves performance and produces a more localized layout.

    The default value is infinity.

    Parameters

    • distance: number

      The maximum distance between nodes over which this force is considered.

distanceMin

  • distanceMin(): number
  • distanceMin(distance: number)
  • Returns the current minimum distance over which this force is considered, which defaults to 1.

    Returns number

  • Sets the minimum distance between nodes over which this force is considered.

    A minimum distance establishes an upper bound on the strength of the force between two nearby nodes, avoiding instability. In particular, it avoids an infinitely-strong force if two nodes are exactly coincident; in this case, the direction of the force is random.

    The default value is 1.

    Parameters

    • distance: number

      The minimum distance between nodes over which this force is considered.

initialize

  • initialize(nodes: NodeDatum[]): void
  • 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.

    Parameters

    • nodes: NodeDatum[]

    Returns void

strength

  • strength(): function
  • strength(strength: number)
  • strength(strength: function)
  • Return the current strength accessor.

    For details regarding the default behavior see: https://github.com/d3/d3-force#manyBody_strength

    Returns function

      • (d: NodeDatum, i: number, data: NodeDatum[]): number
      • Parameters

        • d: NodeDatum
        • i: number
        • data: NodeDatum[]

        Returns number

  • Set the strength accessor to the specified constant strength for all nodes, re-evaluates the strength accessor for each node, and returns this force.

    A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge.

    The default represents a constant value of -30.

    The constant is internally wrapped into a strength accessor function.

    The strength accessor is invoked for each node in the simulation, being passed the node, its zero-based index and the complete array of nodes. The resulting number is then stored internally, such that the strength of each node 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.

    Parameters

    • strength: number

      The constant strength to be used for all nodes.

  • Set the strength accessor to the specified function, re-evaluates the strength accessor for each node, and returns this force.

    A positive value causes nodes to attract each other, similar to gravity, while a negative value causes nodes to repel each other, similar to electrostatic charge.

    The default represents a constant value of -30.

    The strength accessor is invoked for each node in the simulation, being passed the node, its zero-based index and the complete array of nodes. The resulting number is then stored internally, such that the strength of each node 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.

    Parameters

    • strength: function

      A strength accessor function which is invoked for each node in the simulation, being passed the node, its zero-based index and the complete array of nodes. The function returns the strength.

        • (d: NodeDatum, i: number, data: NodeDatum[]): number
        • Parameters

          • d: NodeDatum
          • i: number
          • data: NodeDatum[]

          Returns number

theta

  • theta(): number
  • theta(theta: number)
  • Return the current value of the Barnes–Hut approximation criterion , which defaults to 0.9

    Returns number

  • Set the Barnes–Hut approximation criterion to the specified number and returns this force.

    To accelerate computation, this force implements the Barnes–Hut approximation which takes O(n log n) per application where n is the number of nodes. For each application, a quadtree stores the current node positions; then for each node, the combined force of all other nodes on the given node is computed. For a cluster of nodes that is far away, the charge force can be approximated by treating the cluster as a single, larger node. The theta parameter determines the accuracy of the approximation: if the ratio w / l of the width w of the quadtree cell to the distance l from the node to the cell’s center of mass is less than theta, all nodes in the given cell are treated as a single node rather than individually.

    The default value is 0.9.

    Parameters

    • theta: number

      Value for the theta parameter.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc