我最近使用v3库创建了我的第一个强制导向图,但现在我需要使用D3版本4库创建相同的图形,但是这些方法在v4中发生了巨大的变化,现在我得到了所有的错误()/ drag()方法3现在在v4中不存在.
我的图表基于以下模型 - http://www.ourd3js.com/wordpress/?p=606
是否存在已在d3的v4库中创建的样本存储库,在那里我可以查看并学习一些我可以替换为此特定图表的函数?
编辑:
我当前的代码看起来像这样,但我无法将其完全转换,例如,节点链接非常接近,链接和节点的文本有时会重叠.
<svg width="960" height="600"></svg>
Run Code Online (Sandbox Code Playgroud)
Javascript代码:
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var graph = root;
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
var width = x;
var height = y;
var img_w = 24;
var img_h = 24;
var k = Math.sqrt(root.nodes.length / (width * height));
var simulation = d3.forceSimulation() …
Run Code Online (Sandbox Code Playgroud) d3.js ×1