added id to notes

This commit is contained in:
2025-07-28 18:48:28 +02:00
parent 1a0f47beb3
commit 1db922d44d
3 changed files with 13 additions and 13 deletions

View File

@@ -382,7 +382,7 @@
} }
}) })
#let render(participants, elements) = context canvas(length: 1pt, { #let render(participants, elements, notes) = context canvas(length: 1pt, {
setup-ctx(participants, elements) setup-ctx(participants, elements)
// Draw participants (start) // Draw participants (start)

View File

@@ -126,6 +126,7 @@
"linked", "linked",
note.pos == none and note.side != "across" note.pos == none and note.side != "across"
) )
note.insert("id", ctx.notes.len())
let names = ctx.participants.map(p => p.name) let names = ctx.participants.map(p => p.name)
if note.pos == none and note.side != "across" { if note.pos == none and note.side != "across" {
let i1 = names.position(n => n == ctx.last-seq.p1) let i1 = names.position(n => n == ctx.last-seq.p1)
@@ -186,6 +187,8 @@
} }
} }
ctx.notes.push(note)
ctx.elmts.at(ctx.i) = note ctx.elmts.at(ctx.i) = note
ctx.last-note = ( ctx.last-note = (
@@ -226,6 +229,7 @@
linked: (), linked: (),
last-seq: none, last-seq: none,
last-note: none, last-note: none,
notes: (),
participants: (), participants: (),
elmts: elmts, elmts: elmts,
i: 0 i: 0
@@ -290,10 +294,10 @@
).first()) ).first())
} }
return (ctx.elmts, participants) return (ctx.elmts, participants, ctx.notes)
} }
#let finalize-setup(elmts, participants) = { #let finalize-setup(elmts, participants, notes) = {
for (i, p) in participants.enumerate() { for (i, p) in participants.enumerate() {
p.insert("i", i) p.insert("i", i)
participants.at(i) = p participants.at(i) = p
@@ -323,14 +327,11 @@
elmts.at(i).insert("max-i", max-i) elmts.at(i).insert("max-i", max-i)
} }
return (elmts, participants) return (elmts, participants, notes)
} }
#let setup(elements) = { #let setup(elements) = {
let (elmts, activation-history) = unwrap-containers(elements) let (elmts, activation-history) = unwrap-containers(elements)
let (elmts, participants, notes) = prepare-participants(elmts)
let participants return finalize-setup(elmts, participants, notes)
(elmts, participants) = prepare-participants(elmts)
return finalize-setup(elmts, participants)
} }

View File

@@ -1,16 +1,15 @@
#import "core/draw/event.typ": render as evt-render
#import "core/renderer.typ": render #import "core/renderer.typ": render
#import "core/setup.typ": setup #import "core/setup.typ": setup
#import "core/utils.typ": fit-canvas, set-ctx #import "core/utils.typ": fit-canvas
#let diagram(elements, width: auto) = { #let diagram(elements, width: auto) = {
if elements == none { if elements == none {
return return
} }
let (elmts, participants) = setup(elements) let (elmts, participants, notes) = setup(elements)
let canvas = render(participants, elmts) let canvas = render(participants, elmts, notes)
fit-canvas(canvas, width: width) fit-canvas(canvas, width: width)
} }