Compare commits

...

2 Commits

Author SHA1 Message Date
8ee14167de fixed ignored multiple linked notes 2025-07-16 17:21:20 +02:00
1f24ba8efe added allow-overlap parameter for notes 2025-07-16 17:20:31 +02:00
7 changed files with 57 additions and 22 deletions

View File

@ -5,13 +5,15 @@
/// - color (color): The note's color
/// - shape (str): The note's shape (see @@SHAPES for accepted values)
/// - aligned (bool): True if the note is aligned with another note, in which case `side` must be `"over"`, false otherwise
/// - allow-overlap (bool): If set to `false`, the note will try to reserve space in the column to avoid overlapping with neighboring participants. If set to `true`, the not will overlap other participants
#let _note(
side,
content,
pos: none,
color: rgb("#FEFFDD"),
shape: "default",
aligned: false
aligned: false,
allow-overlap: true
) = {}
/// Accepted values for `shape` argument of @@_note()

Binary file not shown.

View File

@ -67,9 +67,12 @@
if comment != none {
h = calc.max(h, measure(comment).height / 1pt + 6)
}
if "linked-note" in seq {
h = calc.max(h, note.get-size(seq.linked-note).height / 2)
}
h = calc.max(
h,
..seq.linked-notes.map(n => {
note.get-size(n).height / 2
})
)
ctx.y -= h
let start-info = (
@ -165,9 +168,8 @@
)
let y0 = start-info.y
if "linked-note" in seq {
// TODO: adapt note.render
(seq.linked-note.draw)(seq.linked-note, y: start-info.y, forced: true)
for n in seq.linked-notes {
(n.draw)(n, y: start-info.y, forced: true)
}
let flip-mark = end-info.i <= start-info.i
@ -348,9 +350,14 @@
ctx.lifelines.at(i2) = dst-line
}
if "linked-note" in seq {
let m = note.get-size(seq.linked-note)
end-info.y = calc.min(end-info.y, y0 - m.height / 2)
if seq.linked-notes.len() != 0 {
end-info.y = calc.min(
end-info.y,
y0 - calc.max(..seq.linked-notes.map(n => {
let m = note.get-size(n)
return m.height / 2
}))
)
}
set-ctx(c => {

View File

@ -82,12 +82,12 @@
let (p1, p2) = (none, none)
let cell = none
if note.side == "left" {
p1 = "["
p1 = note.pos2
p2 = note.pos
cell = get-note-box(note)
} else if note.side == "right" {
p1 = note.pos
p2 = "]"
p2 = note.pos2
cell = get-note-box(note)
} else if note.side == "over" and note.aligned-with != none {
let box1 = get-note-box(note)

View File

@ -126,8 +126,8 @@
"linked",
note.pos == none and note.side != "across"
)
let names = ctx.participants.map(p => p.name)
if note.pos == none and note.side != "across" {
let names = ctx.participants.map(p => p.name)
let i1 = names.position(n => n == ctx.last-seq.p1)
let i2 = names.position(n => n == ctx.last-seq.p2)
let pars = (
@ -141,8 +141,8 @@
note.pos = pars.last().last()
}
let seq = ctx.last-seq.seq
seq.insert("linked-note", note)
let seq = ctx.elmts.at(ctx.last-seq.i)
seq.linked-notes.push(note)
ctx.elmts.at(ctx.last-seq.i) = seq
}
if note.aligned {
@ -150,10 +150,26 @@
n.aligned-with = note
ctx.elmts.at(ctx.last-note.i) = n
}
if note.side == "left" {
ctx.linked.push("[")
} else if note.side == "right" {
ctx.linked.push("]")
if note.side in ("left", "right") {
let i = names.position(n => n == note.pos)
let pos2 = note.pos
if note.side == "left" {
if i <= 0 or note.allow-overlap {
ctx.linked.push("[")
pos2 = "["
} else {
pos2 = names.at(i - 1)
}
} else if note.side == "right" {
if i >= names.len() - 1 or note.allow-overlap {
ctx.linked.push("]")
pos2 = "]"
} else {
pos2 = names.at(i + 1)
}
}
note.insert("pos2", pos2)
}
let pars = none

View File

@ -14,7 +14,15 @@
"hex"
)
#let _note(side, content, pos: none, color: COL-NOTE, shape: "default", aligned: false) = {
#let _note(
side,
content,
pos: none,
color: COL-NOTE,
shape: "default",
aligned: false,
allow-overlap: true
) = {
if side == "over" {
if pos == none {
panic("Pos cannot be none with side 'over'")
@ -37,6 +45,7 @@
color: color,
shape: shape,
aligned: aligned,
aligned-with: none
aligned-with: none,
allow-overlap: allow-overlap
),)
}

View File

@ -38,7 +38,8 @@
disable-src: disable-src,
destroy-src: destroy-src,
lifeline-style: lifeline-style,
slant: slant
slant: slant,
linked-notes: ()
),)
}