Graphviz:将边缘标签放在另一侧(II) [英] Graphviz: Place edge label on the other side (II)

查看:267
本文介绍了Graphviz:将边缘标签放在另一侧(II)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题是:

Graphviz:将边缘标签放在另一侧

如何在graphviz的边缘上放置边缘标签

考虑以下点文件:

digraph {
0 -> 1 [ len=2, label="(1, 0)"];
0 -> 1 [ len=0.5, dir=none, weight=10];
1 -> 0 [ len=2, label="(0, -1)"];
}

给出以下结果:

我如何设法获得对称版本? (0,-1)应该在右手的左边.

How can I manage to get a symmetric version? (0,-1) should be left of the right egde.

推荐答案

正如您所发现的,graphviz不允许您选择水平标签放置,因此所有解决方案都有些笨拙.

As you've found out, graphviz doesn't let you choose horizontal label placement, so all solutions are slightly hacky.

尝试#1:marapet发布的两个解决方案(这里)

Attempt #1: The two solutions posted by marapet (here)

  1. labelangle和labeldistance技巧不适用于 标签文本的长度不同(您必须重新计算新的 距离/角度数).

  1. The labelangle and labeldistance trick doesn't adapt well to different lengths of label text (you'd have to recalculate new distance/angle numbers).

splines = false技巧在其中 节点之间的边>节点数(最终得到 重叠的边缘.)

The splines=false trick doesn't work so well where the number of edges between nodes > the number of nodes (you end up with overlapping edges).

尝试#2:使用xlabel和锚点创建弯曲的边缘

这使用了graphviz的一个相对较新的功能, xlabel (将标签放置在确定了节点/边的坐标之后). 端口功能用于创建弯曲的边缘.标签上的填充是使用空格字符完成的.

This uses a relatively new feature of graphviz, xlabel (which places the label AFTER the coordinates for the nodes/edges have been decided). The ports feature is used to create curved edges. The padding on the labels is achieved with space characters.

digraph {
forcelabels=true;

    0:sw -> 1:nw [ dir=forward, xlabel="  (1, 0)  "];
    0 -> 1 [dir=none];
    1:ne -> 0:se [ dir=backward, xlabel= "  (0, -1)  "];

}

我相信您需要graphviz版本> 2.29才能使用xlabel.

I believe you need graphviz version >2.29 to use xlabel.

这篇关于Graphviz:将边缘标签放在另一侧(II)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆