Compare commits

...

4 Commits

5 changed files with 64 additions and 5 deletions

View File

@ -1,6 +1,7 @@
#import "utils.typ": get-group-span, fit-canvas
#import "renderer.typ": render
#import "participant.typ" as participant: _par, PAR-SPECIALS
#import "sequence.typ": _seq
#let _gap(size: 20) = {
return ((
@ -38,7 +39,9 @@
let elmts = elements
let i = 0
// Flatten groups
let activation-history = ()
// Flatten groups + convert returns
while i < elmts.len() {
let elmt = elmts.at(i)
if elmt.type == "grp" {
@ -62,6 +65,30 @@
),) +
elmts.slice(i+1)
)
} else if elmt.type == "seq" {
if elmt.enable-dst {
activation-history.push(elmt)
}
} else if elmt.type == "evt" {
if elmt.event == "enable" {
for elmt2 in elmts.slice(0, i).rev() {
if elmt2.type == "seq" {
activation-history.push(elmt2)
break
}
}
}
} else if elmt.type == "ret" {
if activation-history.len() == 0 {
panic("Cannot return if no lifeline is activated")
}
let seq = activation-history.pop()
elmts.at(i) = _seq(
seq.p2, seq.p1,
comment: elmt.comment,
disable-src: true,
dashed: true
).first()
}
i += 1
}
@ -130,6 +157,21 @@
} else if elmt.side == "right" {
linked.push("]")
}
let pars = none
if type(elmt.pos) == str {
pars = (elmt.pos,)
} else if type(elmt.pos) == array {
pars = elmt.pos
}
if pars != none {
for par in pars {
if not participant._exists(participants, par) {
participants.push(_par(par).first())
}
}
}
last-note = (
elmt: elmt,
i: i

View File

@ -1,7 +1,7 @@
#let version = version(0, 1, 1)
#import "diagram.typ": diagram, from-plantuml, _gap, _evt, _col
#import "sequence.typ": _seq
#import "sequence.typ": _seq, _ret
#import "group.typ": _grp, _loop, _alt, _opt, _break
#import "participant.typ": _par
#import "separator.typ": _sep

View File

@ -25,6 +25,9 @@
panic("Aligned notes can only be over a participant (got side '" + side + "')")
}
}
if color == auto {
color = COL-NOTE
}
return ((
type: "note",
side: side,

View File

@ -13,6 +13,7 @@
"queue",
"custom"
)
#let DEFAULT-COLOR = rgb("#E2E2F0")
#let _par(
name,
@ -20,11 +21,14 @@
from-start: true,
invisible: false,
shape: "participant",
color: rgb("#E2E2F0"),
color: DEFAULT-COLOR,
custom-image: none,
show-bottom: true,
show-top: true,
) = {
if color == auto {
color = DEFAULT-COLOR
}
return ((
type: "par",
name: name,

View File

@ -4,6 +4,9 @@
#import "note.typ"
#let get-arrow-marks(sym, color) = {
if sym == none {
return none
}
if type(sym) == array {
return sym.map(s => get-arrow-marks(s, color))
}
@ -85,6 +88,13 @@
),)
}
#let _ret(comment: none) = {
return ((
type: "ret",
comment: comment
),)
}
#let render(pars-i, x-pos, participants, elmt, y, lifelines) = {
let shapes = ()
@ -294,7 +304,7 @@
// Start circle tip
if is-circle-tip(elmt.start-tip) {
shapes += draw.circle(pts.first(), radius: CIRCLE-TIP-RADIUS, stroke: elmt.color, fill: none, name: "_circle-start-tip")
shapes += draw.circle(pts.first(), radius: CIRCLE-TIP-RADIUS, stroke: none, fill: elmt.color, name: "_circle-start-tip")
pts.at(0) = "_circle-start-tip"
// Start cross tip
@ -316,7 +326,7 @@
// End circle tip
if is-circle-tip(elmt.end-tip) {
shapes += draw.circle(pts.last(), radius: 3, stroke: elmt.color, fill: none, name: "_circle-end-tip")
shapes += draw.circle(pts.last(), radius: 3, stroke: none, fill: elmt.color, name: "_circle-end-tip")
pts.at(pts.len() - 1) = "_circle-end-tip"
// End cross tip