From 14cbda2ffbbe2ef6112166809296d7228075a4c6 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Tue, 18 Jun 2024 13:39:38 +0200 Subject: [PATCH] initial commit + basic sequences --- gallery/example1.pdf | Bin 0 -> 14082 bytes gallery/example1.typ | 19 ++++++++ src/diagram.typ | 51 ++++++++++++++++++++ src/lib.typ | 1 + src/renderer.typ | 108 +++++++++++++++++++++++++++++++++++++++++++ typst.toml | 14 ++++++ 6 files changed, 193 insertions(+) create mode 100644 gallery/example1.pdf create mode 100644 gallery/example1.typ create mode 100644 src/diagram.typ create mode 100644 src/lib.typ create mode 100644 src/renderer.typ create mode 100644 typst.toml diff --git a/gallery/example1.pdf b/gallery/example1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..30c3a0911709a1dae43e494c5fd8a335b146e0e4 GIT binary patch literal 14082 zcmb7rbwHF|)3+jufD$4gN~|EIvc(2VN{dJc2-3MUyTH;ZAYCdV5`uz+ARW@6A|Z{G zbV*7H3P^p|g5G-H&;7jb`z>eLYv#=+c*nA z3kyOMc@(0e6o4erCJLg^|7x71oD^|PqK)wXlZ}9asw=?(Ya@p<#e)tU2h32xnpqGW z>|H@T;=trsUSKGIt7LD2wI}++^UI%~9jcDDw$@l1z()`*Cr}h@M4tRSI z>cAg>FQsuH1OaAN!^_G^DHz)R4iHgM1EdWFgpp7vh#&ZaBY|HOv7s;sumBtZ2l1nc z4Jm*I3t*rq5R(6(3826j7y_VC0>p+uqQFQ59D@e*hz)^(gHdQCS^$KG5*q@J2BY~A z`~VFnHUt6%Mxy}^2#q8*BtIIA#Gp|q5c;6O(NHi3gMxw37-EB?_<`YI0sC>)F-+9m)9AOUY+V59&X3W%bJ zjb8u*Mj-?cfGi*acnd=UzM+Zoz;2=IY5(ySSVu0uYWK!Ws(%`XH(PC=z1T{Eop*EY8fq90)LmsCHP-l0d!@ zqXwim*3gE6^P;jU-$9b|@q>Yi!xHe0_QqJg12IlcDZH^GF|QS|SQD(tuU>*6$krZj zO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>OQ=0J!U)14sgJUm^~j z2N;O};MBn|7#IN662~I;0I*sqU~>oYND0CLG$<4W6M(_^0Sva*fs6v)m``3KZdSj+`@XIKF!-UE=X2>WtH4LiufM1)-f zsQ^{5mBgA`Tz9j_s=6tv8M|2-V@%k^M1@@hU2JS^fYCuNHr6kR7M>PIs3eW+V!VgFSk+-oG{Fz>Ac)YdfpBW|$`DgEMaV#;VM2YFf2SxG0 z1k_+KL4K4VkaK@%9SR*N0ZC|K>iWMZ{UJnD0{j(JB)(?|qOgNe|6mB47z>)>?QIMl zL=Axp92Uk0WdH$O6NdcmB1%~U#{frQki%q=Ff==Su(lAz;)Ef@^#&df9}YT+>c4dW zGZYjAe?jTxq(n_jHE~D;L`h!bjw9lZq0)6l8)ulfh{%C~e-|bC0C41R1P4Q$G4}tU z{D0|9t;i>0M4Jp4+!^* z2jd5B-29UVg#y<%{w4@_UptCIk=N`@E$uj%E?KAw0Ztp?eK#Bd)L8x5hx&ghlBM3-fR4bLyZ3a E1Hx1tk^lez literal 0 HcmV?d00001 diff --git a/gallery/example1.typ b/gallery/example1.typ new file mode 100644 index 0000000..5ee06c8 --- /dev/null +++ b/gallery/example1.typ @@ -0,0 +1,19 @@ +#import "/src/lib.typ" as chronos + +#chronos.from-plantuml(```plantuml +Alice -> Bob: Authentication Request +Bob --> Alice: Authentication Response + +Alice -> Bob: Another authentication Request +Alice <-- Bob: Another authentication Response +```) + + +#chronos.diagram({ + import "/src/diagram.typ": * + _seq("Alice", "Bob", comment: "Authentication Request") + _seq("Bob", "Alice", comment: "Authentication Response", style: "dashed") + + _seq("Alice", "Bob", comment: "Another authentication Request") + _seq("Bob", "Alice", comment: "Another authentication Response", style: "dashed") +}) \ No newline at end of file diff --git a/src/diagram.typ b/src/diagram.typ new file mode 100644 index 0000000..75d7241 --- /dev/null +++ b/src/diagram.typ @@ -0,0 +1,51 @@ +#import "renderer.typ": render + +#let _seq(p1, p2, comment: none, style: auto) = { + return (( + type: "seq", + p1: p1, + p2: p2, + comment: comment, + style: style + ),) +} + +#let _par(name, display-name: auto, start-at: 0) = { + return (( + type: "par", + name: name, + display-name: if display-name == auto {name} else {display-name}, + start-at: start-at + ),) +} + +#let _par-exists(participants, name) = { + for p in participants { + if name == p.name { + return true + } + } + return false +} + +#let diagram(elements) = { + let participants = () + for elmt in elements { + if elmt.type == "par" { + participants.push(elmt) + } else if elmt.type == "seq" { + if not _par-exists(participants, elmt.p1) { + participants.push(_par(elmt.p1).first()) + } + if not _par-exists(participants, elmt.p2) { + participants.push(_par(elmt.p2).first()) + } + } + } + + render(participants, elements) +} + +#let from-plantuml(code) = { + let code = code.text +} \ No newline at end of file diff --git a/src/lib.typ b/src/lib.typ new file mode 100644 index 0000000..2f20eb6 --- /dev/null +++ b/src/lib.typ @@ -0,0 +1 @@ +#import "diagram.typ": diagram, from-plantuml \ No newline at end of file diff --git a/src/renderer.typ b/src/renderer.typ new file mode 100644 index 0000000..849d8ad --- /dev/null +++ b/src/renderer.typ @@ -0,0 +1,108 @@ +#import "@preview/cetz:0.2.2": canvas, draw + +#let X-SPACE = 2 +#let Y-SPACE = 30 + +#let get-participants-i(participants) = { + let pars-i = (:) + for (i, p) in participants.enumerate() { + pars-i.insert(p.name, i) + } + return pars-i +} + +#let get-columns-width(participants, elements) = { + let pars-i = get-participants-i(participants) + let cells = () + for elmt in elements { + if elmt.type == "seq" { + let com = if elmt.comment == none {""} else {elmt.comment} + let i1 = pars-i.at(elmt.p1) + let i2 = pars-i.at(elmt.p2) + cells.push( + ( + elmt: elmt, + i1: calc.min(i1, i2), + i2: calc.max(i1, i2), + cell: box(com, inset: 3pt) + ) + ) + } + } + + let widths = participants.slice(0, -1).map(_ => 0) + for cell in cells.filter(c => c.i2 - c.i1 == 1) { + let m = measure(cell.cell) + widths.at(cell.i1) = calc.max( + widths.at(cell.i1), + m.width / 1pt + ) + } + return widths +} + +#let render(participants, elements) = context canvas(length: 1pt, { + let pars-i = get-participants-i(participants) + + let widths = get-columns-width(participants, elements) + + let x-pos = (0,) + for width in widths { + x-pos.push(x-pos.last() + width) + } + + // Draw participants + for (i, p) in participants.enumerate() { + draw.content( + (x-pos.at(i), 0), + p.display-name, + name: p.name, + frame: "rect", + padding: (5pt, 3pt), + anchor: "south" + ) + } + + let y = -Y-SPACE + // Draw sequences + for elmt in elements { + if elmt.type == "seq" { + let x1 = x-pos.at(pars-i.at(elmt.p1)) + let x2 = x-pos.at(pars-i.at(elmt.p2)) + draw.line( + (x1, y), + (x2, y), + mark: (end: "straight") + ) + if elmt.comment != none { + draw.content( + (calc.min(x1, x2), y), + elmt.comment, + anchor: "south-west", + padding: 3pt + ) + } + y -= Y-SPACE + } + } + + // Draw vertical lines + end participants + draw.on-layer(-1, { + for (i, p) in participants.enumerate() { + let x = x-pos.at(i) + draw.line( + (x, 0), + (x, y), + stroke: (dash: "dashed", paint: gray.darken(40%)) + ) + draw.content( + (x, y), + p.display-name, + name: p.name, + frame: "rect", + padding: (5pt, 3pt), + anchor: "north" + ) + } + }) +}) \ No newline at end of file diff --git a/typst.toml b/typst.toml new file mode 100644 index 0000000..e721a3c --- /dev/null +++ b/typst.toml @@ -0,0 +1,14 @@ +[package] +name = "chronos" +version = "0.0.1" +compiler = "0.11.0" +repository = "https://git.kb28.ch/HEL/chronos" +entrypoint = "src/lib.typ" +authors = [ + "Louis Heredero " +] +categories = ["visualization"] +license = "Apache-2.0" +description = "A package to draw sequence diagrams with CeTZ" +keywords = ["sequence", "diagram", "plantuml"] +exclude = [ "/gallery/*" ]