mingrammer/diagrams

can't change direction of cluster to TB

Open

#1,139 建立於 2025年4月15日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)Python (2,701 fork)batch import
comp/clusterhelp wantedstatus/need-to-review

倉庫指標

Star
 (41,903 star)
PR 合併指標
 (平均合併 53天 15小時) (30 天內合併 5 個 PR)

描述

Hi ALL,

I've been playing around with this tool and came up with a simple use case. Using TF statefiles create an OU structure diagram.

Image

As you can see that works fine.

What's falling apart is when I introduce accounts.

Image

It looks like a mess. There are few possible ideas I've had for fixing this, though to me the easiest would be to change the cluster direction from the default LR to TB, but I can't seem to get this working.

# Generate Organisation Structure
with Diagram(filename="Org", show=False, curvestyle='curved'):
    
    data_ou_resources = []
    root_ou_id = data['org']['outputs']['ou_root_id']['value']
    root_ou = OU('root')

    # get a list of OU Resources
    for resource in data['org']['resources']:
        if resource['type'] == "aws_organizations_organizational_unit":
            data_ou_resources.append(resource['instances'][0]['attributes'])

    # Draw them
    for ou in data_ou_resources:
        ou.update({"diagram_obj" : OU(ou['name'])} )

    # Setup the relationships between the objects
    for ou in data_ou_resources:
        if ou['parent_id'] != root_ou_id:
            for obj in data_ou_resources:
                if obj['id'] == ou['parent_id']:
                    obj['diagram_obj'] >> ou['diagram_obj']
                    break
        else:
             root_ou >> ou['diagram_obj']

    for ou in data_ou_resources:
        with Cluster(ou['name'], direction='TB'):
            for account in ou['accounts']:
                ou['diagram_obj'] - ACC(account['name'])

Any ideas?


UPDATE:

I am a moron. Who realised too late that already am in TB and what I want is LR.

Image

So with that change, the accounts are now stacked like I want, but it's not perfect.

I would much prefer it if it looked something like this.

貢獻者指南