Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
Detroit v2.6.3
Light Logo Dark Logo
Detroit v2.6.3
  • Line chart
  • Area chart
  • Stack chart
  • Scatter chart
  • Bar chart
  • Histogram chart
  • Heatmap
  • Chord chart
  • Pie chart
  • Density chart
  • Geographical Map
  • Voronoi diagram
  • Tree chart
  • Treemap chart
  • Pack chart
  • Complex charts
    • Step Response of a Second Order System (Control Theory)
    • Principal Component Analysis on MNIST dataset
    • Fan Chart
    • Scatter Matrix chart
    • Kernel Speed Comparison between Numba et Cupy
    • Hertzsprung Russell Diagram
    • Gantt Chart
  • API
    • Array
    • Axis
    • Chord
      • Chords
      • Ribbons
    • Color
    • Contours
      • Contour polygons
      • Density estimation
    • Delaunay
      • Delaunay triangulations
      • Voronoi diagrams
    • Ease
    • Force
      • Force simulations
      • Center Force
      • Collide Force
      • Link Force
      • Many-body Force
      • Position Forces
    • Format
    • Geo
      • Paths
      • Projections
        • Azimuthal projections
        • Conic projections
        • Cylindrical projections
      • Streams
      • Spherical shapes
      • Spherical math
    • Hierarchy
      • Hierarchies
      • Stratify
      • Tree
      • Cluster
      • Partition
      • Pack
      • Treemap
    • Interpolate
    • Path
    • Polygon
    • Quadtree
    • Scale
      • Abstract classes
      • Continuous base classes
      • Linear scales
      • Time scales
      • Power scales
      • Log scales
      • Symlog scales
      • Ordinal scales
      • Band scales
      • Sequential scales
      • Diverging scales
      • Quantile scales
      • Quantize scales
      • Threshold scales
    • Scale Chromatic
      • Categorical schemes
      • Cyclical schemes
      • Diverging schemes
      • Sequential schemes
    • Selection
    • Shapes
      • Arcs
      • Areas
      • Curves
      • Lines
      • Links
      • Pies
      • Stacks
      • Symbols
      • Radial Areas
      • Radial Lines
    • Time
    • Time Format
    • Types
Back to top
View this page

Link Force¶

detroit.force_link(links: list[SimulationLink] | None = None) → ForceLink¶

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.

Parameters:

links (list[SimulationLink] | None) – List of links

Returns:

Force object

Return type:

ForceLink

class detroit.force.link.ForceLink(links: list[SimulationLink])¶
initialize(nodes: list[SimulationNode], random: Callable[[None], float])¶
set_links(links: list[SimulationLink]) → ForceLink¶

Sets the array of links associated with this force, recomputes the distance and strength parameters for each link, and returns this force.

Each link is an object with the following properties:

  • source - the link’s source node; see simulation.nodes

  • target - the link’s target node; see simulation.nodes

  • index - the zero-based index into links, assigned by this method

For convenience, a link’s source and target properties may be initialized using numeric or string identifiers rather than object references.

Parameters:

links (list[SimulationLink]) – List of links

Returns:

Itself

Return type:

ForceLink

set_id(id_func: Callable[[SimulationNode, int, list[SimulationNode]], int]) → ForceLink¶

Sets the node ID accessor to the specified function and returns this force.

Parameters:

id_func (SimulationNodeFunction[int]) –

ID accessor function which takes the following arguments:

  • node (SimulationNode) - the node element

  • i (int) - the index of the node

  • nodes (list[SimulationNode]) - the list of nodes

It returns the ID value (int)

Returns:

Itself

Return type:

ForceLink

set_iterations(iterations: int) → ForceLink¶

Sets the number of iterations per application to the specified number and returns this force.

Parameters:

iterations (int) – Number of iterations

Returns:

Itself

Return type:

ForceLink

set_strength(strength: Callable[[SimulationLink, int, list[SimulationLink]], float] | float) → ForceLink¶

Sets the strength accessor to the specified number or function, re-evaluates the strength accessor for each link, and returns this force.

Parameters:

strength (SimulationLinkFunction[float] | float) –

Strength function or constant value. If it is a function, it takes the following arguments:

  • link (SimulationLink) - the link element

  • i (int) - the index of the node

  • links (list[SimulationLink]) - the list of links

It returns the strength value (float)

Returns:

Itself

Return type:

ForceLink

set_distance(distance: Callable[[SimulationNode, int, list[SimulationNode]], float] | float) → ForceLink¶

Sets the distance accessor to the specified number or function, re-evaluates the distance accessor for each link, and returns this force.

Parameters:

distance (SimulationNodeFunction[float] | float) –

Distance function or constant value. If it is a function, it takes the following arguments:

  • node (SimulationNode) - the node element

  • i (int) - the index of the node

  • nodes (list[SimulationNode]) - the list of nodes

It returns the distance value (float)

Returns:

Itself

Return type:

ForceLink

Next
Many-body Force
Previous
Collide Force
Copyright © 2024-2026, bourbonut
Made with Sphinx and @pradyunsg's Furo
On this page
  • Link Force
    • force_link()
    • ForceLink
      • ForceLink.initialize()
      • ForceLink.set_links()
      • ForceLink.set_id()
      • ForceLink.set_iterations()
      • ForceLink.set_strength()
      • ForceLink.set_distance()