image = {
const color = d3.scaleOrdinal(d3.schemeCategory10);
const nodes = data.map((d) => ({ ...d }));
const simulation = d3
.forceSimulation(nodes)
.force(
"collide",
d3
.forceCollide()
.radius((d) => d.r)
.iterations(3)
)
.force("x", d3.forceX().strength(0.02))
.force("y", d3.forceY().strength(0.02));
const svg = d3
.create("svg")
.attr("width", w)
.attr("height", h)
.attr("viewBox", [-w / 2, -h / 2, w, h])
.attr("style", "max-width: 100%; height: auto;");
const node = svg
.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("image")
.data(nodes)
.join("image")
.attr("href", (d) => d.url)
.attr("width", (d) => d.r)
.attr("preserveAspectRatio", "xMidYMid meet")
.attr("transform", (d) => `rotate(${d.angle})`);
simulation.on("tick", () => {
node
.attr("x", (d) => d.x)
.attr("y", (d) => d.y)
.attr("transform", (d) => `rotate(${d.angle}, ${d.x}, ${d.y})`);
});
invalidation.then(() => simulation.stop());
return svg.node();
}