All examples By author By category About

sathomas

Understanding D3.js Force Layout - 7: linkStrength

This is part of a series of examples that describe the basic operation of the D3.js force layout. Eventually they may end up in a blog post that wraps everything together. If you missed the beginning of the series, here's a link to first example.

An earlier example introduced linkDistance as a key parameter for force layouts. It sets the desired distance between any connected nodes. The force layout includes an additional parameter that serves to modify the linkDistance. That parameter is linkStrength. The default linkStrength value is 1.0, which maintains the full effect of linkDistance. By setting the value of linkStrength less than 1, though, the distance constraint can be relaxed.

In this example the red link has a linkStrength of 0.1, while all the other links retain the default value of 1.0. Use the controls in the upper left to run the layout and see the effect of this reduced link strength.

Note: the force that's drawing the nodes together in this case is gravity, which the next example considers in more detail. The links with a default strength are able to resist gravity more than the red link.