Graphviz-页面压缩,排名不被尊重

时间:2018-06-29 01:52:57

标签: configuration graphviz dot image-size

[在此处输入图片描述] [1]我只是在学习GraphViz,并且正在解决一些基本问题。我有两个子图应该能够显示基本节点及其之间的链接,请参见代码:

digraph G {
graph [rankdir="TB", splines=ortho, nodesep=2, ranksep=2.5, fontsize=18, fontname="Verdana"];
node [shape=record, height=3, width=3];
rankdir = TB;


subgraph cluster_0 {    
    node [style=filled, color=lightgrey, fontsize=18, fontname="Verdana"];
    label = "DMZ 1";
    PWI -> PWE -> PWI
}

subgraph cluster_1 {
    node [style=filled, color=lightgrey, fontsize=18, fontname="Verdana"];
    label = "Trusted Zone EBC" ;
    PR1 -> PWI [headlabel="test text", labeldistance=2.5] 
    PWI -> PR1  
    PR1 -> PWE  
    PWE -> PR1  
    PWI -> PWE -> PWI  
    PFI -> PWE  
    PFI -> PWI  
    PWE -> PFI  
    PWI -> PFI  
    PBW -> PWI  
    PBW -> PWE  
    PWI -> PBW  
    PWE -> PBW  
    PSM -> PWE  
    PSM -> PWI  
    PWE -> PSM  
    PWI -> PSM  
    {rank = same; PR1; PFI; PSM; PBW}
    {rank = same; PWI}
    {rank = same; PWE}
}

}

这将导致以下结果。.我是否碰到了[画布] [2]的边缘,如果可以,可以增加它吗?为何在最高排名与最低排名相同,中间排名高于最高排名的情况下却不受到尊重呢?

谢谢!

https://i.stack.imgur.com/meU6p.png

1 个答案:

答案 0 :(得分:0)

不,您不会碰到“画布”的边缘,因为默认情况下会对其进行扩展以适合您的图形。

图形中等级的问题是节点之间的两个方向上都有边。由于Graphviz认为边缘的左侧比右侧具有更高的等级,因此所有这些边缘都会使Graphviz感到困惑。

如果您始终从排名较高的节点(根据需要)到排名较低的节点,并使用dir属性来创建边缘指定边缘应指向后退方向,例如:n1 -> n2 [dir=back],Graphviz将获得对节点等级的一致感知并尊重您的预期等级。

也许这更符合您的需求:

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v5.js"></script>
<script src="https://unpkg.com/viz.js@1.8.2/viz.js" type="javascript/worker"></script>
<script src="https://unpkg.com/d3-graphviz@2.4.2/build/d3-graphviz.js"></script>
<div id="graph" style="text-align: center;"></div>
<script>

var dotSrc = `
digraph G {
graph [rankdir="TB", splines=ortho, nodesep=2, ranksep=2.5, fontsize=18, fontname="Verdana"];
node [shape=record, height=3, width=3];
rankdir = TB;


subgraph cluster_0 {    
    node [style=filled, color=lightgrey, fontsize=18, fontname="Verdana"];
    label = "DMZ 1";
    PWE -> PWI
    PWE -> PWI [dir=back]
}

subgraph cluster_1 {
    node [style=filled, color=lightgrey, fontsize=18, fontname="Verdana"];
    label = "Trusted Zone EBC" ;
    PWI -> PR1 [headlabel="test text", labeldistance=2.5 dir=back] 
    PWI -> PR1  
    PWE -> PR1 [dir=back]
    PWE -> PR1  
    PWE -> PWI [dir=back]
    PWE -> PWI  
    PWE -> PFI [dir=back]
    PFI -> PWI  
    PWE -> PFI  
    PFI -> PWI [dir=back]
    PWI -> PBW [dir=back]   
    PWE -> PBW [dir=back]
    PWI -> PBW  
    PWE -> PBW  
    PWE -> PSM [dir=back]
    PWI -> PSM [dir=back]
    PWE -> PSM  
    PWI -> PSM  
    {rank = same; PR1; PFI; PSM; PBW}
    {rank = same; PWI}
    {rank = same; PWE}
}
}
`;

d3.select("#graph").graphviz()
  .renderDot(dotSrc);

</script>