سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top