diff --git a/gallery/example1.pdf b/gallery/example1.pdf index d58715e..e01bb3e 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example1.typ b/gallery/example1.typ index 9849119..e0d31d5 100644 --- a/gallery/example1.typ +++ b/gallery/example1.typ @@ -53,4 +53,16 @@ Alice <-- Bob: Another authentication Response _sep("Repetition") _seq("Alice", "Bob", comment: "Another authentication Request") _seq("Bob", "Alice", comment: "another authentication Response", dashed: true) +}) + +#chronos.diagram({ + import "/src/diagram.typ": * + _seq("Alice", "Bob", comment: "message 1") + _seq("Bob", "Alice", comment: "ok", dashed: true) + _gap() + _seq("Alice", "Bob", comment: "message 2") + _seq("Bob", "Alice", comment: "ok", dashed: true) + _gap(size: 45) + _seq("Alice", "Bob", comment: "message 3") + _seq("Bob", "Alice", comment: "ok", dashed: true) }) \ No newline at end of file diff --git a/src/diagram.typ b/src/diagram.typ index 605d1de..616ee07 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -55,6 +55,13 @@ ),) } +#let _gap(size: 20) = { + return (( + type: "gap", + size: size + ),) +} + #let diagram(elements) = { let participants = () let elmts = elements diff --git a/src/renderer.typ b/src/renderer.typ index 50268a2..9cf45a7 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -4,6 +4,7 @@ #let Y-SPACE = 10 #let PAR-PAD = (5pt, 3pt) #let PAR-SPACE = 10 +#let COMMENT-PAD = 8 #let get-columns-width(participants, elements) = { @@ -38,7 +39,7 @@ let m = measure(cell.cell) widths.at(cell.i1) = calc.max( widths.at(cell.i1), - m.width / 1pt + m.width / 1pt + COMMENT-PAD ) } @@ -133,9 +134,13 @@ ) if elmt.comment != none { + let x = calc.min(x1, x2) + if x2 < x1 { + x += COMMENT-PAD + } y -= measure(box(elmt.comment)).height / 1pt + 6 draw.content( - (calc.min(x1, x2), y), + (x, y), elmt.comment, anchor: "south-west", padding: 3pt @@ -200,6 +205,8 @@ ) y -= h / 2 y -= Y-SPACE + } else if elmt.type == "gap" { + y -= elmt.size } }