【问题标题】:GraphViz temporal ordering of nodesGraphViz 节点的时间排序
【发布时间】:2017-07-09 00:34:49
【问题描述】:

我是 graphviz 的新手,并生成了一个包含时间约束的图。也就是说,节点从左到右的顺序很重要,但仅限于本地。这是我要强制执行的规则集:

1) 只有和所有“盒子”形状的节点都应该在图表的底部。这些代表终端节点。

2) “双圆”形节点上的任何规则都有时间约束(即排序问题)。

这是执行这些规则的尝试:

digraph G {
0 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
1 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
2 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
3 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
4 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
5 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
6 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
7 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
8 [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
9 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
9 -> 0 [penwidth=3, weight=3]
9 -> 2 [penwidth=3, weight=3]
{
  rank=same;
  0->2[color=white]
  rankdir=LR;
}
10 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
10 -> 9 [penwidth=3, weight=3]
10 -> 5 [penwidth=3, weight=3]
{
  rank=same;
  9->5[color=white]
  rankdir=LR;
}
11 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
11 -> 4 [penwidth=3, weight=3]
11 -> 10 [penwidth=3, weight=3]
{
  rank=same;
  4->10[color=white]
  rankdir=LR;
}
12 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
12 -> 10 [penwidth=3, weight=3]
12 -> 11 [penwidth=3, weight=3]
{
  rank=same;
  10->11[color=white]
  rankdir=LR;
}
13 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
13 -> 4 [penwidth=3, weight=3]
13 -> 9 [penwidth=3, weight=3]
{
  rank=same;
  4->9[color=white]
  rankdir=LR;
}
14 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
14 -> 26 [penwidth=3, weight=3]
14 -> 8 [penwidth=3, weight=3]
{
  rank=same;
  26->8[color=white]
  rankdir=LR;
}
15 [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
15 -> 12 [penwidth=3, weight=3]
15 -> 13 [penwidth=3, weight=3]
{
  rank=same;
  12->13[color=white]
  rankdir=LR;
}
26 [shape=circle, fillcolor=palegreen1, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
26 -> 12[label = "0.50", penwidth=2.0, weight=3 ]
26 -> 15[label = "0.50", penwidth=2.0, weight=3 ]
}

从规则集中,节点 9 应该有 0 作为左孩子,2 作为右孩子,依此类推。该图也没有强制要求所有的 'box; 形节点都应位于图的底部。是否可以用 GraphViz 构建这样的图?

谢谢!

【问题讨论】:

    标签: graphviz graph-visualization


    【解决方案1】:

    我不完全确定您希望这张图表的外观如何,但我已经尝试过了。所有框都在底部,这是使用集群子图完成的(如果您不喜欢该框,可以更改样式)。为了防止“特殊”边缘的边缘(代码中的白色,我的代码中的红色,因为背景也是白色)干扰排序,我在这些边缘上指定了 constraint = false。让我知道这是否有帮助。

    代码:

    digraph G {
        subgraph clusterSquares {
            rank = same
            node [shape=box, fillcolor=lightgrey, style=filled, ranksep=0.5, nodesep=0.5]
            0; 1; 2; 3; 4; 5; 6; 7; 8;
        }
        {
            node [shape=doublecircle, fillcolor=palegreen3, style=filled, color=blue, ranksep=0.5, nodesep=0.5]
            edge [penwidth=3, weight=3]
            9 -> { 0; 2; }
            10 -> { 5; 9; }
            11 -> { 4; 10 }
            12 -> { 10; 11; }
            13 -> { 4; 9; }
            14 -> { 26; 8; }
            15 -> { 12; 13; }
            26 -> { 12; 15; }
        }
        {
            edge [color = red, constraint = false]
            0 -> 2
            9 -> 5
            4 -> 10
            10 -> 11
            4 -> 9
            26 -> 8
            13 -> 13
        }
    }
    

    生成的图像:

    【讨论】:

      猜你喜欢
      • 2011-11-29
      • 2014-10-09
      • 2023-03-11
      • 2016-02-06
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多