'How can I have ranks layout in different directions, in order to to double back?

I have a graph of a process that has an "outbound" phase and a "return" phase. I want the return phase to rum back in the other direction.

strict digraph {
rankdir="TB"
code 
PO 
SLP_out
{rank="same" code PO SLP_out}

translators
{rank="same" translators}

SLP_Back
POTs
merged_POs
MOs
{rank="same"  SLP_Back POTs merged_POs MOs}

code -> PO [fillcolor="#a6cee3" color="#1f78b4" label="makemesseges"]
PO -> SLP_out [fillcolor="#a6cee3" color="#1f78b4" label="slmake.exe"]
SLP_out -> translators [fillcolor="#a6cee3" color="#1f78b4" style=dashed ]
translators -> SLP_Back [fillcolor="#a6cee3" color="#1f78b4"]
SLP_Back -> POTs [fillcolor="#a6cee3" color="#1f78b4"]
POTs -> merged_POs [fillcolor="#a6cee3" color="#1f78b4"]
merged_POs -> MOs [fillcolor="#a6cee3" color="#1f78b4"]   

}

Right now this reuns left-to-right, drops down, then keeps running left-to-right. I want bottom rung to come back right-to-left. How can I make it double back on it self?



Solution 1:[1]

Swap head & tail of the edges you want to go right-to-left then add dir=back (https://graphviz.org/docs/attrs/dir/) to get the arrowheads placed correctly

// https://stackoverflow.com/questions/72193265/how-can-i-have-ranks-layout-in-different-directions-in-order-to-to-double-back
strict digraph {
rankdir="TB"
code 
PO 
SLP_out
{rank="same" code PO SLP_out}

translators
{rank="same" translators}

SLP_Back
POTs
merged_POs
MOs
{rank="same"  SLP_Back POTs merged_POs MOs}

code -> PO [fillcolor="#a6cee3" color="#1f78b4" label="makemesseges"]
PO -> SLP_out [fillcolor="#a6cee3" color="#1f78b4" label="slmake.exe"]
SLP_out -> translators [fillcolor="#a6cee3" color="#1f78b4" style=dashed ]
translators -> SLP_Back [fillcolor="#a6cee3" color="#1f78b4"]
// reverse edge directions
//SLP_Back -> POTs [fillcolor="#a6cee3" color="#1f78b4"]
POTs -> SLP_Back [dir=back fillcolor="#a6cee3" color="#1f78b4"]
//POTs -> merged_POs [fillcolor="#a6cee3" color="#1f78b4"]
 merged_POs -> POTs [dir=back fillcolor="#a6cee3" color="#1f78b4"]
//merged_POs -> MOs [fillcolor="#a6cee3" color="#1f78b4"]
MOs -> merged_POs [dir=back fillcolor="#a6cee3" color="#1f78b4"]   
}

Giving:
enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sroush