简体   繁体   English

如何防止边缘标签弄乱graphviz中的布局?

[英]How to prevent edge labels from messing up the layout in graphviz?

I have a simple vertical graph that looks nice and symmetrical without any labels using the following code: 我有一个简单的垂直图,使用以下代码看起来很漂亮且对称,没有任何标签:

digraph test_alignment
{
    {rank=same; a -> b;}
    a -> c;
    b -> c;
    c -> d;
    d -> e;
    d -> f;
    {rank=same; e -> f;}
}

The initial graph

I'd like to label the edge between A and B as well as the one between E and F, using the same string for each label. 我想标记A和B之间的边缘以及E和F之间的边缘,并为每个标签使用相同的字符串。 I'm expecting the same output, except with longer A->B and E->F edges bearing the same label. 我期望相同的输出,但带有相同标签的A-> B和E-> F边缘更长。

Unfortunately, as soon as I add a label to one of these edges, the general layout looks slightly askew (the result is similar if I add a label to the E->F edge): 不幸的是,一旦我在这些边缘之一上添加标签,总体布局就会看起来有点歪斜(如果我在E-> F边缘上添加标签,结果也差不多):

digraph test_alignment
{
    {rank=same; a -> b [label="Label"];}
    a -> c;
    b -> c;
    c -> d;
    d -> e;
    d -> f;
    {rank=same; e -> f;}
}

The same graph with one label

I'm very new to graphviz and, following many questions on Stack Overflow, I have been experimenting with different combinations of rank and constraint, I tried using clusters to see if it would keep the top and bottom part properly aligned independently, and tried using a mix of dot, ccomp, gvpack and neato that produced similar results. 我是graphviz的新手,在Stack Overflow上提出了许多问题之后,我一直在尝试使用等级和约束的不同组合,我尝试使用群集来查看它是否可以使顶部和底部保持独立的正确对齐,并尝试使用点,ccomp,gvpack和neato的混合产生了相似的结果。

It always seems to boil down to the fact adding a label to the edge between nodes with the same rank affects how these nodes are positioned in a way I don't yet understand. 似乎总是归结为这样的事实,即在具有相同等级的节点之间的边缘添加标签会影响这些节点的定位方式,而我所不了解的方式。

Am I missing something trivial, or am I attempting something I shouldn't instead of letting dot do its thing? 我是在错过一些琐碎的事情,还是在尝试一些我不应该做的事情,而不是让dot做它的事情?

I'm using dot - graphviz version 2.36.0 (20140111.2315) and the linked pictures were produced with dot only (though I obtained similar results when using : 我正在使用点-graphviz版本2.36.0(20140111.2315)并且链接图片仅使用点来生成(尽管在使用时我得到了类似的结果:

dot test_alignment.dot -Tpng -O

You may try to use the xlabel attribute, together with forcelabels if necessary. 如果必要,您可以尝试将xlabel属性与forcelabels一起使用。 From the description: 根据描述:

... For edges, the label will be placed near the center of the edge. ...对于边缘,标签将放置在边缘中心附近。 This can be useful in dot to avoid the occasional problem when the use of edge labels distorts the layout. 这在点中很有用,可以避免在使用边缘标签使布局变形时偶尔出现的问题。 ... ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM