Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Add maxLevels prop for the number of levels to display #3

Open

Description

@alexcjohnson

If you have data with highly nested nodes, it might be preferable to only show a few levels at a time, diving deeper as you select inner nodes.

If the data were TOO big (so performance would lag if you send it all to the front end) you need to do something like usage_backend_update_via_selections to fetch the appropriate data whenever the selection changes. But for intermediate-size data, we should be able to simply restrict the number of visible levels by adding a prop called something like maxLevels.

The key to this will be altering the radial range, which is set by selectedY

d3.layout.partition (note we're using v3 here) sets node.y and node.dy for all nodes such that the root node has y=0 and the deepest level of nesting has y+dy=1, while dy is 1/(total number of levels)

So the main thing we need is to change selectedY from:

node => [node.y, 1]

to something like:

node => [node.y,  maxLevels ? Math.min(1, node.y + maxLevels * node.dy)] : 1]

ie if maxLevels is 0 or missing, keep the current behavior, otherwise restrict the end of the radial range to no more than the requested number.

Then maxLevels needs to be propagated up from the d3 component to the react wrapper component (the d3 component receives props from the react component as figure here)

It's possible that other things will be needed, like explicitly removing text and/or path elements that are collapsed against the outside edge... we'll have to see how it looks and performs to determine if this is needed.

Activity

  1. added
    enhancement
    on Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions