Mermaid知识点总结6 - Sequence diagram 2

Mermaid知识点总结6 - Sequence diagram 2

描述循环

以下语法可以在Sequence diagram中描述循环:

loop Loop text
... statements ...
end

如下实例所示:

sequenceDiagram
    Alice->John: Hello John, how are you?
    loop Every minute
        John-->Alice: Great!
    end
Alice John Hello John, how are you? 1 Great! 2 loop [Every minute] Alice John
可选对话

可以使用alt…else…或者opt进行可选对话的描述,如下所示:

sequenceDiagram
    Alice->>Bob: Hello Bob, how are you?
    alt is sick
        Bob->>Alice: Not so good :(
    else is well
        Bob->>Alice: Feeling fresh like a daisy
    else is hy
    	Bob->>Alice: Always feeling well if you are around
    end
    opt Extra response
        Bob->>Alice: Thanks for asking
    end
Alice Bob Hello Bob, how are you? 1 Not so good :( 2 Feeling fresh like a daisy 3 Always feeling well if you are around 4 alt [is sick] [is well] [is hy] Thanks for asking 5 opt [Extra response] Alice Bob
多个参与者

参与者可以不只两个人,相应的某个参与者可以与多个参与者进行互动,使用par表示平行关系,如下所示:

par [Action 1]
... statements ...
and [Action 2]
... statements ...
and [Action N]
... statements ...
end

讲道理,这个教程中只给出了结果没有给原文,下面是根据结果自己写的:

sequenceDiagram
	par Alice to Bob
    	Alice->>Bob: Hello guys!
    and Alice to John
        Alice->>John: Hello guys!
    end
    Bob -->> Alice: Hi Alice!
    John -->> Alice: Hi Alice!
Alice Bob John Hello guys! 1 Hello guys! 2 par [Alice to Bob] [Alice to John] Hi Alice! 3 Hi Alice! 4 Alice Bob John

同样,可以嵌套进行par,下面也是根据教程中的图例自己写的:

sequenceDiagram
	par Alice to Bob
    	Alice->>Bob: Go Help John
    and Alice to John
        Alice->>John: I want this done today
        par John to Charlie
            John->>Charlie: Can we do this today?
        and John to Diana
            John->>Diana: Can we do this today?
        end
    end
Alice Bob John Charlie Diana Go Help John 1 I want this done today 2 Can we do this today? 3 Can we do this today? 4 par [John to Charlie] [John to Diana] par [Alice to Bob] [Alice to John] Alice Bob John Charlie Diana
背景强调

可以使用以下语法将相应内容区域背景填充颜色,背景颜色以rgb或者rgba进行规定:

rect rgb(0, 255, 0)
... content ...
end
rect rgba(0, 0, 255, .1)
... content ...
end

不给源码哦,难顶,下面是根据样例自己写的:

sequenceDiagram
	rect rgb(191, 223, 255)
        Note right of Alice: Alice calls John.
            Alice ->>+ John:Hello John, how are you?
            rect rgb(200, 150, 255)
                Alice ->>+ John:John, can you hear me?
                John -->>- Alice:Hi Alice, I can hear you!
            end
        John -->>- Alice:I feel great!
	end
	Alice ->>+ John:Do you want to go to the game tonight?
	John -->>- Alice:Yeah!See you there.
Alice John Alice calls John. Hello John, how are you? 1 John, can you hear me? 2 Hi Alice, I can hear you! 3 I feel great! 4 Do you want to go to the game tonight? 5 Yeah!See you there. 6 Alice John

我怀疑原教程此处有语法错误:

image-20210908113717056

序列号

可以对序列顺序添加序号,如下所示:

sequenceDiagram
    autonumber
    Alice->>John: Hello John, how are you?
    loop Healthcheck
        John->>John: Fight against hypochondria
    end
    Note right of John: Rational thoughts!
    John-->>Alice: Great!
    John->>Bob: How about you?
    Bob-->>John: Jolly good!
Alice John Bob Hello John, how are you? 1 Fight against hypochondria 2 loop [Healthcheck] Rational thoughts! Great! 3 How about you? 4 Jolly good! 5 Alice John Bob
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值