gpt4 book ai didi

d3.js - d3.js 强制布局是否允许动态链接距离?

转载 作者:行者123 更新时间:2023-12-03 21:39:18 24 4
gpt4 key购买 nike

我正在使用力布局来表示有向未加权网络。我的灵感来自以下例子:http://bl.ocks.org/mbostock/1153292

enter image description here

我的问题是,在我的情况下,节点之间有更多的链接,我觉得给出一个固定的 linkDistance,它总是相同的,对我的布局来说是一个非常大的约束。

是否可以设置动态linkDistance ,如果减少图形内的链接交叉有用,那么链接的长度会增加吗?

最佳答案

来自 the documentation :

force.linkDistance([distance])

If distance is specified, sets the target distance between linked nodes to the specified value. If distance is not specified, returns the layout's current link distance, which defaults to 20. If distance is a constant, then all links are the same distance. Otherwise, if distance is a function, then the function is evaluated for each link (in order), being passed the link and its index, with the this context as the force layout; the function's return value is then used to set each link's distance. The function is evaluated whenever the layout starts. Typically, the distance is specified in pixels; however, the units are arbitrary relative to the layout's size.


请注意,链接距离仍会在布局运行时进行调整。您还可以找到设置 linkStrength()有用。

关于d3.js - d3.js 强制布局是否允许动态链接距离?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16567750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com