network = {
nodes.forEach(d => {
d.lat = locations[d.id].lat;
d.lon = locations[d.id].lon;
});
let nodeDots = mapViz.select("#nodes").selectAll(".node").data(nodes).join("circle")
.attr("r",5)
.attr("cx", d=>projection([d.lon,d.lat])[0])
.attr("cy", d=>projection([d.lon,d.lat])[1])
.classed("node",true);
let linkLines = mapViz.select("#nodes").selectAll(".link").data(links).join("path")
.classed("link",true)
.attr("d", d=> {
let sourceNode = nodes.find(n => n.id == d.source);
let targetNode = nodes.find(n => n.id == d.target);
let sourceLoc = projection([sourceNode.lon,sourceNode.lat]);
let targetLoc = projection([targetNode.lon,targetNode.lat]);
let sourceXY = sourceLoc[0] + " " + sourceLoc[1];
let targetXY = targetLoc[0] + " " + targetLoc[1];
let arcMultiplier = 1.5;
var dx = sourceLoc[1] - sourceLoc[0],
dy = targetLoc[1] - targetLoc[0],
dr = Math.sqrt(dx * dx + dy * dy) * arcMultiplier;
let pathString = "M" + sourceLoc[0] + "," + sourceLoc[1] + "A" + dr + "," + dr + " 0 0,1 " + targetLoc[0] + "," + targetLoc[1];
return pathString;
})
.attr("marker-end", "url(#arrow)")
.style("stroke-width", d => Math.random()*3 + "px")
.style("stroke", "#aa5")
return [nodeDots,linkLines];
}