Record and struct (GraphViz)

Record shapes give a node internal structure, and edges can point at an individual field. That is what makes Graphviz workable for data structure diagrams.


#What this example shows

  • shape=record with pipe-separated fields.

  • Named ports, addressed as node:port in an edge.

  • A linked list, drawn without any manual positioning.


#A worked example

Open it, edit it, or copy the source below.

Record and struct (GraphViz)

The source, which you can paste into a new diagram and edit:

digraph structs {
  rankdir=LR;
  node [shape=record, fontname="Helvetica", fontsize=10];

  head [label="<f0> head", shape=plaintext];

  n1 [label="{<data> 42 | <next> next}"];
  n2 [label="{<data> 17 | <next> next}"];
  n3 [label="{<data> 93 | <next> null}"];

  table [label="{orders | {id | uuid} | {customer_id | uuid} | {status | text} | {total | numeric}}"];

  head:f0 -> n1:data;
  n1:next -> n2:data;
  n2:next -> n3:data;
  n3:next -> table [style=dashed, label="row per order"];
}

#Making it your own

  • Angle brackets define a port name; a colon in an edge addresses it.

  • Braces flip the field direction, which is how you get a vertical record.

  • Escape any literal pipe, brace or angle bracket inside a label.



Give it the edges. It does the rest.