【问题标题】:graphviz - how to create labels over straight arrowsgraphviz - 如何在直箭头上创建标签
【发布时间】:2019-03-01 18:35:39
【问题描述】:

也许我试图弯曲 graphviz 比我应该做的更多,但它会 可以拉直箭头吗?我需要标签在箭头上方,而不是像 label/xlabel 那样在侧面;我使用框来保存本质上是标签文本的内容,因为在标签很长时在边缘使用标签似乎会导致奇怪的行为。

digraph G {
    node [shape=rect style=filled
         fontcolor=white fontsize=12 fontname="Helvetica Bold"]
    edge [style=solid color="#777777"]

    // introduce nodes; set fill
    a1, a2, a3 [fillcolor="#438dd5"]
    c1         [fillcolor="#08427b"]

    b1, b2, b3 [fillcolor=white fontcolor=black fontname="Helvetica" shape=plain]

    a1 -> b1[dir=none]
    a2 -> b2[dir=none]
    a3 -> b3[dir=none]

    b1 -> c1
    b2 -> c1
    b3 -> c1

    { rankdir=LR  rank=same  a1 a2 a3  }
    { rankdir=LR  rank=same  b1 b2 b3 }
    { rankdir=LR  rank=same  c1 }
}

我得到了什么:

我想要什么:

【问题讨论】:

标签: graphviz


【解决方案1】:

我通常使用没有边框和白色背景的tables 来代替标签。您可能还需要使用headlabeltaillabel,因为在这种情况下,您可以使用labeldistancelabelangle 精确控制它们的位置:

digraph G {
    node  [shape=rect style=filled
           fontcolor=white fontsize=12 fontname="Helvetica Bold"]
    graph [ranksep=1]
    edge  [style=solid color="#777777"]

    a1 [fillcolor="#438dd5"]
    a2 [fillcolor="#438dd5"]
    a3 [fillcolor="#438dd5"]
    c1 [fillcolor="#08427b"]

    a1 -> c1 [
        labeldistance=5
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b1</td>
                </tr>
            </table>
        >
    ]
    a2 -> c1 [
        labeldistance=4
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b2</td>
                </tr>
            </table>
        >
    ]
    a3 -> c1 [
        labeldistance=5
        labelangle=0
        headlabel=<
            <table bgcolor="white" border="0">
                <tr>
                    <td>b3</td>
                </tr>
            </table>
        >
    ]
}

结果:

【讨论】:

  • 谢谢.. 我试过表格,但我不知道 labelangle 和 labeldistance 的使用。非常有意义...也喜欢使用 rankep 将行分开。
  • @RoyM rankep 会影响整个图表,而您有时并不想要它。在这种情况下,您只需将“不可见”标签添加到边缘之一。在这个例子中你可以a2 -&gt; c1 [label=" \n \n \n \n" ...
猜你喜欢
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-30
  • 2010-10-22
相关资源
最近更新 更多