Fix [simulation] update graph

This commit is contained in:
niclas 2024-02-06 13:56:08 +01:00
parent 5899d5d5c8
commit a921d1b192

View file

@ -158,14 +158,37 @@ document$.subscribe(function () {
node = node.data(nodes, d => d.id) node = node.data(nodes, d => d.id)
.join( .join(
enter => enter.append("circle") enter => enter.append("circle")
.attr("r", NODE_RADIUS) .attr("r", function (d, i) {
.attr("fill", NODE_COLOR), return i === 0 ? NODE_RADIUS + 5 : NODE_RADIUS;
})
.attr("fill", function (d, i) {
return i === 0 ? Parent_Node_COLOR : NODE_COLOR;
}),
update => update, update => update,
exit => exit.remove() exit => exit.remove()
); );
node.call(drag); node.call(drag);
// Apply tooltip on nodes
node.on("mouseover", function (event, d) {
tooltip.transition()
.duration(200)
.style("opacity", .9);
tooltip.html(d.id)
.style("left", (event.pageX) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mousemove", function (event) {
tooltip.style("left", (event.pageX) + "px")
.style("top", (event.pageY - 28) + "px");
})
.on("mouseout", function (d) {
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
// Process new links // Process new links
const oldLinksMap = new Map(link.data().map(d => [`${d.source.id},${d.target.id}`, d])); const oldLinksMap = new Map(link.data().map(d => [`${d.source.id},${d.target.id}`, d]));
links = newLinks.map(d => Object.assign(oldLinksMap.get(`${d.source.id},${d.target.id}`) || {}, d)); links = newLinks.map(d => Object.assign(oldLinksMap.get(`${d.source.id},${d.target.id}`) || {}, d));