如何使用点创建依赖树

时间:2012-02-07 17:53:11

标签: tree dependencies dot

尝试创建依赖关系树。虽然我已经设法将盒子连接在一起,但我没能使它看起来像一棵树,更具代表性。

digraph G{
m1[shape=box, color=grey, style=filled]
m2[shape=box, color=grey, style=filled]
m3[shape=box, color=grey, style=filled]
m4[shape=box, color=grey, style=filled]
m5[shape=box, color=grey, style=filled]
p1[shape=diamond,color=lightblue, style=filled]
p2[shape=diamond, color=lightblue, style=filled]
p3[shape=diamond, color=lightblue, style=filled]
p4[shape=diamond, color=lightblue, style=filled]
{rank=sink;x1;x2;x3;x4;}
{rank=source;y1;}
{rank=same;m3;p3;x11;x5;x6;x7;x8;}
node[shape=circle]
y1 -> x9
y1 -> m5
x10 -> m4
x10 -> p4
x9-> m3
x9-> p3
x6 ->m1
x6 ->p1
x5 ->m1
x5 ->p1
x8 -> m2
x8 -> p2
x7 -> m2
x7 -> p2
y1 -> x10
y1 -> x12  
x5 -> x1
x5 -> x2
x6 -> x1
x6 -> x2
x7 -> x3
x7 -> x4
x8 -> x3
x8 -> x4
x9 -> x6
x9 -> x5
x9 -> x11
x10 -> x8
x10 -> x7
}

我没有创造类似的东西 enter image description here

1 个答案:

答案 0 :(得分:1)

你的图表对我来说并不那么糟糕。为了更接近你的模型图片,这是可以做的:

  • 拉直边缘(splines=false
  • 增加节点之间的距离(ranksep=1
  • 添加隐藏边以确保节点顺序
  • 个人偏好:边缘来自同一点(edge[tailport=s]

以下是修改后的图表:

digraph G{
splines=false;
ranksep=1;

node[shape=box, color=grey, style=filled];
m1;m2;m3;m4;m5;

node[shape=diamond,color=lightblue, style=filled]
p1;p2;p3;p4;

node[style=solid, color=black, shape=circle, width=0.6, height=0.6];
{
    rank=same;
    x9;x12;x10;m5;
}
{
    rank=same;
    edge[style=invis];
    p3->x11->x5->x6->m3;
    p4->x7->x8->m4;
}
{
    rank=same;
    edge[style=invis];
    p1->x1->x2->m1;
    p2->x3->x4->m2;
}

edge[tailport=s]; // also try adding: headport=n
y1 -> m5
y1 -> x9
y1 -> x12  
y1 -> x10
x10 -> m4
x10 -> p4
x9-> m3
x9-> p3
x6 ->m1
x6 ->p1
x5 ->m1
x5 ->p1
x8 -> m2
x8 -> p2
x7 -> m2
x7 -> p2
x5 -> x1
x5 -> x2
x6 -> x1
x6 -> x2
x7 -> x3
x7 -> x4
x8 -> x3
x8 -> x4
x9 -> x6
x9 -> x11
x9 -> x5
x10 -> x8
x10 -> x7
}

graphivz output

可能还有更多可以做的事情,具体取决于你究竟追求的是什么。