-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GraphWriter API for programatically building graphs and outputting as ASCII or dot #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. Thank you sooo much for doing this!
I got interrupted and have to stop. I will just leave the comments that I have now, but I will need another round.
I think I made most of your suggested changes. It was nice to not have switch-case on |
I have only a minor comment in that I prefer the layout of the nodes in @davidmetz graphs #308 (comment) over the square table shown in the "A dataflow graph" above. I talked with David, and he says that he also use HTML table, so I guess it's not difficult to modify the layout. |
@sjalander I copied most of his table layout, was it something like this you wanted? I can also reduce the font size of argument and result nodes to match the input and output ports, since they pretty much represent freestanding ports. On another note, input and output ports are currently named with globally unique names, as a fallback if they don't have a label. It might be better to use either a blank box or the port's index within the node. |
@haved I think that looks better. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry that it took so long. I was sick the last 3 days.
Nothing major. The only reason why I block this is because of the missing unit tests.
Great work!
@haved @phate |
@sjalander Absolutely, it is very nice to be able to pan around and zoom, and it looks crisp. The dot that is emitted by this PR is quite close to the dot David has, especially if you add "tooltip" attributes. I don't quite know what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Fantastic work. Thanks a lot!
This is the API I ended up with, it uses some
friend
declarations to ensure internal consistency, so the public API should be hard to misuse.You create graphs, where you can add nodes and edges. These can all have labels and arbitrary attributes set, which will be included in the dot output. The ASCII output ignores attributes for brevity.
There are also ArgumentNode, ResultNode and InOutNode that are nice when representing data flowing into the graph, through nodes, and out of the graph. InOutNodes have an arbitrary number of input ports and output ports, which can also have labels and attributes. They can also have subgraphs.
The InOutNodes use the HTML table labels in dot. In dot, subgraphs are rendered as separate graphs, so I was planning on customizing a JavaScript library for GraphViz to make graphs inside nodes render nicely when requested.
The ArgumentNodes and ResultNodes have the option of being connected to ports in outside graphs. Otherwise, edges must go between ports within the same graph.
All GraphElements have the option of being mapped to a program object (any type of pointer), which serves two purposes: You can look up elements by program object, to aid in building the graphs, and you can refer to program objects by pointer in attributes, and have the pointer be replaced by the short unique id of the graph element.
I'm very open to suggestions for changes to the interface, internals or the output, as this should be something usable for everybody.
There is currently a helper function for setting the background color on a node/port.
I could envision a lot more helper functions, to make it easier for the end user to find useful and correct attributes, e.g.
The code takes care to escape strings in both regular dot and the HTML sub-language.
I will of course add tests to all the functionality that it makes sense to test.
Under follows some examples of API usage, and the corresponding output in ASCII and rendered GraphViz:
A regular graph
becomes
and
A dataflow graph
becomes
and
A graph with a subgraph
becomes
and
This PR is part of #308