chart = {
const nodes = Array.from({length: 200}, () => ({}));
const simulation = d3.forceSimulation(nodes)
.force("charge", d3.forceManyBody().strength(-10))
.force("x", d3.forceX().strength(0.05))
.force("y", d3.forceY().strength(0.05))
.alphaDecay(0)
.on("tick", ticked);
invalidation.then(() => simulation.stop());
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", `${-width / 2} ${-height / 2} ${width} ${height}`);
const bg = svg.append("rect")
.attr("x", "-477")
.attr("y", "-400")
.attr("width", "100%")
.attr("height", "100%")
.attr("fill", "#F5F7FA");
const target1 = svg.append("line")
.attr("stroke", "#F5F7FA")
.attr("y1", -height / 2)
.attr("y2", +height / 2);
const target2 = svg.append("line")
.attr("stroke", "#F5F7FA")
.attr("y1", -height / 2)
.attr("y2", +height / 2);
const node = svg.append("g")
.selectAll("circle")
.data(nodes)
.join("rect")
.attr("fill", "#fff")
.attr("stroke", "#899BB0")
.attr("width", 8)
.attr("height", 13)
.attr("rx", 2)
function ticked() {
node.attr("x", d => d.x).attr("y", d => d.y);
}
yield svg.node();
await Promises.delay(1000);
while (true) {
const x1 = (Math.random() - 0.5) * width / 2;
const x2 = (Math.random() - 0.5) * width / 2;
target1.attr("x1", x1).attr("x2", x1);
target2.attr("x1", x2).attr("x2", x2);
simulation.force("x").x((d, i) => i & 1 ? x1 : x2);
simulation.alpha(1).restart();
yield svg.node();
await Promises.delay(2500);
}
}