graphviz: record node with a bold title

eordano picture eordano · May 30, 2011 · Viewed 9k times · Source

I'm trying to use graphviz to do something similar to UML class diagrams.

I wonder whether there is a way to make a node of style 'register' have its first field in a bold font, to make it different from the other fields.

My node looks like this:

digraph i { 
  "node" [
    label = "<f0> title | <f1> index | ... | <f2> field1 | <f3> field2"
    shape = "record"
  ];  
}

I tried this but it doesn't work: (embedding html)

digraph i { 
  "node" [
    label = "<f0> <B>title</B> | <f1> index | ... | <f2> field1 | <f3> field2"
    shape = "record"
  ];  
}

Answer

Dan picture Dan · May 30, 2011

I don't believe record-based nodes allow HTML formatting in them. The node shape documentation suggests that record-based nodes have been deprecated in favor of using a none-shaped node with an HTML-like label, which is much more flexible with formatting. These labels are surrounded with <> instead of double quotes.

I haven't been able to test this, but this is close to what you want:

digraph i { 
  "node" [
    label =<<TABLE BORDER="1" CELLBORDER="1" CELLSPACING="0">
                    <TR><TD PORT="f0"><B>title</B></TD></TR>
                    <TR><TD PORT="f1">index</TD></TR>
                    <TR><TD PORT="f2">field1</TD></TR>
                    <TR><TD PORT="f3">field2</TD></TR>
                </TABLE>>
    shape = "none"
  ];  
}

Output:

enter image description here