最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Relation between LinkDistance and LinkStrength in D3.js Force layout - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Jan 19, 2014 at 15:24 VividD 10.5k8 gold badges66 silver badges112 bronze badges asked Jun 27, 2013 at 23:54 vijayvijay 2,6942 gold badges25 silver badges37 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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 remend you to have a look at the Gauss-Seidel wikipedia page.

发布评论

评论列表(0)

  1. 暂无评论