【问题标题】:Parallel Edges for Tree Chart in GraphvizGraphviz 中树形图的平行边
【发布时间】:2020-02-21 04:56:02
【问题描述】:

我一直在尝试制作一个在节点之间运行多组边的树形图。 目标是看起来像这样:

我可以很容易地制作一个带有一组边的图表,如下所示: 但是,我无法弄清楚如何添加第二组边缘而不会使边缘遍布整个地方。

当我尝试这样做时,我的输出看起来像这样:

我不知道该怎么做。我的假设是 graphviz 试图避免允许边缘重叠。

我的问题是:

如何在 graphviz 中显示三个图像中的第一个,而不是三个图像中的最后一个。

我用来生成图表的代码是:

graph test_chart{
splines=ortho
rankdir=UD
ratio="fill"
graph[nodesep=1]
A[shape=box color=red, labe="A"group=1]
B[shape=box color=blue, label="B"]
C[shape=box color=blue, label="C" ]
D[shape=box color=blue label="D" ]
E[shape=box color=blue label="E"]
F[shape=box color=blue label="F"]
{p0, p1, p2, n0, n1, n2[shape=point label=""]}
p0[group=1]
edge[color="red"]
A-- p0

p1--B
p1--C
p2--D
p2--E

rank=same{p1--p0--p2}
{rank=same B--C--D--E[style=invis]}

edge[color=blue]
A-- n0
rank=same{n1--n0--n2}
n1--C
n1--D
n2--E
n2--F
}

【问题讨论】:

    标签: tree graphviz vector-graphics dot


    【解决方案1】:

    是的,几乎可以做到,但我只能通过大量的折腾来做到这一点。但我不得不放弃正交边缘并使用直线。

    1. 不知何故,创建一个输入文件,将节点放置在您想要的位置。
    2. 运行命令 dot/fdp/neato -Tdot >work.dot 这将创建一个增强但有效的输入文件
    3. 编辑 work.dot 以添加中间(点)节点并根据需要替换任何原始边。
    4. 运行命令 neato -n -Tsvg/png/... 以生成所需的 uotput。

    graphviz FAQ 谈论 neato -n
    总而言之,我建议使用 PIC 语言。更重要的是。

    graph test_chart {
        graph [bb="0,0,578,147.6",
            nodesep=1,
            splines=line
        ];
        node [label="\N",
            shape=point
        ];
        {
            graph [rank=min];
            node [label="",
                shape=point
            ];
    
            A    [color=red,
                height=0.5,
                label=A,
                pos="226,129.6",
                shape=box,
                width=0.75];
        }
        {
            graph [rank=max];
            node [shape=box];
            B    [color=blue,
                height=0.5,
                label=B,
                pos="27,18",
                shape=box,
                width=0.75];
            C    [color=blue,
                height=0.5,
                label=C,
                pos="153,18",
                shape=box,
                width=0.75];
            D    [color=blue,
                height=0.5,
                label=D,
                pos="299,18",
                shape=box,
                width=0.75];
            E    [color=blue,
                height=0.5,
                label=E,
                pos="425,18",
                shape=box,
                width=0.75];
            F    [color=blue,
                height=0.5,
                label=F,
                pos="551,18",
                shape=box,
                width=0.75];
        }
      edge [color=red]
        __Ab    [height=0.05,
            pos="221,73.8",
            width=0.05];
        __Bb    [height=0.05,
            pos="26,73.8",
            width=0.05];
        __Cb    [height=0.05,
            pos="143,73.8",
            width=0.05];
        __Db    [height=0.05,
            pos="289,73.8",
            width=0.05];
        __Eb    [height=0.05,
            pos="415,73.8",
            width=0.05];
    
        __Ab -- A
        __Bb -- B
        __Cb -- C
        __Db -- D
        __Eb -- E
            __Bb --  __Eb
    
      edge [color=blue]
        __Ac    [height=0.05,
            pos="236,52",
            width=0.05];
        __Cc    [height=0.05,
            pos="163,52",
            width=0.05];
        __Dc    [height=0.05,
            pos="309,52",
            width=0.05];
        __Ec    [height=0.05,
            pos="435,52",
            width=0.05];
        __Fc    [height=0.05,
            pos="561,52",
            width=0.05];
        __Ac -- A
        __Cc -- C
        __Dc -- D
        __Ec -- E
        __Fc -- F
        __Cc -- __Fc
    }
    

    【讨论】:

    【解决方案2】:

    这是 PIC (dpic) 中未优化的版本。宏会使其更小。

    .PS
     move down;
     right;
     move right
     B: box "B"; move right
     C: box "C"; move right
     D: box "D"; move right
     E: box "E"; move right
     F: box "F"; move right
     b2cX=C.c.x-B.c.x
    
     move to C.e + (D.w-C.e)/2; move up 1
    
     A: box "A" outline "red"
     a2redlineY=A.s.y - D.n.y
     redDeltaYtop=a2redlineY * .5
     redDeltaYbottom=a2redlineY-redDeltaYtop
     blueDeltaYtop=a2redlineY * .75
     blueDeltaYbottom=a2redlineY-blueDeltaYtop
    
     down
     ############################################################
     # RED
     ############################################################
     # draw line down from  A to the (to be drawn) bus
     X: line down  redDeltaYtop from .25 <A.sw,A.se>  outline "red" 
     Ap: X.s
     line left to ((B.w.x+((B.e.x-B.w.x)*.3)), Here.y) outline "red" 
    
     line down redDeltaYbottom outline "red"      # down to B
     move up  redDeltaYbottom                     # back up
    
     line right b2cX   outline "red"              # line to C 
     X: line down redDeltaYbottom outline "red"   # line down
     Cp: X.n
     move up redDeltaYbottom                      # back up
    
     line right b2cX   outline "red"              # line to D 
     X: line down redDeltaYbottom outline "red"   # line down
     Dp: X.n
     move up  redDeltaYbottom                     # back up
    
     line right b2cX   outline "red"              # line to E 
     X: line down redDeltaYbottom outline "red"   # line down
     Ep: X.n
     move up  redDeltaYbottom                     # back up
    
    
     ### draw connection points
     circle diam .05 shaded "black" with .c at Ap
     circle diam .05 shaded "black" with .c at Cp
     circle diam .05 shaded "black" with .c at Dp
    
     ############################################################
     # blue
     ############################################################
     # draw line down from  A to the (to be drawn) bus
     X: line down  blueDeltaYtop from .75 <A.sw,A.se>  outline "blue" 
     Ap: X.s
     line left to ((C.e.x+((C.w.x-C.e.x)*.3)), Here.y) outline "blue" 
    
     line down blueDeltaYbottom outline "blue"      # down to C
     move up  blueDeltaYbottom                     # back up
    
     line right b2cX   outline "blue"              # line to D 
     X: line down blueDeltaYbottom outline "blue"   # line down
     Dp: X.n
     move up  blueDeltaYbottom                     # back up
    
     line right b2cX   outline "blue"              # line to E 
     X: line down blueDeltaYbottom outline "blue"   # line down
     Ep: X.n
     move up  blueDeltaYbottom                     # back up
    
     line right b2cX   outline "blue"              # line to F 
     X: line down blueDeltaYbottom outline "blue"   # line down
     Fp: X.n
     move up  blueDeltaYbottom                     # back up
    
     ### draw connection points
     circle diam .05 shaded "black" with .c at Ap
     circle diam .05 shaded "black" with .c at Dp
     circle diam .05 shaded "black" with .c at Ep
    .PE
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2012-05-09
      相关资源
      最近更新 更多