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:
- 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:
- 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 elementi (
int) - the index of the nodenodes (
list[SimulationNode]) - the list of nodes
It returns the ID value (
int)- Returns:
Itself
- Return type:
- 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:
- 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 elementi (
int) - the index of the nodelinks (
list[SimulationLink]) - the list of links
It returns the strength value (
float)- Returns:
Itself
- Return type:
- 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 elementi (
int) - the index of the nodenodes (
list[SimulationNode]) - the list of nodes
It returns the distance value (
float)- Returns:
Itself
- Return type: