Search code examples
pythongraphvizdiagram

How to visualize nodes in horizontal cluster with invisible edges (Python diagrams)


I'm trying to make a horizontal cluster containing two nodes (here visualized as users) in Python module diagrams which uses Graphviz for rendering.

But the only way to achieve this is by adding edges between the nodes.

Horizontal, but with edge shown between nodes

from diagrams import Cluster, Diagram
from diagrams.onprem.client import User

with Diagram("sample", show=False) as diag:
    with Cluster("sample horizontal cluster with edge"):
        node1 = User("Some Node")
        node2 = User("Some other Node")
        node1 >> node2

Which produces:

enter image description here

Without edge, but vertical

I've tried without the connection node1 >> node2:

    with Cluster("sample horizontal cluster with edge", direction="LR"):
        node1 = User("Some Node")
        node2 = User("Some other Node")

Then it renders vertically, which I don't want: enter image description here

I don't want to see that edge but have the nodes arranged horizontally.

How can I achieve that?


Solution

  • See this example from Edges guide and connect with an invisible edge using style="invis" like supported by GraphViz's style atrribute:

    from diagrams import Cluster, Diagram, Edge
    from diagrams.onprem.client import User
    
    with Diagram("invisible_edge", show=False) as diag:
        with Cluster("sample horizontal cluster with invisible edge"):
            node1 = User("Some Node")
            node2 = User("Some other Node")
            node1 - Edge(style='invis') - node2
    

    Renders using GraphViz to: nodes connected using invisible edge