我一直在尝试制作一个树形图,该树形图具有在节点之间运行的多组边。目标是看起来像这样:
我可以轻松地制作具有一组边的图表,如下所示:但是,我无法弄清楚如何添加第二组边缘,而不会使边缘遍及整个地方。
我不确定如何执行此操作。我的假设是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
}
是的,这几乎可以做到,但是我只能花很多时间去做。但是我必须删除正交边缘并使用直线。
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
}
这里是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