问题
(I'm a d3js newbie)
I'm using the d3.layout.force to visualize a graph of nodes that are divided into clusters, basically something like this (even if in my version every cluster's node keep the gravity focus set to its cluster's center):
http://bl.ocks.org/mbostock/1747543
What I'd like to accomplish is to keep each cluster separated from the other with a MIN distance.
I set random points for each cluster center at initial stage:
for(var i = 0; i < clusterLength; i++) {
var baseX = 3
var baseY = 7
var x = halton(i + 1, baseX) * width + (Math.random() * 50)
var y = halton(i + 1, baseY) * height + (Math.random() * 50)
clusterCoords.push({
x: x,
y: y
})
j += 1
}
Then I'd like to be able to reposition each cluster keeping a distance between the others.
Hope it's clear.
回答1:
This is what the padding
variable is used for in the mbostock example.
See my example with padding set to 30: http://bl.ocks.org/mccannf/5548435
来源:https://stackoverflow.com/questions/16465719/d3-clustered-force-layout-distance-between-cluster-center