graphviz:如何防止集群覆盖rank=source语句

发布于 2024-11-02 22:36:12 字数 3792 浏览 4 评论 0原文

在此处输入图像描述

以下代码生成上面的图表:

digraph G {


//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica


        ]


    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]



// --- # nodes  

{// records
node [shape=record, width=1]


b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]

}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}


//--- # edges

{
edge [weight = 1000] 

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20
}


//--- # Clusters 

// subgraph cluster_1{
// label="a "
// e d10 d20
// }

// subgraph cluster_2{
// label="b "
// c b10 b20 b30
// }

// subgraph cluster_3{
// label="c "
// a30 a20
// }



// --- # bugfixes

{// c before e
edge [style=invis] 
c -> e


{rank=source e c} // force same rank before other nodes
}



}

这正是我想要的那样漂亮和干净。 然而,我希望能够标记和评论结构的某些部分,并且我认为集群应该是实现这一点的正确方法。

如果取消注释代码的 CLUSTERS 部分,您将获得以下代码和相应的图表:

digraph G {


//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica


        ]


    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]



// --- # nodes  

{// records
node [shape=record, width=1]


b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]

}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}


//--- # edges

{
edge [weight = 1000] 

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20
}


//--- # Clusters 

subgraph cluster_1{
label="a "
e d10 d20
}

subgraph cluster_2{
label="b "
c b10 b20 b30
}

subgraph cluster_3{
label="c "
a30 a20
}



// --- # bugfixes

{// c before e
edge [style=invis] 
c -> e


{rank=source e c} // force same rank before other nodes
}



}

在此处输入图像描述

如您所见从代码末尾的错误修复部分,我希望节点 C 和 E 肯定以相同的排名“高于”所有其他节点。

此外,我希望上下记录序列像第一个示例一样用漂亮的直线连接起来。我引入的边缘权重没有帮助。

有谁知道如何解决这个问题以及如何使 graphviz 生成一个漂亮的干净图表,如示例#1 所示,仅添加 3 个拥抱框和相应的标签?

enter image description here

the following code produces the graph above:

digraph G {


//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica


        ]


    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]



// --- # nodes  

{// records
node [shape=record, width=1]


b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]

}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}


//--- # edges

{
edge [weight = 1000] 

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20
}


//--- # Clusters 

// subgraph cluster_1{
// label="a "
// e d10 d20
// }

// subgraph cluster_2{
// label="b "
// c b10 b20 b30
// }

// subgraph cluster_3{
// label="c "
// a30 a20
// }



// --- # bugfixes

{// c before e
edge [style=invis] 
c -> e


{rank=source e c} // force same rank before other nodes
}



}

This is exactly as nice and clean as I want it to be.
However, I want to be able to mark and comment certain sections of the structure and I thouht clusters should be the right means to do that.

If you uncomment the CLUSTERS section of the code you get the following code and respective graph:

digraph G {


//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica


        ]


    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]



// --- # nodes  

{// records
node [shape=record, width=1]


b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]

}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}


//--- # edges

{
edge [weight = 1000] 

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20
}


//--- # Clusters 

subgraph cluster_1{
label="a "
e d10 d20
}

subgraph cluster_2{
label="b "
c b10 b20 b30
}

subgraph cluster_3{
label="c "
a30 a20
}



// --- # bugfixes

{// c before e
edge [style=invis] 
c -> e


{rank=source e c} // force same rank before other nodes
}



}

enter image description here

As you can see from the bugfixes section at the end of the code I want nodes C and E definitely to appear with the same rank 'above' all other nodes.

Furhtermore, I want the upper and lower sequence of records to be connected with nice straight lines like in the first example. The weight of the edges that I introduced does not help.

Does anyone know how to fix this problem and how to make graphviz produce a nice clean graph as in example #1 with just 3 embracing boxes and respective labels added?

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

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

发布评论

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

评论(1

空城缀染半城烟沙 2024-11-09 22:36:12

我尝试只修改需要的内容:

  • 添加了一个没有标签的附加集群,并且 style=invis (对于 d30)
  • 更改了节点的顺序,使集群 b 位于集群 a 之上
  • 边缘重量已删除
  • 错误修复部分已删除
  • 一些删除换行符

这是我从最新的 graphviz 版本(2.29)中得到的结果:

在此处输入图像描述

不完美,但是更近了。

digraph G {
//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica
        ]

    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]

// --- # nodes  

{// records
node [shape=record, width=1]

d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]
}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}

//--- # edges

{

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20}

//--- # Clusters 


 subgraph cluster_1{
 label="a "
 e d10 d20
 }

 subgraph cluster_2{
 label="b "
 c b10 b20 b30
 }

 subgraph cluster_3{
 label="c "
 a30 a20
 }

 subgraph cluster_4{
 label=""
 style=invis
 d30
 }

}

I tried to only modify what was needed:

  • Added an additional cluster without label and style=invis (for d30)
  • Changed the order of the nodes to have cluster b above cluster a
  • Edge weigth removed
  • Bugfixes section removed
  • Some linebreaks removed

Here's what I get with a recent graphviz version (2.29):

enter image description here

Not perfect, but a lot closer.

digraph G {
//---graph config

    fontname=Helvetica

    rankdir = RL
    splines = polyline
    compound = true
    //concentrate = true

    labeljust = c
    labelloc = t

    ranksep=0.5
    nodesep=0.5

    //size="10,10"
    ratio=compress

    edge [
        minlen=1
        arrowsize=0.75
        labeldistance=5     

        fontname=Helvetica
        fontsize=12
        fontcolor=black     

        labelfontsize=12
        labelfontcolor=red
        labelfontname=Helvetica
        ]

    node [
        fontname=Helvetica
        fontsize=12
        fontcolor=black

        regular=true
        shape=diamond
        // width=0.25
        // height=0.25
        ]

// --- # nodes  

{// records
node [shape=record, width=1]

d10 [label="  { R-10 | 15 } | D/10  "]
d20 [label="  { R-9 | 10 } | D/20  "]
d30 [label="  { R-8 | 10 } | D/30  "]
b10 [label="  { R-7 | 5 } | B/10  "]
b20 [label="  { R-6 | 10 } | B/20  "]
b30 [label="  { R-5 | 10 } | B/30  "]
a20 [label="  { R-2 | 5 } | A/20  "]
a30 [label="  { R-1 | 10 } | A/30  "]
}

{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}

{// box
node [shape=box]
a [label="A"]
}

//--- # edges

{

//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a

//combination
{b30 d30} -> a20}

//--- # Clusters 


 subgraph cluster_1{
 label="a "
 e d10 d20
 }

 subgraph cluster_2{
 label="b "
 c b10 b20 b30
 }

 subgraph cluster_3{
 label="c "
 a30 a20
 }

 subgraph cluster_4{
 label=""
 style=invis
 d30
 }

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