Compare commits

..

No commits in common. "c7fba373a5b402391db9f10c5cea76af52d8cfbc" and "14cbda2ffbbe2ef6112166809296d7228075a4c6" have entirely different histories.

4 changed files with 10 additions and 60 deletions

Binary file not shown.

View File

@ -12,20 +12,8 @@ Alice <-- Bob: Another authentication Response
#chronos.diagram({ #chronos.diagram({
import "/src/diagram.typ": * import "/src/diagram.typ": *
_seq("Alice", "Bob", comment: "Authentication Request") _seq("Alice", "Bob", comment: "Authentication Request")
_seq("Bob", "Alice", comment: "Authentication Response", dashed: true) _seq("Bob", "Alice", comment: "Authentication Response", style: "dashed")
_seq("Alice", "Bob", comment: "Another authentication Request") _seq("Alice", "Bob", comment: "Another authentication Request")
_seq("Bob", "Alice", comment: "Another authentication Response", dashed: true) _seq("Bob", "Alice", comment: "Another authentication Response", style: "dashed")
})
#chronos.diagram({
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")
}) })

View File

@ -1,21 +1,12 @@
#import "renderer.typ": render #import "renderer.typ": render
#let _seq( #let _seq(p1, p2, comment: none, style: auto) = {
p1,
p2,
comment: none,
dashed: false,
tip: "default",
color: black
) = {
return (( return ((
type: "seq", type: "seq",
p1: p1, p1: p1,
p2: p2, p2: p2,
comment: comment, comment: comment,
dashed: dashed, style: style
tip: tip,
color: color,
),) ),)
} }

View File

@ -1,8 +1,7 @@
#import "@preview/cetz:0.2.2": canvas, draw #import "@preview/cetz:0.2.2": canvas, draw
#let Y-SPACE = 20 #let X-SPACE = 2
#let PAR-PAD = (5pt, 3pt) #let Y-SPACE = 30
#let PAR-SPACE = 10
#let get-participants-i(participants) = { #let get-participants-i(participants) = {
let pars-i = (:) let pars-i = (:)
@ -31,15 +30,7 @@
} }
} }
let widths = () let widths = participants.slice(0, -1).map(_ => 0)
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) { for cell in cells.filter(c => c.i2 - c.i1 == 1) {
let m = measure(cell.cell) let m = measure(cell.cell)
widths.at(cell.i1) = calc.max( widths.at(cell.i1) = calc.max(
@ -47,18 +38,6 @@
m.width / 1pt 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 return widths
} }
@ -79,7 +58,7 @@
p.display-name, p.display-name,
name: p.name, name: p.name,
frame: "rect", frame: "rect",
padding: PAR-PAD, padding: (5pt, 3pt),
anchor: "south" anchor: "south"
) )
} }
@ -90,18 +69,10 @@
if elmt.type == "seq" { if elmt.type == "seq" {
let x1 = x-pos.at(pars-i.at(elmt.p1)) let x1 = x-pos.at(pars-i.at(elmt.p1))
let x2 = x-pos.at(pars-i.at(elmt.p2)) let x2 = x-pos.at(pars-i.at(elmt.p2))
let style = (
mark: (end: "straight"),
stroke: (
dash: if elmt.dashed {"dashed"} else {"solid"},
paint: elmt.color
)
)
draw.line( draw.line(
(x1, y), (x1, y),
(x2, y), (x2, y),
..style mark: (end: "straight")
) )
if elmt.comment != none { if elmt.comment != none {
draw.content( draw.content(
@ -129,7 +100,7 @@
p.display-name, p.display-name,
name: p.name, name: p.name,
frame: "rect", frame: "rect",
padding: PAR-PAD, padding: (5pt, 3pt),
anchor: "north" anchor: "north"
) )
} }