forked from HEL/chronos
refactored groups, separators and delays
This commit is contained in:
@ -354,7 +354,6 @@
|
||||
},)
|
||||
|
||||
#let render(participants, elements) = context canvas(length: 1pt, {
|
||||
let shapes = ()
|
||||
setup-ctx(participants, elements)
|
||||
|
||||
// Draw participants (start)
|
||||
@ -372,80 +371,6 @@
|
||||
(elmt,)
|
||||
} else if "draw" in elmt and elmt.type != "par" {
|
||||
(elmt.draw)(elmt)
|
||||
|
||||
// Groups (start) -> reserve space for labels + store position
|
||||
} else if elmt.type == "grp" {
|
||||
y -= Y-SPACE
|
||||
let m = measure(
|
||||
box(
|
||||
elmt.name,
|
||||
inset: (
|
||||
left: 5pt,
|
||||
right: 5pt,
|
||||
top: 3pt,
|
||||
bottom: 3pt
|
||||
),
|
||||
)
|
||||
)
|
||||
groups = groups.map(g => {
|
||||
if g.at(1).min-i == elmt.min-i { g.at(2) += 1 }
|
||||
if g.at(1).max-i == elmt.max-i { g.at(3) += 1 }
|
||||
g
|
||||
})
|
||||
if elmt.grp-type == "alt" {
|
||||
elmt.insert("elses", ())
|
||||
}
|
||||
groups.push((y, elmt, 0, 0))
|
||||
y -= m.height / 1pt
|
||||
|
||||
// Groups (end) -> actual drawing
|
||||
} else if elmt.type == "grp-end" {
|
||||
y -= Y-SPACE
|
||||
let (start-y, group, start-lvl, end-lvl) = groups.pop()
|
||||
let x0 = x-pos.at(group.min-i) - start-lvl * 10 - 20
|
||||
let x1 = x-pos.at(group.max-i) + end-lvl * 10 + 20
|
||||
shapes += draw-group(x0, x1, start-y, y, group)
|
||||
|
||||
if group.grp-type == "alt" {
|
||||
for (else-y, else-elmt) in group.elses {
|
||||
shapes += draw-else(x0, x1, else-y, else-elmt)
|
||||
}
|
||||
}
|
||||
|
||||
// Alt's elses -> reserve space for label + store position
|
||||
} else if elmt.type == "else" {
|
||||
y -= Y-SPACE
|
||||
let m = measure(text([\[#elmt.desc\]], weight: "bold", size: .8em))
|
||||
groups.last().at(1).elses.push((
|
||||
y, elmt
|
||||
))
|
||||
y -= m.height / 1pt
|
||||
|
||||
// Separator
|
||||
} else if elmt.type == "sep" {
|
||||
let shps
|
||||
(y, shps) = draw-sep(elmt, y)
|
||||
shapes += shps
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,6 +401,4 @@
|
||||
|
||||
participant.render-lifelines()
|
||||
})
|
||||
|
||||
shapes
|
||||
})
|
Reference in New Issue
Block a user