【问题标题】:Force square corners on edges with graphviz使用 graphviz 强制边缘上的方角
【发布时间】:2016-05-02 15:41:23
【问题描述】:

我有以下.dot 文件。

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"]
}

使用 graphviz 渲染我得到以下结果。

有什么方法可以强制边缘具有方角而不是圆角?文档中的splines=ortho 属性原则上似乎是为此设计的,但实际上,当我将graph [splines=ortho] 添加到我的有向图时,我只会得到直线。

我可以用graphviz在边缘上得到方角吗?类似于以下内容:

  ------ Multiple genes? -----
  |                          |
  | N                      Y |
  |                          |
  v                          V
siLocus                   ciLocus

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    也许你可以从使用splines=line开始

    digraph
    {
        splines=line
        ...
    

    这会给你这个图表:

    从那里您可能需要手动定位节点,或插入隐藏节点和边缘,例如

    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"]
    }
    

    产生

    或者,您可以在顶部标签中插入空格以使较低的节点更好地排列:

    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"]
    }
    

    产生

    【讨论】:

    • 绝对有帮助,但令人沮丧的是,我无法在“包含基因?”之间的“否”边上获得 90° 角。和“两边都有基因?”。
    【解决方案2】:

    您可以简单地使用splines=false (link to GraphvizFiddle)。

    【讨论】:

    • 也许我的解释不清楚。我已经更新以准确显示“方角”的含义。
    • 对不起,我误会了。不幸的是,ortho 很少做人们想要做的事情......
    猜你喜欢
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2011-05-14
    • 1970-01-01
    • 2010-10-24
    • 2019-06-19
    相关资源
    最近更新 更多