mermaid之序列图

mermaid中的序列图

1. 句法规则

  1. 参与者:

    隐式定义:角色的顺序按照定义顺序呈现

    sequenceDiagram
    Alice ->> John:Hello john,how are you?
    John -->> Alice:Great!

    Alice John Hello john,how are you? Great! Alice John

    也可以显式的定义角色的顺序

    sequenceDiagram
    participant John
    participant Alice
    Alice ->> John: Hello John, how are you?
    John -->> Alice: Great!

    John Alice Hello John, how are you? Great! John Alice
  2. 别名:可以为角色定义别名(别名在前)

    sequenceDiagram
    participant J as John
    participant A as Alice
    A ->> J: Hello John, how are you?
    J -->> A: Great!

    John Alice Hello John, how are you? Great! John Alice

2. 消息

  1. 目前支持六种类型的箭头:

    类型 描述
    -> 无箭头实线
    –> 无箭头虚线
    ->> 带箭头实线
    –>> 带箭头虚线
    -X(或x) 带箭头实线末端有×
    –X(或x) 带箭头虚线末端有×

3. 激活

  1. 角色可以选择激活或停用,可以以专用声明决定是否激活

    sequenceDiagram
    Alice ->> John : Hello John, how are you?
    activate John
    John -->> Alice: Great!
    deactivate John

    Alice John Hello John, how are you? Great! Alice John
  2. 还可以在箭头上附加+/-作为快捷表示方法

    sequenceDiagram
    Alice ->>+ John : Hello John, how are you?
    John -->>- Alice: Great!

    Alice John Hello John, how are you? Great! Alice John
  3. 同一个角色可以多次激活

    sequenceDiagram
    Alice ->>+ John: Hello John, how are you?
    Alice ->>+ John: John, can you hear me?
    John -->>- Alice: Hi Alice, I can hear you!
    John -->>- Alice: I feel great!

    Alice John Hello John, how are you? John, can you hear me? Hi Alice, I can hear you! I feel great! Alice John

4. 注释

  1. 序列图可以添加注释,格式为:N(n)ote [right of | left of | over][Actor]

    sequenceDiagram
    participant John
    Note right of John: Text in note

    John Text in note John
  2. 也可以创建跨越两个角色的笔记

    sequenceDiagram
    Alice -> John: Hello John, how are you?
    Note over Alice, John: A typical interaction

    Alice John Hello John, how are you? A typical interaction Alice John

5. 循环

  1. 可以在序列图中实现用符号表示的循环

    loop Loop-text

    示例:

    sequenceDiagram
    Alice->John: Hello John, how are you?
    loop Every minute
    John–>Alice: Great!
    end

    Alice John Hello John, how are you? Great! loop [ Every minute ] Alice John

6. 备选路径

  1. 可以在序列图中实现用符号表示的备选路径

    alt Describing text
    … statements …
    else
    … statements …
    end

    或者如果还有序列是可选的

    opt Describing-text
    … statements …
    end

    示例:

    Alice Bob Hello Bob, how are you? Not so good :( Feeling fresh like a daisy alt [ is sick ] [ is well ] Thanks for asking opt [ Extra response ] Alice Bob

7. CSS样式

Markdown不支持。

8. 组态

Markdown不支持。

你可能感兴趣的:(mermaid,markdown)