如何使用d3 v4设置固定链接距离 [英] how do you set a fixed link distance with d3 v4
问题描述
所有的API示例都似乎适用于v3。
我试图理解如何创建一个固定距离链接的力图,如:
http://bl.ocks.org/d3noob/5141278
All the API examples seem to be for v3 still. I'm trying to understand how to create a force graph with links of a fixed distance, like: http://bl.ocks.org/d3noob/5141278
我看过link_distance但不知道如何应用它:
https://github.com/d3/d3-force /blob/master/README.md#link_distance
I looked at link_distance but not sure how to apply it: https://github.com/d3/d3-force/blob/master/README.md#link_distance
创建如下图表:
let simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) { return d.id; }))
.force("charge", d3.forceManyBody().strength(-150))
.force("center", d3.forceCenter(width / 2, height / 2));
我尝试了各种组合,如:
I tried various combos like:
// .force("link", d3.forceLink().distance(20).strength(1))
// .force("linkDistance", 20)
// .force("link", d3.forceLink().id(function(d) { return d.id; }))
但没有运气!
所以看来link_distance不能修复?
它的强度和(距离,无论是什么)
So it seems link_distance can't be fixed? its a result of strength and (distance, whatever that is)
那么如何应用 strength
和 distance
到d3 v4中的链接?
是否应用于模拟或其他?
So how do I apply strength
and distance
to links in d3 v4 ?
Is it applied to the simulation or something else?
推荐答案
你几乎更接近改变v4中的距离!检查此更改,它适用于我:
You are almost closer to change the distance in v4! Check this change, it works for me:
var simulation = d3.forceSimulation()
.force("link", d3.forceLink().id(function(d) { return d.id; }).distance(100).strength(1))
.force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2));
这篇关于如何使用d3 v4设置固定链接距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!