dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.83k stars 588 forks source link

how to remove the clusters after re-set the nodes? #383

Open ding-kai opened 4 years ago

ding-kai commented 4 years ago

I removed all nodes before I set new nodes, but the cluster is still there, any method to remove it? A temporary solution: container.select('g.output').selectAll('.clusters').remove();

xanterx commented 3 years ago

Removing only clusters was causing it to overlap on the nodes, so I just cleared all the elements in order as they are rendered to fix that.

.selectAll('.clusters').remove();
.selectAll('.nodes').remove();
.selectAll('.edgePaths').remove();
.selectAll('.edgeLabels').remove();
vquilon commented 1 year ago

I found a maintained fork https://github.com/tbo47/dagre-es

If you search on the source code of that fork, the create_clusters.js, has the answer of why the clusters are not being removed, is because are not merged the enter selection of D3 clusters, with the exit selection of D3. I mentioned that because the merge between the enter and exit selection is the pattern that D3 uses to know which cluster has to be removed and which clusters enter or keep in the graph.

Just take a look at this repository, build it, because has support to D3 V7 with ES6 modules, and it has support for typescript too.