d3.js - set links size to a force layout

d3.js, force-layout

Solution

It's a characteristic of the force layout that the length of the links is variable -- the point is that the nodes are laid out automatically and you don't have to worry about it. You could implement checks that make sure that the distances are always what you want them to be, but this would be quite difficult.

The `linkDistance` function that you're using already is the only direct way to (weakly) enforce such a constraint. If that's not enough, there's no easy way of mitigating it. Your only option would be to implement checks like I've mentioned above at each tick of the simulation.

Problem

Based on the "Molecule" example of Michael Bostock, available at this url : http://bl.ocks.org/mbostock/3037015. I'm trying to set the size of my links with several values. For that, I disabled the "gravity", put an important negative value in "charge" and fixed the first node to the center of my window. ``` var force = d3.layout.force() .size([width, height]) .charge(-800) .friction(0.45) .linkStrength(1) .gravity(0) .linkDistance(function(d) { return radius(d.target.size * 10); }); ``` My problem is () sometimes the size of the links are differents, especially for links defined with a little value. Does somebody know one good solution for my problem? You can see my code here : http://jsfiddle.net/awPn3/

Original source