【问题标题】:Graphviz edges not discernible / edge labels overwrittenGraphviz 边缘不可辨别/边缘标签被覆盖
【发布时间】:2014-06-12 01:15:23
【问题描述】:

我已将我的问题简化为以下简单示例:

digraph {
subgraph {rank=same; 0 -> 1 -> 2;}
0 -> 2 [label="A"];
2 -> 0 [label="B"];
}

产生

在将 0、1 和 2 保持在同一等级的同时(原始示例是在更大图的上下文中),我需要 A 和 B 边是可辨别的。即边缘清晰匹配标签和标签可读。

我想象的一个解决方案是在由指定的边缘连接上使用端口

0:ne -> 2:nw [label="A"];
2:sw -> 0:se [label="B"];

然而这会产生

其他想法?我正在生成具有相同问题的更大图表,因此最佳解决方案不是完全临时手动放置边/标签。

编辑:生成的较大图的一个(仍然是简化的)示例如下。

digraph {
size = "6,8.5";
ratio = "fill";
node [shape = circle];
node [fontsize = 24];
edge [fontsize = 24];
{graph [rank=same]; edge[color=invis];1;}
{graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
0 -> 0 [label="6: 0.1764"];
0 -> 4 [label="4: 0.1304"];
0 -> 3 [label="5: 0.1551"];
0 -> 2 [label="7: 0.1489"];
0 -> 1 [label="Z: 0.3893"];
4 -> 0 [label="6: 0.1237"];
4 -> 3 [label="5: 0.05201"];
4 -> 2 [label="7: 0.15  "];
4 -> 1 [label="Z: 0.4585"];
3 -> 0 [label="6: 0.1658"];
3 -> 4 [label="4: 0.13  "];
3 -> 3 [label="5: 0.1038"];
3 -> 2 [label="7: 0.1616"];
3 -> 1 [label="Z: 0.4388"];
2 -> 0 [label="6: 0.1661"];
2 -> 4 [label="4: 0.1295"];
2 -> 3 [label="5: 0.2078"];
2 -> 2 [label="7: 0.1406"];
2 -> 1 [label="Z: 0.356 "];
1 -> 0 [label="6: 0.1103"];
1 -> 4 [label="4: 0.2591"];
1 -> 3 [label="5: 0.1382"];
1 -> 2 [label="7: 0.08581"];
1 -> 1 [label="Z: 0.1906"];
}

这会产生:

在上面的简单示例中表现出相同的边缘/标签重叠问题。

其他说明:

  • 当同一秩子图中的双向连接的节点对中间有一个节点时,会出现此问题。这可能是出现错误的条件的一个子集。
  • 无向图也存在此问题。

【问题讨论】:

    标签: graphviz overlap rank dot subgraph


    【解决方案1】:

    ssteveemden 的回答非常有用,并得到了支持。 (谢谢你们!)

    我正在整合双方的意见,并以更复杂的版本回答这个问题。我仍然不觉得这个解决方案是完美的,但它是迄今为止我能产生的最好的。将来会对此进行改进的答案(请参阅下文了解似乎仍然缺乏的内容)并以可以自动化的方式解决更大的图形版本(请参阅问题)来代替此答案。

    首先,总结迄今为止最好的解决方案:将标签转换为 xlabels 用于 一些 边缘(例如,所有双向边缘的一半,随机选择)并随机着色边缘和相应的标签(通过fontcolor)。

    具体来说,这里是这个解决方案的一个实例,其中边缘是随机的红色、绿色或黑色:

    digraph {
    size = "6,10.5";
    ratio = "fill";
    node [shape = circle];
    node [fontsize = 24];
    edge [fontsize = 24];
    {graph [rank=same]; edge[color=invis];1;}
    {graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
    0 -> 0 [label="6: 0.1764"];
    0 -> 4 [xlabel="4: 0.1304" color=blue fontcolor=blue];
    0 -> 3 [xlabel="5: 0.1551" color=green fontcolor=green];
    0 -> 2 [label="7: 0.1489" color=red fontcolor=red];
    0 -> 1 [label="Z: 0.3893"];
    4 -> 0 [xlabel="6: 0.1237" color=green fontcolor=green];
    4 -> 3 [xlabel="5: 0.05201 " color=green fontcolor=green];
    4 -> 2 [xlabel="7: 0.15" color=blue fontcolor=blue];
    4 -> 1 [label="Z: 0.4585" color=red fontcolor=red];
    3 -> 0 [xlabel="6: 0.1658"];
    3 -> 4 [xlabel="4: 0.13" color=red fontcolor=red];
    3 -> 3 [label="5: 0.1038" color=blue fontcolor=blue];
    3 -> 2 [xlabel="7: 0.1616"];
    3 -> 1 [label="Z: 0.4388"];
    2 -> 0 [label="6: 0.1661" color=blue fontcolor=blue];
    2 -> 4 [xlabel="4: 0.1295" color=red fontcolor=red];
    2 -> 3 [label="5: 0.2078" color=green fontcolor=green];
    2 -> 2 [label="7: 0.1406"];
    2 -> 1 [label="Z: 0.356 "];
    1 -> 0 [label="6: 0.1103" color=red fontcolor=red];
    1 -> 4 [label="4: 0.2591" color=blue fontcolor=blue];
    1 -> 3 [label="5: 0.1382" color=green fontcolor=green];
    1 -> 2 [label="7: 0.08581 "];
    1 -> 1 [label="Z: 0.1906"];
    }  
    

    这会产生:

    这仍然不能完全令人满意,因为:

    1. 虽然现在可以更轻松地将标签追溯到其边缘,但使用 xlabel 时,某些标签会出现在奇怪的位置。 (例如上面的 2 -> 4 标签)
    2. 随机选择哪些标签成为 xlables 似乎是任意的。也没有办法(我知道)保证这总是可行的。

    我尝试过的其他事情:

    • 将每个标签都设为 xlabel。结果:所有内容都被压缩,标签相互重叠和模糊。
    • 对所有双向边使用 xlabel。结果:与上述相同的问题。
    • 使用不带颜色的 xlabels。结果:很难追踪哪个标签属于什么。
    • 使用 ssteve 的 dir="both" + 颜色列表 solution。随机着色边缘。并为头尾标签随机设置labeldistance在3到11之间,以避免节点处的标签重叠。结果:这更难以自动化,并且仍然导致边缘标签重叠和标签难以追溯到它们对应的边缘。 (见下文)

    这是上面“我尝试过的其他事情”解决方案列表中最后一项的示例。

    size = "6,8.5";
    ratio = "fill";
    node [shape = circle];
    node [fontsize = 24];
    edge [fontsize = 24];
    {graph [rank=same]; edge[color=invis];1;}
    {graph [rank=same]; edge[color=invis];2 -> 0 -> 3 -> 4;}
    0 -> 0 [label="6: 0.1764"];
    0 -> 4 [dir="both", color="yellow:blue", labeldistance="5", headlabel=<<font color="yellow">4: 0.1304</font>>, taillabel=<<font color="blue">6: 0.1237</font>>];
    0 -> 3 [dir="both", color="blue:black", labeldistance="8", headlabel=<<font color="blue">5: 0.1551</font>>, taillabel=<<font color="black">6: 0.1658</font>>];
    0 -> 1 [label="Z: 0.3893"];
    4 -> 1 [label="Z: 0.4585"];
    3 -> 4 [dir="both", color="green:red", labeldistance="5", headlabel=<<font color="green">4: 0.13</font>>, taillabel=<<font color="red">5: 0.05201</font>>];
    3 -> 3 [label="5: 0.1038"];
    3 -> 1 [label="Z: 0.4388"];
    2 -> 0 [dir="both", color="yellow:blue", labeldistance="11", headlabel=<<font color="yellow">6: 0.1661</font>>, taillabel=<<font color="blue">7: 0.1489</font>>];
    2 -> 4 [dir="both", color="black:red", labeldistance="5", headlabel=<<font color="black">4: 0.1295</font>>, taillabel=<<font color="red">7: 0.15</font>>];
    2 -> 3 [dir="both", color="blue:green", labeldistance="8", headlabel=<<font color="blue">5: 0.2078</font>>, taillabel=<<font color="green">7: 0.1616</font>>];
    2 -> 2 [label="7: 0.1406"];
    2 -> 1 [label="Z: 0.356 "];
    1 -> 0 [label="6: 0.1103"];
    1 -> 4 [label="4: 0.2591"];
    1 -> 3 [label="5: 0.1382"];
    1 -> 2 [label="7: 0.08581 "];
    1 -> 1 [label="Z: 0.1906"];
    }
    

    这会产生:

    征求其他想法/改进...

    【讨论】:

      【解决方案2】:

      第一个例子显然是一个错误;边缘标签应放置在单独的位置,然后将边缘分开。 (一般来说,我们知道平边代码中存在漏洞,尤其是在处理标签时。)一种解决方法是将部分或全部边缘标签视为外部标签:

      digraph {
      subgraph {rank=same; 0 -> 1 -> 2;}
      0 -> 2 [xlabel="A"];
      2 -> 0 [xlabel="B"];
      }
      

      关于更改上一个答案中提到的标签字体颜色的问题,可以使用类似HTML的标签来完成:

      0 -> 2 [dir="both", color="black:gray", labeldistance="2", 
        headlabel=<<font color="red">A</font>>, taillabel="B"];
      

      这可用于代替通常的双引号字符串的任何文本。

      【讨论】:

        【解决方案3】:

        您可以通过dir="both"colorList 获得一部分。

        digraph {
            subgraph {rank=same; 0 -> 1 -> 2;}
            0 -> 2 [dir="both", color="black:gray", labeldistance="2", headlabel="A", taillabel="B"];
        }
        

        结果:

        我必须使用labelDistance 来防止“A”标签被绘制在箭头顶部。不幸的是,我无法弄清楚如何分别更改头部标签和尾部标签的字体颜色,以更清楚地了解哪个标签适用于哪个箭头。

        【讨论】:

          猜你喜欢
          • 2010-10-24
          • 2017-06-17
          • 1970-01-01
          • 2020-02-09
          • 1970-01-01
          • 2023-03-22
          • 2019-06-19
          • 1970-01-01
          • 2012-09-05
          相关资源
          最近更新 更多