chart = {
const width = 960;
const height = 600;
const path = d3.geoPath();
const radius = d3.scaleSqrt().domain([0, 1e6]).range([0, 15]);
var nodes = [
{name: "A"},
{name: "B"},
{name: "C"},
{name: "D"},
{name: "E"},
{name: "F"},
{name: "G"}
];
var links = [
{ source: "A", target: "B" },
{ source: "B", target: "C" },
{ source: "C", target: "D" },
{ source: "D", target: "E" },
{ source: "E", target: "F" },
{ source: "F", target: "G" }
];
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.name))
.force("charge", d3.forceManyBody())
.force("center", d3.forceCenter(width / 2, height / 2));
const svg = d3.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto");
svg.append("path")
.datum(topojson.feature(us, us.objects.nation))
.attr("fill", "#ccc")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
const link = svg.append("g")
.attr("stroke", "darkgrey")
.attr("stroke-opacity", 1)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke-width", d => Math.sqrt(d.value));
const palette = d3.interpolateRdYlBu
const color = d3.scaleLinear().range([0,1]).domain([-1,nodes.length-1])
const node = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", 8)
.attr("fill", (d,i) => palette(color(i)))
.call(drag(simulation));
node.append("title")
.text(d => d.name);
const text = svg.append("g")
.selectAll("text")
.data(nodes)
.join("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
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("cx", d => d.x)
.attr("cy", d => d.y);
text
.attr("x", d => d.x)
.attr("y", d => d.y);
});
invalidation.then(() => simulation.stop());
return svg.node();
}