4

I am trying to make a dot script generator for a homework problem, it's going well except I have this issue where some nodes that are not defined in subgraphs are being placed in them. For example the following dot script:

digraph dg {
    compound=true;
    labelloc="t";
    label="test.cpp";
    Vehicle;
    Make;
    subgraph clusterFord {
        label="Ford"
        Ford[shape="none"][style="invis"][label=""];
        Mustang -> Vehicle [label="private"];
        Thunderbird -> Vehicle [label="private"];
    }
    Ford -> Make [label="public"][ltail ="clusterFord"];
    subgraph clusterChevrolet {
        label="Chevrolet"
        Chevrolet[shape="none"][style="invis"][label=""];
        Camero -> Vehicle [label="private"];
    }
    Chevrolet -> Make [label="public"][ltail ="clusterChevrolet"];
}

Generates this image: enter image description here

The "Vehicle" node is supposed to be outside of the "Ford" subrgraph. What am I missing here?

Axel Kemper
  • 10,544
  • 2
  • 31
  • 54
agilesynapse
  • 41
  • 1
  • 5

1 Answers1

1

This will give what you want:

digraph dg {
    compound=true;
    labelloc="t";
    label="test.cpp";
    subgraph clusterFord {
        label="Ford"
        Ford[shape="none"][style="invis"][label=""];
        Mustang
        Thunderbird
    }
    subgraph clusterChevrolet {
        label="Chevrolet"
        Chevrolet[shape="none"][style="invis"][label=""];
        Camero
    }
    Ford -> Make [label="public"][ltail ="clusterFord"];
    Chevrolet -> Make [label="public"][ltail ="clusterChevrolet"];
    Mustang -> Vehicle [label="private"];
    Thunderbird -> Vehicle [label="private"];
    Camero -> Vehicle [label="private"];
}
Bodey Baker
  • 296
  • 2
  • 11
  • 1
    In other words, it looks like the location (in source code) where an edge is specified can change the position (in/out of subgraph) of the nodes. Solution: write the edge outside of any subgraph. – Stéphane Gourichon Feb 09 '18 at 08:07