function build_net(data) {
const links = data.links.map(d => Object.create(d));
const nodes = data.nodes.map(d => Object.create(d));
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.name).distance(150))
.force("charge", d3.forceManyBody().strength(-200))
.force('center', d3.forceCenter(width/2, height/2).strength(0.5))
.force('collision', d3.forceCollide(25));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font", "14px sans-serif");
svg.append("defs").selectAll("marker")
.data(links)
.join("marker")
.attr("id", d => `arrow-${d}`)
.attr("viewBox", "0 -5 10 10")
.attr("refX", 7)
.attr("refY", 0)
.attr("markerWidth", 4)
.attr("markerHeight", 4)
.attr("orient", "auto")
.append("path")
.attr("fill", "black")
.attr("d", "M0,-5L10,0L0,5");
const link = svg.append("g")
.attr("fill", "none")
.selectAll("path")
.data(links)
.join("path")
.attr("stroke", d => "black")
.attr("stroke-width", function(d) { return d.count; })
.attr("stroke-opacity", 0.75)
.attr("marker-end", d => `url(${new URL(`#arrow-${d}`, location)})`);
const node = svg.append("g")
.attr("stroke-linecap", "round")
.selectAll("g")
.data(nodes)
.join("g")
.attr("fill", function(d) { return d.color; })
.call(drag(simulation));
node.append("circle")
.attr("stroke", "white")
.attr("stroke-width", 1.5)
.attr("r", function(d) {
d.radius = Math.sqrt(d.count)*5+10;
return d.radius;});
node.append("text")
.attr("x", 0)
.attr("y", "0.31em")
.attr("text-anchor","middle")
.style('fill', 'black')
.text(d => d.name)
.clone(true).lower()
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-width", 3);
simulation.on("tick", () => {
link.attr("d", linkArc);
node.attr("transform", d => `translate(${d.x},${d.y})`);
node.attr("cx", function(d) { return d.x = Math.max((d.radius + 15), Math.min((width - d.radius -15), d.x)); })
.attr("cy", function(d) { return d.y = Math.max((d.radius + 15), Math.min((height - d.radius -15), d.y)); });
});
invalidation.then(() => simulation.stop());
return svg.node();
}