Skip to content

Commit

Permalink
Merge pull request #1 from chanwutk/ck/fix-removed-cluster
Browse files Browse the repository at this point in the history
fix: error after removing a cluster node from graph and re-render
  • Loading branch information
tbo47 authored Apr 9, 2022
2 parents 5176818 + 1fcc856 commit ae81baf
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions src/dagre-js/create-clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,35 @@ function createClusters(selection, g) {
var svgClusters = selection.selectAll("g.cluster")
.data(clusters, function (v) { return v; });

svgClusters.selectAll("*").remove();
svgClusters.enter().append("g")
util.applyTransition(svgClusters.exit(), g)
.style("opacity", 0)
.remove();

var enterSelection = svgClusters.enter().append('g')
.attr("class", "cluster")
.attr("id", function (v) {
var node = g.node(v);
return node.id;
})
.style("opacity", 0);
.style("opacity", 0)
.each(function(v) {
var node = g.node(v);
var thisGroup = d3.select(this);
d3.select(this).append("rect");
var labelGroup = thisGroup.append("g").attr("class", "label");
addLabel(labelGroup, node, node.clusterLabelPos);
});

svgClusters = selection.selectAll("g.cluster");
svgClusters = svgClusters.merge(enterSelection);

util.applyTransition(svgClusters, g)
svgClusters = util.applyTransition(svgClusters, g)
.style("opacity", 1);

svgClusters.each(function (v) {
var node = g.node(v);
var thisGroup = d3.select(this);
d3.select(this).append("rect");
var labelGroup = thisGroup.append("g").attr("class", "label");
addLabel(labelGroup, node, node.clusterLabelPos);
});

svgClusters.selectAll("rect").each(function (c) {
var node = g.node(c);
var domCluster = d3.select(this);
util.applyStyle(domCluster, node.style);
});

var exitSelection;

if (svgClusters.exit) {
exitSelection = svgClusters.exit();
} else {
exitSelection = svgClusters.selectAll(null); // empty selection
}

util.applyTransition(exitSelection, g)
.style("opacity", 0)
.remove();

return svgClusters;
}
}

0 comments on commit ae81baf

Please sign in to comment.