1.3 在参与者中使用非字母符号
关键字 用于改变参与者的先后顺序。
你也可以使用其它关键字来声明参与者:
@startuml
actor Foo1
boundary Foo2
control Foo3
entity Foo4
database Foo5
collections Foo6
Foo1 -> Foo2 : To boundary
Foo1 -> Foo3 : To control
Foo1 -> Foo4 : To entity
Foo1 -> Foo5 : To database
Foo1 -> Foo6 : To collections
@enduml
关键字 as 用于重命名参与者
你可以使用 RGB 值或者颜色名修改actor或参与者的背景颜色。
@startuml
actor Bob #red
' The only difference 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
@enduml
您可以使用关键字 order 自定义顺序来打印参与者。
@startuml
participant Last order 30
participant Middle order 20
participant First order 10
@enduml
1.3 在参与者中使用非字母符号
你可以使用引号定义参与者,还可以用关键字as 给参与者定义别名。
Alice -> "Bob()" : Hello
"Bob()" -> "This is very\nlong" as Long
' You can also declare:
' "Bob()" -> Long as "This is very\nlong"
Long --> "Bob()" : ok
1.4 给自己发消息
参与者可以给自己发信息,
消息文字可以用 \n来换行。
@startuml
Alice --> Alice: This is a signal to self.\nIt also demonstrates\nmultiline \ntext
@enduml
1.5 修改箭头样式
修改箭头样式的方式有以下几种:
@startuml
Bob ->x Alice
Bob -> Alice
Bob ->> Alice
Bob -\ Alice
Bob \\- Alice
Bob //-- Alice
Bob ->o Alice
Bob o\\-- Alice
Bob <-> Alice
Bob <->o Alice
@enduml
1.6 修改箭头颜色
你可以用以下记号修改箭头的颜色:
@startuml
Bob -[#red]> Alice : hello
Alice -[#0000FF]->Bob : ok
@enduml
1.7 对消息序列编号
关键字 用于自动对消息编号。
@startuml
autonumber
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
@enduml
语句 start用于指定编号的初始值,而 start 可以同时指定编号的初始值和每次增加的值。
@startuml
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
@enduml
@startuml
autonumber "[000]"
Bob -> Alice : Authentication Request
Bob <- Alice : Authentication Response
autonumber 15 "(##)"
Bob -> Alice : Another authentication Request
Bob <- Alice : Another authentication Response
autonumber 40 10 "Message 0 "
Bob -> Alice : Yet another authentication Request
Bob <- Alice : Yet another authentication Response
@enduml
你还可以用语句 stop 和 来表示暂停或继续使用自
动编号。
1.8 Page Title, and
The title is used to add a title to the page.
@startuml
header Page Header
footer Page %page% of %lastpage%
title Example Title
Alice -> Bob : message 1
Alice -> Bob : message 2
@enduml
1.9 分割示意图 (可分多个图)
关键字 用于把一张图分割成多张。
在 之后添加文字,作为新的示意图的标题。
这样就能很方便地在 Word 中将长图分几页打印。
@startuml
Alice -> Bob : message 1
Alice -> Bob : message 2
newpage
Alice -> Bob : message 3
Alice -> Bob : message 4
newpage A title for the\nlast page
Alice -> Bob : message 5
Alice -> Bob : message 6
@enduml
1.10 组合消息
我们可以通过以下关键词将组合消息:
@startuml
Alice -> Bob: Authentication Request
alt successful case
Bob -> Alice: Authentication Accepted
else some kind of failure
Bob -> Alice: Authentication Failure
group My own label
Alice -> Log : Log attack start
loop 1000 times
Alice -> Bob: DNS Attack
end
Alice -> Log : Log attack end
end
else Another type of failure
Bob -> Alice: Please repeat
end
@enduml
1.11 给消息添加注释
我们可以通过在消息后面添加 note left或者 note right 关键词来给消息添加注释。
你也可以通过使用 end note 来添加多行注释。
@startuml
Alice->Bob : hello
note left: this is a first note
Bob->Alice : ok
note right: this is another note
Bob->Bob : I am thinking
note left
a note
can also be defined
on several lines
end note
@enduml
1.12 其他的注释
可以使用 note left of,note right of 或note over 在节点 () 的相对位置放置注释。
还可以通过修改背景色来高亮显示注释。
以及使用关键字 end note 来添加多行注释。
@startuml
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 is 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
@enduml
1.13 改变备注框的形状
你可以使用 hnote 和 rnote 这两个关键字来修改备注框的形状。
@startuml
caller -> server : conReq
hnote over caller : idle
caller <- server : conConf
rnote over server
"r" as rectangle
"h" as hexagon
endrnote
@enduml
1.14 和 HTML
可以使用 格式。
@startuml
participant Alice
participant "The **Famous** Bob" as Bob
Alice -> Bob : hello --there--
... Some ~~long delay~~ ...
Bob -> Alice : ok
note left
This is **bold**
This is //italics//
This is ""monospaced""
This is --stroked--
This is __underlined__
This is ~~waved~~
end note
Alice -> Bob : A //well formatted// message
note right of Alice
This is displayed
__left of__ Alice.
end note
note left of Bob
This</u> is displayedor>
**<color purple>left of Alice Bob**.
end note
note over Alice, Bob
<w:#FF33FF>This is hosted by
end note
@enduml
1.15 分隔符
你可以通过使用 == 关键词来将你的图表分割多个步骤。
@startuml
== Initialization ==
Alice -> Bob: Authentication Request
Bob --> Alice: Authentication Response
== Repetition ==
Alice -> Bob: Another authentication Request
Alice <-- Bob: another authentication Response
@enduml
1.16 引用
你可以在图中通过使用 ref over关键词来实现引用
@startuml
participant Alice
actor Bob
ref over Alice, Bob : init
Alice -> Bob : hello
ref over Bob
This can be on
several lines
end ref
@enduml
1.17 延迟
你可以使用... 来表示延迟,并且还可以给延迟添加注释。
@startuml
Alice -> Bob: Authentication Request
...
Bob --> Alice: Authentication Response
...5 minutes latter...
Bob --> Alice: Bye !
@enduml
1.18 空间
你可以使用 |||来增加空间。
还可以使用数字指定增加的像素的数量。
@startuml
Alice -> Bob: message 1
Bob --> Alice: ok
|||
Alice -> Bob: message 2
Bob --> Alice: ok
||45||
Alice -> Bob: message 3
Bob --> Alice: ok
@enduml
1.19 生命线的激活与撤销
关键字 和 用来表示参与者的生命活动。
一旦参与者被激活,它的生命线就会显示出来。
和 适用于以上情形。
表示一个参与者的生命线的终结。
@startuml
participant User
User -> A: DoWork
activate A
A -> B: << createRequest >>
activate B
B -> C: DoWork
activate C
C --> B: WorkDone
destroy C
B --> A: RequestCreated
deactivate B
A -> User: Done
deactivate A
@enduml
还可以使用嵌套的生命线,并且运行给生命线添加颜色。
@startuml
participant User
User -> A: DoWork
activate A #FFBBBB
A -> A: Internal call
activate A #DarkSalmon
A -> B: << createRequest >>
activate B
B --> A: RequestCreated
deactivate B
deactivate A
A -> User: Done
deactivate A
@enduml
1.20
生成消息有可选的 方式。表示返回到最近的生命线。
@startuml
Bob -> Alice : hello
activate Alice
Alice -> Alice : some action
return bye
@enduml
1.21 创建参与者
你可以把关键字 放在第一次接收到消息之前,以强调本次消息实际上是在创建新的对象。
@startuml
Bob -> Alice : hello
create Other
Alice -> Other : new
create control String
Alice -> String
note right : You can also put notes!
Alice --> Bob : ok
@enduml
1.22 进入和发出消息
如果只想关注部分图示,你可以使用进入和发出箭头。
使用方括号 [和] 表示图示的左、右两侧。
@startuml
[-> A: DoWork
activate A
A -> A: Internal call
activate A
A ->] : << createRequest >>
A<--] : RequestCreated
deactivate A
[<- A: Done
deactivate A
@enduml
还可以使用下面的语法:
@startuml
[-> Bob
[o-> Bob
[o->o Bob
[x-> Bob
[<- Bob
[x<- Bob
Bob ->]
Bob ->o]
Bob o->o]
Bob ->x]
Bob <-]
Bob x<-]
@enduml
1.23 构造类型和圈点
可以使用 给参与者添加构造类型。
在构造类型中,你可以使用(X,color)格式的语法添加一个圆圈圈起来的字符。
@startuml<