From ff6a7e52bc305b6b831805fff5e17e62741d2b94 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 30 Jul 2024 14:26:16 +0200 Subject: [PATCH] added slanted sequences --- gallery/example2.pdf | Bin 38162 -> 39522 bytes gallery/example2.typ | 24 +++++++++++++++++++ src/consts.typ | 1 + src/sequence.typ | 56 ++++++++++++++++++++++++++----------------- 4 files changed, 59 insertions(+), 22 deletions(-) diff --git a/gallery/example2.pdf b/gallery/example2.pdf index 20e2e3327921ba031b0965af256157c5c3972b1d..00341c9bfe687578267d5f5a0489b077bc25b2f7 100644 GIT binary patch delta 2225 zcmZ`)X;@R&7BvtaF(8H)WXdDl%1}U%J0!VDDl!xUG788T5s?Im15rqj$b-~E5G}ER zi>M&rP>c3~w1Q9-tWYb1JSHtrN`tZj5=mmJ%3$5->NJSDLulYGT!* zcLbrEq8xFmi<7Yyku{Eqy%5Ed&;>N0T8Dd}Rz=cJ#qKkF>%$*3m9z1LqC`Kp8c+ACV;zZ>(?=CbXZ z^Y_hOO<^T$?u|@xn&-`z4QA6AUJoY|hrihoAj@(|U}j0Rj#KlfTlf3jxBqhPY59el z2fvwjjM}cV#rk*&P!aW8i(T_PzA5z09Jk+8Fz{S5ASJGo>W4a;yAGIXnQmNDva+tr zj~b%2rFiW{NtjL0mc|`mp^dcElwyI~Rh;Qwu>MMyviA@intm$WyD#dIEV-`9GR*qc zkj~SB2>M`9lH5czMQ%J>JDccr#t7w)h51^H7N&pw_BV9J!xF#7$*#egA9nU5mjjNc z&5p}!C01#*(Vh-Alwe(^@94Saz^3qmhP`k7uSq-g&=WtmpLMTVODn%UEiV_Fj&z*( z=T|>$IN{mdXm{yRNH5!aw5G-2!HWren-%P8f4#8N|ME{?%(bwe>)7e*@H><5u%Rb2 zAKL2oUH;_Z8bw-Mcyi{RhQ|Sh+gWB2(c6xNR(G4^p{Go`p~BLuP0CZV!Tm(;uIA~G z(;u^MNsDe@x3|u+ib9mOMO<-IxOSQ=f5`T6PfWhd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CKhY>R=PvF}>Of%%|1sK)#>~FhgEvfC=%Nt?ZtJ3d0O`NOheB88Zz%*dQ}asa<^$PRX9a zJSk)9;(7^@QtNxIe>sfDJO4W) fslL80yuYhDoQtK&V(DISCXcwTX-TB2nXB1fq3i)E diff --git a/gallery/example2.typ b/gallery/example2.typ index cbb301e..4993132 100644 --- a/gallery/example2.typ +++ b/gallery/example2.typ @@ -82,5 +82,29 @@ }) _gap() + _evt("bob", "disable") +}) + +#chronos.diagram({ + import chronos: * + _par("alice", display-name: "Alice") + _par("bob", display-name: "Bob") + _par("craig", display-name: "Craig") + + _seq("alice", "bob") + _seq("bob", "craig", slant: auto) + _seq("alice", "craig", slant: 20) + + _sync({ + _seq("alice", "bob", slant: 10) + _seq("craig", "bob", slant: 20) + }) + + _sync({ + _seq("alice", "bob", slant: auto) + _seq("bob", "alice", slant: auto) + }) + + _gap() _evt("bob", "disable") }) \ No newline at end of file diff --git a/src/consts.typ b/src/consts.typ index 57e5051..4857aa7 100644 --- a/src/consts.typ +++ b/src/consts.typ @@ -3,6 +3,7 @@ #let COMMENT-PAD = 8 #let LIFELINE-W = 10 #let CREATE-OFFSET = 15 +#let DEFAULT-SLANT = 10 #let SYM-GAP = 5 #let PAR-PAD = (5pt, 3pt) diff --git a/src/sequence.typ b/src/sequence.typ index ad76e19..4866e41 100644 --- a/src/sequence.typ +++ b/src/sequence.typ @@ -35,7 +35,8 @@ destroy-dst: false, disable-src: false, destroy-src: false, - lifeline-style: auto + lifeline-style: auto, + slant: none ) = { return (( type: "seq", @@ -54,6 +55,7 @@ disable-src: disable-src, destroy-src: destroy-src, lifeline-style: lifeline-style, + slant: slant ),) } @@ -87,27 +89,38 @@ y: y, ll-lvl: lifelines.at(i2).level * LIFELINE-W / 2 ) + let slant = if elmt.slant == auto { + DEFAULT-SLANT + } else if elmt.slant != none { + elmt.slant + } else { + 0 + } + end-info.y -= slant + if elmt.p1 == elmt.p2 { + end-info.y -= 10 + } if elmt.disable-src { let src-line = lifelines.at(i1) src-line.level -= 1 - src-line.lines.push(("disable", y)) + src-line.lines.push(("disable", start-info.y)) lifelines.at(i1) = src-line } if elmt.destroy-src { let src-line = lifelines.at(i1) - src-line.lines.push(("destroy", y)) + src-line.lines.push(("destroy", start-info.y)) lifelines.at(i1) = src-line } if elmt.disable-dst { let dst-line = lifelines.at(i2) dst-line.level -= 1 - dst-line.lines.push(("disable", y)) + dst-line.lines.push(("disable", end-info.y)) lifelines.at(i2) = dst-line } if elmt.destroy-dst { let dst-line = lifelines.at(i2) - dst-line.lines.push(("destroy", y)) + dst-line.lines.push(("destroy", end-info.y)) lifelines.at(i2) = dst-line } if elmt.enable-dst { @@ -120,7 +133,7 @@ let m = measure(box(par.display-name)) let f = if i1 > i2 {-1} else {1} end-info.x -= (m.width + PAR-PAD.last() * 2) / 2pt * f - shapes += participant.render(x-pos, par, y: y - CREATE-OFFSET) + shapes += participant.render(x-pos, par, y: end-info.y - CREATE-OFFSET) } end-info.ll-lvl = lifelines.at(i2).level * LIFELINE-W / 2 @@ -156,9 +169,9 @@ ) ) - let y0 = y + let y0 = start-info.y if "linked-note" in elmt { - let shps = note.render(pars-i, x-pos, elmt.linked-note, y, lifelines).last() + let shps = note.render(pars-i, x-pos, elmt.linked-note, start-info.y, lifelines).last() shapes += shps } @@ -177,7 +190,7 @@ if elmt.comment != none { shapes += draw.content( - (x1, y), + (x1, start-info.y), elmt.comment, anchor: if elmt.flip {"south-east"} else {"south-west"}, padding: 3pt @@ -185,13 +198,12 @@ } shapes += draw.line( - (x1, y), - (x-mid, y), - (x-mid, y - 10), - (x2, y - 10), + (x1, start-info.y), + (x-mid, start-info.y), + (x-mid, end-info.y), + (x2, end-info.y), ..style ) - y -= 10 } else { if elmt.comment != none { @@ -200,7 +212,7 @@ x += COMMENT-PAD } shapes += draw.content( - (x, y), + (x, start-info.y), elmt.comment, anchor: "south-west", padding: 3pt @@ -208,28 +220,28 @@ } shapes += draw.line( - (x1, y), - (x2, y), + (x1, start-info.y), + (x2, end-info.y), ..style ) } if elmt.enable-dst { let dst-line = lifelines.at(i2) - dst-line.lines.push(("enable", y, elmt.lifeline-style)) + dst-line.lines.push(("enable", end-info.y, elmt.lifeline-style)) lifelines.at(i2) = dst-line } if elmt.create-dst { - y -= CREATE-OFFSET + end-info.y -= CREATE-OFFSET let dst-line = lifelines.at(i2) - dst-line.lines.push(("create", y)) + dst-line.lines.push(("create", end-info.y)) lifelines.at(i2) = dst-line } if "linked-note" in elmt { let m = note.get-size(elmt.linked-note) - y = calc.min(y, y0 - m.height / 2) + end-info.y = calc.min(end-info.y, y0 - m.height / 2) } - let r = (y, lifelines, shapes) + let r = (end-info.y, lifelines, shapes) return r } \ No newline at end of file