【问题标题】:Making graphviz trees have parents centred above children制作graphviz树的父母以孩子为中心
【发布时间】:2015-08-31 18:54:26
【问题描述】:

我有以下graphviz代码:

graph {
    node[width = 0.6, height = 0.6, fixedsize=true, shape=circle];
    a[label="22"];
    b[label="22"];
    c[label="34"];
    d[label="22"];
    e[label="99"];
    f[label="34"];
    g[label="40"];
    h[label="37"];
    i[label="22"];
    j[label="99"];
    k[label="135"];
    l[label="129"];
    m[label="40"];
    edge[penwidth=3.0];
    a -- b;
    b -- d;
    c -- f;
    d -- i;
    e -- j;
    g -- m;
    edge[penwidth=1.0];
    a -- c;
    b -- e;
    c -- g;
    d -- h;
    e -- k;
    g -- l;
}

这是为了绘制一个突出显示一些边缘的二叉树。但是,这棵树看起来不太对 - 特别是在树的更下方,父子关系的排列如下所示:

          parent
child     child

而我希望它看起来更像这样:

    parent
child    child

(即让父级居中于其子级之上,而不是坐在其中一个之上)。这可能吗?如果可以,我该怎么做?

【问题讨论】:

    标签: tree drawing graphviz


    【解决方案1】:

    按照this linked answer using gvpr and Emden R. Gansner's script 中的说明正确布局二叉树,我得到以下输出:

    想不出更好或更快的方法。

    【讨论】:

      【解决方案2】:

      我确实玩了很多,我认为没有完美的解决方案。有一些方法。


      带有额外不可见边和节点的经典方法。这适用于小图,但在大图上变得非常难看。为确保这是可行的,您必须用不可见的节点填充整个网格。否则点引擎会否决你。


      我期望解决的是这种方法

      digraph {
          edge [weight=1]
          0->L
          0->R
          edge [weight=10]
          L->LL
          L->LR
          R->RL
          R->RR
          edge [weight=100]
          LL->LLL
          LL->LLR
          LR->LRL
          LR->LRR
          RL->RLL
          RL->RLR
          RR->RRL
          RR->RRR
      }
      

      不幸的是,它没有。似乎点布局引擎试图最小化的不是边缘长度,而是水平部分,即子节点之间的任何父位置都被认为是理想的。


      我试过的另一个是

      digraph {
          splines=line
          style=dotted
          edge [weight=1]
          subgraph cluster_0 {
              subgraph cluster_L {
                  subgraph cluster_LL {
                      LLL
                      LLM [style=dotted]
                      LLR
                      LL->LLL
                      LL->LLM [style=dotted weight=100]
                      LL->LLR
                  }
                  LM [style=dotted]
                  subgraph cluster_LR {
                      LRL
                      LRM [style=dotted]
                      LRR
                      LR->LRL
                      LR->LRM [style=dotted weight=100]
                      LR->LRR
                  }
                  L->LL
                  L->LM [style=dotted weight=100]
                  L->LR
              }
              M [style=dotted]
              subgraph cluster_R {
                  subgraph cluster_RL {
                      RLL
                      RLM [style=dotted]
                      RLR
                      RL->RLL
                      RL->RLM [style=dotted weight=100]
                      RL->RLR
                  }
                  RM [style=dotted]
                  R->RL
                  R->RM [style=dotted weight=100]
                  R->RR
              }
              0->L
              0->M [style=dotted weight=100]
              0->R
          }
      }
      

      这给了

      似乎确实可行,水平顺序取决于外观。但是集群在许多其他结构中表现不佳,您必须尝试它是否适合您。


      如果您省略集群,布局将横向更紧凑。不可见的中间节点仍然会阻止垂直边缘。

      digraph {
          splines=line
          style=dotted
          edge [weight=1]
          LLL
          LLM [style=dotted]
          LLR
          LL->LLL
          LL->LLM [style=dotted weight=100]
          LL->LLR
          LM [style=dotted]
          LRL
          LRM [style=dotted]
          LRR
          LR->LRL
          LR->LRM [style=dotted weight=100]
          LR->LRR
          L->LL
          L->LM [style=dotted weight=100]
          L->LR
          M [style=dotted]
          RLL
          RLM [style=dotted]
          RLR
          RL->RLL
          RL->RLM [style=dotted weight=100]
          RL->RLR
          RM [style=dotted]
          R->RL
          R->RM [style=dotted weight=100]
          R->RR
          0->L
          0->M [style=dotted weight=100]
          0->R
      }
      

      给了


      最后剩下一件事,ERG 用于树布局的 gvpr 脚本。您可以在 marapets 中找到详细信息,回复此question。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-02
        • 1970-01-01
        • 1970-01-01
        • 2015-08-10
        • 2020-05-26
        相关资源
        最近更新 更多