markdown mermaid sequence diagram

Sequence diagram (sequence diagram)

A sequence diagram is an interaction diagram that shows how processes operate with each other and in what order.

sequenceDiagram
	participant l as timber wolf
	participant y as lamb

	l->>y:Little villain, dirty the water I drink
	y->>l:Mr. wolf, you are upstream and I am downstream
	l->>y:I heard you spoke ill of me last year
	y->>l:I wasn't born last year
	l->>y:It's not you, it's your father, and he jumped on it
	
	%% left or right
	note left of l:For bad guys,<br>There is always a reason to want to do bad things.
sequenceDiagram participant l as the wolf participant y as lamb L - > > y: little villain, dirty the water I drink Y - > L: Mr. wolf, you are upstream and I am downstream L - > > y: I heard you spoke ill of me last year Y - > L: I wasn't born last year L - > > y: it's not you, it's your father too. He jumped on it %% left or right note left of l: for bad people, < br > there is always a reason to do bad things.

Basic grammar

sequenceDiagram
	 participant A as Mr Black   		: Participant declaration (not required unless you need to define a simple alias)
	
	[Actor][Arrow][Actor]:Message text  
  • participant: participant

The participant is participant by default, so it is generally unnecessary to display the declaration. However, when the participant's characters are long, you can define a simple alias by displaying the declaration, so that you can knock the keyboard less.

sequenceDiagram 
    participant A as Mr Black
    participant B as Tom Cat
sequenceDiagram participant A as Mr Black participant B as Tom Cat A->>B:Hello.How are you! B->>A:I am fine ,thank you.
  • Participant: actor (due to the higher version, many mrkdown editors don't support it, so they just skim over)

If you especially want to use actor symbols instead of rectangles with text, you can use actor to declare participants.

sequenceDiagram
    actor Alice
    actor Bob
    Alice->>Bob: Hi Bob
    Bob->>Alice: Hi Alic

alias

Participants can have convenient identifiers and descriptive labels, that is, aliases. If the participant name is too long, it can be replaced by an alias.

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

Connection and arrow types

type describe
-> Solid line without arrow
--> Dotted line without arrow
->> Solid lines have arrows
-->> The dotted line has an arrow
-x Solid line crossing arrow
--x Dashed cross arrow
-) Solid line with an open arrow at the end (async)
The version is too high and is not supported by most markdown editors.
--) Dotted line with a open arrow at the end (async)
The version is too high. Most markdown editors do not support it
sequenceDiagram
	participant A as Tom
	participant B as Cat
	note left of A: Test line shapes and arrows
	
	A->B:have you had dinner
	B->>A:Eat.
	A-->B:It's almost the new year. Are you going home?
	B-->>A:Novel coronavirus pneumonia is so serious that it can't go back.
	A-xB:Yes, I have to be isolated for 14 days.
	B--xA:Shit, isolation for 14 days, not so many holidays.
	%%A-) B:hello
	%%B--)A:ok	
sequenceDiagram participant A as Tom participant B as Cat note left of A: test line shape and arrow A - > b: have you eaten yet? B - > A: Yes. A -- > b: it's almost the new year. Are you going home? B-->>A: novel coronavirus pneumonia is so serious that it can't go back. A-xB: Yes, I have to be isolated for 14 days. B--xA: shit, isolation for 14 days. There aren't so many holidays. %%A-) B:hello %%B--)A:ok

activity

Make a participant active. This is done by activating and deactivating a participant

sequenceDiagram
	participant t as Math teacher
	participant s as Gaussian
	
	t->>s:Give a question:<br>1+2+3+...+100=?
	activate s
		s-->>s:I think it over. Small case
		s->>t:1+2+3+...+100=5050	
	deactivate s
	t-->>s:0-0,Smart.
	s--xt: *_*	
sequenceDiagram Participant as math teacher participant s as Gauss T - > > s: give a question: < br > 1 + 2 + 3 ++ 100=? activate s S -- > > s: let me see. Small case s->>t:1+2+3+...+100=5050 deactivate s T -- > > s: 0-0, smart. s--xt: *_*

This is also a quick representation by appending + / - suffix to the message arrow (recommended, this method is more concise):

sequenceDiagram
	participant t as Math teacher
	participant s as Gaussian
	
	t->>+s:Give a question:<br>1+2+3+...+100=?
	s-->>s:I think it over. Small case
	s->>-t:1+2+3+...+100=5050	
	t-->>s:0-0,Smart.
	s--xt: *_*	
sequenceDiagram Participant as math teacher participant s as Gauss T - > > + s: give a question: < br > 1 + 2 + 3 ++ 100=? S -- > > s: let me see. Small case s->>-t:1+2+3+...+100=5050 T -- > > s: 0-0, smart. s--xt: *_*

notes

You can add comments to the sequence diagram.

grammar

Note [ right of | left of | over ] [Paticipant]: Text in note content

eg:

sequenceDiagram
	participant l as timber wolf
	participant y as lamb
	participant d as Dog Warrior
	
	%% left or right
	Note left of l:For bad guys,<br>There is always a reason to want to do bad things.
	Note right of y:Countermeasures for bad guys: do or hide.
	Note over  d:The Ranger stood up for justice and roared when he saw injustice.
sequenceDiagram participant l as the wolf participant y as lamb participant d as dog Warrior %% left or right note left of l: for bad people, < br > there is always a reason to do bad things. note right of y: the choice for bad people: do or hide. Note over D: Rangers stand up for justice and shout when they see injustice.

Comments across 2 participants (up to 2)

Syntax:

Note [ right of | left of | over ] [Paticipant,Participant]: Text in note content

eg:

sequenceDiagram
	participant l as timber wolf
	participant y as lamb
	participant d as Dog Warrior
	
	%% left or right
	note left of l:For bad guys,<br>There is always a reason to want to do bad things.<br>The mutton is delicious.
	note over  d,y:Sister sheep, don't be afraid.
	Note over  l,d:Brother dog, I roared when I saw injustice. Big gray wolf, you go quickly
sequenceDiagram participant l as the wolf participant y as lamb participant d as dog Warrior %% left or right note left of l: for bad people, < br > there is always a reason to do bad things< Br > the mutton is delicious. Note over D, Y: don't be afraid, sister sheep. Note over L, D: brother dog, I yell when I see injustice. Wolf, you go quickly.

loop

Loops can be represented in sequence diagrams. The syntax is as follows:

loop Loop text
	... statements ...
end

eg:

sequenceDiagram
	participant t as sir
	participant s as scholar
	participant k as Ministry of Rites
	
	loop persevere ten years in one 's studies in spite of hardships
        t->>+ s:teach
        s-->>s:study&reflection
        s->>-t:ask

	end
	
	s->>+k:Go to Beijing for the exam and participate in the autumn palace
	k-->>k:Find problems and select materials for our country
	k->>-s:Live up to your heart<br>Trouble on the wedding night
	
	loop A day on the street
    	s-->>s:Complacent horseshoe disease,<br>See all the Changan flowers in one day.
	end
sequenceDiagram Mr. participant as participant s as scholar participant k as etiquette Department loop decade cold window T - > > + s: teach S -- > > s: Learning & Thinking S - > > - t: ask end S - > > + K: go to Beijing for the exam and participate in the autumn palace K -- > > k: find problems and select materials for our country K - > > - s: live up to those who have a heart < br > No. 1 and loop Street Day S -- > > s: proud of horseshoe disease, < br > see all the Changan flowers in a day. end

Route selection

Alternative paths can be represented in sequence diagrams. The syntax is as follows:

alt Describing text
... statements ...
else  Describing text
... statements ...
end

Other options

opt Describing text
... statements ...
end

eg:

sequenceDiagram
    participant s as successful candidates of the national civil service examination
    participant d as Palace examination
    
     s->> d:Take the palace exam
     alt One armour
         d->>s:Jinshi and
      else Two armour
         d->>s:Jinshi origin
      else Top three
         d->>s:The same Jinshi origin
     end
     opt Not in it
      d--xs:Take it. You're not a Gonz.
     end
sequenceDiagram participant s as Gongshi participant d as S - > > D: take the palace test alt a D - > > s: Jinshi and else dimethyl D - > s: Jinshi background else triple A D - > > s: from the same scholar end opt is not among them d--xs: take it. You're not a Gongshi. end

parallel

You can display actions that occur in parallel. The syntax is as follows:

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

Parallelism can also be nested. The syntax is as follows:

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

eg

sequenceDiagram
	participant t as Tom
	participant k as Kite
	participant b as Black
	par notice
		t->>k:Went out together?
	and
		t->> b:Go out together?
	end
	k->>t:OK
	b->>t:ok
sequenceDiagram participant t as Tom participant k as Kite participant b as Black par notification T - > > k: go out and play and T - > > b: go out and play end K - > t: OK b->>t:ok

Background color

You can highlight the stream by providing a colored background rectangle. grammar

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

Or add transparent color

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

0.1 can be expressed as. 1.

Introduction to rgb: https://www.cnblogs.com/wwwxxxyyy/p/13973380.html

eg

sequenceDiagram participant s as Gongshi participant d as rect rgb(1,150,200) S - > > D: take the palace test alt a D - > > s: Jinshi and else dimethyl D - > s: Jinshi background else triple A D - > > s: from the same scholar end end rect rgba(200,100,50,.2) opt is not among them d--xs: take it. You're not a Gongshi. end end

serial number

You can add a serial number to each connection in the sequence diagram. Turn on automatic numbering with code (autonumber):

sequenceDiagram
	autonumber
	participant k as Laokong
	participant m as Lao Meng
    k->>m: Have you eaten yet?
    m-->>k: Ate rougamo!
sequenceDiagram autonumber participant k as old Kong participant m as Lao Meng K - > > m: have you eaten yet? M -- > > k: I ate rougamo!

Code annotation

You can enter comments in the sequence diagram, which the parser ignores. Comments require a separate line and must begin with%% (double percentile). Any text from the beginning of a comment to the next line break is considered a comment, including any chart syntax.

sequenceDiagram
    Alice->>John: Have you eaten yet?
    %% this is a comment
    John-->>Alice: Ate rougamo!
sequenceDiagram %%autonumber participant k as old Kong participant m as Lao Meng K - > > m: have you eaten yet? %% this is a comment M -- > > k: I ate rougamo!

Comprehensive examples

sequenceDiagram participant a as participant y as Israel participant m as USA participant l as United Nations %%Phase I rect rgb(200,250,150) A - > > + Y: get out of Arab territory< Br > open and dry directly par loop Y -- > > - A: sneak attack I'm on top end and y--x m: brother, give me a hand An immediate ceasefire is needed end M -- > L: it is suggested that both sides cease fire L -- > > L: listen to boss Mei. par ceasefire for three days l ->>a:stop and l->>y:stop end par loop Y - > > y: military expansion, military restructuring end and Y - > > m: purchase weapons M - > > y: give me what you want for airplanes and cannons and loop Arab A -- > > A: just make some adjustments. Little Israel is vulnerable. end end end %%Phase II rect rgb(90,200,255) loop 10 day attack Y - > > + A: everything is ready. Go dry! A - > > - Y: I'm on top. end par ceasefire l ->>a:stop a-->>l:ok and l->>y:stop y->>l:ok end end %%Phase III rect rgb(100,100,200) loop Y - > > + A: with the support of the American boss, the ceasefire agreement is a ball. I'll fight! A - > > - Y: I have to top, top... A -- > > A: what a tragedy. Y - > A: it has occupied a lot of territory. Stop the troops. Ya, be honest in the future. end end

Keywords: markdown

Added by slava on Thu, 13 Jan 2022 11:00:10 +0200