mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
39.81k stars 2.55k forks source link

bug: Arrow directions reverse when there is a cycle between three or more nodes #481

Open arihantsurana opened 3 years ago

arihantsurana commented 3 years ago

Using version 0.19.1 when there are cycles within a diagram, the edge arrow direction seems to reverse.

to reproduce:

from diagrams.onprem.database import PostgreSQL
from diagrams import Diagram
with Diagram("check", show=False, direction="LR", curvestyle="curved"):
  a = PostgreSQL("A")
  b = PostgreSQL("B")
  c = PostgreSQL("C")
  d = PostgreSQL("D")
  a >> b >> c
  b >> d >> a

Output: image

the arrow from d to a is reversed.

clayms commented 3 years ago

Likely related to issue https://github.com/mingrammer/diagrams/issues/367 , as you can see in the output below when I run your code in a notebook.

image

This does not address the bug you reported, but see if the following work-around will help.

from diagrams.onprem.database import PostgreSQL
from diagrams import Diagram

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

with Diagram("check", show=False, graph_attr=graph_attr) as diag:
    a = PostgreSQL("A")
    b = PostgreSQL("B")
    c = PostgreSQL("C")
    d = PostgreSQL("D")
    a >> b >> c
    b >> d >> a

diag

image

See graphviz splines docs for more info.

clayms commented 3 years ago

I think it may be related to the headclip and tailclip Edge attributes.

from diagrams.onprem.database import PostgreSQL
from diagrams import Diagram, Edge

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

with Diagram("check", show=False, graph_attr=graph_attr) as diag:
    a = PostgreSQL("A")
    b = PostgreSQL("B")
    c = PostgreSQL("C")
    d = PostgreSQL("D")
    a >> Edge(headclip="a", tailclip="a") >> b >> Edge(headclip="b", tailclip="b") >> c
    b >> Edge(headclip="c", tailclip="c") >> d >> Edge(headclip="d", tailclip="d") >> a

diag

image

clayms commented 3 years ago

looks like an underlying issue with Graphviz:

https://github.com/mdaines/viz.js/issues/29#issuecomment-41865753

clayms commented 3 years ago

Perhaps Stephen North, Graphviz Developer (github) knows. see this post on the Graphviz forums.

arihantsurana commented 3 years ago
from diagrams.onprem.database import PostgreSQL
from diagrams import Diagram

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

with Diagram("check", show=False, graph_attr=graph_attr) as diag:
    a = PostgreSQL("A")
    b = PostgreSQL("B")
    c = PostgreSQL("C")
    d = PostgreSQL("D")
    a >> b >> c
    b >> d >> a

diag

This workaround works for me!

clayms commented 3 years ago

@arihantsurana are you being facetious, or does it actually plot correctly for you? I can't imagine that you want the double arrows. Also, one of the arrows from D to A is still reversed.

The second plot in this comment is closer to what you want, no?

arihantsurana commented 3 years ago

@arihantsurana are you being facetious, or does it actually plot correctly for you? I can't imagine that you want the double arrows. Also, one of the arrows from D to A is still reversed.

The second plot in this comment is closer to what you want, no?

Apologies. I must have incorrectly quote replied. You are correct, the second plot is what works. Updated my comment.