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

Edge labels not placed with line #433

Open
jonnyhoff opened this issue Jan 8, 2021 · 7 comments
Open

Edge labels not placed with line #433

jonnyhoff opened this issue Jan 8, 2021 · 7 comments

Comments

@jonnyhoff
Copy link

Green line labels not displaying correctly.

with Diagram("Diagram", outformat="svg") as diag:
    with Cluster("cluster01"):
        s1prox1 = ociVM("Proxy01")
        s1prox2 = ociVM("Proxy02")
        proxygrp = [ s1prox1, s1prox2 ]

    with Cluster("cluster02"):
        s1 = ociVM("s1")

    with Cluster("cluster02"):
        nfs1 = FileStorage("/nfs1")
        nfs2 = FileStorage("/nfs2")
        nfs3 = FileStorage("/nfs3")
        mounts = [nfs1,nfs2,nfs3]

    # s1 - s1prox1
    s1 - Edge(color="blue", style="bold") - proxygrp
    s1prox1 - Edge(color="blue", style="bold") - s1prox2
    s1 >> Edge(label="collect", color="green") >> mounts
    s1prox1 >> Edge(label="collect", color="green") >> mounts
    s1prox2 >> Edge(label="collect", color="green") >> mounts

diag

image

@clayms
Copy link

clayms commented Jan 8, 2021

Try using the xlabel Edge parameter instead of label.

Ref:
https://graphviz.gitlab.io/doc/info/attrs.html#d:xlabel

For more Edge label placement options see:
#427 (comment)

from diagrams import Diagram, Edge, Cluster
from diagrams.oci.compute import VM as ociVM
from diagrams.oci.storage import FileStorage

with Diagram("Diagram", outformat="svg", graph_attr=graph_attr, show=False) as diag:
    with Cluster("cluster01"):
        s1prox1 = ociVM("Proxy01")
        s1prox2 = ociVM("Proxy02")
        proxygrp = [ s1prox1, s1prox2 ]

    with Cluster("cluster02"):
        s1 = ociVM("s1")

    with Cluster("cluster03"):
        nfs1 = FileStorage("/nfs1")
        nfs2 = FileStorage("/nfs2")
        nfs3 = FileStorage("/nfs3")
        mounts = [nfs1,nfs2,nfs3]

    # s1 - s1prox1
    s1 - Edge(color="blue", style="bold") - proxygrp
    s1prox1 - Edge(color="blue", style="bold") - s1prox2
    s1 >> Edge(xlabel="collect", color="green") >> mounts
    s1prox1 >> Edge(xlabel="collect", color="green", minlen="1") >> mounts
    s1prox2 >> Edge(xlabel="collect", color="green", minlen="2") >> mounts

diag

image

@clayms
Copy link

clayms commented Jan 8, 2021

For a slightly cleaner look, try the following:

from diagrams import Diagram, Node, Edge, Cluster
from diagrams.oci.compute import VM as ociVM
from diagrams.oci.storage import FileStorage

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

with Diagram("Diagram", outformat="svg", graph_attr=graph_attr, show=False) as diag:
    blank1 = Node("", shape="plaintext", height="0.0", width="0.0")
    blank2 = Node("", shape="plaintext", height="0.0", width="0.0")

    with Cluster("cluster02"):
        s1 = ociVM("s1")

    with Cluster("cluster01"):
        s1prox1 = ociVM("Proxy01")
        s1prox2 = ociVM("Proxy02")
        proxygrp = [ s1prox1, s1prox2 ]


    with Cluster("cluster03"):
        nfs1 = FileStorage("/nfs1")
        nfs2 = FileStorage("/nfs2")
        nfs3 = FileStorage("/nfs3")
        mounts = [nfs1,nfs2,nfs3]

    (s1 - 
        Edge(color="blue", style="bold", tailport="se", headport="nw", minlen="1") - 
        proxygrp)
    (s1prox1 - 
        Edge(color="blue", style="bold", tailport="e", headport="w", minlen="1") - 
        s1prox2)
    (s1 - 
        Edge(color="green", tailport="e", headport="w", minlen="1") -
        blank1)
    (proxygrp -
        Edge(color="green", tailport="se", headport="w", minlen="2") -
        blank1)
    (blank1 -
        Edge(xlabel="collect", color="green", tailport="e", headport="w", minlen="1") -
        blank2 >> 
        Edge(color="green", tailport="e", headport="w", minlen="1") >> 
        mounts)

diag

image

@jonnyhoff
Copy link
Author

Thank you @clayms ! Legend! Works like a charm.

@gabriel-tessier
Copy link
Collaborator

@clayms
Good examples why not adding them in the edge page?
https://diagrams.mingrammer.com/docs/guides/edge

@clayms
Copy link

clayms commented Jan 11, 2021

@gabriel-tessier
The diagram in #358 (comment) would be a better one to be added to the Edge examples page. It has most of the features above, and it is the same as the example already on the Edge examples page.

I can add it and do a pull request when I get time.

@clayms
Copy link

clayms commented Jan 11, 2021

@gabriel-tessier
Also should include examples that demonstrate features shown in the issue comments linked to below:

#432 (comment)
#427 (comment)
#352 (comment)
#390 (comment)
#389 (comment)
#367 (comment)
#367 (comment)
#367 (comment)
#17 (comment) (although PR #407 may yield another option to do that. When that feature is made available, it should also be added)

@gabriel-tessier
Copy link
Collaborator

@clayms
I pushed a PR #495 if you have time to review.

Thanks a lot for your contributions.

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

3 participants