Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw three squares, one inside another, with Graphviz

I'm using Graphviz tool in dot language using Linux. I want to draw three squares, one inside another. The below code is incorrect:

graph A
 { label="a";

   subgraph cluster_A
     {
        b [shape=box,label="b"];
           subgraph cluster_b
                { 
                 c[label="c",shape=box];
                }
     }

 }
like image 662
bansal Avatar asked Mar 16 '23 06:03

bansal


1 Answers

you have multiple possibilities to do that

  • box node in cluster in cluster
  • plaintext node in cluster in cluster in cluster
  • node with HTML like label and HTML tables

box in clusters:

graph "graph A"
{
    label="\G"
    subgraph "cluster A"
    {
        subgraph "cluster B"
        {
            c[shape=box];
        }
    }
}

enter image description here

plaintext in clusters:

graph "graph A"
{
    label="\G"
    subgraph "cluster A"
    {
        subgraph "cluster B"
        {
            subgraph "cluster C"
            {
                d[shape=none];
            }
        }
    }
}

enter image description here

both variants have the labels set to their names which is default for nodes but not for graphs (and all included subgraphs). as the graph label is inherited you can either set all labels manually or use the name palceholder as I did.

for HTML like lables

graph "graph A"
{
    label="\G"
    a [shape=none label=<<table><tr><td><table><tr><td><table><tr><td>node a</td></tr></table></td></tr></table></td></tr></table>>];
}

you have a lot more of freedom in formatting (margin, padding, border, ...)

enter image description here

like image 56
stefan Avatar answered Mar 23 '23 22:03

stefan