【问题标题】:GRAPHVIZ: Force node to top of pageGRAPHVIZ:强制节点到页面顶部
【发布时间】:2021-01-25 13:41:42
【问题描述】:

我正在使用graphviz,但是我想将节点“This on top”强制到页面顶部,而不是侧面。这是图表:

这是代码:

g= Digraph('trial', filename='trial.gv')
g.attr(compound='true', rankdir="TB" )

with g.subgraph() as s:
  s.attr(rank='max')
  s.node('This on top ')
  s.edge('this right under', "Fabrication")

with g.subgraph(name='cluster0') as c:
    c.node("This")

    c.node("that")
    c.node("and this on the same level")
g.edge("this right under","that", lhead="cluster0" )
g.edge("that","This on top ", ltail="cluster0" )

g

是否有命令确保节点按我希望的 TOP/Bottom 顺序显示?

【问题讨论】:

    标签: python graphviz pygraphviz


    【解决方案1】:

    第一个问题是设置rank='max' 会强制第一个子图中的所有内容都达到最高等级,也就是最低等级。您可能打算设置rank='min',这会将子图中的项目置于最高排名,但这仍然不会创建您想要的排列。

    相反,您可以通过在创建边缘时设置style = 'invis' 来使用不可见边缘,以强制“This on top”出现在“this right under”之前。

    from graphviz import Digraph
    
    g= Digraph('trial', filename='trial.gv')
    g.attr(compound='true', rankdir="TB" )
    
    with g.subgraph() as s:
      # s.attr(rank='min') # you don't need this line
      s.node('This on top ')
      s.edge('This on top ', 'this right under', style='invis') # add this invisible edge
      s.edge('this right under', "Fabrication")
    
    with g.subgraph(name='cluster0') as c:
        c.node("This")
    
        c.node("that")
        c.node("and this on the same level")
    g.edge("this right under", "that", lhead="cluster0" )
    g.edge("that", "This on top ", ltail="cluster0", constraint="false" )
    
    g
    

    产生:

    【讨论】:

      猜你喜欢
      • 2014-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-15
      • 1970-01-01
      • 2015-07-04
      • 2011-07-30
      • 1970-01-01
      相关资源
      最近更新 更多