Change font attributes within a (node) label's text?

Using dot:
MyMessageBox [label = “WARNING\nThis may be the most boring graph you’ve ever seen.”

I’d like “WARNING” in red, with the rest of the label text in black. And might possibly want to change fonts at that point, or some other.

How, if at all, can dot produce this effect?

1 Like

HTML-like labels (Node Shapes | Graphviz) allow this. You do not need any of the <TABLE stuff, just look at label, text and textitem.
Like so:

digraph H {
  a [label=<<FONT COLOR="RED" POINT-SIZE="24.0" FACE="ambrosia">line4</FONT> and then more stuff>]
  b [label=simple]
  c
  a->b->c
}

Giving:
htmlText

1 Like

Steve: I pasted your sample into WebGraphViz on my browser, then clicked Generate Graph!. The result was:

Warning: Not built with libexpat. Table formatting is not available in label of node a.
image
I don’t know if that image shows…I’m new around here and may have mucked this up…
At any rate, the upper bubble just said a : it didn’t have any of your formatting.

I did some more experimenting in another diagram, taking a box with a label and replacing the " . . ." with < . . . >, as specified in the html-label documentation. (There were no special characters inside the label.) Various things went wrong, but I don’t think it would be enlightening to describe them.

Finally, I inserted you “a” line of text into my own diagram. It just added an a with an elllipse aroud it to a spot in the diagram, and gave the same warning that you got.

I’ll be grateful for any suggestions about what the next step should be.

Thanks for your help with this.

–Kirk

If WebGraphViz can’t produce HTML-like labels, and if a multi-color label is important to you, I suggest you install the Graphviz package on your computer or try one of the other interactive packages listed here: External Resources | Graphviz

Thanks… I had seen only viz.js, not the others listed. I actually tried installing one of the current Windows versions before falling back on WebGraphviz: but the installation gave peculiar results and I couldn’t get the program to run.

Since I haven’t found anybody who’s associated with WebGraphviz, I’ll probably have to try an alternative. Fingers crossed.

I normally use Graphviz on a Linux system, but I just

  • downloaded and installed stable_windows_10_cmake_Release_x64_graphviz-install-2.48.0-win64.exe form here Download | Graphviz
  • “opened” it to inslall it
  • added it to PATH during the installation
  • brought up a Windows “cmd” screen
  • and used this command to successfully run dot and create an SVG output file:
    dot -Tsvg unix.gv >O.svg

I hope this helps

WebGraphViz actually uses “Viz.js” under the covers which is an old and archived project.
@hpcc-js/wasm - GitHub - hpcc-systems/hpcc-js-wasm: HPCC-Systems Web-Assembly (JavaScript) is similar (but maintained and up to date), you can see a test of the above here: HTML attributes in GraphViz / Gordon Smith / Observable (observablehq.com)

You can try the Grapviz Visual Editor which is based on @hpcc-js/wasm that Gordon mentioned and thanks to that supports HTML-like attributes.

You might still have the usual problems with web fonts. The link above does not look good with Firefox on my Ubuntu 21.04, but here’s an example without font specififcation that looks good.

1 Like

Nice to know, thanks

1 Like

Thanks for the link. The tool looks great: very slick editing of both text and graphs. I’ve pasted 5 test dot files into the tool in turn, and it automatically generated all their graphs correctly.

However, one of the test graphs was about 2/3 off of the drawing canvas (to the left); but when I backed up to the previous file and then re-advanced to the problem one, it presented properly. I mention that on the off chance that it’s related to the following problem:

When I paste my own dot file (177 lines) into the Graphviz Visual Editor, there is no visible change to the 34" display. even after an hour or more. The same dot file generates a graph in a second or two on WebGraphviz.

Have you any pointers on what I might be doing wrong?

Please share the problematic DOT source code and I will have a look at it.

Here’s my code. Thanks for your help.

(Attachment Sample Graphviz for Magnus Jacobsson.txt is missing)

I tried to send DOT code (with extension txt) but it bounced because of the invalid extension: the system wants jpg, jpeg, png, gif, svg

The message suggested I contact a staff member, and you were the first one listed. Should I just switch to one of the 5 even though it would be inaccurate or is there a better way?

You can email it to me. I’ve sent my email address in a private message.

Just to let you know I’m not ignoring your note (if it matters). Thanks for letting me know what worked for you. My concern is that even if I do get GraphViz running on my Windows system, I’ll lack the font/face information that the documentation indicates is required in order to take control over text appearance. So now that I have Graphviz Visual Editor and thus HTML–your tip on that was critical–Windows is some way down the todo list.

After two minor fixes to the DOT source we ended up with this graph.

1 Like