GraphViz:使用pos属性的网格布局出现问题

问题描述 投票:0回答:1

我正在尝试对齐此图表,其目的是显示排序结果。我需要一个通用的解决方案点文件生成,所以我不能用手调整。

我已经尝试过pospos!dot -ndot -Kneatodot -Kfdp等等。

这是源(为人类grokkability布局):

digraph x {
  rankdir=LR

   11 [pos="1,1"]   21 [pos="2,1"]   31 [pos="3,1"]   41 [pos="4,1"]
   12 [pos="1,2"]   22 [pos="2,2"]   32 [pos="3,2"]   42 [pos="4,2"]
   13 [pos="1,3"]   23 [pos="2,3"]   33 [pos="3,3"]
   14 [pos="1,4"]   24 [pos="2,4"]

   11:e ->  21:w    21:e ->  31:w    31:e ->  41:w
   12:e ->  22:w    22:e ->  32:w    32:e ->  42:w
                    22:e ->  31:w
#                                                     41:e ->  21:w
#                                                     41:e ->  22:w 
#  12:e ->  12:w
#                                    32:e ->  32:w

   13:e ->  23:w    23:e ->  33:w
   14:e ->  24:w
#  13:e ->  14:w
#  14:e ->  13:w
#                   23:e ->  24:w
#                   24:e ->  23:w
}

在第一次渲染中,您将看到它应该看起来如何(除了混洗的行顺序)。稍后的渲染(包括循环边缘)应保留此基本布局。

dot -Tpng -o test.png test.dot

enter image description here

现在在取消注释循环边缘后的一些渲染。

dot -Tpng -o test.png test.dot

enter image description here

dot -Kneato -Tpng -o test.png test.dot

enter image description here

dot -Kfdp -Tpng -o test.png test.dot

enter image description here

graphviz
1个回答
1
投票

根据我的经验(通过你的尝试证实)不使用pos,它与dot引擎不兼容,并且与neato和其他我从未能够产生类似网格布局的东西。

dot接近的三个一般步骤:

  • 使用rank = same垂直对齐节点
  • 使用weight = 10(或任何其他有效的任意数字)水平对齐节点
  • 根据需要添加不可见的垂直支柱(此处为14 - > 12)
  • 确保将边缘指向已建立的层次结构,这意味着在适当的情况下明确使用dir = back

我对你情况的看法:

digraph 
{
    rankdir = LR;

    {rank = same; 14 -> 13 -> 12 -> 11[ style = invis ] }
    {rank = same; 24 -> 23 -> 22 -> 21[ style = invis ] }
    {rank = same; 33 -> 32 -> 31[ style = invis ] }
    {rank = same; 42 -> 41[ style = invis ] }

    14 -> 24[ weight = 10 ];
    13 -> 23 -> 33[ weight = 10 ];
    12 -> 22 -> 32 -> 42[ weight = 10 ];
    11 -> 21 -> 31 -> 41[ weight = 10 ];

    22:e -> 31:w;

    12:e -> 12:w
    32:e -> 32:w

    21:se ->  41:sw[ dir = back ];
    22:se ->  41:sw[ dir = back ];

    14 -> 12    [ color = red ];
    14:w -> 13:w
    13:e -> 14:e[ dir = back ];

    24:w -> 23:w
    23:e -> 24:e[ dir = back ];
}

产量

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.