added delay function

This commit is contained in:
Louis Heredero 2024-10-08 11:44:53 +02:00
parent c4f09a0a3e
commit eb09a23fc1
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
6 changed files with 61 additions and 2 deletions

View File

@ -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

Binary file not shown.

View File

@ -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")

View File

@ -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

View File

@ -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)
}
}

View File

@ -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