Interface ForceCenter<NodeDatum>

The centering force translates nodes uniformly so that the mean position of all nodes (the center of mass if all nodes have equal weight) is at the given position [x,y]. This force modifies the positions of nodes on each application; it does not modify velocities, as doing so would typically cause the nodes to overshoot and oscillate around the desired center. This force helps keeps nodes in the center of the viewport, and unlike the positioning force, it does not distort their relative positions.

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

interface ForceCenter {
    initialize(nodes, random): void;
    strength(): number;
    strength(strength): ForceCenter<NodeDatum>;
    x(): number;
    x(x): ForceCenter<NodeDatum>;
    y(): number;
    y(y): ForceCenter<NodeDatum>;
    (alpha): void;
}

Type Parameters

Hierarchy

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

  • Supplies 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

  • Returns the force’s current strength, which defaults to 1.

    Returns number

  • Sets the centering force’s strength. A reduced strength of e.g. 0.05 softens the movements on interactive graphs in which new nodes enter or exit the graph.

    Parameters

    • strength: number

      The centering force's strength.

    Returns ForceCenter<NodeDatum>

  • Return the current x-coordinate of the centering position, which defaults to zero.

    Returns number

  • Set the x-coordinate of the centering position.

    Parameters

    • x: number

      x-coordinate.

    Returns ForceCenter<NodeDatum>

  • Return the current y-coordinate of the centering position, which defaults to zero.

    Returns number

  • Set the y-coordinate of the centering position.

    Parameters

    • y: number

      y-coordinate.

    Returns ForceCenter<NodeDatum>