Skip to content
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

multiple incoming edges #198

Closed
drdv opened this issue Apr 28, 2023 · 2 comments
Closed

multiple incoming edges #198

drdv opened this issue Apr 28, 2023 · 2 comments

Comments

@drdv
Copy link

drdv commented Apr 28, 2023

Consider the following graph

import graphviz

g = graphviz.Digraph()
for node in ['A', 'B']:
    g.edge(node, 'C')

In dot I could do

digraph {
    {A, B} -> C
}

Is there a way to do something similar from python in a concise way.

@xflr6
Copy link
Owner

xflr6 commented Apr 30, 2023

This 'shorthand for multiple edges' use of subgraphs (see https://www.graphviz.org/doc/info/lang.html#subgraphs-and-clusters) is currently not supported by the graph building API.

If this is for a one-off, one could still put that in manually (https://graphviz.readthedocs.io/en/stable/manual.html#custom-dot-statements, though I would in general not recommend to go that route).

Not sure if it's worth adding because it only affects the DOT source code (not the rendered graph) and we can often just use Python for making things more DRY/concise as you demonstrate. I don't see an obvious way how to add that to the existing subgraph API (https://www.graphviz.org/doc/info/lang.html#subgraphs-and-clusters). Maybe if you have a proposal for an API then we could discuss that.

Btw, another unavailable DOT language conciseness feature that only affect the source code is chaining edges (A -> B -> C, AFAICT this is not even be documented in the DOT grammar, used e.g. in https://nbviewer.org/github/xflr6/graphviz/blob/master/examples/graphviz-notebook.ipynb).

@drdv
Copy link
Author

drdv commented May 1, 2023

I was mostly curious. Thanks for putting my question in a brother context.

@drdv drdv closed this as completed May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants