ribbon = {return function (data,stretch=0){
var π = Math.PI,
halfπ = π / 2;
data.source.startAngle -= halfπ
data.target.startAngle -= halfπ
data.source.endAngle -= halfπ
data.target.endAngle -= halfπ
data.source.midpoints = [[ data.source.radius * Math.cos(data.source.startAngle), data.source.radius * Math.sin(data.source.startAngle)],[ data.source.radius * Math.cos(data.source.endAngle), data.source.radius * Math.sin(data.source.endAngle)]]
data.target.midpoints = [[ data.target.radius * Math.cos(data.target.startAngle), data.target.radius * Math.sin(data.target.startAngle)],[ data.target.radius * Math.cos(data.target.endAngle), data.target.radius * Math.sin(data.target.endAngle)]]
function arc(entry){
var a = entry.startAngle - entry.endAngle;
var sign = (entry.midpoints[1][0] >= 0 ? 1 : -1);
return " A" + entry.radius + "," + entry.radius + " 0 " + +(a > π) + ",1 " + (entry.midpoints[1][0] + sign*stretch) + "," + entry.midpoints[1][1];
}
function line (entry){
var a = entry.startAngle - entry.endAngle;
var sign = (entry.midpoints[1][0] >= 0 ? 1 : -1);
return " A" + 99999 + "," + 99999 + " 0 " + +(a > π) + ",1 " + (entry.midpoints[1][0] + sign*stretch) + "," + entry.midpoints[1][1];
}
function inverse(entry){
var a = entry.startAngle - entry.endAngle;
var sign = (entry.midpoints[1][0] >= 0 ? 1 : -1);
return " A" + entry.radius + "," + entry.radius + " 0 " + +(a > π) + ",0 " + (entry.midpoints[1][0] + sign*stretch) + "," + entry.midpoints[1][1];
}
function curve(entry) {
var sign = (entry.midpoints[0][0] >= 0 ? 1 : -1);
return " Q 0,0 " + (entry.midpoints[0][0] + sign*stretch) + "," + entry.midpoints[0][1];
}
var myarc={'arc':arc, 'line':line, 'inverse':inverse}
data.source.style = myarc[data.source.style] || arc
data.target.style = myarc[data.target.style] || arc
var path = "M" + (data.source.midpoints[0][0] + stretch) + "," + data.source.midpoints[0][1] +
data.source.style(data.source) +
curve(data.target) +
data.target.style(data.target) +
curve(data.source) +
" Z";
console.log(path,data)
return path
}}