简体   繁体   English

d3.js-防止在力导向图中与父/其他组“聚类”

[英]d3.js - prevent “clustering” with parent / other groups in force-directed graph

I'm facing an issue right now where I'm trying to make a force-directed graph that's smart about how it clusters. 我现在正面临一个问题,我试图制作一个力图,该图智能地说明了其如何聚类。 Currently I'm getting the following, which as you can see, has a very broken layout in regards to readability. 目前,我得到以下内容,正如您所看到的,在可读性方面布局非常混乱。 I would much prefer to have each child group cluster with itself, and repel sibling groups, so it's a bit easier to follow. 我更希望每个子组都有自己的集群,并排斥同级组,因此遵循起来要容易一些。 Preferably, I'd also like these clusters to be equally distributed in a circle around the parent node so when there are a lot of nodes, they're at least more readable than they would otherwise be if they all clustered on one side of the parent. 最好,我还希望这些集群在父节点周围均匀分布成一个圆圈,因此,当有很多节点时,它们的可读性至少比如果它们都聚集在父节点的一侧要好得多。家长。

I did a bit of research, and I would like something similar to this , but I'm not sure how I can apply that to my site. 我做了一些研究,我想类似的东西这个 ,但我不知道我怎么可以应用到我的网站。 For reference, my site layout is based off of this force layout. 作为参考,我的站点布局基于强制布局。

I ended up playing with the d3 force options a bit, and I came across this as a viable solution: 我最终使用了d3 force选项,并发现它是可行的解决方案:

var force = d3.layout.force()
    .linkDistance(function(d) { 
        return d.target._children ? d.target._children.length * 30 : 
            d.target.children ? d.target.children.length * 30 :
            60;
    })
    .charge(-400)
    .gravity(0.05)
    .friction(0.45)
    .linkStrength(0.6)
    .size([width, height])
    .on("tick", tick);

gravity / friction / linkStrength are not necessary but make transitions overall smoother; gravity / friction /连接linkStrength不是必需的,但可使过渡总体上更平滑; having a very negative charge was the key component to solving my original problem. charge是解决我原来的问题的关键。

Much thanks to @AmeliaBR for pointing me in the right direction! 非常感谢@AmeliaBR为我指出正确的方向!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM