【问题标题】:Order cluster nodes in graphviz在graphviz中订购集群节点
【发布时间】:2016-03-01 19:24:10
【问题描述】:

我有以下(简化的)图表,由以下 .dot 生成:

digraph Configurations {

  subgraph cluster_1 {
    s_0_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
    s_0_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
  }
  subgraph cluster_2 {
    s_1_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
    s_1_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=white]
  }
  subgraph cluster_3 {
    s_2_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=white]
    s_2_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
  }
  subgraph cluster_4 {
    s_3_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=white]
    s_3_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=white]
  }

  s_0_1 -> s_1_1
  s_0_0 -> s_2_0
  s_2_1 -> s_3_1
  s_1_0 -> s_3_0
}

我希望能够在子图中强制执行排序,以便每个子图的节点按升序显示(每个集群应该放置节点 (0, 1),从不 (1, 0)) .据我了解,我第一次尝试的 rankdir 在子图中不受支持,那么这样做的正确方法是什么?我正在寻找一种解决方案,它可以为我提供相当相似的布局(然后将包括更多相交的箭头)并且是可扩展的,因为真实的图形会很大。

【问题讨论】:

    标签: graphviz


    【解决方案1】:

    事实证明,这可以通过在内部添加不可见边并在图中强制相同等级来解决,如下所示:

    
    subgraph cluster_1 {
        {rank=same; s_0_0 s_0_1}
        s_0_0 -> s_0_1 [style=invis]
        s_0_0 [shape=circle,style=filled,fixedsize=true,width=0.5,label="0",fillcolor=yellowgreen]
        s_0_1 [shape=circle,style=filled,fixedsize=true,width=0.5,label="1",fillcolor=yellowgreen]
    }
    

    【讨论】:

    • 使用了这两个答案并且无法重新排列节点,因为图中其他节点之间的连接似乎重新排列了顺序。
    • 对我来说就像一个魅力!即使有多个节点。谢谢!
    • 在某些情况下使用此解决方案,连接不同集群中的节点可以再次更改排序。您还可以在图表上设置remincross=false 以防止这种情况发生。
    【解决方案2】:

    如果节点多于2个,我们需要改变解决方案。

    subgraph cluster1 {
    {
        HL_1_n HL_1_1 HL_1_2 HL_1_3 HL_1_m
    }
    HL_1_1   [label="Hidden Layer 1 Node 1" color=3]
    HL_1_2   [label="Hidden Layer 1 Node 2" color=3]
    HL_1_3   [label="Hidden Layer 1 Node 3" color=3]
    HL_1_m   [label="Hidden Layer 1 Node ..." color=3]
    HL_1_n   [label="Hidden Layer 1 Node H_1" color=3]
    label = "Hidden Layer"
    

    }

    似乎顺序是确定的,所以我们只需要更改节点的位置以适应输出。该解决方案不使用边缘约束和排名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多