I'm trying to make a force directed graph using 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. | ||||
In addition to charge and linkDistance, you also have gravity. If you want the graph to maintain the same relative density to the layout size, then you'll want to scale both charge and gravity. These are the main two computing forces that determine the overall size of the blob. See my force layout talk for more details. I tried a few different versions, and this one seemed to work pretty well:
Here |
联系客服