NodeGraphQt icon indicating copy to clipboard operation
NodeGraphQt copied to clipboard

Graphviz DOT export ?

Open nyue opened this issue 3 years ago • 2 comments

Hi,

To keep the documentation and graph in sync, is there a way to generate Graphviz dot file from NodeGraphQt ?

Cheers

nyue avatar Sep 10 '20 23:09 nyue

Hi @nyue ,

Currently this is not possible.

Cheers, Johnny

jchanvfx avatar Sep 20 '20 23:09 jchanvfx

Walking all nodes in the graph can be tricky - but its not impossible.

By sub-classing all nodes in use (which I'm doing anyway in my little toy project), and adding a call_inputs function that iterates over each input for that node calling the call_inputs() method of that node, you can walk from any "output" or "sink" node, and get everything that it connects to.

The end result of this approach is that for any output Node, you to emit some string to identify the node contributing to that result. By printing before the next "call_inputs" you can traverse in the "up" (output -> input) direction, or by printing after the call you print on the way "down" the graph again (input -> ouput).

This approach also has a property that Nodes not contributing results to the output node are not displayed, as they are never iterated - automatically pruning the output to display only nodes that are of use.

Hope that helps! -Harry

PS: If you don't want to subclass every node, you can always implement the logic in the NodeGraph owned BaseClass, but I didn't want to modify the library code itself.

harryhaaren avatar Mar 07 '21 15:03 harryhaaren