added separators

This commit is contained in:
Louis Heredero 2024-06-18 16:18:40 +02:00
parent dc5d868a5d
commit b8d0c3468c
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
4 changed files with 49 additions and 4 deletions

Binary file not shown.

View File

@ -43,3 +43,14 @@ Alice <-- Bob: Another authentication Response
_seq("Alice", "Bob", comment: "Log attack end") _seq("Alice", "Bob", comment: "Log attack end")
}) })
}) })
#chronos.diagram({
import "/src/diagram.typ": *
_sep("Initialization")
_seq("Alice", "Bob", comment: "Authentication Request")
_seq("Bob", "Alice", comment: "Authentication Response", dashed: true)
_sep("Repetition")
_seq("Alice", "Bob", comment: "Another authentication Request")
_seq("Bob", "Alice", comment: "another authentication Response", dashed: true)
})

View File

@ -48,11 +48,17 @@
),) ),)
} }
#let _sep(name) = {
return ((
type: "sep",
name: name
),)
}
#let diagram(elements) = { #let diagram(elements) = {
let participants = () let participants = ()
let elmts = elements let elmts = elements
let i = 0 let i = 0
let a = elmts.len()
while i < elmts.len() { while i < elmts.len() {
let elmt = elmts.at(i) let elmt = elmts.at(i)
if elmt.type == "grp" { if elmt.type == "grp" {
@ -67,9 +73,6 @@
} }
i += 1 i += 1
} }
let b = elmts.len()
[#a / #b]
[#elmts.map(e => e.type)]
for elmt in elmts { for elmt in elmts {
if elmt.type == "par" { if elmt.type == "par" {

View File

@ -169,6 +169,37 @@
draw-group(x0, x1, start-y, y, group) draw-group(x0, x1, start-y, y, group)
y -= Y-SPACE y -= Y-SPACE
} else if elmt.type == "sep" {
let x0 = x-pos.first() - 20
let x1 = x-pos.last() + 20
let m = measure(
box(
elmt.name,
inset: (left: 3pt, right: 3pt, top: 5pt, bottom: 5pt)
)
)
let w = m.width / 1pt
let h = m.height / 1pt
let cx = (x0 + x1) / 2
let xl = cx - w / 2
let xr = cx + w / 2
y -= h / 2
draw.line((x0, y), (xl, y))
draw.line((xr, y), (x1, y))
y -= 3
draw.line((x0, y), (xl, y))
draw.line((xr, y), (x1, y))
draw.content(
((x0 + x1) / 2, y + 1.5),
elmt.name,
anchor: "center",
padding: (5pt, 3pt),
frame: "rect"
)
y -= h / 2
y -= Y-SPACE
} }
} }