我正在尝试实现d3力布局,无法弄清楚如何以正确的方式定位链接的标记.
这是我到目前为止所得到的:
var links = force_data.force_directed_data.links;
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function (link) {
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
});
console.log(nodes);
var width = 1000,
height = 1000;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(300)
.charge(-120)
.friction(0.9)
.on("tick", tick)
.start();
var svg = d3.select("#force-graph").append("svg")
.attr("width", width)
.attr("height", height);
// Per-type markers, as they don't inherit styles.
svg.append("defs").selectAll("marker")
.data(["dominating"])
.enter().append("marker")
.attr("id", …Run Code Online (Sandbox Code Playgroud)