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

Allow nodes to have edges that reference themselves #432

Closed
ashleyconnor opened this issue Jan 7, 2021 · 2 comments
Closed

Allow nodes to have edges that reference themselves #432

ashleyconnor opened this issue Jan 7, 2021 · 2 comments

Comments

@ashleyconnor
Copy link

ashleyconnor commented Jan 7, 2021

I'm looking at using diagrams to produce network diagrams for AWS Security Groups and one of the requirements is that a Security Group can reference itself to allow inbound and outbound traffic on a certain port.

I'm looking a producing a node that can have edges that look something like this.

@clayms
Copy link

clayms commented Jan 7, 2021

You just need to change the graph_attr dictionary key "splines" to the value "spline" (default in this library is "ortho").

Then specify the headport and tailport of the self-referring Edges.

from diagrams import Diagram, Node, Edge

graph_attr = {
    "splines": "spline",
}

with Diagram('',show=False, graph_attr=graph_attr) as diag:
    idle = Node('Idle', shape="doublecircle", labelloc="c",)
    working = Node('Working', shape="circle", labelloc="c",)

    idle >> Edge(label="boot",) >> working

    working >> Edge(label="sendtx[i]", tailport="n", headport="n") >> working
    working >> Edge(label="qry", tailport="e", headport="e") >> working
    working >> Edge(label="response[j]", tailport="s", headport="s") >> working

diag

image

Ref:
https://graphviz.gitlab.io/doc/info/attrs.html#d:headport
https://graphviz.gitlab.io/doc/info/attrs.html#d:tailport
https://graphviz.gitlab.io/doc/info/attrs.html#k:portPos

@ashleyconnor
Copy link
Author

ashleyconnor commented Jan 11, 2021

This worked!

Thank you for the quick answer and contributing to such an awesome project.

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