Ax9D / pw-viz

Pipewire graph editor written in Rust. WIP⚠️
GNU General Public License v3.0
230 stars 14 forks source link

Auto-layout #7

Open jansol opened 2 years ago

jansol commented 2 years ago

Did you have any plans regarding the layout algorithm yet? If so, feel free to just close this.

Overall I quite like the auto-layout and grouping features in patchage, although I wish it would also re-center the viewport when re-generating the layout. This is a feature I would love to see in pw-viz as well, or maybe even re-layout on the fly as nodes appear and disappear from the graph? Live re-layout should probably not touch the viewport and needs an option to toggle it on and off.

image

As for the algorithm itself a good start would probably be a basic mass-spring system where the nodes 1) have a "gravity" towards left/right based on their ports' directions to determine the rough initial position and 2) push each other away to avoid overlap. Links would act as springs pulling the connected nodes together. For things like effect chains I suppose it's a matter of complexity and preference whether a left-to-right or top-down flow would be preferrable. There is probably a decent heuristic to detect effect nodes (such as 'has "input" and "output" ports but no others' connected) and flip the direction in which the springs are pulling

To reduce clutter it would be handy to be able to collapse nodes into only the title and the layout algorithm could potentially collapse by default nodes that don't currently have any links. This would probably require keeping track of nodes that the user manually expands. Collapsed nodes should also probably have some indicator for what kind of ports they have, not sure what the best way to handle that would be.

Ax9D commented 2 years ago

Some sort of an auto layout system would be nice, although I wouldn't want pw-viz to have live relayouting like Patchage or Carla, atleast not by default.

I don't like the jitter and nodes shifting randomly as demonstrated here: patchage_jitter.

Also, I think respecting the user's placement of nodes, and laying out newly added nodes around them is a better idea, as it reduces visual noise.

Alternatively, having an "arrange" button which cleanly lays out nodes overriding the current layout seems like a good option to me. As for the implementation, I'll need to do some research into the algorithm you mentioned, I don't know much about mass spring simulations :(

I want to support collapsing of nodes, Collapsed nodes could be displayed like how Blender does it: image

jansol commented 2 years ago

Agreed, the jitter while dragging a node is distracting. I would still appreciate the graph fixing itself when nodes appear or disappear, but it certainly doesn't need to do that while a node is being dragged around. Adjusting the graph once the user lets go of a dragged node should be enough. "Stickying" manually dragged nodes to the user-defined position until a full recomputation is requested makes a lot of sense.