我有一个图表
digraph BST {
subgraph{
s00 [ label = "s00" ];
s00 -> { s10 s11 s12};
s10 [ label = "s10" ];
s10 -> { s22 s23 };
s11 [ label = "s11" ];
s11 -> { };
s12 [ label = "s12" ];
s12 -> { };
s22 [ label = "s22" ];
s22 -> { };
s23 [ label = "s23" ];
s23 -> { s30 s31 };
s30 [ label = "s30" ];
s30 -> { };
s31 [ label = "s31" ];
s31 -> { };
}
subgraph{
g00 [ label = "g00" ];
g00 -> { g10 g11 g111 };
g10 [ label = "g10" ];
g10 -> { };
g11 [ label = "g11" ];
g11 -> { };
g111 [ label = "g111" ];
g111 -> { g20 };
g20 [ label = "g20" ];
g20 -> { g30 g31 g32 };
g30 [ label = "g30" ];
g30 -> { };
g31 [ label = "g31" ];
g31 -> { };
g32 [ label = "g32" ];
g32 -> { };
}
}
如何使树从g00反转(从下到上增长),节点s00与g00(垂直对齐)具有相同的x坐标值,并从g31到s30添加边。
答案 0 :(得分:0)
你可以使用g子图中边缘的dir
属性来做到这一点,如下所示:
digraph {
subgraph{
node [fillcolor = red, style = filled]
s00 -> { s10 s11 s12};
s10 -> { s22 s23 };
s23 -> { s30 s31 };
}
subgraph{
edge [dir = back]
node [fillcolor = blue, style = filled]
{ g10 g11 g111 } -> g00;
{ g20 } -> g111;
{ g30 g31 g32 } -> g20;
}
}
我简化了你的代码并使用颜色来标记不同的图形。 使用点布局时看起来像这样: Graph
编辑: 要“移动”其中一个子图,您可以插入几个不可见的节点(无论您要移动多少级别):
digraph {
subgraph{
node [fillcolor = red, style = filled]
{
node [style = invis]
invis1 invis2 invis3
}
invis1 -> invis2 -> invis3 -> s00 [style = invis]
s00 -> { s10 s11 s12};
s10 -> { s22 s23 };
s23 -> { s30 s31 };
}
subgraph{
edge [dir = back]
node [fillcolor = blue, style = filled]
{ g10 g11 g111 } -> g00;
{ g20 } -> g111;
{ g30 g31 g32 } -> g20;
}
}
看起来像这样:Graph