【发布时间】:2023-06-07 05:36:02
【问题描述】:
我已经看到了几个关于如何根据节点的半径移动有向图中的箭头的问题,但在我的示例中我无法弄清楚如何做到这一点:https://jsfiddle.net/Lx58yux4/
//arrows
svg.append("defs").selectAll("marker")
.data(["suit", "licensing", "resolved"])
.enter().append("marker")
.attr("id", function(d) { return d; })
.attr("viewBox", "0 -5 10 10")
.attr("refX", 25)
.attr("refY", 0)
.attr("markerWidth", 8)
.attr("markerHeight", 8)
.attr("orient", "auto")
.append("path")
.attr("d", "M0,-5L10,0L0,5 L10,0 L0, -5")
.style("stroke", "#4679BD")
.style("opacity", "0.6");
//onTick
force.on("tick", function () {
link.attr("x1", function (d) {
return d.source.x;
})
.attr("y1", function (d) {
return d.source.y;
})
.attr("x2", function (d) {
return d.target.x;
})
.attr("y2", function (d) {
return d.target.y;
});
d3.selectAll("circle").attr("cx", function (d) {
//return d.x;
return d.x = Math.max(radius, Math.min(width - 10, d.x));
})
.attr("cy", function (d) {
return d.y = Math.max(radius, Math.min(height - 10, d.y));
//return d.y;
});
d3.selectAll("text").attr("x", function (d) {
return d.x;
})
.attr("y", function (d) {
return d.y;
});
node.each(collide(5.0)); //collision detection
});
【问题讨论】:
标签: layout d3.js graph force-layout