首页 > 解决方案 > 两个子图中的相同节点

问题描述

我想在两个子图周围画一个边框,但我有一个属于两个子图的节点。

digraph {
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }

    subgraph cluster_1 {
            color = blue

            B -> C
            B -> E
            C -> E
    }
}

现在C应该是两个集群的一部分-相反,我得到了这个:

C 应该是两个子图的一部分

标签: graphvizdot

解决方案


There s a difference between tha name / label of a node and its identification. When a node has no name / label ithe identification is taken as name / label.

Not sure if the following is what uou intended (otherwise clarify you question).

digraph {
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }

    subgraph cluster_1 {
            color = blue
            node C2 [label="C"]
            B -> C2
            B -> E
            C2 -> E
    }
}

From the comment of OP (image should be in original question) looks like OP wants something more like:

digraph {
    subgraph cluster_2 {
    color = none;
    node C
    }
    subgraph cluster_0 {
            color = red

            A -> D
            A -> C
            C -> D
    }

    subgraph cluster_1 {
            color = blue

            B -> C
            B -> E
            C -> E
    }
}

this image does not provide the exact picture OP wants but I think a direction and with some ran setting together with some hidden nodes and edges it should give the right picture.


推荐阅读