链接将节点与圆心连接起来。但我想从圆周连接节点 我正在使用以下代码创建链接并连接它:
var link = svg.selectAll(".link")
.data(links)
.enter()
.append("g")
.attr("class", "link")
.append("line")
.attr("class", function(d) { return "link " + d.rtype; })
.attr("class", "link-line")
.style("stroke-width", function(d)
{
return Math.sqrt(d.rtype);
});
var path = svg.append("svg:g").selectAll("path")
.data(force.links())
.enter().append("svg:path")
.attr("class", function(d)
{
return "link " + d.rtype;
})
.attr("id", function(d, i)
{
return "linkId_" + i;
})
.attr("marker-end", function(d)
{
return "url(#" + d.rtype + ")";
});
在tick功能中,我正在使用它:
path.attr("d", function(d)
{
console.log(d.radius);
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = 75 / d.linknum; //linknum is defined above
return "M" + (d.source.x) + "," + (d.source.y) + "A" + dr + "," + dr + " 0 0,1 " + (d.target.x) + "," + d.target.y;
});
link.attr("d", function(d)
{
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" +
(d.source.x ) + "," +
d.source.y + "A" +
dr + "," + dr + " 0 0,1 " +
(d.target.x) + "," +
d.target.y;
});
有人可以告诉我,我必须做出哪些改变?