使用 PNG 或 SVG 图像作为 Graphviz 节点。

12

我曾尝试在Graphviz中使用自定义图像节点(节点d):

digraph foo {
    rankdir=LR;
    node [shape=record];
    a [label="{ <data> 12 | <ref>  }", width=1.2]
    b [label="{ <data> 99 | <ref>  }"];
    c [label="{ <data> 37 | <ref>  }"];
    d [image="X_Shape_Pillar_Yellow.png"];
    a:ref:c -> b:data [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false, arrowsize=1.2];
    b:ref:c -> c:data [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
    c:ref:c -> d      [arrowhead=vee, arrowtail=dot, dir=both, tailclip=false];
}

很遗憾,这张图片无法显示:

enter image description here

我使用以下方式编译了dot文件:

dot -v -Tpng list.dot -o list.png

我的代码,包括png图片,存储在Github上

如何使用自定义图像替换节点d

1个回答

13

只需为此节点定义另一个形状,例如 shape=none:

d [shape=none, label="", image="X_Shape_Pillar_Yellow.png"];

默认情况下,以record 形式定义的形状不显示图像,而nonebox 甚至 plaintext 形式会显示。

同时,将标签设置为空可能是一个好主意。


1
可以运行,谢谢!https://github.com/adamatan/graphviz_linked_list/blob/master/list.png - Adam Matan
在设置图像之前,必须先使用shape=none。 - morpheus
1
我不知道这个解决方案是否还有效。在上面的 GitHub 链接中,似乎不再添加该图像。 - Lionel Duarte

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接