Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Force Crossing Edges in GraphViz

I’m very new to GraphViz and dot (I only started today!), and I’m having a difficult time forcing "crossing edges" (I think that’s the term) on my first real graph. Specifically, I’m trying to show that the pins on an electrical component were out of place by one. GraphViz continues to shift one of my clusters downward to avoid crossing the lines, but I want them to cross; I want my clusters to be even and of the same-size. (I’ll work on the size part next.)

How can I force edge-crossing in GraphViz?

digraph {
    rank=same        
    subgraph cluster_designed {
        label="*As Designed*";
        node [shape=square]
        rankdir=TB
        rank=same
        Drain_design -> Gate_design -> Source_design [style=invis];
    }

    subgraph cluster_actual {
        label="*On Chip*";
        node [shape=square]
        rankdir=TB
        rank=same
        Gate_actual -> Source_actual -> Drain_actual [style=invis];
    }

    Drain_design -> Drain_actual;
    Gate_design -> Gate_actual;
    Source_design -> Source_actual;
}

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No simple tweak, it is very difficult to manage the position of clusters. Instead, I’d suggest using "html-like nodes" (https://graphviz.org/doc/info/shapes.html). They are fairly easy to position and seem to produce the result you want.

p.s. rank=same applies to subgraphs (not Root) and rankdir applies to Root graph (not subgraphs)

digraph {

  {rank=same
  t1 [shape=plaintext,label=<
  <TABLE CELLSPACING="2" CELLPADDING="2" BORDER="1">
  <TR><TD CELLSPACING="5" BORDER="0" CELLPADDING="0">"as designed"</TD></TR>
  <TR><TD PORT="p1">Drain design</TD></TR>
  <TR><TD PORT="p2">Gate design</TD></TR>
  <TR><TD PORT="p3">Source design</TD></TR>    
  </TABLE>
  >
  ]
  t2 [shape=plaintext,label=<
  <TABLE CELLSPACING="2" CELLPADDING="2" BORDER="1">
  <TR><TD CELLSPACING="5" BORDER="0" CELLPADDING="0">"On Chip"</TD></TR>
  <TR><TD PORT="p1">Gate Actual</TD></TR>
  <TR><TD PORT="p2">Source Actual</TD></TR>
  <TR><TD PORT="p3">Drain Actual</TD></TR>    
  </TABLE>
  >
  ]

  t1:p1 -> t2:p3
  t1:p2 -> t2:p1
  t1:p3 -> t2:p2
  }
}

Giving:
enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading