Center Force

detroit.force_center(x: float | None = None, y: float | None = None) ForceCenter

The center 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 keep nodes in the center of the viewport, and unlike the position forces, it does not distort their relative positions.

Parameters:
  • x (float | None) – X-coordinate of the centering position

  • y (float | None) – Y-coordinate of the centering position

Returns:

Force object

Return type:

ForceCenter

class detroit.force.center.ForceCenter(x: float, y: float)
initialize(nodes: list[SimulationNode], random: Callable[[None], float])
x(x: float) ForceCenter

Sets the x-coordinate of the centering position to the specified number and returns this force.

Parameters:

x (float) – X-coordinate of the centering position

Returns:

Itself

Return type:

ForceCenter

y(y: float) ForceCenter

Sets the y-coordinate of the centering position to the specified number and returns this force.

Parameters:

y (float) – Y-coordinate of the centering position

Returns:

Itself

Return type:

ForceCenter

set_strength(strength: float) ForceCenter

Sets the center 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 (float) – Strength value

Returns:

Itself

Return type:

ForceCenter