【问题标题】:Graphviz: Creating flowchart with straight edges between nodes in three clustersGraphviz:在三个集群中的节点之间创建具有直边的流程图
【发布时间】:2020-04-01 09:35:21
【问题描述】:

我正在尝试重新创建这个区块链流程图

即使将边缘权重设置为 100 并使用不可见节点,我也无法将某些边缘设为水平。我写的代码如下。我创建了三个集群,其中两个(第 2 和第 3d)我在节点之间放置了假边。

digraph S {
    rankdir=TB

    subgraph cluster1 {
            graph [style="invis"]
            rank="same"

     node [fixedsize="true", width="3", height="1", shape="diamond", style="filled"]
     A [label="Is multi-party\nrequired?", fillcolor=""]
     B [label="Is trusted_authority\nrequired?", fillcolor=""]
     C [label="Is operation\ncentralized?", fillcolor=""]
     D [label="Is immutability\nrequired?", fillcolor=""]
     E [label="Is high performace\nrequired?", fillcolor=""]
     F [label="Is transparency\nrequired?", fillcolor=""]

     A -> B [label="Yes"]
     B -> C [label="No"]
     C -> D [label="No"]
     D -> E [label="Yes"]
     E -> F [label="No"]

    }


subgraph cluster2 {
     graph [style="invis"]
     rank="same"

     node [shape="diamond", fixedsize="true", width="3", height="1", style="filled"]

     P [label="Is trusted authority\ndecentralizable", fillcolor=""]
     P1 [style="invis"]
     P2 [style="invis"] 
     Q [label="Can big data be\nstored off-chain", fillcolor=""]
     R [label="Can encrypted data\nbe shared", fillcolor=""]

     P -> P1 -> P2 -> Q -> R [style="invis", dir="none"]
   }                           

     B -> P [label="Yes", weight=200]
     P -> C [label="Yes"]
     E -> Q [label="Yes", weight=1]
     Q -> F [label="Yes"]
     F -> R [label="No", weight=1]


subgraph cluster3 {
     graph [style="invis"]
     rank="same"

     node [shape="box", style="filled"]
     X [label="Consider Conventional\nDatabase", fillcolor=""]
     Y [label="Consider Blockchain", fillcolor=""]
     Z [label="Consider DLTs", fillcolor=""]

     X -> Y -> Z [style="invis", dir="none"]
}

     A -> X [label="No"]
     P -> X [label="No", weight=100]
     C -> X [label="Yes", weight=200]
     D -> X [label="No"]

     Q -> X [label="No"]
     F -> Y [label="Yes"]

     R -> Y [label="Yes"]
     R -> Z [label="No", weight=100] 
}

然而,即使修改了不同的权重并将约束设置为假,第三个集群仍然在前两个之间。或者应该是最左边的第一个集群位于中间。

这是输出之一。

权重未按预期工作。我错过了什么吗?请帮忙!谢谢

【问题讨论】:

    标签: layout graphviz dot pygraphviz


    【解决方案1】:

    我已经接近了,但需要两个步骤才能到达那里。
    1. 将以下内容另存为 myfile.gv,然后运行 ​​dot -tdot myfile.gv >myfile.dot 这确定了节点

    digraph S {
      graph [splines=polyline compound=true]
    
      subgraph clusterA {
         graph [style="invis" margin=30]
         rank="min"
    
         node [fixedsize="true", width="3", height="1", shape="diamond", style="filled"]
         A [label="Is multi-party\nrequired?", fillcolor=""]
         B [label="Is trusted_authority\nrequired?", fillcolor=""]
         C [label="Is operation\ncentralized?", fillcolor=""]
         D [label="Is immutability\nrequired?", fillcolor=""]
         E [label="Is high performace\nrequired?", fillcolor=""]
         F [label="Is transparency\nrequired?", fillcolor=""]
    
         A:s -> B:n [label="Yes"]
         B:s -> C:n [label="No"]
         C:s -> D:n [label="No"]
         D:s -> E:n [label="Yes"]
         E:s -> F:n [label="No"]
    
        }
    
       subgraph clusterB {
         graph [style="invis" margin=30] 
         rank="same"
    
         node [shape="diamond", fixedsize="true", width="3", height="1", style="filled"]
    
         P [label="Is trusted authority\ndecentralizable", fillcolor=""]
         Q [label="Can big data be\nstored off-chain", fillcolor=""]
         R [label="Can encrypted data\nbe shared", fillcolor=""]
         node [label="" style="invis" shape=plain]
         x0 
         x1 
         x2 
    
         x0 -> P -> x1 -> x2 -> Q -> R [style="invis"]  // , dir="none"]
    
       }                           
    
        subgraph clusterC {
         graph [style="invis" margin=30]
         rank="max"
    
         node [shape="box", style="filled"]
         X [label="Consider Conventional\nDatabase", fillcolor=""]
         Y [label="Consider Blockchain", fillcolor=""]
         Z [label="Consider DLTs", fillcolor=""]
         node [label="" style="invis" shape=plain]
         z0 
         z1 
         z2 
    
         z0 -> z1 -> X -> z2 -> Y -> Z [style="invis"]  // , dir="none"]
      }
    }
    

    2,将以下内容添加到 myfile.dot 的最后一个括号之前并运行 neato -n1 -Tpng myfile.dot >myfile.png 这将路由边缘。

     [B:e -> P:w \[label="Yes" constraint=false\];
     P:sw -> C:ne \[label="Yes" constraint=false\]
     E:e -> Q:w \[label="Yes" constraint=false\]
     Q:sw -> F:ne \[label="Yes" constraint=false\]
     F:e -> R:w \[label="No" constraint=false\]
    
     A:e -> X:n \[label="No" constraint=false\]
     P -> X \[label="No" constraint=false\]
     C:e -> X:w \[label="Yes" constraint=false\]
     D:e -> X \[label="No" constraint=false\]
    
     Q -> X \[label="No" constraint=false\]
     F -> Y \[label="Yes" constraint=false\]
    
     R -> Y \[label="Yes" constraint=false\]
     R -> Z \[label="No" constraint=false\]
    
    E -> Q \[ltail=clusterA,lhead=clusterB\];
    Q -> Y \[ltail=clusterB,lhead=clusterC\];][1]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 2021-03-11
      • 1970-01-01
      • 2016-12-16
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多