时序图
简单示例
你可以用->来绘制参与者之间传递的消息, 而不必显式地声明参与者。
你也可以使用 --> 绘制一个虚线箭头。
另外,你还能用 <- 和 <–,这不影响绘图,但可以提高可读性。 注意:仅适用于时序图,对于其它示意图,规则是不同的。
声明参与者
声明参与者使用的关键字(不区分大小写)
- participant
- Actor
- Boundary
- DataBase
- control
- Entity
您可以使用关键字 order自定义顺序来打印参与者。这里测试不能和color同时设置,如下所示的代码会报错,As L后面color和order不能同时出现。
@startuml
participant f001 order 40
' The only different between actor
' and participant is the color
participant Alice order 20
participant "I have long \n name " As L #red order 10
f001 -> Alice: Authentication Request
Alice --> f001: Authenticaton Response
@enduml
在参与者中使用非字母符号
需要使用双引号,单引号测试不成功。注意这里括号是非字母符号
@startuml
participant f001 order 40
' The only different between actor
' and participant is the color
participant "Bob()"order 20
participant "I have long \n name " As L order 10
f001 -> "Bob()": Authentication Request
L --> f001: Authenticaton Response
@enduml
修改箭头的样式
箭头的样式:
- 表示一条丢失的消息,末尾加x
- 箭头只有上半部分或者下半部分:将<和>替换成\或者 /
- 虚线箭头:用 – 替代 -
- 箭头末尾加圈:->o
- 双向箭头:<->
- 细箭头:将箭头标记写两次 (如 >> 或 //)
@startuml
participant f001 order 40
' The only different between actor
' and participant is the color
participant "Bob()"order 20
participant "I have long \n name " As L order 10
f001 -> f001: Authentication Request
f001 ->x "Bob()"
f001 <<->>o "Bob()"
f001 -/ "Bob()"
"Bob()" -\ f001
@enduml
修改箭头的颜色
f001 -[#red]> f001: Authentication Request :将箭头的颜色变成红色
@startuml
participant f001 order 40
' The only different between actor
' and participant is the color
participant "Bob()"order 20
participant "I have long \n name " As L order 10
f001 -[#red]> f001: Authentication Request
f001 ->x "Bob()"
f001 <<->>o "Bob()"
f001 -/ "Bob()"
"Bob()" -\ f001
@enduml
基础总结性代码
@startuml
header Page Header
footer Page %page% of %lastpage%
title Exampale Title
participant f001 order 40
' The only different between actor
' and participant is the color
participant "Bob()"order 20
participant "I have long \n name " As L order 10
f001 -[#red]> f001: Authentication Request
autonumber 15 15 "<font color=red><b>Message 0"
f001 ->x "Bob()": Hi
f001 <<->>o "Bob()": Hello
newpage A title for the\nlast page
f001 -/ "Bob()": world
"Bob()" -\ f001: vender
@enduml
效果如下所示: