My question is how to create a network visualization scheme such that the edges and/or arrowheads terminate at the borders of the nodes.
I am drawing a directed graph using D3.js based on the Curved Links base model with added "marker" arrowheads as described in this other question. The nodes in my visualization vary their size and opacity based on their properties. This introduces two problems: (1) The arrowheads do not point to the edge of the nodes when the nodes change size, and (2) the tails of the edges appear through the nodes when they are partially transparent.
For the first problem, there are a few solutions available: this one purports to get the arrow heads offset correctly, but it does not affect the link end terminations. There are also suggestions of solutions here, but I didn't see any actual complete working code there. This JS fiddle has exactly the arrowhead look that I'd like, but the code is rather opaque and not modular in a way I can figure out how to apply to my own case.
As I said, my links are defined based on the Curved Links example:
graph.links.forEach(function(link) {
var s = nodes[link.source],
t = nodes[link.target],
i = {}, // intermediate node
property1 = link.property1;
nodes.push(i);
links.push({source: s, target: i}, {source: i, target: t});
bilinks.push([s, i, t, property1]);
});
Then, if my loose understanding of how D3 works is basically correct, the links are drawn each tick via the following code:
force.on("tick", function() {
link.attr("d", function(d) {
if (d[0] == d[2]) {
return "M" + d[0].x + "," + d[0].y
+ "A" + "20,20 -50 1,1 " + (1.001 * d[2].x) + "," + (1.001 * d[2].y)
;
} else {
return "M" + d[0].x + "," + d[0].y
+ "S" + d[1].x + "," + d[1].y
+ " " + d[2].x + "," + d[2].y;
}
});
node.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")";
});
});
So my question is how to change this code in a way that achieves the generally desired (and I think normal) visualization scheme such that the edges and/or arrowheads terminate at the border of the nodes even as they change size.
I've created a JS Fiddle that includes all the necessary bits to see and solve the problem. It also includes an adjustment for getting the arrowheads to match the links they are on, and that capability needs to be compatible with the solution to this issue.