2011-08-19 105 views
17

我想使用Graphviz创建一个流程图(类似于Visio)。这是一个示例有向图。在Graphviz中创建直边

digraph start_up { 
node [style = rounded]; 
node [shape = rect] start end; 
node [style = ""]; 
node [shape = diamond] "USB\nCommand\nArrived"; 
start -> "Initialize\nCode"; 
"Initialize\nCode" -> "USB\nCommand\nArrived"; 
"USB\nCommand\nArrived" -> "USB\nCommand\nArrived" [label="No" tailport=w headport=n]; 
"USB\nCommand\nArrived" -> "Has USB 3.0\nInterface Been\nSelected" [label = "Yes"]; 
"Has USB 3.0\nInterface Been\nSelected" -> end 
} 

问题是,当我使这个在Graphviz的由"USB\nCommand\nArrived" -> "USB\nCommand\nArrived" [label="No" tailport=w headport=n]; 创建线条看起来很丑陋。我不介意曲线,但这条线看起来变形了。你可以看到什么样的Graphviz创建这里

有没有办法让这个更好看?

回答

28

我认为最好是通过示例学习点。请阅读我的评论,如果有任何不清楚的地方,我会很乐意回答。

作为侧节点: 虽然graphviz的非常适合生成用于大型数据集的曲线图,它是用于创建之类的东西ER图,流动字符和序列图少真棒。这是可能的,也是相对简单的,但是你必须花时间做出正确的事情往往是没有道理的,因为你可以在很短的时间内用Wsywig-GUI建模工具实现同样的目标。然而,当你需要可视化一些大的或复杂的问题(GUI建模工具无用)时,你花这些时间来帮助你学习语言的语法和属性。


digraph start_up { 
    { 
/* fake levels (level0 -> level1) and support nodes 
* 
* graphviz to charts is what latex is to documents, 
* sometimes you'll have to fight it. 
* This is typically done by defining levels and connection points that 
* don't really have anything to do with your graph, but are used to 
* force the graph to appear in a certain way. 
*/ 
     node [shape=none, /*label="."*/]; l1a; l2a; l3a; l4a; l5a; l6a; 
     node [shape=square label="no"]; l20a; 
    } 

    { /* connectiong point for the no arrow above "arrived" */ 
     node [width=0 shape=point label=""]; 
     d1; no; 
    } 

    node [style = rounded]; 
    node [shape = rect] start end; 
    node [style = ""]; 

    node [shape = diamond]; { 
     node [label="USB\nCommand\nArrived"]; arrived; 
     node [label="Has USB 3.0\nInterface Been\nSelected"]; selected; 
     node [label="Initialize\nCode"]; init; 
    } 

    start -> init; 
    /*init -> arrived; */ 
    init -> d1 [arrowhead=none]; 
      d1 -> arrived; 

/* 
* tricky part: 
* since nodes in a digrap go either from top to bottom or left to right, we 
* can usually not connect (->) two nodes and have them appear on the same 
* level unless the connection is specified within a block that has the 
* parameter `rank' set to `same' 
*/ 
      l20a->no [arrowhead=none]; 

    { rank=same; no -> arrived [dir=back arrowtail=none]; } 
    { rank=same; l20a -> d1; } 

    /*arrived  -> arrived;*/ /* [label="No" tailport=w headport=n]; */ 
    arrived  -> selected [label = "Yes"]; 
    selected -> end 


    /* just to demonstrate */ 
    l1a-> l2a-> l3a-> l4a-> l5a-> l6a; 
} 

Solution proposal

+0

顺便提及,[plantUML](http://plantuml.com/)是用于创建与代码相关的图表多于真棒和它是基于graphviz的。 –