简体   繁体   English

graphviz/dot graph:对集群/子图中的节点进行排序

[英]graphviz/dot graph: Order nodes within a cluster/a subgraph

Help sort nodes within subgraphs or clusters such as subgraph A and B below.帮助对子图或集群中的节点进行排序,例如下面的子图 A 和 B。

graph {
    splines=line;
    subgraph cluster_0 {
        label="Subgraph A";
        a; b; c
    }

    subgraph cluster_1 {
        label="Subgraph B";
        d; e;
    }

    a -- e;
    a -- d;
    b -- d;
    b -- e;
    c -- d;
    c -- e;
}

This graph is not desirable.这个图是不可取的。 Help us sort "a", "b", "c" and "d", and "e" from left-to-right, please.请帮助我们从左到右对“a”、“b”、“c”和“d”以及“e”进行排序。

https://graphs.grevian.org/resources/static/images/example6a.png https://graphs.grevian.org/resources/static/images/example6a.png

I found this difficult to do, and don't guarantee that it works with a more complex graph.我发现这很难做到,并且不保证它适用于更复杂的图形。 In addition to getting the nodes in the desired sequence, it is quite difficult to position clusters where you want.除了按所需顺序获取节点之外,将集群定位在您想要的位置也非常困难。 That said, this:也就是说,这个:

graph {
    splines=line;
    rankdir=LR

    subgraph cluster_0 {
        label="Subgraph A";
        rank=same
        a -- b -- c [style=invis]
    }

    subgraph cluster_1 {
        label="Subgraph B";
        rank=same
        d -- e  [style=invis]
    }

  edge[constraint=false]
    a -- e;
    a -- d;
    b -- d;
    b -- e;
    c -- d;
    c -- e;
}

produces this:产生这个:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM