function link() { // Exposed variables var _ = { source : function(d) { return d.source; }, target : function(d) { return d.target; }, angle : function(d) { return d.angle; }, startRadius : function(d) { return d.radius; }, endRadius : function(d) { return d.radius; }, arcOffset : -Math.PI / 2 }; d3.expose.call(link,_) function link(d, i) { var s = node(_.source, this, d, i), t = node(_.target, this, d, i), x; if (t.a < s.a) x = t, t = s, s = x; if (t.a - s.a > Math.PI) s.a += 2 * Math.PI; var a1 = s.a + (t.a - s.a) / 3, a2 = t.a - (t.a - s.a) / 3; return s.r0 - s.r1 || t.r0 - t.r1 ? "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 + "L" + Math.cos(s.a) * s.r1 + "," + Math.sin(s.a) * s.r1 + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1 + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1 + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1 + "L" + Math.cos(t.a) * t.r0 + "," + Math.sin(t.a) * t.r0 + "C" + Math.cos(a2) * t.r0 + "," + Math.sin(a2) * t.r0 + " " + Math.cos(a1) * s.r0 + "," + Math.sin(a1) * s.r0 + " " + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 : "M" + Math.cos(s.a) * s.r0 + "," + Math.sin(s.a) * s.r0 + "C" + Math.cos(a1) * s.r1 + "," + Math.sin(a1) * s.r1 + " " + Math.cos(a2) * t.r1 + "," + Math.sin(a2) * t.r1 + " " + Math.cos(t.a) * t.r1 + "," + Math.sin(t.a) * t.r1; } function node(method, thiz, d, i) { var node = method.call(thiz, d, i), a = +(typeof _.angle === "function" ? _.angle.call(thiz, node, i) : _.angle) + _.arcOffset, r0 = +(typeof _.startRadius === "function" ? _.startRadius.call(thiz, node, i) : _.startRadius), r1 = (_.startRadius === _.endRadius ? r0 : +(typeof _.endRadius === "function" ? _.endRadius.call(thiz, node, i) : _.endRadius)); return {r0: r0, r1: r1, a: a}; } return link; }; // Standard getter/setter d3.expose = function(_) { var self = this Object.keys(_).forEach(function(key) { self[key] = function(x) { if (!arguments.length) return _[key]; _[key] = x; return self; } }); }