chart2 = {
const links = force_graph.links.map(d => Object.create(d));
const nodes = force_graph.nodes.map(d => Object.create(d));
const height = 800;
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).strength(1.7).id(d => d.id))
.force("charge", d3.forceManyBody().strength(-200))
.force("x", d3.forceX())
.force("y", d3.forceY());
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height])
.style("font", "12px sans-serif");
const link = svg.append("g")
.attr("fill", "none")
.attr("stroke-width", 3.5)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke", d => '#555555');
const node = svg.append("g")
.attr("stroke-linecap", "round")
.attr("stroke-linejoin", "round")
.selectAll("g")
.data(nodes)
.join("g")
.call(drag(simulation));
node.append("circle")
.attr("fill", "#333333")
.attr("stroke", "white")
.attr("stroke-width", 1.5)
.attr("r", d => 2+d.rate);
node.append("text")
.attr("y", "0.31em")
.text(d => d.id+(d.rate>0?'-'+d.rate:''))
.attr('font-size','12px')
.attr('text-anchor','middle')
.attr("fill", d=> (d.id=='AA')?'#ff0000':'#000000')
.clone(true).lower()
.attr("stroke", "white")
.attr("stroke-width", 3);
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node.attr("transform", d => `translate(${d.x},${d.y})`);
});
invalidation.then(() => simulation.stop());
return svg.node();
}