From 3610c868843f644ae4206394818bcfb8a5d503b1 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Thu, 20 Jun 2024 00:46:42 +0200 Subject: [PATCH] removed useless invisible participants --- src/diagram.typ | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/diagram.typ b/src/diagram.typ index 26866e1..c44ad0d 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -10,6 +10,10 @@ } #let diagram(elements) = { + if elements == none { + return + } + let participants = () let elmts = elements let i = 0 @@ -31,6 +35,7 @@ } // List participants + let linked = () for elmt in elmts { if elmt.type == "par" { participants.push(elmt) @@ -42,24 +47,49 @@ let par = _par(elmt.p2, from-start: not elmt.create-dst).first() participants.push(par) } + + if elmt.p1 == "?" { + linked.push("?" + elmt.p2) + } else { + linked.push(elmt.p1) + } + if elmt.p2 == "?" { + linked.push(elmt.p1 + "?") + } else { + linked.push(elmt.p2) + } } } + linked = linked.dedup() let pars = participants participants = () - participants.push(_par("[", invisible: true).first()) + + if "[" in linked { + participants.push(_par("[", invisible: true).first()) + } + for (i, p) in pars.enumerate() { let before = _par("?" + p.name, invisible: true).first() let after = _par(p.name + "?", invisible: true).first() - if i == 0 { - participants.push(before) - } else { - participants.insert(-1, before) + + if before.name in linked { + if participants.len() == 0 or not participants.last().name.ends-with("?") { + participants.push(before) + } else { + participants.insert(-1, before) + } } + participants.push(p) - participants.push(after) + + if after.name in linked { + participants.push(after) + } + } + if "]" in linked { + participants.push(_par("]", invisible: true).first()) } - participants.push(_par("]", invisible: true).first()) // Add index to participant for (i, p) in participants.enumerate() {