added column width options

This commit is contained in:
2024-10-04 15:11:45 +02:00
parent 647d50e125
commit 56cc1b11c0
10 changed files with 90 additions and 3 deletions

View File

@ -18,6 +18,17 @@
),)
}
#let _col(p1, p2, width: auto, margin: 0, min-width: 0) = {
return ((
type: "col",
p1: p1,
p2: p2,
width: width,
margin: margin,
min-width: min-width
),)
}
#let diagram(elements, width: auto) = {
if elements == none {
return

View File

@ -1,5 +1,5 @@
#let version = version(0, 1, 1)
#import "diagram.typ": diagram, from-plantuml, _gap, _evt
#import "diagram.typ": diagram, from-plantuml, _gap, _evt, _col
#import "sequence.typ": _seq
#import "group.typ": _grp

View File

@ -1,5 +1,5 @@
#import "@preview/cetz:0.2.2": canvas, draw
#import "utils.typ": get-participants-i, get-style
#import "utils.typ": get-participants-i, get-style, normalize-units
#import "group.typ"
#import "participant.typ"
#import participant: PAR-SPECIALS
@ -194,6 +194,37 @@
}
widths.at(i) = w
}
for elmt in elements {
if elmt.type == "col" {
let i1 = pars-i.at(elmt.p1)
let i2 = pars-i.at(elmt.p2)
if calc.abs(i1 - i2) != 1 {
let i-min = calc.min(i1, i2)
let i-max = calc.max(i1, i2)
let others = pars-i.pairs()
.sorted(key: p => p.last())
.slice(i-min + 1, i-max)
.map(p => "'" + p.first() + "'")
.join(", ")
panic(
"Column participants must be consecutive (participants (" +
others +
") are in between)"
)
}
let i = calc.min(i1, i2)
if elmt.width != auto {
widths.at(i) = normalize-units(elmt.width)
}
widths.at(i) = calc.max(
widths.at(i),
normalize-units(elmt.min-width)
) + normalize-units(elmt.margin)
}
}
return widths
}

View File

@ -1,3 +1,12 @@
#let normalize-units(value) = {
if type(value) == int or type(value) == float {
return value
}
if type(value) == length {
return value / 1pt
}
panic("Unsupported type '" + str(type(value)) + "'")
}
#let get-participants-i(participants) = {
let pars-i = (:)
for (i, p) in participants.enumerate() {