added column width options

This commit is contained in:
Louis Heredero 2024-10-04 15:11:45 +02:00
parent 647d50e125
commit 56cc1b11c0
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
10 changed files with 90 additions and 3 deletions

View File

@ -22,6 +22,7 @@
- [ ] Add args verification to catch user errors + pretty error messages - [ ] Add args verification to catch user errors + pretty error messages
- [ ] PlantUML parser - [ ] PlantUML parser
- [ ] (Message numbering) - [ ] (Message numbering)
- [ ] Mainframes
- [ ] Different types of groups (alt/loop/etc.) - [ ] Different types of groups (alt/loop/etc.)
- [ ] Delays - [ ] Delays
- [ ] Auto-fit in parent - [ ] Auto-fit in parent

View File

@ -49,3 +49,19 @@
show-bottom: true, show-bottom: true,
show-top: true, show-top: true,
) = {} ) = {}
/// Sets some options for columns between participants
///
/// Parameters `p1` and `p2` MUST be consecutive participants (also counting found/lost messages), but they do not need to be in the left to right order
/// - p1 (str): The first neighbouring participant
/// - p2 (str): The second neighbouring participant
/// - width (auto, int, float, length): Optional fixed width of the column\ If the column's content (e.g. sequence comments) is larger, it will overflow
/// - margin (int, float, length): Additional margin to add to the column\ This margin is not included in `width` and `min-width`, but rather added separately
/// - min-width (int, float, length): Minimum width of the column\ If set to a larger value than `width`, the latter will be overriden
#let _col(
p1,
p2,
width: auto,
margin: 0,
min-width: 0
) = {}

Binary file not shown.

View File

@ -145,3 +145,22 @@ chronos.diagram({
_gap() _gap()
}) })
#chronos.diagram({
import chronos: *
_par("a", display-name: "Alice")
_par("b", display-name: "Bob")
_par("c", display-name: "Caleb")
_par("d", display-name: "Danny")
_par("e", display-name: "Erika")
_col("a", "b")
_col("b", "c", width: 2cm)
_col("c", "d", margin: .5cm)
_col("d", "e", min-width: 2cm)
//_seq("b", "c", comment: [Hello World !])
//_seq("c", "d", comment: [Hello World])
//_seq("d", "e", comment: [Hello World])
})

Binary file not shown.

View File

@ -155,7 +155,7 @@ chronos.diagram({
doc-ref: doc-ref doc-ref: doc-ref
) )
) )
#tidy.show-module(par-docs, show-outline: false) #tidy.show-module(par-docs, show-outline: false, sort-functions: none)
#pagebreak(weak: true) #pagebreak(weak: true)

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) = { #let diagram(elements, width: auto) = {
if elements == none { if elements == none {
return return

View File

@ -1,5 +1,5 @@
#let version = version(0, 1, 1) #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 "sequence.typ": _seq
#import "group.typ": _grp #import "group.typ": _grp

View File

@ -1,5 +1,5 @@
#import "@preview/cetz:0.2.2": canvas, draw #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 "group.typ"
#import "participant.typ" #import "participant.typ"
#import participant: PAR-SPECIALS #import participant: PAR-SPECIALS
@ -194,6 +194,37 @@
} }
widths.at(i) = w 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 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 get-participants-i(participants) = {
let pars-i = (:) let pars-i = (:)
for (i, p) in participants.enumerate() { for (i, p) in participants.enumerate() {