layout = {
const height = width;
const links = data.links.map((d) => Object.create(d));
const nodes = data.nodes.map((d) => Object.create(d));
let out = { nodes, links };
return new Promise((resolve) => {
const simulation = d3
.forceSimulation(nodes)
.alphaDecay(0.015)
.force("charge", d3.forceManyBody().strength(-30))
.force(
"link",
d3
.forceLink(links)
.strength(0.9)
.distance((link) => {
return link.source.bl === link.target.bl ? 3 : 1000;
})
.iterations(20)
)
.force(
"collide",
d3.forceCollide(nodes).radius(radius).iterations(10).strength(1.4)
)
.on("tick", () => {
out.nodes = nodes;
})
.on("end", () => {
resolve({ nodes, links });
});
invalidation.then(() => simulation.stop());
});
}