diff --git a/README.md b/README.md index 15f6b1f..922d5ee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,150 @@ # chronos -A Typst package to draw sequence diagrams with CeTZ \ No newline at end of file +A Typst package to draw sequence diagrams with CeTZ + +--- + +This package lets you render sequence diagrams directly in Typst. The following boilerplate code creates an empty sequence diagram with two participants: + + + + + + + + + + +
TypstResult
+ +```typst +#import "@preview/chronos:0.1.0" +#chronos.diagram({ + import chronos: * + _par("Alice") + _par("Bob") +}) +``` + +
+ +> *Disclaimer*\ +> The package cannot parse PlantUML syntax for the moment, and thus requires the use of element functions, as shown in the examples. +> A PlantUML parser is in the TODO list, just not the top priority + +## Basic sequences + +You can make basic sequences using the `_seq` function: + + + + + + + + + + +
TypstResult
+ +```typst +#chronos.diagram({ + import chronos: * + _par("Alice") + _par("Bob") + + _seq("Alice", "Bob", comment: "Hello") + _seq("Bob", "Bob", comment: "Think") + _seq("Bob", "Alice", comment: "Hi") +}) +``` + +
+ +You can make lifelines using the following parameters of the `_seq` function: + - `enable-dst`: enables the destination lifeline + - `create-dst`: creates the destination lifeline and participant + - `disable-dst`: disables the destination lifeline + - `destroy-dst`: destroys the destination lifeline and participant + - `disable-src`: disables the source lifeline + - `destroy-src`: destroy the source lifeline and participant + + + + + + + + + + +
TypstResult
+ +```typst +#chronos.diagram({ + import chronos: * + _par("A", display-name: "Alice") + _par("B", display-name: "Bob") + _par("C", display-name: "Charlie") + _par("D", display-name: "Derek") + + _seq("A", "B", comment: "hello", enable-dst: true) + _seq("B", "B", comment: "self call", enable-dst: true) + _seq("C", "B", comment: "hello from thread 2", enable-dst: true, lifeline-style: (fill: rgb("#005500"))) + _seq("B", "D", comment: "create", create-dst: true) + _seq("B", "C", comment: "done in thread 2", disable-src: true, dashed: true) + _seq("B", "B", comment: "rc", disable-src: true, dashed: true) + _seq("B", "D", comment: "delete", destroy-dst: true) + _seq("B", "A", comment: "success", disable-src: true, dashed: true) +}) +``` + +
+ +## Showcase + +Several features have already been implemented in Chronos. Don't hesitate to checkout the examples in the [gallery](./gallery) folder to see what you can do. + +#### Quick example reference: + + + + + + + + + + + + + + + + + + + + + +
ExampleFeatures
+ +`example1`
([PDF](./gallery/example1.pdf)|[Typst](./gallery/example1.typ)) + +
Simple cases, color sequences, groups, separators, gaps, self-sequences
+ +`example2`
([PDF](./gallery/example2.pdf)|[Typst](./gallery/example2.typ)) + +
Lifelines, found/lost messages, synchronized sequences, slanted sequences
+ +`example3`
([PDF](./gallery/example3.pdf)|[Typst](./gallery/example3.typ)) + +
Participant shapes, sequence tips, hidden partipicant ends
+ +`notes`
([PDF](./gallery/notes.pdf)|[Typst](./gallery/notes.typ)) + +
Notes (duh), deferred participant creation
+ +> [!NOTE] +> +> Many examples were taken/adapted from the PlantUML [documentation](https://plantuml.com/sequence-diagram) on sequence diagrams \ No newline at end of file diff --git a/gallery.bash b/gallery.bash index 9038014..ea50654 100644 --- a/gallery.bash +++ b/gallery.bash @@ -14,3 +14,14 @@ do typst c --root ./ "$f" "$f2" i=$((i+1)) done + +set -- ./gallery/readme/*.typ +cnt="$#" +i=1 +for f +do + f2="${f/typ/png}" + echo "($i/$cnt) $f -> $f2" + typst c --root ./ "$f" "$f2" + i=$((i+1)) +done diff --git a/gallery/example1.pdf b/gallery/example1.pdf index df9f41a..de434a8 100644 Binary files a/gallery/example1.pdf and b/gallery/example1.pdf differ diff --git a/gallery/example2.pdf b/gallery/example2.pdf index 68205a3..7b186d7 100644 Binary files a/gallery/example2.pdf and b/gallery/example2.pdf differ diff --git a/gallery/example3.pdf b/gallery/example3.pdf index 21602b3..7e9f09a 100644 Binary files a/gallery/example3.pdf and b/gallery/example3.pdf differ diff --git a/gallery/notes.pdf b/gallery/notes.pdf index f90fe88..8030aea 100644 Binary files a/gallery/notes.pdf and b/gallery/notes.pdf differ diff --git a/gallery/readme/boilerplate.pdf b/gallery/readme/boilerplate.pdf new file mode 100644 index 0000000..7e9c184 Binary files /dev/null and b/gallery/readme/boilerplate.pdf differ diff --git a/gallery/readme/boilerplate.png b/gallery/readme/boilerplate.png new file mode 100644 index 0000000..04af7e8 Binary files /dev/null and b/gallery/readme/boilerplate.png differ diff --git a/gallery/readme/boilerplate.typ b/gallery/readme/boilerplate.typ new file mode 100644 index 0000000..7bef29e --- /dev/null +++ b/gallery/readme/boilerplate.typ @@ -0,0 +1,13 @@ +#import "/src/lib.typ" as chronos + +#set page( + width: auto, + height: auto, + margin: 0.5cm +) + +#chronos.diagram({ + import chronos: * + _par("Alice") + _par("Bob") +}) \ No newline at end of file diff --git a/gallery/readme/lifelines.pdf b/gallery/readme/lifelines.pdf new file mode 100644 index 0000000..8f58cc1 Binary files /dev/null and b/gallery/readme/lifelines.pdf differ diff --git a/gallery/readme/lifelines.png b/gallery/readme/lifelines.png new file mode 100644 index 0000000..ffb48ec Binary files /dev/null and b/gallery/readme/lifelines.png differ diff --git a/gallery/readme/lifelines.typ b/gallery/readme/lifelines.typ new file mode 100644 index 0000000..520d827 --- /dev/null +++ b/gallery/readme/lifelines.typ @@ -0,0 +1,24 @@ +#import "/src/lib.typ" as chronos + +#set page( + width: auto, + height: auto, + margin: 0.5cm +) + +#chronos.diagram({ + import chronos: * + _par("A", display-name: "Alice") + _par("B", display-name: "Bob") + _par("C", display-name: "Charlie") + _par("D", display-name: "Derek") + + _seq("A", "B", comment: "hello", enable-dst: true) + _seq("B", "B", comment: "self call", enable-dst: true) + _seq("C", "B", comment: "hello from thread 2", enable-dst: true, lifeline-style: (fill: rgb("#005500"))) + _seq("B", "D", comment: "create", create-dst: true) + _seq("B", "C", comment: "done in thread 2", disable-src: true, dashed: true) + _seq("B", "B", comment: "rc", disable-src: true, dashed: true) + _seq("B", "D", comment: "delete", destroy-dst: true) + _seq("B", "A", comment: "success", disable-src: true, dashed: true) +}) \ No newline at end of file diff --git a/gallery/readme/simple_sequence.pdf b/gallery/readme/simple_sequence.pdf new file mode 100644 index 0000000..018d75f Binary files /dev/null and b/gallery/readme/simple_sequence.pdf differ diff --git a/gallery/readme/simple_sequence.png b/gallery/readme/simple_sequence.png new file mode 100644 index 0000000..1af1870 Binary files /dev/null and b/gallery/readme/simple_sequence.png differ diff --git a/gallery/readme/simple_sequence.typ b/gallery/readme/simple_sequence.typ new file mode 100644 index 0000000..fb28924 --- /dev/null +++ b/gallery/readme/simple_sequence.typ @@ -0,0 +1,17 @@ +#import "/src/lib.typ" as chronos + +#set page( + width: auto, + height: auto, + margin: 0.5cm +) + +#chronos.diagram({ + import chronos: * + _par("Alice") + _par("Bob") + + _seq("Alice", "Bob", comment: "Hello") + _seq("Bob", "Bob", comment: "Think") + _seq("Bob", "Alice", comment: "Hi") +}) \ No newline at end of file diff --git a/typst.toml b/typst.toml index e721a3c..b62853f 100644 --- a/typst.toml +++ b/typst.toml @@ -11,4 +11,4 @@ categories = ["visualization"] license = "Apache-2.0" description = "A package to draw sequence diagrams with CeTZ" keywords = ["sequence", "diagram", "plantuml"] -exclude = [ "/gallery/*" ] +exclude = [ "/gallery/*", "/gallery.bash", "/TODO.md" ]