【问题标题】:Graphviz : Ordering node in a clusterGraphviz:集群中的排序节点
【发布时间】:2023-03-11 04:41:01
【问题描述】:

我正在开发一个自动生成的 Graphviz(因此它需要是一个通用解决方案,而不是针对这个特定示例)。它绘制了网络的拓扑。但集群内的结果看起来没有条理。

这是拓扑:

这是相关代码:

digraph G {

splines=polyline;

subgraph cluster_sh5sl8 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl8_L1 [label = "L1"];
    label = "5/8";
}
subgraph cluster_sh5sl10 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl10_L1 [label = "L1"];
    label = "5/10";
}
subgraph cluster_sh5sl12 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl12_L1 [label = "L1"];
    label = "5/12";
}
subgraph cluster_sh5sl14 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl14_L1 [label = "L1"];
    label = "5/14";
}
subgraph cluster_sh5sl16 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh5sl16_L1 [label = "L1"];
    label = "5/16";
}
subgraph cluster_sh6sl3 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl3_L1 [label = "L1"];
    label = "6/3";
}
subgraph cluster_sh6sl8 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl8_L1 [label = "L1"];
    label = "6/8";
}
subgraph cluster_sh6sl10 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl10_L1 [label = "L1"];
    label = "6/10";
}
subgraph cluster_sh6sl12 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl12_L1 [label = "L1"];
    label = "6/12";
}
subgraph cluster_sh6sl14 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl14_L1 [label = "L1"];
    label = "6/14";
}
subgraph cluster_sh6sl16 {
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh6sl16_L1 [label = "L1"];
    label = "6/16";
}
subgraph cluster_sh30sl1 {
    rank=same;
    style=filled;
    color=lightgrey;
    node [style=filled,color=white];
    sh30sl1_9600 [label = "9600"]; sh30sl1_9590 [label = "9590"]; sh30sl1_9580 [label = "9580"]; sh30sl1_9570 [label = "9570"]; sh30sl1_9560 [label = "9560"]; sh30sl1_9280 [label = "9280"]; sh30sl1_9270 [label = "9270"]; sh30sl1_9260 [label = "9260"]; sh30sl1_9250 [label = "9250"]; sh30sl1_9220 [label = "9220"]; sh30sl1_9190 [label = "9190"]; sh30sl1_OMD [label = "OMD"];
    label = "30/1";
}

sh30sl1_9570 -> sh5sl8_L1;
sh30sl1_9560 -> sh5sl10_L1;
sh30sl1_9280 -> sh5sl12_L1;
sh30sl1_9270 -> sh5sl14_L1;
sh30sl1_9260 -> sh5sl16_L1;
sh30sl1_9220 -> sh6sl3_L1;
sh30sl1_9250 -> sh6sl8_L1;
sh30sl1_9190 -> sh6sl10_L1;
sh30sl1_9600 -> sh6sl12_L1;
sh30sl1_9590 -> sh6sl14_L1;
sh30sl1_9580 -> sh6sl16_L1;
sh6sl12_L1 -> sh30sl1_9600;
sh6sl14_L1 -> sh30sl1_9590;
sh6sl16_L1 -> sh30sl1_9580;
sh5sl8_L1 -> sh30sl1_9570;
sh5sl10_L1 -> sh30sl1_9560;
sh5sl12_L1 -> sh30sl1_9280;
sh5sl14_L1 -> sh30sl1_9270;
sh5sl16_L1 -> sh30sl1_9260;
sh6sl8_L1 -> sh30sl1_9250;
sh6sl3_L1 -> sh30sl1_9220;
}

请注意,我正在使用 FDP,但如果它有效,我可以使用其他任何东西。目前,FDP 给了我最好的结果。

如何订购?

我已经尝试过使用clusterrank, ranksep, nodesep, constraint=false,或者以其他顺序调用它们,等等。我尝试创建 un inivible 节点并链接集群内的所有其他节点以使它们等距,但它不起作用。

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    我还没有一个适用于生成结果的答案 - 我有一个类似的问题,我可以自己修改 graphviz 文件:

    <graphviz>
      digraph hierachy {
        rankdir="LR"
        graph [ordering="out"];
        subgraph cluster_Hierachie {
          label="Hierachie"
          n0 
          n10000 
          n20000 
          n30000 
          n40000 
          n50000 
          n0->n10000
          n0->n20000
          n0->n30000
          n0->n40000
          n0->n50000
       }
      }
    </graphviz>
    

    呈现为:

    到目前为止找到了以下链接:

    请注意关于如何指定“ordering=out”的不同建议

    digraph g {
      ordering=out ;
    

    digraph bt {
      graph [ordering="out"];
    

    这些都不适合我,尽管 https://stackoverflow.com/a/9169194/1497139 得到了 1 个赞,https://stackoverflow.com/a/9168680/1497139 得到了 2 个赞

    http://www.graphviz.org/content/ordering-edges 建议使用

    rank=same
    

    所以我尝试了:

    <graphviz>
      digraph hierachy {
        rankdir="LR"
        graph [ordering="out"];
    
        subgraph cluster_Hierachie {
          label="Hierachie"
          n0 
          n10000 
          n20000 
          n30000 
          n40000 
          n50000 
          n0->n10000
          n0->n20000
          n0->n30000
          n0->n40000
          n0->n50000
          {
            rank=same;n0;n10000;n20000;n30000;n40000;n50000
          }
       }
    
      }
    </graphviz>
    

    呈现为:

    http://www.graphviz.org/content/cluster-changes-nodes-order

    建议添加

    style=invis
    {  rank=same  0 -- 1 [style=invis]
    }
    

    节点。我试过没有用,最后还是做了

    <graphviz>
      digraph hierachy {
        rankdir="LR"
        graph [ordering="out"];
    
        subgraph cluster_Hierachie {
          label="Hierachie"
          n0 
          n10000 
          n20000 
          n30000 
          n40000 
          n50000 
          n0->n50000
          n0->n40000
          n0->n30000
          n0->n20000
          n0->n10000
       }
      }
    </graphviz>
    

    呈现为:

    考虑到集群中反向排序的奇怪行为,我认为这是一种有效的解决方法。

    【讨论】:

    • 非常感谢您的详细回答。我的问题更多是关于子图集群到子图集群。所以我改变了图表,用一个节点表示一个集群,然后编辑 svg 文件以使节点动态化。通过单击它,显示子图。不过非常感谢您的关注!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 2011-11-29
    相关资源
    最近更新 更多