2

I want to create graphs representing processes so the order of the nodes is important.

I'm struggling with graphviz logic for ordering clusters subgraphs and nodes. I'm using the graphviz python library to automate rendering. Each time I render the same code the result is not the same.

digraph G {
    graph [rankdir=LR]
    subgraph cluster_0 {
        subgraph cluster_start {
            start;
        }
        subgraph cluster_1 {
            style=filled;
            color=lightgrey;
            node [style=filled,color=white];
            A00;
            A0;
            A1;
            A2;
            A3;
            A00 -> A0;
            A00 -> A1;
            A1 -> A2;
            A0 -> A3;
            label = "process #1";
        }
        subgraph cluster_2 {
            node [style=filled];
            B00;
            B0;
            B1;
            B2;
            B3;
            B00 -> B0;
            B00 -> B1;
            B1-> B3;
            B0 -> B2;
            label = "process #2";
        }
        subgraph cluster_end {
            end;
        }
        start -> A00 [constraint=false];
        A00 -> B00 [constraint=false];
        B00-> end [constraint=false];
    }
}

I've searched for hours but Graphviz still renders the graphs randomly. In some cases I will have what I want as the graph below. What I want to display But many times I will have What I don't want

The things I'm quite certain about is I want to use the rankdir LR to display my nodes horizontally in clusters. I tried setting a high weight on 'vertical' edges or grouping first nodes of each clusters but it still displays my graph's clusters randomly and I'm quite frustrated about being unable to arrange thoses graphs as I want and this example is a very simple one compared to much more complex processes I want to represent

I have no other clue of what can impact the clusters positions. Any help or clue about what to check would be so much apreciated

2
  • Wow - same input, varying result. Without python, I get identical result 100 for 100 times. Could it be the python interface? If you produce "dot" format output 10 times (using python), are they identical? Are Graphviz & the python library up-to-date? Commented Nov 17, 2023 at 15:21
  • 1
    Maybe I was linked to the online editor I used such as edotor.net. There still something I definitly don't get. Why clusters with no rank are displayed in the opposite direction to that in which they are defined. If I define cluster one with a node and then a cluster two with another node. The cluster one will be displayed below the cluster two. Commented Nov 17, 2023 at 17:08

1 Answer 1

0

No python involved, but using a very recent release of Graphviz, This requires reversing the order of the clusters.

digraph G {
    graph [rankdir=LR]
    newrank=true  // no impact on result

    subgraph cluster_0 {
      // the clusters seem to be arranged from top-to-bottom
      // so we reverse the order
       subgraph cluster_end {
            end;
        }
        subgraph cluster_2 {
            node [style=filled];
            B00;
            B0;
            B1;
            B2;
            B3;
            B00 -> B0;
            B00 -> B1;
            B1-> B3;
            B0 -> B2;
            label = "process #2";
        }
     subgraph cluster_1 {
            style=filled;
            color=lightgrey;
            node [style=filled,color=white];
            A00;
            A0;
            A1;
            A2;
            A3;
            A00 -> A0;
            A00 -> A1;
            A1 -> A2;
            A0 -> A3;
            label = "process #1";
        }   
       subgraph cluster_start {
            start;
        }

    edge [ constraint=false]  // because constraint=false, these edges do not influance order
        start -> A00 -> B00 -> end
  }
}

Giving:
enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.