Interface ForceRadial<NodeDatum>

The radial force is similar to the x- and y-positioning forces, except it pushes nodes towards the closest point on a given circle. The circle is of the specified radius centered at ⟨x,y⟩. If x and y are not specified, they default to ⟨0,0⟩. The strength of the force is proportional to the one-dimensional distance between the node’s position and the target position. While this force can be used to position individual nodes, it is intended primarily for global forces that apply to all (or most) nodes.

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

interface ForceRadial {
    initialize(nodes, random): void;
    radius(): ((d, i, data) => number);
    radius(radius): ForceRadial<NodeDatum>;
    strength(): ((d, i, data) => number);
    strength(strength): ForceRadial<NodeDatum>;
    x(): ((d, i, data) => number);
    x(x): ForceRadial<NodeDatum>;
    y(): ((d, i, data) => number);
    y(y): ForceRadial<NodeDatum>;
    (alpha): void;
}

Type Parameters

Hierarchy

  • Force<NodeDatum, any>
    • ForceRadial
  • 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.

    Parameters

    • alpha: number

    Returns void

Methods

  • Assigns the array of nodes and random source 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[]
    • random: (() => number)
        • (): number
        • Returns number

    Returns void

  • Return the current radius accessor for the circle.

    Returns ((d, i, data) => number)

      • (d, i, data): number
      • Return the current radius accessor for the circle.

        Parameters

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

        Returns number

  • Sets the circle radius to the specified number or function, re-evaluates the radius accessor for each node, and returns this force. The radius accessor is invoked for each node in the simulation, being passed the node and its zero-based index. The resulting number is then stored internally, such that the target radius of each node is only recomputed when the force is initialized or when this method is called with a new radius, and not on every application of the force.

    Parameters

    • radius: number | ((d, i, data) => number)

    Returns ForceRadial<NodeDatum>

  • Returns the current strength accessor, which defaults to a constant strength for all nodes of 0.1.

    Returns ((d, i, data) => number)

      • (d, i, data): number
      • Returns the current strength accessor, which defaults to a constant strength for all nodes of 0.1.

        Parameters

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

        Returns number

  • Sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each node, and returns this force. The strength determines how much to increment the node’s x- and y-velocity. For example, a value of 0.1 indicates that the node should move a tenth of the way from its current position to the closest point on the circle with each application. Higher values moves nodes more quickly to the target position, often at the expense of other forces or constraints. A value outside the range [0,1] is not recommended. The strength accessor is invoked for each node in the simulation, being passed the node and its zero-based index. 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 | ((d, i, data) => number)

    Returns ForceRadial<NodeDatum>

  • Return the current x-accessor for the circle center, which defaults to a function returning 0 for all nodes.

    Returns ((d, i, data) => number)

      • (d, i, data): number
      • Return the current x-accessor for the circle center, which defaults to a function returning 0 for all nodes.

        Parameters

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

        Returns number

  • Sets the x-coordinate of the circle center to the specified number and returns this force.

    Parameters

    • x: number | ((d, i, data) => number)

    Returns ForceRadial<NodeDatum>

  • Return the current y-accessor for the circle center, which defaults to a function returning 0 for all nodes.

    Returns ((d, i, data) => number)

      • (d, i, data): number
      • Return the current y-accessor for the circle center, which defaults to a function returning 0 for all nodes.

        Parameters

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

        Returns number

  • Sets the y-coordinate of the circle center to the specified number and returns this force.

    Parameters

    • y: number | ((d, i, data) => number)

    Returns ForceRadial<NodeDatum>