简体中文
English 简体中文 繁體中文
Methodox 首页

时序图

时序图展示谁对谁说了什么,按顺序从上往下排列。它以 sequence 及其标题开头。

sequence Paying at the till
actor Customer
participant Till
participant bank: Bank of Example
database Ledger
Customer -> Till: Scan the items
Till -> bank: Ask to pay 12.50
bank -> Ledger: Hold the amount
Ledger --> bank: Held
if Card accepted
  bank --> Till: Approved
  Till --> Customer: Receipt
else Card declined
  bank --> Till: Declined
  Till --> Customer: Try another card
note over Till, bank: Card details never stay on the till

上面的文本:顾客、收银台、银行和账本,它们之间的调用及其激活条,以及同一个框中的 if 和 else

设置

设置 别名 值
numbers numbered, numbering, autonumber on 为消息编号;默认关闭。单独一行的 autonumber 效果相同。
activations activation, bars off 表示不画激活条;默认开启
mirror footer, heads below off 表示不在底部重复画出参与者的头部;默认开启

参与者

参与者以列表示,按首次命名的顺序排列 —— 无论是在消息中命名,还是在顶部声明:

行 绘制为
participant Till 方框
actor Customer(也可写作 person) 人形
database Ledger 圆柱体

声明时可以为长名称指定一个用于书写消息的短名称,两种顺序均可:participant bank: Bank of Example,或 participant Bank of Example as bank。名称后方括号中的颜色会为参与者的头部着色:actor Customer [orange]。

消息

From -> To: what is said 是一条消息,消息按书写顺序从上往下排列。

箭头 含义
->, ->> 调用:带实心箭头的实线
-->, -->>, ..> 回复:带开放箭头的虚线
<-, <-- 同上,但指回第一个名称

得到回复的调用会在接收方画一个激活条,从调用一直延续到回复返回;从未得到回复的调用则不画。发给自己的消息 —— Ann -> Ann: Think —— 是位于其自身列上的一个回环。文字后方括号中的颜色或角色会为消息着色:Till --> Customer: Declined [bad]。

块

缩进在块关键字下方的行会被画在一个框中,框以该关键字命名,关键字之后的文字作为其条件:

单词 别名 用途
loop 重复进行的事情
if alt 选择;在其各行之后、以相同缩进写的 else 会增加另一种情况
opt optional 可能发生的事情
par parallel 同时发生的事情;and 会增加另一条分支
critical 必须完整发生的事情
break 代替其余部分发生的事情
region 其他任何需要加框的片段
sequence A month of banking
numbers: on
actor Ann
participant Bank of Example as Bank
Ann -> Bank: Log in
Bank --> Ann: Welcome
== Every month ==
loop Until the account is closed
  Bank -> Ann: Statement
  Ann --> Bank: Read
par
  Ann -> Bank: Pay the rent
and
  Ann -> Bank: Save a little
note right of Ann: Busy month
Ann -> Ann: Plan next month

上面的文本:带编号的消息、一条分隔线、一个循环、一个包含两条分支的 par、一条注释,以及一条发给自己的消息

没有紧跟在其 if 或 par 之后的 else 或 and 会被指出。下方有缩进行的消息会收到警告 —— 只有块才能包含行 —— 这些行会被当作消息读取。

注释和分隔线

行 绘制为
note over A: text 位于 A 上方的注释
note over A, C: text 从 A 横跨到 C 的注释
note left of A: text 位于 A 左侧的注释
note right of A: text 位于 A 右侧的注释
== Later that day == 横贯所有列的分隔线