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?

4

1 回答 1

9

您可以将链接距离视为预期距离,将强度视为您希望在每次迭代中达到此目标距离的速度。


如果您查看强制定向布局的源代码,您会发现以下行:

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

该算法是一种优化算法,因此,在您修改的每次迭代l中。现在问题是你必须指定你修改了多少。

在基本算法中,您将拥有以下内容以优化距离:

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

但是,您可能希望对每个链接以及每个单独的链接进行更多控制。因此,您可以将alpha属性视为固定参数,将strength属性视为随每个链接变化的参数。

如果您想了解更多关于使用的优化方法,我建议您查看Gauss-Seidel 维基百科页面

于 2013-06-28T01:05:54.777 回答