added participant creation

This commit is contained in:
2024-06-18 23:01:53 +02:00
parent 4dd940f584
commit a9b467152a
7 changed files with 103 additions and 43 deletions

View File

@ -1,6 +1,7 @@
#import "@preview/cetz:0.2.2": canvas, draw
#import "utils.typ": get-participants-i, get-style
#import "group.typ"
#import "participant.typ"
#import "sequence.typ"
#import "separator.typ"
#import "consts.typ": *
@ -106,17 +107,17 @@
for width in widths {
x-pos.push(x-pos.last() + width)
}
let draw-seq = sequence.render.with(pars-i, x-pos, participants)
let draw-group = group.render.with()
let draw-sep = separator.render.with(x-pos)
let draw-par = participant.render.with(x-pos)
// Draw participants (start)
for (i, p) in participants.enumerate() {
shapes += draw.content(
(x-pos.at(i), 0),
p.display-name,
name: p.name,
frame: "rect",
padding: PAR-PAD,
anchor: "south"
)
for p in participants {
if p.from-start {
shapes += draw-par(p)
}
}
let y = -Y-SPACE
@ -126,10 +127,6 @@
lines: ()
))
let draw-seq = sequence.render.with(pars-i, x-pos)
let draw-group = group.render.with()
let draw-sep = separator.render.with(x-pos)
// Draw elemnts
for elmt in elements {
// Sequences
@ -181,11 +178,7 @@
let x = x-pos.at(i)
// Draw vertical line
draw.line(
(x, 0),
(x, y),
stroke: (dash: "dashed", paint: gray.darken(40%))
)
let last-y = 0
let rects = ()
let destructions = ()
@ -194,19 +187,45 @@
// Compute lifeline rectangles + destruction positions
for line in lifelines.at(i).lines {
let event = line.first()
if event == "enable" {
if event == "create" {
last-y = line.at(1)
} else if event == "enable" {
if lines.len() == 0 {
draw.line(
(x, last-y),
(x, line.at(1)),
stroke: (dash: "dashed", paint: gray.darken(40%))
)
}
lines.push(line)
} else if event == "disable" or event == "destroy" {
let l = lines.pop()
let lvl = lines.len()
rects.push((x + lvl * LIFELINE-W / 2, l.at(1), line.at(1)))
let lvl = 0
if lines.len() != 0 {
let l = lines.pop()
lvl = lines.len()
rects.push((
x + lvl * LIFELINE-W / 2,
l.at(1),
line.at(1),
l.at(2)
))
last-y = line.at(1)
}
if event == "destroy" {
destructions.push((x + lvl * LIFELINE-W / 2, line.at(1)))
}
}
}
draw.line(
(x, last-y),
(x, y),
stroke: (dash: "dashed", paint: gray.darken(40%))
)
// Draw lifeline rectangles (reverse for bottom to top)
for rect in rects.rev() {
let (cx, y0, y1, style) = rect