DOT:如何将群集放置在同一级别而不将这些群集中的节点平均排名?

时间:2019-05-04 16:34:08

标签: graphviz dot

我有下面的DOT代码。它描述了五个子图(群集)。我对两个较低聚类的渲染以及聚类的相对位置(三个在相同级别的顶部,两个在各个顺序的底部)感到满意。但是,我希望上面三个群集中的节点按照它们节点的内部关系进行排序,这与下面两个群集中的节点相似(如您所见,上面群集中的节点全部呈现在一个单行,尽管其中一些之间存在隐藏的边缘)。

我了解到它们不是rank=same;命令的原因。但是,如果删除该位置,则会丢失群集的位置。我使用命令的不同组合和其他clusterrank=local;尝试了几种变体,但以下结果保持最接近。同样,subgraph cluster ranking in dot并没有得到我想要的东西。

digraph G {

    splines=line;
    size=1;
    ranksep=2;
    newrank=true;
    rankdir=BT

    subgraph cluster_z {
      label="Z";
      rank=same;

      "ZSF" [fillcolor = red];
      "ZTA" [fillcolor = red]; 
      "ZSS" [fillcolor = red];
      "ZIN" [fillcolor = red];
      "ZOW" [fillcolor = red];
      "ZNT" [fillcolor = red];
      "ZSS" [fillcolor = red];
      "ZCE" [fillcolor = red];
      "ZAY" [fillcolor = red];
      "ZNT" [fillcolor = red];
      "ZTA" [fillcolor = red];
      "ZTA" [fillcolor = red];
      "ZST" [fillcolor = red];
      "ZTO" [fillcolor = red];
      "ZON" [fillcolor = red];
      "ZPP" [fillcolor = red];
      "TNT" [fillcolor = red];
      "TCE" [fillcolor = red];
      "TNT" [fillcolor = red];


      "ZNT" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]
      "ZSF" -> "ZNT" [style=invis]

      "ZIN" -> "ZTA" [style=invis]
      "ZTA" -> "ZON" [style=invis]
      "ZON" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]
      "ZSF" -> "ZNT" [style=invis]
      "ZNT" -> "ZIN" [style=invis]

      "ZPP" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]
      "ZSF" -> "ZPP" [style=invis]

      "ZSF" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]

      "ZOW" -> "ZSS" [style=invis]
      "ZSS" -> "ZOW" [style=invis]

      "ZAY" -> "ZCE" [style=invis]
      "ZCE" -> "ZTA" [style=invis]
      "ZTA" -> "ZAY" [style=invis]

      "ZSF" -> "ZTA" [style=invis]
      "ZAY" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]

      "ZAY" -> "ZTA" [style=invis]
      "ZTA" -> "ZTA" [style=invis]
      "ZTA" -> "ZCE" [style=invis]
      "ZCE" -> "ZTA" [style=invis]
      "ZTA" -> "ZSF" [style=invis]
      "ZSF" -> "ZAY" [style=invis]

    }

    subgraph cluster_y {
      rank=same;
      label="Y";

      "YCY" [fillcolor = blue];
      "YES" [fillcolor = blue];
    }

    subgraph cluster_w {

      rank=same;
      label="W";

      "WER" [fillcolor = green];
      "WRT" [fillcolor = green];
    }

    subgraph cluster_o {

      label="O";
      "OOL" [fillcolor = white];
      "OOL" [fillcolor = white];
      "OIT" [fillcolor = white];
      "ONT" [fillcolor = white];
      "OGE" [fillcolor = white];
      "OTA" [fillcolor = white];
      "OTA" [fillcolor = white];
      "OTS" [fillcolor = white];
      "OTS" [fillcolor = white];
      "OCE" [fillcolor = white];
      "ORT" [fillcolor = white];
      "ORT" [fillcolor = white];
      "OON" [fillcolor = white];
      "OCT" [fillcolor = white];
      "OOL" [fillcolor = white];
      "OTO" [fillcolor = white];
      "OPE" [fillcolor = white];
      "OPY" [fillcolor = white];

      "OIT" -> "ORT" [style=invis]
      "ORT" -> "OON" [style=invis]
      "OON" -> "OPE" [style=invis]
      "OPE" -> "OIT" [style=invis]

      "OON" -> "OPE" [style=invis]
      "OPE" -> "OON" [style=invis]

      "OOL" -> "OOL" [style=invis]
      "OOL" -> "OOL" [style=invis]

      "OCE" -> "OON" [style=invis]
      "OON" -> "OCE" [style=invis]

      "OTA" -> "OON" [style=invis]
      "OON" -> "OTA" [style=invis]

      "OIT" -> "OTA" [style=invis]
      "OTA" -> "ORT" [style=invis]
      "ORT" -> "ORT" [style=invis]
      "ORT" -> "OON" [style=invis]
      "OON" -> "OIT" [style=invis]

      "OIT" -> "OTA" [style=invis]
      "OTA" -> "OTS" [style=invis]
      "OTS" -> "OON" [style=invis]
      "OON" -> "OPE" [style=invis]
      "OPE" -> "OIT" [style=invis]

    }

    subgraph cluster_e {
      label="E";

      "EUT" [fillcolor = grey];
      "EON" [fillcolor = grey];
      "ERT" [fillcolor = grey];
      "ERT" [fillcolor = grey];
      "EST" [fillcolor = grey];
      "EON" [fillcolor = grey];
      "EER" [fillcolor = grey];
      "ERE" [fillcolor = grey];
      "ETO" [fillcolor = grey];

    }

    "OIT" -> "ZSF";
    "ORT" -> "ZSF";
    "OON" -> "ZSF";
    "OPE" -> "ZSF";
    "EON" -> "ZSF";
    "EER" -> "ZSF";

    "OON" -> "ZTA";
    "OPE" -> "ZTA";
    "EER" -> "ZTA";

    "OOL" -> "ZSS";
    "OOL" -> "ZSS";

    "OGE" -> "ZIN";
    "EON" -> "ZIN";

    "OOL" -> "ZOW";

    "OTS" -> "ZNT";

    "OCT" -> "ZSS";

    "OCE" -> "ZCE";
    "OON" -> "ZCE";

    "OTA" -> "ZAY";
    "OON" -> "ZAY";

    "OIT" -> "ZNT";
    "EON" -> "ZNT";

    "OIT" -> "ZTA";
    "OTA" -> "ZTA";
    "ORT" -> "ZTA";
    "ORT" -> "ZTA";
    "OON" -> "ZTA";
    "EON" -> "ZTA";
    "ERE" -> "ZTA";

    "OIT" -> "ZTA";
    "OTA" -> "ZTA";
    "OTS" -> "ZTA";
    "OON" -> "ZTA";
    "OPE" -> "ZTA";
    "EON" -> "ZTA";
    "ERE" -> "ZTA";

    "OOL" -> "ZST";

    "OTO" -> "ZTO";

    "ONT" -> "ZON";
    "EON" -> "ZON";

    "OPY" -> "ZPP";
    "EER" -> "ZPP";


  { rank=same; "ZSF"; "YCY"; "WER" }
  { rank=same; "OPY"; "EER"}


}

Output

1 个答案:

答案 0 :(得分:1)

我删除了所有重复的线条,不可见的边缘和颜色属性。

然后我给它加了一些颜色以使我所做的事情可见。

来源是这样的:

digraph G {

newrank=true;
rankdir=BT;
ranksep=2;
splines=line;

subgraph cluster_z {
    label="Z";
    "TCE";
    "TNT";
    "ZAY";
    "ZCE";
    "ZIN";
    "ZNT";
    "ZON";
    "ZOW";
    "ZPP";
    "ZSF";
    "ZSS";
    "ZST";
    "ZTA";
    "ZTO";
}

subgraph cluster_y {
    rank=same;
    label="Y";
    "YCY";
    "YES";
}

subgraph cluster_w {
    rank=same;
    label="W";
    "WER";
    "WRT";
}

subgraph cluster_o {
    label="O";
    "OCE";
    "OCT";
    "OGE";
    "OIT";
    "ONT";
    "OOL";
    "OON";
    "OPE";
    "OPY";
    "ORT";
    "OTA";
    "OTO";
    "OTS";
}

subgraph cluster_e {
  label="E";
  "EUT";
  "ERT";
  "EST";
  "EON";
  "EER";
  "ERE";
  "ETO";
}

/* All the edges */
"EER" -> "ZPP";
"EER" -> "ZSF";
"EER" -> "ZTA";
"EON" -> "ZIN";
"EON" -> "ZNT";
"EON" -> "ZON";
"EON" -> "ZSF";
"EON" -> "ZTA";
"ERE" -> "ZTA";
"OCE" -> "ZCE";
"OCT" -> "ZSS";
"OGE" -> "ZIN";
"OIT" -> "ZNT";
"OIT" -> "ZSF";
"OIT" -> "ZTA";
"ONT" -> "ZON";
"OOL" -> "ZOW";
"OOL" -> "ZSS";
"OOL" -> "ZST";
"OON" -> "ZAY";
"OON" -> "ZCE";
"OON" -> "ZSF";
"OON" -> "ZTA";
"OPE" -> "ZSF";
"OPE" -> "ZTA";
"OPY" -> "ZPP";
"ORT" -> "ZSF";
"ORT" -> "ZTA";
"OTA" -> "ZAY";
"OTA" -> "ZTA";
"OTO" -> "ZTO";
"OTS" -> "ZNT";
"OTS" -> "ZTA";

/* 15 nodes from cluster_z and cluster_y and cluster_w */
{ rank = same;
    "TCE" [style = filled; color = green;]
    "TNT" [style = filled; color = green;]
    "WER" [style = filled; color = green;]
    "WRT" [style = filled; color = green;]
    "YCY" [style = filled; color = green;]
    "YES" [style = filled; color = green;]
    "ZAY" [style = filled; color = green;]
    "ZCE" [style = filled; color = green;]
    "ZIN" [style = filled; color = green;]
    "ZON" [style = filled; color = green;]
    "ZOW" [style = filled; color = green;]
    "ZPP" [style = filled; color = green;]
    "ZSS" [style = filled; color = green;]
    "ZST" [style = filled; color = green;]
    "ZTO" [style = filled; color = green;]
}

/* 10 nodes from cluster_o and cluster_e */
{ rank = same;
    "OCE" [style = filled; color = yellow;]
    "OCT" [style = filled; color = yellow;]
    "OGE" [style = filled; color = yellow;]
    "ONT" [style = filled; color = yellow;]
    "OOL" [style = filled; color = yellow;]
    "OPY" [style = filled; color = yellow;]
    "OTO" [style = filled; color = yellow;]
    "EON" [style = filled; color = yellow;]
    "EER" [style = filled; color = yellow;]
    "ERE" [style = filled; color = yellow;]
}

/* Gives cluster_z 2 rows of nodes. */
"ZSF" -> "ZTO" [color = red];

/* Gives cluster_o 4 rows of nodes. */
"OIT" -> "OON" -> "OPE" -> "ORT" [color = red];

}

图像如下所示: enter image description here 这样您就可以随便摆弄它。