首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Graphviz中创建直边

在Graphviz中创建直边
EN

Stack Overflow用户
提问于 2011-08-19 08:54:54
回答 1查看 15.1K关注 0票数 24

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

代码语言:javascript
复制
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创建的内容

有没有办法让这看起来更好?

EN

回答 1

Stack Overflow用户

发布于 2012-10-13 10:56:58

我认为最好的做法是通过例子来学习dot。只需阅读我的评论,如果有任何不清楚的地方,我将很乐意回答。

作为一个辅助节点:虽然graphviz在为大型数据集生成图形方面很棒,但它在创建ER图、流程图和序列图等方面就不那么棒了。这是可能的,而且是相对简单的,但是您必须投入大量的时间来使事情变得正确,这通常是不合理的,因为您可以使用Wsywig-GUI建模工具在很短的时间内实现相同的事情。然而,您花在这方面的时间将帮助您学习语言的语法和属性,当您需要可视化一些大型或复杂的问题时( GUI建模工具将无用),这些语法和属性将非常有用。

代码语言:javascript
复制
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;
}

票数 38
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7115870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档