如何使用点创建依赖树

发布于 2025-01-03 12:58:37 字数 1017 浏览 4 评论 0原文

尝试创建依赖树。尽管我已经设法将盒子连接在一起,但我未能以更具代表性的方式使其看起来像一棵树。

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
}

我没能创造出类似的东西 在此处输入图像描述

trying to create a dependency tree. although i have managed to get the boxes connect together, i have failed to make it looks like a tree in a more representable way.

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
}

i have failed to create something like
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唐婉 2025-01-10 12:58:37

你的图表对我来说看起来并没有那么糟糕。要更接近您的模型图片,可以执行以下操作:

  • 拉直边缘 (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

可能还有更多事情可以做,具体取决于您到底想要什么。

Your graph didn't look that bad to me. To get a little closer to your mockup picture, here's what could be done:

  • Straighten the edges (splines=false)
  • Increase the distance between the nodes (ranksep=1)
  • Add invisible edges to ensure node order
  • Personal preference: have edges origin from the same point (edge[tailport=s])

Here's the modified graph:

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

There's probably more that could be done, depending on what exactly you're after.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文