svg = {
const svg = d3.select(DOM.svg(width, height));
const nodePadding = 2.5;
const graph = d3
.csvParse(myData, types)
.map((d) => ({ ...d, t: 0 }))
.sort((a, b) => b.size - a.size);
let hovered;
const collide = d3
.forceCollide()
.strength(0.5)
.radius((d) => d.radius + nodePadding)
.iterations(1);
simulation
.nodes(graph)
.force("collide", collide)
.on("tick", () => {
node
.attr("r", (d) => {
d.t = d === hovered ? 1 - (1 - d.t) * 0.9 : d.t * 0.9;
d.r = (1 - d.t) * d.radius + d.t * Math.max(d.radius * 1.2, 50);
return d.r;
})
.attr("cx", (d) => d.x)
.attr("cy", (d) => d.y);
collide.radius((d) => d.r + nodePadding);
})
.alpha(1)
.restart();
const node = svg
.append("g")
.attr("class", "node")
.selectAll("circle")
.data(graph)
.join("circle")
.attr("fill", (d) => color(d.continent));
node
.on("pointerenter", (event, d) => {
hovered = d;
simulation.tick();
})
.on("pointerout", (event, d) => {
hovered = null;
simulation.tick();
});
node.call(
d3.drag().on("start", dragstarted).on("drag", dragged).on("end", dragended)
);
return svg.node();
}