二.PlantUML 之活动图

注:本文只介绍新语法,旧语法由于可读性差,本人未使用.
先来一张整体效果图[源码放到本文最后],后面对语法进行简要的说明.
1. 活动图以@startuml 开始,以@enduml 结束,活动内容写到这对标记以内.
2.以 start 和 stop 表示图示的开始与结束,也可以使用 end 表示结束.
3.活动标签以冒号开始,以分号结束.例如":查询数据库;".活动按书写顺序进行连接.
问题1.活动形状只能是一种吗?当然不是,活动标签结束符也可以是如下符号
|
<
>
/
]
}
例如:
@startuml
start
:step 1;
:step 2<
:step 3>
:step 4|
:step 5]
:step 6}
stop
@enduml
问题2.活动背景色如何设置
在活动开始符:前加上颜色
例如:
#red:step;
问题3:如何改变默认箭头的样式呢?
可以在活动后面添加->,在标记前面可以添加颜色及线形修饰.以-[颜色,线形]
支持的线形如下dotted, dashed, bold,hidden
在箭头后面可以添加备注即->备注内容;注意要以分号作为备注结束符.
例如:
问题4:怎么对活动添加注释
使用 note left|right .....endnote,在 note前可以加 floating.
文本格式支持creole wiki语法
@startuml start :foo1; floating note left: This is a note :foo2; note right This note is on several //lines// and can contain <b>HTML</b> ==== * Calling the method ""foo()"" is prohibited end note stop
@enduml
问题5:如果不想要箭头了,怎么办?
在活动后面添加 detach 关键字处理.
4.条件语句,使用if(条件),then(选择值) ... else ... endif来设置.当然可以使用 elseif 进行多项选择.
例如: if(is class?) then(yes)
:show member;
else
:show error;
endif
5.重复循环,使用关键字 repeat,repeatwhile.
使用场景: 当异步任务执行时,我们要控制最大失败次数.
例:
@startuml
start
repeat
:execute task;
repeatwhile(executeCount<=5)
stop
@enduml
6.循环之二,while,endwhile
@startuml
start
while(executeCount<=5)
:execute task;
endwhile
stop
@enduml
7.并行任务,使用 fork,forkagain,endfork
@startuml
start
fork :handle part A; forkagain :handle part B; endfork
stop
@enduml
8.组合与分区,使用 partition partitionName{..................}语法.
请看如下示例
 
9.泳道,使用|#blue|泳道名|或|泳道名|语法编制.
 
 
缩合示例源码如下:
-------------------------------------------------------------------------------------------------------------------------
@startuml
|第一道|
partition partA {
start
floating note left:浮动提示信息\n使用floating note\n left|right:提示内容
if(is has step1) then(step 1)
#pink:step 1;
-[#blue]->
detach
note left
使用detach 将箭头
分离了
endnote
else(进入步骤2)
:step 2<
-[#green,dotted]->//**wangtingwei**//;
endif
}
|第二道|
partition partb {
repeat
:step 3>
-[#DD3322,dashed]->description;
note left
This note is on several
//lines// and can
contain <b>HTML</b>
====
* Calling the method ""step()""
end note
repeatwhile(executeCount<5)
:step 4|
|#blue|第三道|
-[#gray,bold]->加粗测试;
:step 5]
fork
:step 6}
forkagain
#red:step 7;
forkagain
#pink:step 8;
note right
使用fork
forkagain
endfork
并行处理.
endnote
endfork
}
stop
@enduml
posted @ 2017-09-28 11:40  冰冰与铛铛  阅读(3566)  评论(0编辑  收藏  举报