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

make cluster ranks the same in for loop #968

Open
errolsancaktar opened this issue Feb 8, 2024 · 2 comments
Open

make cluster ranks the same in for loop #968

errolsancaktar opened this issue Feb 8, 2024 · 2 comments

Comments

@errolsancaktar
Copy link

given the code below i'm trying to get each vpc cluster to be on top of each other. typically i would do some penwidth=0 lines to keep everything ordered appropriately but i'm unclear on how to do that when the items were generated using a loop.
Screenshot_20240208_114609

graph_attr = {
    "arrowsize": "2",
    "bgcolor": "white",  # transparent
    "overlap": "false",
    "nodesep": "2.0",
    "ranksep": "1.5",
    "layout": "dot",
    "compound": "false",


}

edge_attr = {
    "penwidth": "2.0",
    "pencolor": "gray",
    
}

subnet_attr = {"bgcolor": "lightgreen"}
environments = ["dev", "qa"]
azs = ["us-east-1b"]
online_vms = {}
with Diagram("Shared Services test", show=False, direction="TB", graph_attr={}, edge_attr={},filename="Shared/Diagrams/sharedsvcs") as diag1:

  with Cluster("Example 1"):
    tgw = TransitGateway("Shared Services TGW")
    for env in environments:
      with Cluster(f"{env} VPC"):
        # Looping through Private first and then Public instead of doing it all in one for loop
        # for rendering purposes (so it doesn't go private, public, private, public)
        for az in azs:
          with Cluster(f"{az}\nPrivate Subnet"):
            instance = [
              EC2Instance(f"Web Service"),
              EC2Instance(f"inst2")
            ]
            nic = VPCElasticNetworkInterface("TGW Connectivity")
            # nic << Edge() >> tgw
        for az in azs:
          with Cluster(f"{az}\nPublic Subnet"):
            alb = ALB(f"ALB")
            # alb >> Edge() >> online_vms[env]
            gw = NATGateway(f"NAT Gateway\nInternet Access")
@errolsancaktar
Copy link
Author

something like this:
dsfg

@Anddd7
Copy link

Anddd7 commented Mar 23, 2024

You can add some 'hidden points & lines' to reorder the nodes.

  • by default, direction="TB" will list your nodes from left2right, because there is no any relations
  • then, if you NAT_QA -- NAT_DEV, TB layout will move dev to next line

So, if you have enough patient, you can create additional Node(color=transparent), Edge(color=transparent), Cluster(color=transparent) to order nodes.

e.g. to make 3 clusters vertical, I create 3 hidden points in each of them, and connect with hidden edge.

with Cluster("identity"):
    S3()
    Terraform()
    Cloudtrail()
    p1 = HiddenPoint()
with Cluster("identity2"):
    S3()
    Terraform()
    Cloudtrail()
    p2 = HiddenPoint()
with Cluster("identity3"):
    S3()
    Terraform()
    Cloudtrail()
    p3 = HiddenPoint()

# p1 - p2 - p3
peercluster(p1, p2, p3, penwidth="0", minlen="1")  # util method in my repo

Sample: https://github.com/Anddd7/diagrams-patterns/blob/main/poc_aws_complex.py#L94
Sample


Another way is using neato as the layout engine, then create node with x,y ... if you really want to control the layout

Sample: https://github.com/Anddd7/diagrams-patterns/blob/main/poc_neato_overlap.py
Sample

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