graphviz - 如何用 GraphViz 分离节点的图片和标签?
问题描述
我正在尝试使用 GraphViz 显示带有图像和标签的图形。我想在图像下显示标签(参见labelloc="b"
图表上的选项),但不知何故它不起作用。标签和图像重叠。
知道我缺少什么吗?
下面是我正在使用的 DOT 代码和当前结果。
谢谢!
digraph {
graph [compound=true, labelloc="b"];
node [shape=box];
edge [dir=none];
Label1[label="Label1",image="images/Avatar1.png"];
Label2[label="Label2",image="images/Avatar2.png"];
Label3[label="Label3",image="images/Avatar3.png"];
{
rank=same;
Label1 -> h0 -> Label2;
h0[shape=circle,label="",height=0.01,width=0.01];
}
{
h0_0;
h0_0[shape=circle,label="",height=0.01,width=0.01];
}
h0 -> h0_0;
h0_0 -> Label3;
}
解决方案
UPD:您只需将imagepos属性添加到您的解决方案中height
:
digraph {
graph [compound=true, labelloc="b"];
node [shape=box];
edge [dir=none];
Label1[
label="Label1"
height="2.1"
imagepos="tc"
labelloc="b"
image="images/Avatar1.png"
];
Label2[
label="Label2"
height="2.1"
imagepos="tc"
labelloc="b"
image="images/Avatar2.png"
];
Label3[
label="Label3"
height="2.1"
imagepos="tc"
labelloc="b"
image="images/Avatar3.png"
];
{
rank=same;
Label1 -> h0 -> Label2;
h0[shape=circle,label="",height=0.01,width=0.01];
}
{
h0_0;
h0_0[shape=circle,label="",height=0.01,width=0.01];
}
h0 -> h0_0;
h0_0 -> Label3;
}
结果:
或者你也可以使用类似 HTML 的标签,特别是表格:
digraph {
graph [compound=true, labelloc="b"];
node [shape=box];
edge [dir=none];
Label1 [
shape=plain
label=<
<table cellspacing="0" border="0" cellborder="1">
<tr><td><img src="images/Avatar1.png" /></td></tr>
<tr><td>Label1</td></tr>
</table>
>
];
Label2 [
shape=plain
label=<
<table cellspacing="0" border="0" cellborder="1">
<tr><td><img src="images/Avatar2.png" /></td></tr>
<tr><td>Label2</td></tr>
</table>
>
];
Label3 [
shape=plain
label=<
<table cellspacing="0" border="0" cellborder="1">
<tr><td><img src="images/Avatar3.png" /></td></tr>
<tr><td>Label3</td></tr>
</table>
>
];
{
rank=same;
Label1 -> h0 -> Label2;
h0[shape=circle,label="",height=0.01,width=0.01];
}
{
h0_0;
h0_0[shape=circle,label="",height=0.01,width=0.01];
}
h0 -> h0_0;
h0_0 -> Label3;
}
代码有点复杂(乍一看),但作为奖励,您可以更灵活地控制边界。结果:
推荐阅读
- label - 我想在标签中显示列表框项目的总量
- c# - 使用 MediaElement 在 UWP 中播放 UDP H.264 字节流
- python - 将多个 Python 子解释器嵌入到 C 程序中
- javascript - 使用服务器端处理的 AngularJS 数据表的计算列的事件
- ubuntu - Docker 运行容器并修改环境设置
- java - 正则表达式返回行,如果它包含所有字母并且整个字符串中只有 2 个大写字母
- shell - 如何将输出重定向到文件,如果它不存在则不创建它?
- html - 在 Bootstrap 中编辑导航窗格
- java - 如何使用 AsyncTask 向目标发送多个请求
- reactjs - 在表单提交后使用 ant design 在 react 中设置表单文本字段值