Graphviz: Putting a Caption on a Node In Addition to a Label
Asked Answered
F

1

75

In my Graphviz graph (written in DOT), I want each node to have a label, but in addition to that, I want some nodes to have a small caption denoting some other unique value for that node. For example, if this were for a history diagram, a node's label might be something like "Birth of George Washington" and the caption might read "See also: American Revolution."

This is fairly flexible, so the caption doesn't necessarily need to be inside the node, but I do need some other way of putting text that clearly isn't part of the label (e.g. is a different size, possibly a different color) and is in a different location but is still clearly a part of the node.

Is there any way to do this?

Fere answered 9/10, 2013 at 18:49 Comment(0)
L
119

To place captions outside the node, you may use xlabel:

digraph g {
    forcelabels=true;
    a [label="Birth of George Washington", xlabel="See also: American Revolution"];
    b [label="Main label", xlabel="Additional caption"];
    a-> b;
}

forcelabels=true makes sure no xlabel is omitted.

xlabel for nodes example


A second option is to use HTML-like labels:

digraph g {
    a[label=<Birth of George Washington<BR />
        <FONT POINT-SIZE="10">See also: American Revolution</FONT>>];
}

html like labels example

Lollapalooza answered 9/10, 2013 at 19:43 Comment(5)
I'm putting this on a webpage and overlaying this with an image map in the HTML so that nodes can be clickable and redirect to URLs. I've found that doing it the second way with < and > to contain the name causes the image map to create a title for that element, and then when you move your mouse over the node to click it, a text box appears with the raw HTML, like the br tag. But if I put quotes, then it displays the font tags and so on as part of the node name, rather than putting the caption like I want. Is there a way to stop that title from being created?Fere
xlabels were implemented after graphviz 2.28 which is still installed on older linux machines.. so if you have some problems with this that's one of the first things to check.Outstrip
A.Duff said: I'm putting this on a webpage and overlaying this with an image map in the HTML so that nodes can be clickable and redirect to URLs. My note: I created an SVG output format image for that. I can use the SVG image as a web page with clickable nodes to download software releases and clickable links to the tickets for the features added between releases. SVG seemed to be the only image format which directly contained URL links embedded in the image by graphviz itself.Numeral
Is there a way to make additonal caption a callout, like: pinclipart.com/pindetail/…?Alonso
Is it possible to position labels?Richelieu

© 2022 - 2024 — McMap. All rights reserved.