【问题标题】:How to enforce the left-to-right node ordering in GraphViz rank layout?如何在 GraphViz 等级布局中强制执行从左到右的节点排序?
【发布时间】:2012-12-16 21:23:49
【问题描述】:

我正在使用 GraphViz 可视化一系列流程。每个进程由程序顺序的一些读或写操作组成。自然地,希望每个进程按从左到右的顺序排列操作。

使用 GraphViz(2.28 版),我的代码如下:

digraph G 
{
ranksep = 1.0; size = "10,10";
{ 
    node [shape = plaintext, fontsize = 20];
    0 -> 1 -> 2 -> 3 -> 4;
}
node [shape = box];
{rank = same;0;wy1;rf1;rc1;rz1;ry1;ra1;rb1;rx2;}
{rank = same;1;wf1;}
{rank = same;2;wx2;wc1;}
{rank = same;3;wf2;wz2;wx3;wa1;}
{rank = same;4;wz1;wy2;wx5;wb1;}
wy1 -> rf1;
rf1 -> rc1;
rc1 -> rz1;
rz1 -> ry1;
ry1 -> ra1;
ra1 -> rb1;
rb1 -> rx2;
wx2 -> wc1;
wf2 -> wz2;
wz2 -> wx3;
wx3 -> wa1;
wz1 -> wy2;
wy2 -> wx5;
wx5 -> wb1;
wf1 -> rf1[color = blue];
wc1 -> rc1[color = blue];
wz1 -> rz1[color = blue];
wy1 -> ry1[color = blue];
wa1 -> ra1[color = blue];
wb1 -> rb1[color = blue];
wx2 -> rx2[color = blue];

// W'WR Order:
wx3 -> wx2[style = dashed, color = red];

// W'WR Order:
wx5 -> wx2[style = dashed, color = red];
}

很抱歉,我不允许发布声誉太低的输出图片。 如果你可以运行代码,你会发现结果不是那么令人满意,因为在 pid = 3 的过程中出现乱序。具体来说,GraphViz 布局算法已将(理想)顺序“wf2-> wz2 -> wa1 -> wx3”重新排列为“wx3, wf2, wz2, wa1”。因此,我的问题是:

我的问题:如何在排名环境中强制从左到右节点排序?

通过在这个网站上的探索,我发现了一些类似的问题和潜在的解决方案。 但是,它们在我的具体示例中不起作用:

  • Graphviz .dot node orderingconstraint = false 选项让我的 PDF 图片更糟。我检查了dot User's Manual,上面写着:

    在等级分配期间,边缘的头节点被限制在比尾节点更高的等级上。但是,如果边缘的约束=false,则不强制执行此要求。

    基于以上陈述,(我猜)constraint = false 选项在不同等级之间而不是在同一等级之间生效。

  • Graphviz---random node order and edges going through labels:令人惊讶的是,constraint = false 选项对“有限状态机”的帮助很大在同一级别。同样,它并没有让我免于麻烦。

  • graphviz: circular layout while preserving node order:过程图在节点数和边数上都是动态的。因此,对节点使用绝对位置可能没有吸引力(导致许​​多边缘交叉?)。

    感谢您的任何建议。并且可执行代码将不胜感激。

【问题讨论】:

  • 我认为您应该/可以根据官方文档自行安排顺序:“如果子图有 ordering=out,则子图中具有相同尾节点的出边将扇出按创建顺序从左到右。”

标签: layout graphviz graph-visualization


【解决方案1】:
    digraph G 
{
ranksep = 1.0; size = "10,10";
{ 
    node [shape = plaintext, fontsize = 20];
    0 -> 1 -> 2 -> 3 -> 4;
}
node [shape = box];
{
rank = same;
0->wy1->rf1->rc1->rz1->ry1->ra1->rb1->rx2 [color=white];
rankdir=LR;
}
{
rank = same;
1->wf1[color=white];
rankdir=LR
}
{
rank = same;
2->wx2->wc1[color=white];
rankdir=LR;
}
{
rank = same;
3->wf2->wz2->wx3->wa1[color=white];
rankdir=LR;
}
{
rank = same;
4->wz1->wy2->wx5->wb1[color=white];
rankdir=LR;
}
wy1 -> rf1;
rf1 -> rc1;
rc1 -> rz1;
rz1 -> ry1;
ry1 -> ra1;
ra1 -> rb1;
rb1 -> rx2;
wx2 -> wc1;
wf2 -> wz2;
wz2 -> wx3;
wx3 -> wa1;
wz1 -> wy2;
wy2 -> wx5;
wx5 -> wb1;
wf1 -> rf1[color = blue];
wc1 -> rc1[color = blue];
wz1 -> rz1[color = blue];
wy1 -> ry1[color = blue];
wa1 -> ra1[color = blue];
wb1 -> rb1[color = blue];
wx2 -> rx2[color = blue];

// W'WR Order:
wx3 -> wx2[style = dashed, color = red];

// W'WR Order:
wx5 -> wx2[style = dashed, color = red];
}

我不太确定我是否正确地解决了您的问题,但请尝试使用它,如果您想要的话,请发表评论。我添加了不可见的边缘以正确排列节点,并使用 rankdir 来使用左右布局。

【讨论】:

  • 抱歉耽搁了(不能上网)。这正是正是我想要的。非常感谢。
  • 你可能想要[color=white]而不是[style=invis]
猜你喜欢
  • 2015-07-04
  • 2016-11-24
  • 1970-01-01
  • 1970-01-01
  • 2016-03-17
  • 1970-01-01
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多