在Markdown中可以使用mermaid画图,但是我在网上看到了Plant UML,功能比mermaid强大,所以就学习了一下。
总体说明
支持图形种类
- Sequence diagram
- Usecase diagram
- Class diagram
- Activity diagram (here is the legacy syntax)
- Component diagram
- State diagram
- Object diagram
- Deployment diagram
- Timing diagram
- Network
- Wireframe graphical interface
- Archimate diagram
- Specification and Description Language (SDL)
- Ditaa diagram
- Gantt diagram
- MindMap diagram
- Work Breakdown Structure diagram
- Mathematic with AsciiMath or JLaTeXMath notation
- Entity Relationship diagram
预处理
所有预处理命令都是以“!”开头,语法类似于C
- 变量:
$a=23
;local $b="foo"
;global $c='foo'
- 条件判断:
if ... else ...
- 函数:
function ... return ... endfunction
- 包含其他文件或URL:
import filename
,include filename!id
,includesub filename!id
- 日志打印:
log
,dump_memory
,assert condition : "message"
- 动态参数名:
##
- 动态函数调用:
%invoke_void_func()
,%call_user_func()
- 内置函数:
%strlen,%substr,%strpos,%intval,%file_exists,function_exists,%variable_exists,%set_variable_value,%get_variable_value,%getenv,%dirpath,%filename,%date,%true,%false,%not,%lower,%upper
通用命令
- 页眉页脚:
[center | left | right] head, footer
- 缩放:
scale
- 标题:
title ... end title
- 图片标题:
caption
- 图片说明:
legend [center | left | right] ... end legend
标准库
参考:https://plantuml.com/zh/stdlib
图形举例
Usecase diagram
- 用例:
(), usecase, as
,用例描述分隔:--text--, ==text==, ..text..
- 角色:
::, actor, as
- 连接
- 箭头连接:
->, -->, <-, <--, <., <.., .>, ..>
,-right->, -left->, -down->, -up->
- 继承:
<|--
- 箭头连接:
- 注释:
note [left | right | top | bottom] of () ... end note
,note message as ID, ID .. ()
- 构造类型:
<< >>
- 方向控制:
top to bottom direction
,left to right direction
- 显示颜色&字体:
skinparam
<img src='https://g.gravizo.com/svg?
@startuml;
left to right direction;
skinparam packageStyle rectangle;
actor customer;
actor clerk;
rectangle checkout {;
customer -- (checkout);
(checkout) .> (payment) : include;
(help) .> (checkout) : extends;
(checkout) -- clerk;
};
@enduml'
alt="用例图举例">
附
gravizo不仅支持PlantUML,还支持Graphviz、UMLGraph以及JSON格式的SVG图。