graphvizsubgraph

Graphs and subgraphs layout


Using graphviz I want to generate the following graph (manually written in tikz for now):

s://i.sstatic.net/Szu8i.png

I currently succeeded in writing a dot file giving me the following result (there is a single node using html for the Pile table on the top, and one node also using html for every grey box):

enter image description here

But unfortunately I was not able to keep the layout of grey boxes that I like AND to have the grey boxes on the right of the Pile table. I read carefully this related question and tried things with rank, subgraphs and rankdir without success.

Is there any hope to reach my goal with dot ?

EDIT: here is the complete dot file I have currently

digraph structs {
node [shape=plaintext]
subgraph stack {
label = STACK;
stack [label=<
<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" BGCOLOR="white">
<TR><TD><i>Nom</i></TD><TD><i>Type</i></TD><TD><i>Portée</i></TD><TD><i>Valeur</i></TD></TR>
<TR><TD BGCOLOR="chartreuse">list2</TD><TD BGCOLOR="chartreuse">référence</TD><TD BGCOLOR="chartreuse">main</TD><TD PORT="port_140407657518560" BGCOLOR="chartreuse">0x7f
b334a23ac0</TD></TR>
<TR><TD BGCOLOR="chartreuse">list1</TD><TD BGCOLOR="chartreuse">référence</TD><TD BGCOLOR="chartreuse">main</TD><TD PORT="port_140407657518032" BGCOLOR="chartreuse">0x7f
b334a23ac0</TD></TR>
</TABLE>
>
];
}
subgraph heap {
label = HEAP;
  struct_140407658920640 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD COLSPAN="6">0x7fb334a23ac0</TD></TR>
<TR><TD COLSPAN="6"><u>list</u></TD></TR>
<TR><TD PORT="port_child0">0x955e80</TD>
<TD PORT="port_child1">0x956360</TD>
<TD PORT="port_child2">0x956040</TD>
<TD PORT="port_child3">0x7fb3348cbbb0</TD>
<TD PORT="port_child4">0x7fb3348cbc30</TD>
<TD PORT="port_child5">0x7fb3348cbc70</TD>
</TR>
</TABLE>>];
  struct_9789056 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x955e80</TD></TR>
<TR><TD><u>int</u></TD></TR>
<TR><TD>3</TD></TR>
</TABLE>>];
struct_140407658920640:port_child0 -> struct_9789056;
  struct_9790304 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x956360</TD></TR>
<TR><TD><u>int</u></TD></TR>
<TR><TD>42</TD></TR>
</TABLE>>];
struct_140407658920640:port_child1 -> struct_9790304;
  struct_9789504 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x956040</TD></TR>
<TR><TD><u>int</u></TD></TR>
<TR><TD>17</TD></TR>
</TABLE>>];
struct_140407658920640:port_child2 -> struct_9789504;
  struct_140407657511856 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x7fb3348cbbb0</TD></TR>
<TR><TD><u>str</u></TD></TR>
<TR><TD>"go"</TD></TR>
</TABLE>>];
struct_140407658920640:port_child3 -> struct_140407657511856;
  struct_140407657511984 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x7fb3348cbc30</TD></TR>
<TR><TD><u>str</u></TD></TR>
<TR><TD>"feu"</TD></TR>
</TABLE>>];
struct_140407658920640:port_child4 -> struct_140407657511984;
  struct_140407657512048 [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
<TR><TD>0x7fb3348cbc70</TD></TR>
<TR><TD><u>str</u></TD></TR>
<TR><TD>"partez"</TD></TR>
</TABLE>>];
struct_140407658920640:port_child5 -> struct_140407657512048;
}
stack:port_140407657518560 -> struct_140407658920640;
stack:port_140407657518032 -> struct_140407658920640;
}

Solution

  • Minor changes

    digraph structs {
    node [shape=plaintext]
    subgraph cluster_stack {  // changed to cluster
    graph [peripheries=0]     // no box around this cluster
    label = STACK;
    stack [label=<
    <TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" BGCOLOR="white">
    <TR><TD><i>Nom</i></TD><TD><i>Type</i></TD><TD><i>Porté?e</i></TD><TD><i>Valeur</i></TD></TR>
    <TR><TD BGCOLOR="chartreuse">list2</TD><TD BGCOLOR="chartreuse">ré?fé?rence</TD><TD BGCOLOR="chartreuse">main</TD><TD PORT="port_140407657518560" BGCOLOR="chartreuse">0x7f
    b334a23ac0</TD></TR>
    <TR><TD BGCOLOR="chartreuse">list1</TD><TD BGCOLOR="chartreuse">ré?fé?rence</TD><TD BGCOLOR="chartreuse">main</TD><TD PORT="port_140407657518032" BGCOLOR="chartreuse">0x7f
    b334a23ac0</TD></TR>
    </TABLE>
    >
    ];
    }
    subgraph cluster_heap {  // changed to cluster
    label = HEAP;
      struct_140407658920640 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD COLSPAN="6">0x7fb334a23ac0</TD></TR>
    <TR><TD COLSPAN="6" port="myport"><u>list</u></TD></TR>
    <TR><TD PORT="port_child0">0x955e80</TD>
    <TD PORT="port_child1">0x956360</TD>
    <TD PORT="port_child2">0x956040</TD>
    <TD PORT="port_child3">0x7fb3348cbbb0</TD>
    <TD PORT="port_child4">0x7fb3348cbc30</TD>
    <TD PORT="port_child5">0x7fb3348cbc70</TD>
    </TR>
    </TABLE>>];
      struct_9789056 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x955e80</TD></TR>
    <TR><TD><u>int</u></TD></TR>
    <TR><TD>3</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child0 -> struct_9789056;
      struct_9790304 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x956360</TD></TR>
    <TR><TD><u>int</u></TD></TR>
    <TR><TD>42</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child1 -> struct_9790304;
      struct_9789504 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x956040</TD></TR>
    <TR><TD><u>int</u></TD></TR>
    <TR><TD>17</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child2 -> struct_9789504;
      struct_140407657511856 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x7fb3348cbbb0</TD></TR>
    <TR><TD><u>str</u></TD></TR>
    <TR><TD>"go"</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child3 -> struct_140407657511856;
      struct_140407657511984 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x7fb3348cbc30</TD></TR>
    <TR><TD><u>str</u></TD></TR>
    <TR><TD>"feu"</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child4 -> struct_140407657511984;
      struct_140407657512048 [label=<
    <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" BGCOLOR="gray">
    <TR><TD>0x7fb3348cbc70</TD></TR>
    <TR><TD><u>str</u></TD></TR>
    <TR><TD>"partez"</TD></TR>
    </TABLE>>];
    struct_140407658920640:port_child5 -> struct_140407657512048;
    }
    edge [constraint=false]  // do not use next two edges to position nodes/clusters
    stack:port_140407657518560 -> struct_140407658920640:myport
    stack:port_140407657518032 -> struct_140407658920640
    // add invisible edge & use to position nodes/clusters
    edge [constraint=true style=invis]  
    stack:port_140407657518032 -> struct_9789056
    }
    
    

    Giving:
    enter image description here