【问题标题】:Force GraphViz force align between subgraphForce GraphViz 强制子图之间对齐
【发布时间】:2013-01-10 10:24:13
【问题描述】:

我将 GraphViz 与以下点文件一起使用:

digraph "Fast-forward"
{
    rankdir=LR;
    subgraph master
    {
        "5c071a6b2c" -> "968bda3251";
    }
    subgraph branch
    {
        "35ee8ce6b6" [color="blue"] [style="filled"];
        "968bda3251" -> "9754d40473" [weight=0];
        "9754d40473" -> "9e59700d33" -> "35ee8ce6b6";
    }
    subgraph c1
    {
        rankdir=LR;
        rank="same";
        "remote/master/HEAD" [shape=box];
        "remote/master/HEAD" -> "35ee8ce6b6" [weight=0];
        oldmh [label="master/HEAD"] [shape=box] [color="red"] [style="filled"];
        newmh [label="master/HEAD"] [shape=box] [color="blue"] [style="filled"];
        oldmh -> "968bda3251" [weight=0];
        newmh -> "35ee8ce6b6" [weight=0];
    }
}

它给了我类似的东西:

但我想要这样的东西:

                                                     white
                                                        |
                                                       \/
                     "9754d40473" -> "9e59700d33" -> "35ee8ce6b6";
                     /                                  /\

5c071a6b2c -> 968bda3251

             /\                                         |
              |
            red                                       blue

我该怎么做?

为了您的帮助, 提前致谢。

【问题讨论】:

    标签: nodes graphviz subgraph


    【解决方案1】:

    我倾向于先定义所有具有特殊需求的节点(例如处于同一等级或具有特殊形状/颜色),然后定义链接。这样,您就可以确保 rank=same 节点被正确分组,并以正确的顺序定义。

    没有weight=0,所有的侧链接都在顶部。将weight=0添加到底部你想要的。

    digraph "Fast-forward"
    {
        rankdir=LR;
        subgraph c1 {
            rank="same";
            "968bda3251";
            oldmh [label="master/HEAD"] [shape=box] [color="red"] [style="filled"];
        }
        subgraph c2
        {
            rank="same";
            "remote/master/HEAD" [shape=box];
            "35ee8ce6b6" [color="blue"] [style="filled"];
            newmh [label="master/HEAD"] [shape=box] [color="blue"] [style="filled"];
        }
        "5c071a6b2c" -> "968bda3251" -> "9754d40473" -> "9e59700d33" -> "35ee8ce6b6";
        oldmh -> "968bda3251" [weight=0];
        "remote/master/HEAD" -> "35ee8ce6b6";
        newmh -> "35ee8ce6b6" [weight=0];
    }
    

    如果你真的想要在 96 和 97 之间慢跑,你可以这样做:

    digraph "Fast-forward"
    {
        rankdir=LR;
        subgraph c1 {
            rank=same;
            "968bda3251";
            oldmh [label="master/HEAD"] [shape=box] [color="red"] [style="filled"];
        }
        subgraph c1p5 {
            rank=same;
            "9754d40473";
            inviso [style="invis"];
        }
        subgraph c2
        {
            rank="same";
            "remote/master/HEAD" [shape=box];
            "35ee8ce6b6" [color="blue"] [style="filled"];
            newmh [label="master/HEAD"] [shape=box] [color="blue"] [style="filled"];
        }
        "5c071a6b2c" -> "968bda3251";
        "968bda3251" -> "9754d40473" [weight=0];
        "9754d40473" -> "9e59700d33" -> "35ee8ce6b6";
        oldmh -> "968bda3251" [weight=0];
        "remote/master/HEAD" -> "35ee8ce6b6";
        newmh -> "35ee8ce6b6" [weight=0];
        "968bda3251" -> inviso [style="invis"];
        "9754d40473" -> inviso [style="invis"];
    }
    

    【讨论】:

      【解决方案2】:

      rank="same" 影响子图的所有节点,因此您必须将标签子图分成两部分:

      digraph "Fast-forward"
      {
          rankdir=LR;
          subgraph master
          {
              "5c071a6b2c" -> "968bda3251";
          }
          subgraph branch
          {
              "968bda3251" -> "9754d40473" [weight=0];
              "9754d40473" -> "9e59700d33" -> "35ee8ce6b6";
              "35ee8ce6b6" [color="blue"] [style="filled"];
          }
          subgraph c1
          {
              rank="same";
              "remote/master/HEAD" [shape=box];
              "remote/master/HEAD" -> "35ee8ce6b6" [weight=0];
              newmh [label="master/HEAD"] [shape=box] [color="blue"] [style="filled"];
              newmh -> "35ee8ce6b6" [weight=0];
          }
          subgraph c2
          {
              rank="same";
              oldmh [label="master/HEAD"] [shape=box] [color="red"] [style="filled"];
              oldmh -> "968bda3251" [weight=0];
          }
      }
      

      这将为您提供:

      【讨论】:

      • 感谢您的回答,但我意识到我的“asciiart”打印不正确,是否可以将远程/主/头放在顶部?提前致谢。
      • 尝试将子图 c2 移动到子图 c1 上方。节点的定义顺序会影响它们在结果图中的显示顺序。这不是保证,但它可能会起作用。 没关系,没用。我再看一下。
      猜你喜欢
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      • 2015-07-22
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      相关资源
      最近更新 更多