打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
graphviz简介

from http://blog.csdn.net/iamljj/article/details/5862930

2010.09

前几天一位朋友向我介绍了一个叫graphviz的工具,回来之后试用了一下,觉得真的是很好很强大。下面简单的介绍一下这个工具。

 

graphviz是贝尔实验室设计的一个开源的画图工具,它的强大主要体现在“所思即所得"(WYTIWYG,what you think is what you get),这是和office的“所见即所得“(WYSIWYG,what you see is what you get)完全不同的一种方式。它的输入是一个用dot语言编写的绘图脚本,通过对输入脚本的解析,分析出其中的点,边以及子图,然后根据属性进行绘制。用graphviz来绘图的时候,你的主要工作就是编写dot脚本,你只要关注图中各个点之间的关系就好了,你不需要考虑如何安排各个节点的位置,怎样布局能够使你所绘制的图看起来更美观一些。呵呵,这也许就是”所思即所得“的魅力吧。

 

下面可以看看来自官方文档的一些例子。

$ cat 1.dot

digraph G {
    main -> parse -> execute;
    main -> init;
    main -> cleanup;
    execute -> make_string;
    execute -> printf
        init -> make_string;
    main -> printf;
    execute -> compare;
}

$ dot -Tgif 1.dot -o 1.gif

效果如下图:

 

$ cat 2.dot

digraph structs {
    node [shape=record];
    struct1 [shape=record,label="<f0> left|<f1> mid/ dle|<f2> right"];
    struct2 [shape=record,label="<f0> one|<f1> two"];
    struct3 [shape=record,label="hello/nworld |{ b |{c|<here> d|e}| f}| g | h"];
    struct1 -> struct2;
    struct1 -> struct3;
}

$ dot -Tgif 2.dot -o 2.gif

效果如下图:

 

$ cat 3.dot

digraph g {
    node [shape = record,height=.1];
    node0[label = "<f0> |<f1> G|<f2> "];
    node1[label = "<f0> |<f1> E|<f2> "];
    node2[label = "<f0> |<f1> B|<f2> "];
    node3[label = "<f0> |<f1> F|<f2> "];
    node4[label = "<f0> |<f1> R|<f2> "];
    node5[label = "<f0> |<f1> H|<f2> "];
    node6[label = "<f0> |<f1> Y|<f2> "];
    node7[label = "<f0> |<f1> A|<f2> "];
    node8[label = "<f0> |<f1> C|<f2> "];
    "node0":f2 -> "node4":f1;
    "node0":f0 -> "node1":f1;
    "node1":f0 -> "node2":f1;
    "node1":f2 -> "node3":f1;
    "node2":f2 -> "node8":f1;
    "node2":f0 -> "node7":f1;
    "node4":f2 -> "node6":f1;
    "node4":f0 -> "node5":f1;
}
$ dot -Tgif 3.dot -o 3.gif

效果如下图:

 

再看一个稍微丰富一点吧

$ cat 4.dot

digraph G {
    node [peripheries=2 style=filled color="#eecc80"]
    edge [color="sienna" fontcolor="green"]
    main -> parse -> execute;
    main -> init [arrowhead = box];
    main -> cleanupi -> main;
    make_string[label = once shape=parallelogram style=filled ]
    execute -> make_string[label=go style=dashed arrowtail=diamond];
    execute -> printf [shape=box];
    init -> make_string;
    main -> printf[dir=none];
    execute -> compare[dir=both];
}
$ dot -Tgif 4.dot -o 4.gif

效果如下图:

 

呵呵,效果还不错吧。改天抽个时间再写个简单的教程。

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
程序员的绘图利器 — Graphviz
使用DOT语言和Graphviz绘图(翻译)
graphviz 安装和入门
DoxyGEN 的使用与Graphviz 的使用
Graphviz使用简介(中文乱码的问题)
用graphviz,pygraphviz快速自动绘图
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服