Connect longer sequential edges first or group edges from same source node first

Hi community,

Should I connect longer sequential edges first or group edges from same source node first as shown in cluster1 and cluster2 respectively?

The results are a bit different.
In cluster1, the node and edge order is different from the code but it has no edge crossing.
In cluster2, the node and edge order follows the code but there is edge crossing.

Thanks

digraph {
    subgraph cluster1 {
        start1 -> input1 -> check1
        
        // connect longer sequential edges first
        check1 -> foo1 foo1 -> finish1
        check1 -> err1 err1 -> finish1
        check1 -> finish1
        check1 -> bar1 bar1 -> finish1
        
        conf1 -> bar1 -> output1
        deps1 -> bar1
    }

    subgraph cluster2 {    
        start2 -> input2 -> check2
        
        // group edges from same source node first
        check2 -> foo2 
        check2 -> err2 
        check2 -> finish2
        check2 -> bar2 
        
        foo2 -> finish2
        err2 -> finish2
        bar2 -> finish2
        
        conf2 -> bar2 -> output2
        deps2 -> bar2
    }
}

[this answer is going to be more convoluted than you probably want, sorry]

The key to the difference between the two graphs is the edge check → finish (surprised me)
Even though your input presents this edge in the same sequence of the four edges starting from check, dot considers the edges in different order. To see this, try dot -Tcanon myfile.gv. You will see that check → finish gets reordered.
This is important to your question because this edge causes a virtual node to be inserted into the nodes on this rank, which in-turn causes the other nodes to be slightly repositioned to the right and the edges to be drawn differently. Whew!

Back to the question of what should you do. Hmm.
It is pretty easy to identify virtual nodes programmatically. But then what? A large, complex graph can contain tens of thousands of virtual nodes. How many would be important to the layout?
This need more thought.

1 Like

I did more tests.

In the style 2, I can move the check2 -> finish2 edge and make the edge line appear between the nodes err2 and foo2.

This can not be done with style 1, no matter how I move the check1 -> finish1 edge , maybe it is because the finish1 node is mentioned too earlier.

The -Tcanon option always break chained edges into this style. So, I think maybe the style 2 is better.

Thanks

digraph {
    subgraph cluster1 {
        start1 -> input1 -> check1 -> foo1 -> finish1;
        
        check1 -> finish1;
        check1 -> err1 -> finish1;
        check1 -> bar1 -> finish1;
        
        conf1 -> bar1 -> output1;
        deps1 -> bar1;
    }
    
    subgraph cluster2 {
        start2 -> input2;
        input2 -> check2;
        
        check2 -> foo2;
        check2 -> finish2;
        check2 -> err2;
        check2 -> bar2;
        
        conf2 -> bar2;
        deps2 -> bar2;
        
        foo2 -> finish2;
        err2 -> finish2;
        bar2 -> finish2;
        
        bar2 -> output2;
    }
}