Relation between LinkDistance and LinkStrength in D3.js Force layout
Asked Answered
L

1

9

How are the LinkDistance and LinkStrength related in a force directed layout in D3.js? I am assuming that they are, correct me if i am wrong.

I understand that the linkDistance defines the length between any pair of nodes and essentially serves as constraint in a force layout. But what role does linkStrength play? The API documentation for D3.js defines it as the "strength (rigidity) of links to the specified value in the range [0,1]" What does "rigidity" mean here exactly?

Ladonnalady answered 27/6, 2013 at 23:54 Comment(0)
M
9

You can see the link distance as the expected distance and the strength as the speed at which you want to reach this target distance on each iteration.


If you have a look at the source code of the force directed layout, you will find the following line:

l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;

This algorithm is an optimization algorithm, thus, on each iteration you modify l. Now the thing is that you have to specify by how much you modify this.

On a basic algorithm you would have the following in order to optimize the distances:

l = ((l = Math.sqrt(l)) - distances[i]) / l;  

However you might want to have more control on every links and also on each individual link. Hence, you can consider the alpha attribute as the fixed parameter and the strength attribute as the parameter that varies for each link.

If you want to know more about the optimization method used, I recommend you to have a look at the Gauss-Seidel wikipedia page.

Merman answered 28/6, 2013 at 1:5 Comment(2)
thanks for your answer! is this alpha by any chance the cooling parameter as provided in the API of the force layout, D3.js?Ladonnalady
Exactly! I really recommend you to have a look at the source code to know more about how it actually works.Merman

© 2022 - 2024 — McMap. All rights reserved.