【问题标题】:GraphViz - How to have a subgraph be left-to-right when main graph is top-to-bottom?GraphViz - 当主图从上到下时,如何让子图从左到右?
【发布时间】:2009-10-12 13:37:04
【问题描述】:

我有一个这样的图形文件:

digraph {
    "Step1" -> "Step2" -> "Step3";

    subgraph step2detail {
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
        rankdir=TB
   }
}

我希望子图 step2detail 挂在“Step2”的右侧。

现在看起来像这样:

我希望 Step1、Step2 和 Step3 都在彼此垂直的下方并在 1 列中。

【问题讨论】:

    标签: graphviz


    【解决方案1】:

    获取您描述的图表的技巧是使用两个子图并从一个子图链接到另一个子图。 “细节”中不可见的边缘是保持笔记对齐的原因。

    digraph {
        rankdir="LR";
    
        subgraph steps {
            rank="same";
            "Step1" -> "Step2" -> "Step3";
        }
    
        subgraph details {
            rank="same";
            edge[style="invisible",dir="none"];
            "note1" -> "note2" -> "note3" -> "note4";
        }
    
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
    }
    

    结果是:

    【讨论】:

    • 我不知道最初的提问者的想法是什么,但这给出了我根据问题的描述想象想要的东西——我认为会帮助我得到我想要的我自己的图表。 :)
    • 非常好的技巧,但对虚假的不可见边缘有点遗憾。如果您只使用图形来生成图像,这将是零问题,这可能几乎总是如此,但如果有一种方法可以在不改变图形结构的情况下以这种方式影响布局,那就太好了。跨度>
    【解决方案2】:

    这很简单 - 只需使用 group 属性让 graphviz 更喜欢直接 边缘:

    digraph {
        node[group=a, fontname="Arial", fontsize=14];
        "Step1" -> "Step2" -> "Step3";
    
        node[group=""];
        "Step2" -> "note1";
        "Step2" -> "note2";
        "Step2" -> "note3";
        "Step2" -> "note4";
    }
    

    【讨论】:

      【解决方案3】:

      通过将Step节点分组为一个聚集子图,输出如下:

      digraph {
          subgraph cluster_0 {
              color=invis;
              "Step1" -> "Step2" -> "Step3";
          }
      
          subgraph cluster_1 {
              color=invis;
              "Step2" -> "note4";
              "Step2" -> "note3";
              "Step2" -> "note2";
              "Step2" -> "note1";
         }
      }
      

      color=invis 删除了在集群周围绘制的边框

      【讨论】:

        【解决方案4】:

        rankdir 不能直接在子图中工作,但如果你添加另一组花括号 - 不管叫什么 - rankdir 工作:

        digraph {
            "Step1" -> "Step2" -> "Step3";
        
            subgraph step2detail {
                {
                    "Step2" -> "note1";
                    "Step2" -> "note2";
                    "Step2" -> "note3";
                    "Step2" -> "note4";
                    rankdir=TB
                    rank=same
                }
           }
        }
        

        【讨论】:

        • 也许晚了,但我使用了这个问题和本页底部的示例graphs.grevian.org/example 来解决我正在处理的图表中的类似问题。因此,我认为您的解决方案可以在没有 subraph 和没有 rankdir 的情况下完成。抱歉格式化。 digraph { Step1 -> Step2 -> Step3 Step2 -> note4, note3, note2, note1 {rank=same Step2, note1, note2, note3, note4} }
        • 我不明白这是在说什么。 note* 节点不是从上到下布置的,因此这实际上似乎不是rankdir 在子图中工作的示例。事实上,如果我删除rankdir=TB,我会得到完全相同的结果;如果我还删除了额外的大括号,我会得到完全相同的结果。这不只是显示rank = same 的示例吗?它似乎是唯一在这里实际做任何事情的语法,尽管它是唯一一个答案没有提到的语法。如果我错了(graphviz 很新,所以很有可能),这可以做更多的解释。
        【解决方案5】:

        使用命令:rankdir=LR;

        digraph {
        rankdir=LR;
        
            "Step1" -> "Step2" -> "Step3";
        
            subgraph step2detail {
                "Step2" -> "note1";
                "Step2" -> "note2";
                "Step2" -> "note3";
                "Step2" -> "note4";
                rankdir=TB
           }
        
        }
        

        【讨论】:

        • 好的,但看起来很奇怪; step1 -> step2 -> step3 不在同一垂直位置
        • 更改子图的 rankdir 似乎并没有改变任何东西 =\
        猜你喜欢
        • 1970-01-01
        • 2010-12-02
        • 2021-11-05
        • 1970-01-01
        • 2020-12-28
        • 2011-12-08
        • 2015-05-08
        • 1970-01-01
        • 2014-12-31
        相关资源
        最近更新 更多