Represent array with indices using dot record nodes (Graphviz)

£可爱£侵袭症+ 提交于 2019-12-12 05:37:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!