트릭은 자체 링크를 호가있는 경로로 그립니다. 물건을 작동 시키려면 arc parameter syntax을 조금 놀 랐고, 열쇠는 호가 같은 지점에서 시작하고 끝날 수없는 것처럼 보였습니다. 다음은 각 업데이트에서 가장자리를 그리는 관련 코드입니다.
function tick() {
link.attr("d", function(d) {
var x1 = d.source.x,
y1 = d.source.y,
x2 = d.target.x,
y2 = d.target.y,
dx = x2 - x1,
dy = y2 - y1,
dr = Math.sqrt(dx * dx + dy * dy),
// Defaults for normal edge.
drx = dr,
dry = dr,
xRotation = 0, // degrees
largeArc = 0, // 1 or 0
sweep = 1; // 1 or 0
// Self edge.
if (x1 === x2 && y1 === y2) {
// Fiddle with this angle to get loop oriented.
xRotation = -45;
// Needs to be 1.
largeArc = 1;
// Change sweep to change orientation of loop.
//sweep = 0;
// Make drx and dry different to get an ellipse
// instead of a circle.
drx = 30;
dry = 20;
// For whatever reason the arc collapses to a point if the beginning
// and ending points of the arc are the same, so kludge it.
x2 = x2 + 1;
y2 = y2 + 1;
}
return "M" + x1 + "," + y1 + "A" + drx + "," + dry + " " + xRotation + "," + largeArc + "," + sweep + " " + x2 + "," + y2;
});
그리고 여기이 모든 일을 보여 a jsfiddle 및 스크린 샷입니다 :
당신은 자체 참조 노드에 대한 적절한 경로 (이하 "D"속성)을 정의해야합니다 중간 점과 적절한 보간법이있는 것입니다. –