I'm assuming you're working from Jason Davies' example.
The relevant code from his script is
function click(d) {
path.transition()
.duration(duration)
.attrTween("d", arcTween(d));
// Somewhat of a hack as we rely on arcTween updating the scales.
text.style("visibility", function(e) {
return isParentOf(d, e) ? null : d3.select(this).style("visibility");
})
.transition()
.duration(duration)
.attrTween("text-anchor", function(d) {
return function() {
return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
};
})
.attrTween("transform", function(d) {
var multiline = (d.name || "").split(" ").length > 1;
return function() {
var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
rotate = angle + (multiline ? -.5 : 0);
return "rotate(" + rotate + ")translate("
+ (y(d.y) + padding) + ")rotate("
+ (angle > 90 ? -180 : 0) + ")";
};
})
.style("fill-opacity", function(e) {
return isParentOf(d, e) ? 1 : 1e-6;
})
.each("end", function(e) {
d3.select(this).style("visibility",
isParentOf(d, e) ? null : "hidden");
});
}
Notice how some of those functions reference two different data objects, d
vs e
. That's because, unless it is masked by an inner function, d
inside the click function is the data object of the clicked element -- the one that becomes the centre of the circle.
If he gives the inner function a different name for the data object (function(e){}
), then that is the data object associated with the individual element that is having attributes changed. So he is able to call functions that compare the two data objects to determine if a given element should be hidden or not at that level of zoom.
You want to do the same thing, except you're not only hiding text if it's a parent of the centre wheel, you're also hiding it if it is too deep a descendent. So you want something like:
if (e.depth > d.depth + 3) return "hidden";
Where you add that code depends on style choices -- Jason Davies is actually changing text opacity or visibility at three points: visibility is set before and after the transition (during the "end" event), with opacity faded in between. Do you want your labels to pop in and out at a click, or do you want them to fade in and out?