Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force square corners on edges with graphviz

Tags:

graphviz

dot

I have the following .dot file.

digraph
{
    node [color=Limegreen,fontcolor=Limegreen,shape=oval]
    ilocus [label="iLocus"]
    gilocus [label="giLocus"]
    pilocus [label="piLocus"]
    nilocus [label="niLocus"]
    silocus [label="siLocus"]
    cilocus [label="ciLocus"]
    filocus [label="fiLocus"]
    iilocus [label="iiLocus"]

    node [color=Blue,fontcolor=Blue,shape=diamond]
    containgene [label="Contains gene(s)?"]
    proteincoding [label="Protein coding?"]
    multiplegenes [label="Multiple genes?"]
    geneflank [label="Flanked by genes\non both sides?"]

    ilocus -> containgene
    containgene:e -> geneflank [xlabel="No"]
    geneflank:e -> filocus [xlabel="No"]
    geneflank:w -> iilocus [xlabel="Yes"]
    containgene:w -> gilocus [xlabel="Yes"]
    gilocus -> proteincoding
    proteincoding:e -> nilocus [xlabel="No"]
    proteincoding:w -> pilocus [xlabel="Yes"]
    pilocus -> multiplegenes
    multiplegenes:e -> silocus [xlabel="No"]
    multiplegenes:w -> cilocus [xlabel="Yes"]
}

Rendering with graphviz I get the following.

Graphviz take 1

Is there any way I can force the edges to have square corners rather than rounded corners? The splines=ortho attribute from the documentation seems to be designed for this in principle, but in practice I just get straight lines when I add graph [splines=ortho] to my digraph.

Graphviz take 2

Any way I can get square corners on the edges with graphviz? Something like the following:

  ------ Multiple genes? -----
  |                          |
  | N                      Y |
  |                          |
  v                          V
siLocus                   ciLocus
like image 367
Daniel Standage Avatar asked Jan 26 '16 05:01

Daniel Standage


1 Answers

Maybe you can start out by using splines=line

digraph
{
    splines=line
    ...

which will give you this graph:

Graph using splines=line

From there you might need to manually position the nodes, or insert hidden nodes and edges like

digraph
{
    splines=line

    node [color=Limegreen,fontcolor=Limegreen,shape=oval]
    ilocus [label="iLocus"]
    gilocus [label="giLocus"]
    pilocus [label="piLocus"]
    nilocus [label="niLocus"]
    silocus [label="siLocus"]
    cilocus [label="ciLocus"]
    filocus [label="fiLocus"]
    iilocus [label="iiLocus"]

    node [color=Blue,fontcolor=Blue,shape=diamond]
    containgene [label="Contains gene(s)?"]
    proteincoding [label="Protein coding?"]
    multiplegenes [label="Multiple genes?"]
    geneflank [label="Flanked by genes\non both sides?"]

    spacer1 [label="xxxx",style=invis]
    {rank=same gilocus spacer1 geneflank}
    gilocus -> spacer1 -> geneflank [style=invis]

    ilocus -> containgene
    containgene:e -> geneflank [xlabel="No"]
    geneflank:e -> filocus [xlabel="No"]
    geneflank:w -> iilocus [xlabel="Yes"]
    containgene:w -> gilocus [xlabel="Yes"]
    gilocus -> proteincoding
    proteincoding:e -> nilocus [xlabel="No"]
    proteincoding:w -> pilocus [xlabel="Yes"]
    pilocus -> multiplegenes
    multiplegenes:e -> silocus [xlabel="No"]
    multiplegenes:w -> cilocus [xlabel="Yes"]
}

which produces

enter image description here

Alternatively, you can insert spaces in the top labels to make lower nodes line up better:

digraph
{
    splines=line

    node [color=Limegreen,fontcolor=Limegreen,shape=oval]
    ilocus [label="iLocus"]
    gilocus [label="giLocus"]
    pilocus [label="piLocus"]
    nilocus [label="niLocus"]
    silocus [label="siLocus"]
    cilocus [label="ciLocus"]
    filocus [label="fiLocus"]
    iilocus [label="iiLocus"]

    node [color=Blue,fontcolor=Blue,shape=diamond]
    containgene [label="    Contains gene(s)?   "]
    proteincoding [label="Protein coding?"]
    multiplegenes [label="Multiple genes?"]
    geneflank [label="Flanked by genes\non both sides?"]

    ilocus -> containgene
    containgene:e -> geneflank [xlabel="No"]
    geneflank:e -> filocus [xlabel="No"]
    geneflank:w -> iilocus [xlabel="Yes"]
    containgene:w -> gilocus [xlabel="Yes"]
    gilocus -> proteincoding
    proteincoding:e -> nilocus [xlabel="No"]
    proteincoding:w -> pilocus [xlabel="Yes"]
    pilocus -> multiplegenes
    multiplegenes:e -> silocus [xlabel="No"]
    multiplegenes:w -> cilocus [xlabel="Yes"]
}

which produces

enter image description here

like image 136
jpsecher Avatar answered Oct 03 '22 19:10

jpsecher