Graphviz Dot将节点放在子图中,即使它已经在别处定义。

4

我正在尝试制作一个用于作业问题的dot脚本生成器,进展顺利,但是我遇到了这样的问题:一些未在子图中定义的节点被放置在其中。例如以下dot脚本:

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"];
}

生成这个图片enter image description here “车辆”节点应该在“福特”子图之外。我错过了什么?
1个回答

1
这将会给你想要的东西:
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"];
}

1
换句话说,边被指定的位置(在源代码中)似乎可以改变节点在子图内/外的位置。解决方案:将边写在任何子图之外。 - Stéphane Gourichon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接