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

Cannot figure out alignment order - Help Needed #243

Open
AdrianSimionov opened this issue Jul 24, 2020 · 2 comments
Open

Cannot figure out alignment order - Help Needed #243

AdrianSimionov opened this issue Jul 24, 2020 · 2 comments

Comments

@AdrianSimionov
Copy link

With the below code, I am trying to figure out the following:

  • what makes cluster 1 to be positioned lower?
  • why Edge from B to D starts on TOP and not on the right side of B?
  • why edge from D to F ends on the BOTTOM side of F instead of the left side of F?
  • why B is down and C is up?

I personally believe there is not enough documentation to explain this behaviour, and I realised looking at older bug reports that it has to do with the way edge connections are defined.

from diagrams import Cluster, Diagram
from diagrams.aws.storage import S3

graph_attr = {
    "bgcolor": "transparent",
    "dpi": "192"
}

with Diagram("Infra", show=True, graph_attr=graph_attr):
    with Cluster("1"):
        A = S3("A")
        B = S3("B")
        C = S3("C")
    with Cluster("2"):
        D = S3("D")
        E = S3("E")
        F = S3("F")
    with Cluster("3"):
        G = S3("G")
        H = S3("H")

    A >> [B, C]
    [B, C] >> D
    D >> [E, F]
    E >> G
    F >> H

image

@clayms
Copy link

clayms commented Nov 4, 2020

You need to change the "layout" engine to either "neato" or "fdp", then for each Node set the pin to "true" and set the pos (position) to the "x,y" you want.

see: https://graphviz.gitlab.io/doc/info/attrs.html#d:pos

Note: I also set "splines" to "spline" instead of the default "ortho".

from diagrams import Diagram, Edge, Node

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

with Diagram("\n\nInfra", show=False, graph_attr=graph_attr) as diag:
    node_shape = "invtrapezium"
    label_loc = "c"

    with Cluster("1"):
        A = Node("A", shape=node_shape, labelloc=label_loc, pin="true", pos="0,1")
        B = Node("B", shape=node_shape, labelloc=label_loc, pin="true", pos="2,0")
        C = Node("C", shape=node_shape, labelloc=label_loc, pin="true", pos="2,2")
    with Cluster("2"):
        D = Node("D", shape=node_shape, labelloc=label_loc, pin="true", pos="4,1")
        E = Node("E", shape=node_shape, labelloc=label_loc, pin="true", pos="6,0")
        F = Node("F", shape=node_shape, labelloc=label_loc, pin="true", pos="6,2")
    with Cluster("3"):
        G = Node("G", shape=node_shape, labelloc=label_loc, pin="true", pos="8,0")
        H = Node("H", shape=node_shape, labelloc=label_loc, pin="true", pos="8,2")

    A >> [B, C]
    [B, C] >> D
    D >> [E, F]
    E >> G
    F >> H

diag

Output:

image

@clayms
Copy link

clayms commented Nov 29, 2020

@AdrianSimionov
another simple solution is to nest the three Clusters in another Cluster.
You can set the "root" Cluster attributes independently to make invisible if you choose.

from diagrams import Diagram, Cluster
from diagrams.aws.storage import S3

graph_attr = {
    "bgcolor": "transparent",
    "dpi": "192"
}

root_clus_attr = {
    "bgcolor": "transparent",
    "pencolor":"transparent",
}

with Diagram("Infra", show=False, graph_attr=graph_attr) as diag:
    with Cluster("", graph_attr=root_clus_attr):
        with Cluster("1"):
            A = S3("A")
            B = S3("B")
            C = S3("C")
        with Cluster("2"):
            D = S3("D")
            E = S3("E")
            F = S3("F")
        with Cluster("3"):
            G = S3("G")
            H = S3("H")

    A >> [B, C]
    [B, C] >> D
    D >> [E, F]
    E >> G
    F >> H

diag

image

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