Here is an example of a similar case: http://bl.ocks.org/mbostock/4339083
The dataset is not large, but the treatment is similar to your approach. When the hierarchical data is first loaded, it is modified by collapsing all descendants of the root. Here only the root is left open. In your case you could choose to leave additional levels open initially. See the recursive collapse function below:
d3.json("/d/4063550/flare.json", function(error, flare) {
root = flare;
root.x0 = height / 2;
root.y0 = 0;
function collapse(d) {
if (d.children) {
d._children = d.children;
d._children.forEach(collapse);
d.children = null;
}
}
root.children.forEach(collapse);
update(root);
});
Then later, as the user drills down (here in response to a node click, in your case maybe in response to something else) each node is adjusted accordingly:
// Toggle children on click.
function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}
All this does is hide the children from whatever hierarchical layout you apply. The update function redraws the hierarchy as if those hidden levels don't exist.