Attempting to visualize a directed acyclic graph using a force layout resulted in some unexpected behavior.
Despite implementing enter/exit conditions for each group element, removed nodes and links were not being removed from the DOM.
Instead, the removed nodes/links seemed to be frozen in the force layout, indicating that the enter/exit conditions were not triggering their removal.
To demonstrate this issue, I isolated the code in a jsfiddle and stack snippet where new nodes/links are added and removed after 3 seconds:
const nodes = [{
// node data objects
}];
const links = [{
// link data objects
}];
// D3 force simulation details
...
body {
background-color: #30404d;
}
svg {
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(16, 22, 26, 0.4);
background: rgba(16, 22, 26, 0.3);
color: #f5f8fa;
}
.link {
stroke: #777;
stroke-opacity: 0.3;
stroke-width: 1.5px;
}
.node circle {
fill: #ccc;
stroke: #000;
stroke-width: 1.5px;
}
.node text {
display: none;
font: 10px monospace;
fill: white;
}
.node:hover circle {
fill: #000;
}
.node:hover text {
display: inline;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"></script>