I would add a class to the groups of circles so they can be selected.
.join("circle")
//.style("opacity", d => {if (highlightNodes.includes(d.id)) {return 1} else {return 0.4}})
.attr("r", d => getNodeSize(d))
.attr(''class',d => `circle${getColor(d)}`) // give unique class that can be selected
In the mouseOverFunction a select can be crafted.
const mouseOverFunction = d => {
if (ifClicked) return;
// selectAll goes here. d.target.classList[0] or d.path[0].classList.value
node
.transition(500)
.style('opacity', o => {