// In the input data, links are provided between nodes -id-, not between node names.
// So one has to link ids and names
// Note Nuño: This is inefficient, and we could have built the data object to avoid this. However, every time I try to refactor this, the thing breaks.
varnodesById={};
data.nodes.forEach(function(n){
nodesById[n.id]=n;
});
// Cool, now if I do nodesById["2"].name I've got the name of the node with id 2
// Add the links
svg
.selectAll('mylinks')
.data(data.links)
.enter()
.append('path')
.attr('d',function(d){
letstart=x(nodesById[d.source].name)
// X position of start node on the X axis
letend=x(nodesById[d.target].name)
// X position of end node
return['M',
start,
height-30,
// the arc starts at the coordinate x=start, y=height-30 (where the starting node is)
'A',
// This means we're gonna build an elliptical arc
(start-end)/2,',',
// Next 2 lines are the coordinates of the inflexion point. Height of this point is proportional with start - end distance
(start-end)/2,0,0,',',
start<end?1:0,end,',',height-30]
// We always want the arc on top. So if end is before start, putting 0 here turn the arc upside down.