2016-11-11 55 views
2

我可以使用“记录”来绘制一个阵列像这样的:的Graphviz画数组

graph G{ 
node [shape = record]; 
node0 [fontsize=13, label ="A[0]|A[1]|A[2]"]; 
} 

但如何我可以得出这样的一个 http://sites.tufts.edu/comp15/files/2013/06/pic2_1darrays1.png

特别是,我怎么能添加数组中每个单元格的索引号,如0,1,2,3,4,5。

我应该使用哪种节点形状?


更新于2016年11月11日

好吧,我得到了基于答案从https://stackoverflow.com/a/37986662/5374561

它的代码是在这里:

digraph so 
{ 
rankdir=LR; 
    subgraph cluster0 
    { 
     rank = same{ Array notes } 
     color = white; 
     Array [ shape = record, label = "{ A | B | C | D }"] ; 
     notes [ shape = record, color = white, label = "{ 0 | 1 | 2 | 3 }" ]; 
     Array -> notes[ style = invis ]; 
    } 
    nodesep = .0; 
} 

但结果是不完善。还有其他方法吗?


更新在2016/8/9

从tequlia2pop解决方案(谢谢)是接近原始照片,而是从“指针”行至“价值”应该是一条直线。

回答

1
digraph { 
    node [shape=plaintext, fontcolor=red, fontsize=18]; 
    "Pointers:" -> "Values:" -> "Indices:" [color=white]; 

    node [shape=record, fontcolor=black, fontsize=14, width=4.75, fixedsize=true]; 
    pointers [label="<f0> A | <f1> A+1 | <f2> A+2 | <f3> A+3 | <f4> A+4 | <f5> A+5", color=white]; 
    values [label="<f0> A[0] | <f1> A[1] | <f2> A[2] | <f3> A[3] | <f4> A[4] | <f5> A[5]", color=blue, fillcolor=lightblue, style=filled]; 
    indices [label="0 | 1 | 2 | 3| 4 | 5", color=white]; 

    { rank=same; "Pointers:"; pointers } 
    { rank=same; "Values:"; values } 
    { rank=same; "Indices:"; indices } 

    edge [color=blue]; 
    pointers:f0 -> values:f0; 
    pointers:f1 -> values:f1; 
    pointers:f2 -> values:f2; 
    pointers:f3 -> values:f3; 
    pointers:f4 -> values:f4; 
    pointers:f5 -> values:f5; 
} 

其产生

image link