d3.js强制布局允许动态linkDistance? [英] Does d3.js force layout allow dynamic linkDistance?

查看:1106
本文介绍了d3.js强制布局允许动态linkDistance?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用强制布局来表示定向未加权网络。我的灵感来自以下示例::


force.linkDistance([distance])



如果指定distance,则将链接节点之间的目标距离设置为指定值。如果未指定distance,则返回布局的当前链接距离,默认为20.如果distance为常量,则所有链接的距离相同。 否则,如果distance是一个函数,那么对每个链接(按顺序)评估函数,传递链接及其索引,并将此上下文作为强制布局;函数的返回值然后用于设置每个链接的距离。每当布局开始时,都会评估该函数。通常,距离以像素指定;


请注意,链接距离仍会随布局运行而调整。您还可能会发现设置 linkStrength()有用。


I'm using the force layout to represent a directed unweighted network. My inspiration comes from the following example: http://bl.ocks.org/mbostock/1153292

My problem is that in my case there much more links between nodes and I have the feeling that giving a fixed linkDistance, which is always the same, is a very big constraint for my layout.

Is it possible to set a dynamic linkDistance, such that a link grows in length if it's useful to reduce link crossing inside the graph?

解决方案

From 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.

Note that the link distance is still adjusted as the layout runs. You may also find setting linkStrength() useful.

这篇关于d3.js强制布局允许动态linkDistance?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆