【问题标题】:DOT: How to place clusters at same level without ranking equally the nodes in those clusters?DOT:如何将集群放置在同一级别而不对这些集群中的节点进行同等排名?
【发布时间】:2019-05-04 16:34:08
【问题描述】:

我有以下 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"}


}

【问题讨论】:

  • 您可能需要更详细地描述一下,最好是减少样本,您的意思是 我希望根据内部关系对上三个集群中的节点进行排名他们的节点,类似于我在较低的两个集群中得到的。您的代码非常复杂,需要花费大量时间才能理解,因此准确了解您想去哪里会很有帮助。

标签: graphviz dot


【解决方案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];

}

虽然图像看起来像这样: 所以你可以随心所欲地摆弄它。

【讨论】:

  • 谢谢。您有什么想要改进的地方吗?
  • 我首先需要看看它在我的较大图表中的表现。我提出了一个不同的解决方案,将 5 个子图的 3/2 放置在每个子图中的两个级别上,并引入更多的不可见节点/边以使其放置正确。这些不可见节点有一定的原因,但您的解决方案完美地解决了所描述的问题。
  • 啊。我想知道所有这些不可见的节点和边缘是干什么用的。无论如何,我为这个示例所做的就是区分具有 3 个或更多箭头的节点和具有两个或更少箭头的节点。希望对您有所帮助。
猜你喜欢
  • 2011-10-13
  • 2014-11-02
  • 2019-09-19
  • 2014-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-06
  • 2020-07-08
相关资源
最近更新 更多