svg = {
const svg = d3.select(DOM.svg(width, height))
const g = svg.append("g");
const node = g.append("g")
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", d => 10)
.style("fill", d => color(d.cluster))
const simulation = d3.forceSimulation()
.force("forceInABox",
forceInABox()
.strength(0.1)
.template("force")
.groupBy("cluster")
.links([])
.forceNodeSize(d => d.r + 3)
.size([width, height])
)
.force("collide", d3.forceCollide().radius(d => d.r + 1) .strength(0.8))
simulation
.nodes(nodes)
.on("tick", ticked)
for(let i = 0; i < 300; i ++) {
simulation.tick()
}
function ticked() {
node
.attr("cx", d => d.x)
.attr("cy", d => d.y)
}
return svg.node()
}