mingrammer / diagrams

:art: Diagram as Code for prototyping cloud system architectures
https://diagrams.mingrammer.com
MIT License
37.35k stars 2.43k forks source link

Is it possible to control Clusters arrangement, from left to right or top down? #44

Open ki11roy opened 4 years ago

ki11roy commented 4 years ago

Is it possible to control Clusters arrangement, from left to right or top-down for example? How?

mingrammer commented 4 years ago

Cluster class also has direction options, but it does not work. So I left a comment on why that does not work.

__init__.py

199: # FIXME:
200:     #  Cluster direction does not work now. Graphviz couldn't render
201:     #  correctly for a subgraph that has a different rank direction.

As the comment says, it is not supported (or impossible?) now because the Graphviz issue.

dotenorio commented 4 years ago

i'll try to fix this

dotenorio commented 4 years ago

failed sorry

TheAshwanik commented 4 years ago

HI @mingrammer , awesome work with the tool.. Loving it totally. The Direction on the Clusters would have been very useful. Any idea any way this could be solved?

FFengIll commented 4 years ago

As we know, Graphviz can not set a new direction (layout) in sub-rank items. Is it possible to create a sub-graph (only the Cluster) first and then put it (as image file) back to the global graph (the original Diagram)?

If we change Cluster, and render cluster to a temp svg, then we can use Custom with the temp one.

I made a demo and output like bellow: image

With this solution, we can use different layout on cluster; link cluster as node. But this solution comes with a serious drawback - edge CAN NOT link any node included in the cluster (of course).

So we must do a choice

Furthermore, more temp files generated, and the direction is a side-effect, not the major motivation

# Diagrams code demo
# Mention: I forked a version, so the code can not work in others.

with Diagram("Demo", show=False, direction="LR", filename="test", outformat='png'):

    parser = Compute('Parser & Analysis')

    with Cluster('object1',direction='LR') as cls1:
        objects = [
            Android(''),
            InternetOfThings('')
        ]

    with Cluster('object2',direction='TB') as cls2:
        objects2 = [
            Android(''),
            InternetOfThings('')
        ]

    parser - cls1
    parser >> cls1
    cls1 - cls2
    cls1 >> cls2 >> cls1

    # sorry, we can not
    # parser >> objects2
HariSekhon commented 1 year ago

This is a critical feature, without this some diagrams come out badly laid out, eg:

https://github.com/HariSekhon/Diagrams-as-Code/blob/master/opentsdb_kubernetes_hbase.py

When this should clearly be stacked on top of each other rather than this awkward side-by-side layout.