I could not come up with a way of nesting g elements after pack
ing the data, so here is a not so elegant solution:
function checkParent(d, w) {
if(!d.parent) return false;
if(d.parent == w) {
return true;
} else {
return checkParent(d.parent, w);
}
}
node.on("mouseover",function(d){
d3.select(this).classed("active",true);
d3.selectAll(".node")
.filter(function(w){ return checkParent(w, d); })
.classed("active",true);
});
node.on("mouseout",function(d){
d3.select(this).classed("active",false);
d3.selectAll(".node")
.filter(function(w){ return checkParent(w, d); })
.classed("active",false);
});