Search code examples
graphviz

Invert edge trajectory graphviz


i am trying to graph a doubly linked circular list in .dot language but it does not display as i want. Both of the circular edges are under the nodes but i want 1 of them above

this is what i want: expected result

but i get this instead: given result

here is my .dot code: https://dreampuf.github.io/GraphvizOnline/#digraph%20{%0A%20%20node[shape=record];%0A%20%20graph[pencolor=transparent];%0A%20%20rankdir=LR;%0A%20%20p1[label=%22{%3Cprev%3E|%3Cdata%3E%2012|%3Cnext%3E}%22];%0A%20%20p2[label=%22{%3Cprev%3E|%3Cdata%3E%2012|%3Cnext%3E}%22];%0A%20%20p3[label=%22{%3Cprev%3E|%3Cdata%3E%2012|%3Cnext%3E}%22];%0A%0A%0A%20%20%20%20p1:next%20-%3E%20p2:prev;%0A%20%20p2:next%20-%3E%20p3:prev;%0A%20%20p2:prev%20-%3E%20p1:next;%0A%20%20p3:prev%20-%3E%20p2:next;%0A%20%20%20%20edge[tailclip=false,dir=%22forward%22%20splines=%22compound%22%20constraint=%20%22false%22];%0A%20%0A%20%0Ap3:next%20-%3E%20p1:prev;%0A%0Ap1:prev%20-%3E%20p3:data;%0A%0A%20%20%20%20%0A}

thank you


Solution

  • Main change was to add a port position (https://graphviz.org/docs/attr-types/portPos/) to the head & tail of the edge. Also removed some unneeded bits.

     digraph {
      node[shape=record];
      graph[pencolor=transparent];
      rankdir=LR;
      
      p1[label="{<prev>|<data> 12|<next>}"];
      p2[label="{<prev>|<data> 12|<next>}"];
      p3[label="{<prev>|<data> 12|<next>}"];
    
      p1:next -> p2:prev;
      p2:next -> p3:prev;
      p2:prev -> p1:next;
      p3:prev -> p2:next;
    
      p1:prev:n -> p3:data:n;
    //  edge[tailclip=false,dir="forward" splines="compound" constraint= "false"];
      p3:next -> p1:prev;    
    }
    

    Giving:
    enter image description here