I'm trying to make a force directed graph using d3.layout.force
, and I need the container to be resizable - that is I'd like to be able calculate appropriate charge and linkDistance values based on the size, or have d3 do it for me in some magical way.
I've made an attempt (link: http://jsfiddle.net/VHdUe/6/) which only uses nodes. I'm setting the charge to a value that's based on the number of nodes that would fit across the radius of the circle that it tends to be shaped like.
The solution works for some middle-sized containers, but if you click resize a few times, you can see it doesn't really work for all sizes...
The only way forward I can see is using an svg scale transform, which will mess up the size of my elements unfavorable. Any other options?
PS: I have seen http://mbostock.github.com/d3/talk/20110921/bounding.html (the answer to D3 force directed layout with bounding box), but I'd rather have a gravity-based solution than a bounding box one.