improved column layout
This commit is contained in:
parent
974eb92159
commit
c7fba373a5
Binary file not shown.
@ -22,4 +22,10 @@ Alice <-- Bob: Another authentication Response
|
||||
import "/src/diagram.typ": *
|
||||
_seq("Bob", "Alice", comment: "bonjour", color: red)
|
||||
_seq("Alice", "Bob", comment: "ok", color: blue)
|
||||
})
|
||||
|
||||
#chronos.diagram({
|
||||
import "/src/diagram.typ": *
|
||||
_seq("Alice", "Bob", comment: "This is a test")
|
||||
_seq("Alice", "Callum", comment: "This is another test with a long text")
|
||||
})
|
@ -1,7 +1,8 @@
|
||||
#import "@preview/cetz:0.2.2": canvas, draw
|
||||
|
||||
#let X-SPACE = 2
|
||||
#let Y-SPACE = 20
|
||||
#let PAR-PAD = (5pt, 3pt)
|
||||
#let PAR-SPACE = 10
|
||||
|
||||
#let get-participants-i(participants) = {
|
||||
let pars-i = (:)
|
||||
@ -30,7 +31,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
let widths = participants.slice(0, -1).map(_ => 0)
|
||||
let widths = ()
|
||||
for i in range(participants.len() - 1) {
|
||||
let p1 = participants.at(i)
|
||||
let p2 = participants.at(i + 1)
|
||||
let w1 = measure(box(p1.display-name)).width + PAR-PAD.last() * 2
|
||||
let w2 = measure(box(p2.display-name)).width + PAR-PAD.last() * 2
|
||||
widths.push(w1 / 2pt + w2 / 2pt + PAR-SPACE)
|
||||
}
|
||||
|
||||
for cell in cells.filter(c => c.i2 - c.i1 == 1) {
|
||||
let m = measure(cell.cell)
|
||||
widths.at(cell.i1) = calc.max(
|
||||
@ -38,6 +47,18 @@
|
||||
m.width / 1pt
|
||||
)
|
||||
}
|
||||
|
||||
let multicol-cells = cells.filter(c => c.i2 - c.i1 > 1)
|
||||
multicol-cells = multicol-cells.sorted(key: c => {
|
||||
c.i1 * 1000 + c.i2
|
||||
})
|
||||
for cell in multicol-cells {
|
||||
let m = measure(cell.cell)
|
||||
widths.at(cell.i2 - 1) = calc.max(
|
||||
widths.at(cell.i2 - 1),
|
||||
m.width / 1pt - widths.slice(0, cell.i2 - 1).sum()
|
||||
)
|
||||
}
|
||||
return widths
|
||||
}
|
||||
|
||||
@ -58,7 +79,7 @@
|
||||
p.display-name,
|
||||
name: p.name,
|
||||
frame: "rect",
|
||||
padding: (5pt, 3pt),
|
||||
padding: PAR-PAD,
|
||||
anchor: "south"
|
||||
)
|
||||
}
|
||||
@ -108,7 +129,7 @@
|
||||
p.display-name,
|
||||
name: p.name,
|
||||
frame: "rect",
|
||||
padding: (5pt, 3pt),
|
||||
padding: PAR-PAD,
|
||||
anchor: "north"
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user