mingrammer/diagrams

can't change direction of cluster to TB

Open

#1,139 opened on Apr 15, 2025

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Python (2,701 forks)batch import
comp/clusterhelp wantedstatus/need-to-review

Repository metrics

Stars
 (41,903 stars)
PR merge metrics
 (Avg merge 53d 15h) (5 merged PRs in 30d)

Description

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.

Contributor guide