linkElements.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return getTargetNodeCircumferencePoint(d)[0]; }) .attr("y2", function(d) { return getTargetNodeCircumferencePoint(d)[1]; });function getTargetNodeCircumferencePoint(d){ var t_radius = d.target.nodeWidth/2; // nodeWidth is just a custom attribute I calculate during the creation of the nodes depending on the node width var dx = d.target.x - d.source.x; var dy = d.target.y - d.source.y; var gamma = Math.atan2(dy,dx); // Math.atan2 returns the angle in the correct quadrant as opposed to Math.atan var tx = d.target.x - (Math.cos(gamma) * t_radius); var ty = d.target.y - (Math.sin(gamma) * t_radius); return [tx,ty]; }
聯(lián)系客服