二.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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM