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

set the position of a cluster / node #249

Open
xu4wang opened this issue Aug 12, 2020 · 8 comments
Open

set the position of a cluster / node #249

xu4wang opened this issue Aug 12, 2020 · 8 comments
Labels
kind/feature New feature or request question Further information is requested status/need-to-review Need to review

Comments

@xu4wang
Copy link

xu4wang commented Aug 12, 2020

I have one diagram as below:

from diagrams import Cluster, Diagram, Edge
from diagrams.onprem.analytics import Spark
from diagrams.onprem.compute import Server
from diagrams.onprem.container import Docker
from diagrams.onprem.database import PostgreSQL
from diagrams.onprem.inmemory import Redis
from diagrams.onprem.logging import Fluentd
from diagrams.onprem.monitoring import Grafana, Prometheus
from diagrams.onprem.network import Nginx

from urllib.request import urlretrieve
from diagrams.aws.database import Aurora
from diagrams.custom import Custom
from diagrams.k8s.compute import Pod
from diagrams.azure.compute import CloudServices


# Download an image to be used into a Custom Node class
zmq_url = "https://zeromq.org/images/logo.gif"
zmq_icon = "zmq.gif"
urlretrieve(zmq_url, zmq_icon)

with Diagram(name=" Architecture", show=False):
    nginx = Nginx("LoadBalancer")

    metrics = Prometheus("metric")
    metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")

    with Cluster("Service Cluster"):
        with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            odoo1 -  Edge(color="brown") - db1
        with Cluster("Multitenancy #2"):
            odoo2 = Docker("Application #2")
            db2   = PostgreSQL("db #2")
            odoo2 -  Edge(color="brown") - db2
        with Cluster("Dedicated #3"):
            odoo3 = Docker("Application #3")
            db3   = PostgreSQL("db #3")
            odoo3 -  Edge(color="brown") - db3

        nginx >> Edge(color="darkgreen") << odoo1
        nginx >> Edge(color="darkgreen") << odoo2
        nginx >> Edge(color="darkgreen") << odoo3

    with Cluster("Sessions HA"):
        master = Redis("session")
        master - Edge(color="brown", style="dashed") - Redis("replica") << Edge(label="collect") << metrics
        odoo1 >> Edge(color="brown") >> master
        odoo2 >> Edge(color="brown") >> master
        odoo3 >> Edge(color="brown") >> master

    with Cluster("Messenging HA"):
        zmq =  Custom("Broker Active", zmq_icon)
        zmq - Edge(color="brown", style="dashed") - Custom("Broker Standby", zmq_icon) << Edge(label="collect") << metrics
        odoo1 >> Edge(color="brown") >> zmq
        odoo2 >> Edge(color="brown") >> zmq
        odoo3 >> Edge(color="brown") >> zmq

    with Cluster("Client Integration"):
        clients = CloudServices("client #1")
        clients - Edge(color="brown", style="dashed") - CloudServices("client #2") - Edge(color="brown", style="dashed") - CloudServices("client #3")         
        zmq >> Edge(color="red") >> clients 


The generated diagram is as below:

architecture

Is there a way I can set the position of the cluster? to make them aligned..

@abhi0977
Copy link

@xu4wang did you find any solution around this?

@xu4wang
Copy link
Author

xu4wang commented Sep 13, 2020 via email

@mingrammer
Copy link
Owner

I need to find a solution to this issue too. Thank you for reporting it.

@mingrammer mingrammer added kind/feature New feature or request question Further information is requested status/need-to-review Need to review labels Sep 26, 2020
@andreujuanc
Copy link

andreujuanc commented Oct 12, 2020

Hi!, just found this project, (It's really cool).
I found a workaround for this issue (while we work out how to do it properly)

I was having exactly the same problem and what I did was to remove the "internal" communication edge between the items causing the problem:

     with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            # By commenting this out, Postgres and Docker will show Vertically instead
            # odoo1 -  Edge(color="brown") - db1

Since the arrow goes from the Docker node to the SessionsHA nodes, if we go horizontally as intended, it will have go on top of the Postgres node, and that's why it does this weird rendering.

The ideal solution is to allow Cluster to Cluster arrows, or even Cluster to Node.

Open issues asking for this: #261 #128 #17

Another solution is to use a custom image node (made from another diagram???) that is a combination of docker+postgres?

Best!

EDIT: Attaching demo:
image

@clayms
Copy link

clayms commented Oct 28, 2020

If you don't mind the arrows coming off of your dbs and placing some Custom transparent 'spacers'.

with Diagram(name=" Architecture", show=False) as diag:
    nginx = Nginx("LoadBalancer")

    metrics = Prometheus("metric")
    metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")

    with Cluster("Service Cluster"):
        with Cluster("Multitenancy #1"):
            odoo1 = Docker("Application #1")
            db1   = PostgreSQL("db #1")
            odoo1 -  Edge(color="brown") - db1
        with Cluster("Multitenancy #2"):
            odoo2 = Docker("Application #2")
            db2   = PostgreSQL("db #2")
            odoo2 -  Edge(color="brown") - db2
        with Cluster("Dedicated #3"):
            odoo3 = Docker("Application #3")
            db3   = PostgreSQL("db #3")
            odoo3 -  Edge(color="brown") - db3

        nginx >> Edge(color="darkgreen") << odoo1
        nginx >> Edge(color="darkgreen") << odoo2
        nginx >> Edge(color="darkgreen") << odoo3

    blank1 = Custom("","transparent.png")
    db2 - Edge(penwidth="0.0") - blank1 - Edge(penwidth="0.0") - metrics

    with Cluster("Sessions HA"):
        master = Redis("session")
        replica = Redis("replica")
        master - Edge(color="brown", style="dashed") - replica << Edge(label="collect") 
        master << metrics
        db1 >> Edge(color="brown") >> master
        db2 >> Edge(color="brown") >> master
        db3 >> Edge(color="brown") >> master

    with Cluster("Messenging HA"):
        zmq =  Custom("Broker Active", zmq_icon)
        zmq2 =  Custom("Broker Standby", zmq_icon)
        zmq - Edge(color="brown", style="dashed") - zmq2 << Edge(label="collect")
        zmq << metrics
        db1 >> Edge(color="brown") >> zmq
        db2 >> Edge(color="brown") >> zmq
        db3 >> Edge(color="brown") >> zmq
 
    with Cluster("Client Integration"):
        client1 = CloudServices("client #1")
        client2 = CloudServices("client #2")
        client3 = CloudServices("client #3")
        client1 - Edge(color="brown", style="dashed") - client2 - Edge(color="brown", style="dashed") - client3
        zmq2 >> Edge(color="red") >> client1
    

diag

image

@xu4wang
Copy link
Author

xu4wang commented Oct 28, 2020

Thanks for the help. I like this workaround.

If you don't mind the arrows coming off of your dbs and placing some Custom transparent 'spacers'.

@clayms
Copy link

clayms commented Oct 31, 2020

@xu4wang
Another option you might like is to set the graph_attr "splines" to "polyline" or "line". See output below.

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

with Diagram(name=" Architecture", show=False, graph_attr=graph_attr) as diag:
     # ... Same as previous posts

image

@xu4wang
Copy link
Author

xu4wang commented Oct 31, 2020

@xu4wang
Another option you might like is to set the graph_attr "splines" to "polyline" or "line". See output below.

Yes! Thanks for sharing the magic. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request question Further information is requested status/need-to-review Need to review
Projects
None yet
Development

No branches or pull requests

5 participants