PlantUML
PlantUML

Alice -> Bob: synchronous call
Alice ->> Bob: asynchronous call
常用模板
顺序图(Sequence Diagram)
顺序图用
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
Alice -> Bob: Another atuhentication Request
Alice <-- Bob: Another authentication Response
注释语句以单引号开始头行,即是一个单行注释。多行注释可以使用
参与者
可以使用
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
使用
actor Bob #red
' The only defference between actor
' and participant is the drawing
participant Alice
participant "I have a really\nlong name" as L #99ff99
/' You can also declare:
participant L as "I have a really\nlong name" #99ff99
'/
Alice -> Bob: Authentication Request
Bob -> Alice: Authentication Response
Bob -> L: Log transaction
一个参与者可以给自己发送消息,消息名如果需要有多行文本,可以用
Alice -> Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
消息与箭头
我们也改变箭头的样式(Change arrow style) 在用例图里可以通过以下方式来改变箭头的样式:
- 使用
\ 或/ 来替换< 或> 可以让箭头只显示上半部分或下半部分。 - 重复输入箭头或斜杠(» //
) ,用来绘制空心箭头。 - 使用双横线 – 替代
- 可以用来绘制点线。 - 在箭头后面加个
o 可以在箭头前绘制一个圆圈。 - 使用
<-> 可用来绘制双向箭头。
Bob -> Alice
Bob ->> Alice
Bob -\ Alice
Bob \\- Alice
Bob //-- Alice
Bob ->o Alice
Bob o\\-- Alice
Bob <-> Alice
Bob <<-\\o Alice
我们要改变箭头的颜色,可以使用
Bob -[#red]> Alice : hello
Alice -[#0000FF]->Bob : ok
消息序号(Message sequence numbering
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
如果需要指定一个起始号码,可以直接在
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
autonumber 15
Bob -> Alice : Another authentication Request
Bob <- Alice : Another authentication Response
autonumber 40 10
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
我们可能经常会在消息的左边或右边使用注解,要添加注解,只要使用
Alice -> Bob : hello
note left: this is a first note
Bob -> Alice : ok
note right: this is anther note
Bob -> Bob : I am thinking
note left
a note
can also be defined
on several lines
end note
通过使用关键词
participant Alice
participant Bob
note left of Alice #aqua
This is displayed
left of Alice.
end note
note right of Alice: This is displayed right of Alice.
note over Alice: This displayed over Alice.
note over Alice, Bob #FFAAAA: This is displayed\n over Bob and Alice.
note over Bob, Alice
This is yet another
example of
a long note.
end note
其他修饰
标题(Title)要给图形加一个标题可以用
title Simple Comunication example
Alice -> Bob : Authentication Request
Bob --> Alice : Authentication Response
使用
Alice -> Bob : Hello
legend right
Short
legend
endlegend
图形分割与分组
关键词
Bliss -> Tia : I love you
Bliss -> Tia : I miss you
newpage
Bliss -> Tia : Let's go home
Bliss -> Tia : Quick
newpage A title for the\nlast page
Tia -> Bliss : Give me money
Tia -> Bliss : No money No love
有时候可能需要对消息进行分组,那么可以使用下面的关键词来实现:alt/else、opt、loop、par、break、critical、
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Atuhentication Failue
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Loag alice end
end
else Another type of failue
Bob -> Alice: Please repeat
end
用例图
用例可以用一对小括号括起来表示,也可以使用
@startuml
(Usecase One)
(Usecase Two) as (UC2)
usecase UC3
usecase (Last\nusecase) as UC4
@enduml
定义参与者时,可以把参与者的名称放在两个冒号的中间,也可以用
:Actor 1:
:Another\nactor: as Men2
actor Men3
actor :Last actor: as Men4
left to right direction
skinparam packageStyle rect
actor customer
actor clerk
rectangle checkout {
customer -- (checkout)
(checkout) .> (payment) : include
(help) .> (checkout) : extends
(checkout) -- clerk
}
活动图(Activity Diagram)
在活动图中,你可以使用 (*)
来表示活动开始点和结束点。使用 –
(*) --> "First Activity"
"First Activity" --> (*)
箭头与分支
缺省情况下,活动图的箭头是没有标注的。但我们可以通过方括号
(*) --> "First Activity"
-->[You can put also labels] "Second Activity"
-->(*)
我们可以使用
-down-> 向下(这个是默认的,等同于= –>=)-right-> 向右-left-> 向左-up-> 向上
(*) --> "1"
-right-> "2"
-down-> "3"
-left-> "4"
-le-> "5"
-up-> "6"
-l-> "7"
-do-> "8"
-d-> "9"
-> "10"
--> (*)
在描述箭头时,
(*) --> "Initialisation"
if " Some Test" then
-->[ture] "Some Activity"
--> "Another Activity"
-right-> (*)
else
->[false] "Something else"
-->[Ending process] (*)
endif
对于多分支:
(*) --> if "Some Test" then
-->[true] "1"
if "" then
-> "3" as a3
else
if "Other test" then
-left-> "5"
--> (*)
else
--> "6"
--> (*)
endif
endif
else
->[false] "2"
--> (*)
endif
a3 --> if "last test" then
--> "7"
--> (*)
else
-> "8"
--> (*)
endif
活动描述
在定义活动的时候,有时候需要用多行文字来描述这个活动,这时我们可以 在描述里添加换行符
<b>
<i>
<font size="nn"> or <size:nn> to change font size
<font color="#AAAAAA"> or <font color="colorName">
<color:#AAAAAA> or <color:colorName>
<img:file.png> to include an image
针对较长文本描述活动,可以起一个较短别名(如
(*) --> "Some Activity" as s
note right: This activity has to be defined
s --> (*)
note left
This note is on
serveral lines
end note
分区(Partition)
通过分区关键词
partition Conductor
(*) --> "Climbs on Platform"
--> === S1 ===
--> Bows
end partition
partition Aduience #LightSkyBlue
=== S1 === --> Applauds
partition Conductor
Bows --> === S2 ===
--> WavesArmes
Applauds --> === S2 ===
end partition
partition Orchestra #CCCCEE
WavesArmes --> Introduction
--> "Play music"
end partition