首页 > 解决方案 > Graphviz 中从左上到右下的树

问题描述

说我从这个开始:

graph {
    graph [splines=ortho]
    node [fontname="Sans-Serif" shape=record]
    rankdir=LR

    "Parent" -- "Child 1"
    "Parent" -- "Child 2"
    "Parent" -- "Child 3"
    "Parent" -- "Child 4 and then some"

}

这产生:

在此处输入图像描述

我需要改变什么才能得到这个(等等后续级别)?

在此处输入图像描述

谢谢!

标签: graphvizdot

解决方案


出乎意料的困难。正交被 DIY 正交边缘取代,使用伪不可见节点。

graph {
    // note: renaming the nodes was optional
    graph [splines=false ] // was ortho
    node  [fontname="Sans-Serif" shape=rect ]    // record features unused
    rankdir=LR  // ranks are now vertical!
    { // non-visible nodes (i1 i2 i3 i4) used to connect edges
      rank=same
      node [label="" peripheries=0]  // keep same size as other nodes, 
                                     // but do not draw (peripheries)
      edge [headclip=false tailclip=false]  // draw center-to-center
      i1:c -- i2:c -- i3:c -- i4:c
    }
    {node [group=T] P  C1}    //group used to place "child 1" w/ parent
    P [label="Parent"]
   {
      rank=same
      C1 [label="Child 1"]
      C2 [label="Child 2"]
      C3 [label="Child 3"]
      C4 [label="Child 4 and then some"]
    }    
    P -- i1  [headclip=false]
    edge     [tailclip=false]
    i1 -- C1
    i2 -- C2
    i3 -- C3
    i4 -- C4
}

给予:
在此处输入图像描述


推荐阅读