问题
I'm using Graphviz to represent arrays, using subgraphs
and record
nodes:
subgraph cluster_array
{
label="my array"
Array [shape="record", label="A | B | C | D"]
Array
}
I would like to add external indices for each array elements, mapping 0 -> A
, 1 -> B
and so on.
I want to achieve a result similar to:
I've searched online and tried using xlabel
but couldn't find a way to correctly add a label for each record element. I've also tried making the indices part of the label, and moving the label with lp
, but it seems to have no effect on record
nodes.
Is it possible to add external element labels to record
nodes using GraphViz?
回答1:
Not a real answer to your question (which, I think, would be "no") but a workaround that may give you what you want. I use a "parallel" record node with no borders (or paper color borders, to be exact), located very close and connected by an invisible edge:
digraph so
{
subgraph cluster0
{
rank = same{ Array notes }
color = white;
Array [ shape = record, label = "{ A | B | C | D }"] ;
notes [ shape = record, color = white, label = "{ a_1 | b_2 | c_3 | d_4 }" ];
Array -> notes[ style = invis ];
}
nodesep = .0;
X -> Array -> Z;
}
which yields
来源:https://stackoverflow.com/questions/37969317/represent-array-with-indices-using-dot-record-nodes-graphviz