reaflow icon indicating copy to clipboard operation
reaflow copied to clipboard

collapse/expand nested nodes?

Open yifanwu opened this issue 3 years ago • 3 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Current behavior

Currently one could specify nested nodes, but there is not way to "collapse" the nested nodes into a smaller summary node

Screen Shot 2021-04-27 at 12 59 50 PM

Expected behavior

Add an API that allows a nested set of nodes to be collapsed/expanded---so here the 2>2.1 and 2>2.2 nodes will be gone, replaced by some "summary node" (whose color/edge style is a little different to indicate interactivity, which we can configure through the component props/css definition).

I think this can be "hacked" together right now by modifying the node specification---update the state and omit/add the nested nodes, but might make the layout funky? Let me know if you think this is actually a proper way to use the library.

What is the motivation / use case for changing the behavior?

I think this is a pretty important feature for visualization---"summary first, detail on demand". At least true for our project!

yifanwu avatar Apr 27 '21 20:04 yifanwu

Yes, I think this would be a great feature. It could be implemented today but just redacting certain nodes from your model and some custom button on a node though I would like to make it easier to do.

The reason I haven't done it yet is because it gets a little tricky in branching scenarios - take the following ( my app ):

image

If you collapse Approve by Email, would the Send Email also be hidden since it would have uncollapse parent?

If you want to take a stab at it, I would recommend looking at this library - it can help you determine children/parents easily to figure out what nodes to remove: https://www.npmjs.com/package/dependency-graph

amcdnl avatar Apr 28 '21 11:04 amcdnl

Interesting! I was more thinking about supporting collapse just for the already nested nodes, like the screenshot I have above. That way the collapsing logic is clear---just shrinking the box of the nested group, that way it's purely visual than semantic.

yifanwu avatar Apr 28 '21 17:04 yifanwu

Ah I see - ya I was thinking of it in a different way.

The approach of trimming the graph would still work ( and be easier ).

I'll try to add an example of that for you but I'm interested in solving this other more generic collapsing too.

amcdnl avatar Apr 28 '21 17:04 amcdnl