diff --git a/gallery/example1.pdf b/gallery/example1.pdf index e01bb3e..672bd3e 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example1.typ b/gallery/example1.typ index e0d31d5..94676cb 100644 --- a/gallery/example1.typ +++ b/gallery/example1.typ @@ -65,4 +65,10 @@ Alice <-- Bob: Another authentication Response _gap(size: 45) _seq("Alice", "Bob", comment: "message 3") _seq("Bob", "Alice", comment: "ok", dashed: true) +}) + +#chronos.diagram({ + import "/src/diagram.typ": * + _seq("Alice", "Alice", comment: "On the\nright") + _seq("Alice", "Alice", flip: true, comment: "On the\nleft") }) \ No newline at end of file diff --git a/src/diagram.typ b/src/diagram.typ index 616ee07..31312c9 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -7,7 +7,8 @@ comment: none, dashed: false, tip: "default", - color: black + color: black, + flip: false ) = { return (( type: "seq", @@ -17,6 +18,7 @@ dashed: dashed, tip: tip, color: color, + flip: flip ),) } diff --git a/src/renderer.typ b/src/renderer.typ index 9cf45a7..0c4a00c 100644 --- a/src/renderer.typ +++ b/src/renderer.typ @@ -133,26 +133,51 @@ ) ) - if elmt.comment != none { - let x = calc.min(x1, x2) - if x2 < x1 { - x += COMMENT-PAD + if elmt.p1 == elmt.p2 { + x2 = if elmt.flip {x1 - 20} else {x1 + 20} + + if elmt.comment != none { + y -= measure(box(elmt.comment)).height / 1pt + 6 + draw.content( + (x1, y), + elmt.comment, + anchor: if elmt.flip {"south-east"} else {"south-west"}, + padding: 3pt + ) } - y -= measure(box(elmt.comment)).height / 1pt + 6 - draw.content( - (x, y), - elmt.comment, - anchor: "south-west", - padding: 3pt + + draw.line( + (x1, y), + (x2, y), + (x2, y - 10), + (x1, y - 10), + ..style + ) + y -= 10 + + } else { + 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( + (x, y), + elmt.comment, + anchor: "south-west", + padding: 3pt + ) + } + + draw.line( + (x1, y), + (x2, y), + ..style ) } - - draw.line( - (x1, y), - (x2, y), - ..style - ) y -= Y-SPACE + } else if elmt.type == "grp" { let m = measure( box(