d3 clustered force layout, distance between cluster center

五迷三道 提交于 2020-01-03 02:51:07

问题


(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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!