diff --git a/TODO.md b/TODO.md index 77e47f9..fa16489 100644 --- a/TODO.md +++ b/TODO.md @@ -23,6 +23,6 @@ - [ ] PlantUML parser - [ ] (Message numbering) - [ ] Mainframes -- [ ] Different types of groups (alt/loop/etc.) +- [x] Different types of groups (alt/loop/etc.) - [ ] Delays - [ ] Auto-fit in parent \ No newline at end of file diff --git a/gallery/example1.pdf b/gallery/example1.pdf index a3f8e8f..0bc4f9c 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example1.typ b/gallery/example1.typ index 28d10de..89ee3ae 100644 --- a/gallery/example1.typ +++ b/gallery/example1.typ @@ -78,6 +78,15 @@ Alice <-- Bob: Another authentication Response _seq("Bob", "Alice", comment: "another authentication Response", dashed: true) }) +#chronos.diagram({ + import chronos: * + _seq("Alice", "Bob", comment: "Authentication Request") + _delay() + _seq("Bob", "Alice", comment: "Authentication Response") + _delay(name: "5 minutes later") + _seq("Bob", "Alice", comment: "Good Bye !") +}) + #chronos.diagram({ import chronos: * _seq("Alice", "Bob", comment: "message 1") diff --git a/src/lib.typ b/src/lib.typ index 79c8ab6..a2568fb 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -4,6 +4,6 @@ #import "sequence.typ": _seq, _ret #import "group.typ": _grp, _loop, _alt, _opt, _break #import "participant.typ": _par -#import "separator.typ": _sep +#import "separator.typ": _sep, _delay #import "note.typ": _note #import "sync.typ": _sync \ No newline at end of file diff --git a/src/renderer.typ b/src/renderer.typ index 4d9c46c..b489bbe 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -322,6 +322,26 @@ // Gap } else if elmt.type == "gap" { y -= elmt.size + + // Delay + } else if elmt.type == "delay" { + let y0 = y + let y1 = y - elmt.size + for (i, line) in lifelines.enumerate() { + line.lines.push(("delay-start", y0)) + line.lines.push(("delay-end", y1)) + lifelines.at(i) = line + } + if elmt.name != none { + let x0 = x-pos.first() + let x1 = x-pos.last() + shapes += draw.content( + ((x0 + x1) / 2, (y0 + y1) / 2), + anchor: "center", + elmt.name + ) + } + y = y1 // Event } else if elmt.type == "evt" { @@ -435,6 +455,28 @@ if event == "destroy" { destructions.push((x + lvl * LIFELINE-W / 2, line.at(1))) } + } else if event == "delay-start" { + draw.line( + (x, last-y), + (x, line.at(1)), + stroke: ( + dash: "dashed", + paint: gray.darken(40%), + thickness: .5pt + ) + ) + last-y = line.at(1) + } else if event == "delay-end" { + draw.line( + (x, last-y), + (x, line.at(1)), + stroke: ( + dash: "loosely-dotted", + paint: gray.darken(40%), + thickness: .8pt + ) + ) + last-y = line.at(1) } } diff --git a/src/separator.typ b/src/separator.typ index a203bc8..c041bc9 100644 --- a/src/separator.typ +++ b/src/separator.typ @@ -8,6 +8,14 @@ ),) } +#let _delay(name: none, size: 30) = { + return (( + type: "delay", + name: name, + size: size + ),) +} + #let render(x-pos, elmt, y) = { let shapes = () y -= Y-SPACE