How to add an annotation outside of a node in Graphviz' dot?
Asked Answered
J

2

17

I am very new to Dot and trying to visualize a callgraph with Dot and Zest in Eclipse. And I would like to annotate nodes with kind of annotation (OK and Failed on the pic.).

Annotated graph I want to get

Is there any common way to do this for Dot or Zest?

Jeanelle answered 11/4, 2014 at 17:11 Comment(0)
C
18

xlabel

Have a look at xlabel (external label).

main.dot

graph {
    node [shape=square];
    1 [xlabel="a"]
    2 [xlabel="b"]
    1 -- 2;
}

Convert:

dot -Tpng main.dot > main.png

Output:

enter image description here

Not sure however how easily you can control exact label placement with this method: even overlaps can happen by default. See:

shape=record

I just tend to prefer the shape=record approach mentioned by https://mcmap.net/q/705278/-how-to-add-an-annotation-outside-of-a-node-in-graphviz-39-dot or their generalization, HTML-like labels, as it makes it clearer what label belongs to each node:

graph {
    rankdir=LR
    node [shape=record];
    1 [label="1|a"]
    2 [label="2|b"]
    1 -- 2;
}

Output:

enter image description here

TODO can you avoid typing 1 and 2 twice?

Tested on Ubuntu 16.10, graphviz 2.38.

Craiova answered 26/12, 2016 at 19:52 Comment(0)
H
0

It's not supported by the Zest rendering, but on the DOT level you could use record-based nodes:

rankdir=LR;
node [shape=record];
m1[label="void m1()|OK"];
m1[label="void m2()|Failed"];

For details see http://www.graphviz.org/doc/info/shapes.html#record

Haymes answered 12/4, 2014 at 14:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.