Skip to content

Commit 823db56

Browse files
Merge pull request #72 from cgreeno/feat/sequence-loop-opt
2 parents aca2416 + 38e60d3 commit 823db56

14 files changed

Lines changed: 745 additions & 9 deletions

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,32 @@ $ mermaid-ascii -f sequence.mermaid
326326
│◄┈┈┈┈┈┈┈┈┈┈┈┤
327327
│ │
328328

329+
# Loop and opt blocks are drawn as labelled frames (and can be nested)
330+
$ cat sequence.mermaid
331+
sequenceDiagram
332+
Alice->>Bob: Hello
333+
loop every minute
334+
Alice->>Bob: Ping
335+
Bob-->>Alice: Pong
336+
end
337+
$ mermaid-ascii -f sequence.mermaid
338+
┌───────┐ ┌─────┐
339+
│ Alice │ │ Bob │
340+
└───┬───┘ └──┬──┘
341+
│ │
342+
│ Hello │
343+
├───────────►│
344+
┌─[loop every minute]─┐
345+
│ │ │ │
346+
│ │ Ping │ │
347+
│ ├───────────►│ │
348+
│ │ │ │
349+
│ │ Pong │ │
350+
│ │◄┈┈┈┈┈┈┈┈┈┈┈┤ │
351+
│ │ │ │
352+
└─────────────────────┘
353+
│ │
354+
329355
# ASCII mode for sequence diagrams
330356
$ cat sequence.mermaid | mermaid-ascii --ascii
331357
+-------+ +-----+
@@ -525,9 +551,11 @@ Note that with `--coords` enabled, the grid-coords shown show the starting locat
525551
- [x] Participant aliases (`participant A as Alice`)
526552
- [x] Unicode support (emojis, CJK characters, etc.)
527553
- [x] Both ASCII and Unicode rendering modes
554+
- [x] `loop` and `opt` blocks (incl. nesting)
555+
- [x] `autonumber`
528556
- [ ] Activation boxes
529557
- [ ] Notes (`Note left of Alice: text`)
530-
- [ ] Loops, alt, opt blocks
558+
- [ ] `alt`/`else`, `par`, `critical`, `break`, `rect` blocks
531559

532560
## TODOs
533561

@@ -555,7 +583,8 @@ The baseline components for Mermaid work, but there are a lot of things that are
555583

556584
- [ ] Activation boxes (activate/deactivate)
557585
- [ ] Notes (`Note left of Alice: text`)
558-
- [ ] Loops, alt, opt, and par blocks
586+
- [x] `loop` and `opt` blocks
587+
- [ ] `alt`, `par`, `critical`, `break`, and `rect` blocks
559588

560589
### General
561590

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
sequenceDiagram
2+
Alice->>Bob: Hello
3+
loop every minute
4+
Alice->>Bob: Ping
5+
Bob-->>Alice: Pong
6+
end
7+
Alice->>Bob: Bye
8+
---
9+
+-------+ +-----+
10+
| Alice | | Bob |
11+
+---+---+ +--+--+
12+
| |
13+
| Hello |
14+
+----------->|
15+
+-[loop every minute]-+
16+
| | | |
17+
| | Ping | |
18+
| +----------->| |
19+
| | | |
20+
| | Pong | |
21+
| |<...........+ |
22+
| | | |
23+
+---------------------+
24+
| |
25+
| Bye |
26+
+----------->|
27+
| |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sequenceDiagram
2+
A->>B: hi
3+
loop nothing here
4+
end
5+
---
6+
+---+ +---+
7+
| A | | B |
8+
+-+-+ +-+-+
9+
| |
10+
| hi |
11+
+-------->|
12+
+-[loop nothing here]-+
13+
| | | |
14+
+---------------------+
15+
| |
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sequenceDiagram
2+
User->>Server: Request
3+
opt is premium
4+
Server->>Server: Apply discount
5+
end
6+
Server-->>User: Response
7+
---
8+
+------+ +--------+
9+
| User | | Server |
10+
+---+--+ +----+---+
11+
| |
12+
| Request |
13+
+------------>|
14+
| +-[opt is premium]-+
15+
| | | |
16+
| | | Apply discount |
17+
| | +--+ |
18+
| | | | |
19+
| | |<-+ |
20+
| | | |
21+
| +------------------+
22+
| |
23+
| Response |
24+
|<............+
25+
| |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sequenceDiagram
2+
participant A
3+
participant B
4+
participant C
5+
A->>C: kickoff
6+
loop poll
7+
B->>C: check
8+
end
9+
---
10+
┌───┐ ┌───┐ ┌───┐
11+
│ A │ │ B │ │ C │
12+
└─┬─┘ └─┬─┘ └─┬─┘
13+
│ │ │
14+
│ kickoff │ │
15+
├──────────────────►│
16+
│ ┌─[loop poll]─┐
17+
│ │ │ │ │
18+
│ │ │ check │ │
19+
│ │ ├────────►│ │
20+
│ │ │ │ │
21+
│ └─────────────┘
22+
│ │ │
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sequenceDiagram
2+
autonumber
3+
A->>B: one
4+
loop twice
5+
A->>B: two
6+
B-->>A: three
7+
end
8+
---
9+
┌───┐ ┌───┐
10+
│ A │ │ B │
11+
└─┬─┘ └─┬─┘
12+
│ │
13+
│ 1. one │
14+
├────────►│
15+
┌─[loop twice]─┐
16+
│ │ │ │
17+
│ │ 2. two │ │
18+
│ ├────────►│ │
19+
│ │ │ │
20+
│ │ 3. three│ │
21+
│ │◄┈┈┈┈┈┈┈┈┤ │
22+
│ │ │ │
23+
└──────────────┘
24+
│ │
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
sequenceDiagram
2+
Alice->>Bob: Hello
3+
loop every minute
4+
Alice->>Bob: Ping
5+
Bob-->>Alice: Pong
6+
end
7+
Alice->>Bob: Bye
8+
---
9+
┌───────┐ ┌─────┐
10+
│ Alice │ │ Bob │
11+
└───┬───┘ └──┬──┘
12+
│ │
13+
│ Hello │
14+
├───────────►│
15+
┌─[loop every minute]─┐
16+
│ │ │ │
17+
│ │ Ping │ │
18+
│ ├───────────►│ │
19+
│ │ │ │
20+
│ │ Pong │ │
21+
│ │◄┈┈┈┈┈┈┈┈┈┈┈┤ │
22+
│ │ │ │
23+
└─────────────────────┘
24+
│ │
25+
│ Bye │
26+
├───────────►│
27+
│ │
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sequenceDiagram
2+
A->>B: hi
3+
loop nothing here
4+
end
5+
---
6+
┌───┐ ┌───┐
7+
│ A │ │ B │
8+
└─┬─┘ └─┬─┘
9+
│ │
10+
│ hi │
11+
├────────►│
12+
┌─[loop nothing here]─┐
13+
│ │ │ │
14+
└─────────────────────┘
15+
│ │
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sequenceDiagram
2+
User->>Server: Request
3+
opt is premium
4+
Server->>Server: Apply discount
5+
end
6+
Server-->>User: Response
7+
---
8+
┌──────┐ ┌────────┐
9+
│ User │ │ Server │
10+
└───┬──┘ └────┬───┘
11+
│ │
12+
│ Request │
13+
├────────────►│
14+
│ ┌─[opt is premium]─┐
15+
│ │ │ │
16+
│ │ │ Apply discount │
17+
│ │ ├──┐ │
18+
│ │ │ │ │
19+
│ │ │◄─┘ │
20+
│ │ │ │
21+
│ └──────────────────┘
22+
│ │
23+
│ Response │
24+
│◄┈┈┈┈┈┈┈┈┈┈┈┈┤
25+
│ │
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sequenceDiagram
2+
A->>B: x
3+
opt
4+
A->>B: y
5+
end
6+
---
7+
┌───┐ ┌───┐
8+
│ A │ │ B │
9+
└─┬─┘ └─┬─┘
10+
│ │
11+
│ x │
12+
├────────►│
13+
┌─[opt]───────┐
14+
│ │ │ │
15+
│ │ y │ │
16+
│ ├────────►│ │
17+
│ │ │ │
18+
└─────────────┘
19+
│ │

0 commit comments

Comments
 (0)