博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用代码画流程图和时序图快餐教程(2) - mermaid数据流图速成
阅读量:5880 次
发布时间:2019-06-19

本文共 5384 字,大约阅读时间需要 17 分钟。

可以嵌入在markdown代码中的mermaid

mermaid的好处是可以在写markdown文档的同时,就直接可以画图了。

下面是我用Haroopad工具直接在markdown中画流图的情况:
mermaid_flow
工具下载地址:

独立使用mermaid

可以通过npm安装mermad:

npm install -g mermaidnpm install -g phantomjs

mermaid依赖于phantomjs

下面是mermaid的帮助信息:

Usage: mermaid [options] 
...file The mermaid description file to be renderedOptions: -s --svg Output SVG instead of PNG (experimental) -p --png If SVG was selected, and you also want PNG, set this flag -o --outputDir Directory to save files, will be created automatically, defaults to `cwd` -e --phantomPath Specify the path to the phantomjs executable -t --css Specify the path to a CSS file to be included when processing output -c --sequenceConfig Specify the path to the file with the configuration to be applied in the sequence diagram -g --ganttConfig Specify the path to the file with the configuration to be applied in the gantt diagram -h --help Show this message -v --verbose Show logging -w --width width of the generated png (number) --version Print version and quit

mermaid数据流图速成

决定图的方向

与graphviz不同,graph语句首先需要设置图的方向

  • TD: 默认方向,从上到下
  • TB: 从上到下
  • BT: 从下到上
  • LR: 从左到右
  • RL: 从右到左

例:

graph TB;    Context_sendbroadcast --> ContextWrapper_sendBroadcast;    ContextWrapper_sendBroadcast --> ContextImpl_sendBroadcast;    ContextImpl_sendBroadcast --> ActivityManagerService_broadcastIntent;

与graphviz的不同

graphviz的dot图是用“节点1 -> 节点2”的格式,而mermaid是用“节点1 --> 节点2”的方式,中间多了一个"-".

属性定义方面,mermaid可以用[]和()几种方式来决定图形的方式。

比如:

graph TD;    Context_sendbroadcast(Context.sendBroadcast Intent);    ContextWrapper_sendBroadcast[ContextWrapper.sendBroadcast Intent];    Context_sendbroadcast --> ContextWrapper_sendBroadcast;

Context_sendbroadcast就是圆脚的矩形,而ContextWrapper_sendBroadcast就是方的。

需要注意的一点,在标签属性定义的时候,不能出现()[]之类引起误会的符号。官方文档说可以用""来引起来,不过在我的版本上有点问题。

下面还是看跟上面一篇中所讲的graphviz完全一样的图的例子:

graph TD    Context_sendbroadcast[Context.sendBroadcast Intent];    Context_sendbroadcast_asUser[Context.sendBroadcastAsUser Intent,UserHandle];    Context_sendOrderedBroadcast[Context.sendOrderedBroadcast Intent,String,BroadcastReceiver,Handler,int,String,Bundle];    Context_sendOrderedBroadcast2[Context.sendOrderedBroadcast Intent,String];    Context_sendStickyBroadcast[Context.sendStickyBroadcast Intent];    Context_sendStickyBroadcast2[Context.sendStickyOrderedBroadcast Intent,BroadcastReceiver,Handler,int,String,Bundle];    ContextWrapper_sendBroadcast[ContextWrapper.sendBroadcast Intent];    ContextWrapper_sendOrderedBroadcast2[ContextWrapper.sendOrderedBroadcast Intent,String];    ContextWrapper_sendOrderedBroadcast[ContextWrapper.sendOrderedBroadcast Intent,String,BroadcastReceiver,Handler,int,String,Bundle];    ContextWrapper_sendStickyBroadcast[ContextWrapper.sendStickyBroadcast Intent];    ContextWrapper_sendStickyBroadcast2[ContextWrapper.sendStickyOrderedBroadcast Intent,BroadcastReceiver,Handler,int,String,Bundle];    ContextWrapper_sendbroadcast_asUser[ContextWrapper.sendBroadcastAsUser Intent,UserHandle];    ContextImpl_sendBroadcast[ContextImpl.sendBroadcast Intent];    ContextImpl_sendOrderedBroadcast2[ContextImpl.sendOrderedBroadcast Intent,String];    ContextImpl_sendOrderedBroadcast[ContextImpl.sendOrderedBroadcast Intent,String,BroadcastReceiver,Handler,int,String,Bundle];    ContextImpl_sendStickyBroadcast[ContextImpl.sendStickyBroadcast Intent];    ContextImpl_sendStickyBroadcast2[ContextImpl.sendStickyOrderedBroadcast Intent,BroadcastReceiver,Handler,int,String,Bundle];    ContextImpl_sendbroadcast_asUser[ContextImpl.sendBroadcastAsUser Intent,UserHandle];    ContextImpl_sendOrderedBroadcast_all(ContextImpl.sendOrderedBroadcast Intent,String,int,BroadcastReceiver,Handler,int,String,Bundle,Bundle);    ActivityManagerService_broadcastIntent(ActivityManagerService.broadcastIntent IApplicationThread,Intent,String,IIntentReceiver,int,String,Bundle,String,int,Bundle,boolean,boolean,int);    Context_sendbroadcast --> ContextWrapper_sendBroadcast;    ContextWrapper_sendBroadcast --> ContextImpl_sendBroadcast;    ContextImpl_sendBroadcast --> ActivityManagerService_broadcastIntent;    Context_sendbroadcast_asUser --> ContextWrapper_sendbroadcast_asUser;    ContextWrapper_sendbroadcast_asUser --> ContextImpl_sendbroadcast_asUser;    ContextImpl_sendbroadcast_asUser --> ActivityManagerService_broadcastIntent;    Context_sendOrderedBroadcast2 --> ContextWrapper_sendOrderedBroadcast2;    ContextWrapper_sendOrderedBroadcast2 --> ContextImpl_sendOrderedBroadcast2;    ContextImpl_sendOrderedBroadcast2 --> ActivityManagerService_broadcastIntent;    Context_sendOrderedBroadcast --> ContextWrapper_sendOrderedBroadcast;    ContextWrapper_sendOrderedBroadcast --> ContextImpl_sendOrderedBroadcast;    ContextImpl_sendOrderedBroadcast --> ContextImpl_sendOrderedBroadcast_all;    ContextImpl_sendOrderedBroadcast_all --> ActivityManagerService_broadcastIntent;    Context_sendStickyBroadcast --> ContextWrapper_sendStickyBroadcast;    ContextWrapper_sendStickyBroadcast --> ContextImpl_sendStickyBroadcast;    ContextImpl_sendStickyBroadcast --> ActivityManagerService_broadcastIntent;    Context_sendStickyBroadcast2 --> ContextWrapper_sendStickyBroadcast2;    ContextWrapper_sendStickyBroadcast2 --> ContextImpl_sendStickyBroadcast2;    ContextImpl_sendStickyBroadcast2 --> ActivityManagerService_broadcastIntent;

下面是生成的图片:

test1_md

转载地址:http://tbjix.baihongyu.com/

你可能感兴趣的文章
修改校准申请遇到的问题
查看>>
Linux 进程中 Stop, Park, Freeze【转】
查看>>
文件缓存
查看>>
远程协助
查看>>
Scrum实施日记 - 一切从零开始
查看>>
关于存储过程实例
查看>>
配置错误定义了重复的“system.web.extensions/scripting/scriptResourceHandler” 解决办法...
查看>>
PHP盛宴——经常使用函数集锦
查看>>
重写 Ext.form.field 扩展功能
查看>>
Linux下的搜索查找命令的详解(locate)
查看>>
福利丨所有AI安全的讲座里,这可能是最实用的一场
查看>>
开发完第一版前端性能监控系统后的总结(无代码)
查看>>
Python多版本情况下四种快速进入交互式命令行的操作技巧
查看>>
MySQL查询优化
查看>>
【Redis源码分析】如何在Redis中查找大key
查看>>
android app启动过程(转)
查看>>
安装gulp及相关插件
查看>>
如何在Linux用chmod来修改所有子目录中的文件属性?
查看>>
Applet
查看>>
高并发环境下,Redisson实现redis分布式锁
查看>>