completed README
This commit is contained in:
parent
226efa46b7
commit
5822d705f2
149
README.md
149
README.md
@ -1,3 +1,150 @@
|
|||||||
# chronos
|
# chronos
|
||||||
|
|
||||||
A Typst package to draw sequence diagrams with CeTZ
|
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:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Typst</strong></td>
|
||||||
|
<td><strong>Result</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```typst
|
||||||
|
#import "@preview/chronos:0.1.0"
|
||||||
|
#chronos.diagram({
|
||||||
|
import chronos: *
|
||||||
|
_par("Alice")
|
||||||
|
_par("Bob")
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td><img src="./gallery/readme/boilerplate.png"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
> *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:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Typst</strong></td>
|
||||||
|
<td><strong>Result</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```typst
|
||||||
|
#chronos.diagram({
|
||||||
|
import chronos: *
|
||||||
|
_par("Alice")
|
||||||
|
_par("Bob")
|
||||||
|
|
||||||
|
_seq("Alice", "Bob", comment: "Hello")
|
||||||
|
_seq("Bob", "Bob", comment: "Think")
|
||||||
|
_seq("Bob", "Alice", comment: "Hi")
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td><img src="./gallery/readme/simple_sequence.png"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Typst</strong></td>
|
||||||
|
<td><strong>Result</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```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)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td><img src="./gallery/readme/lifelines.png"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
## 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:
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Example</strong></td>
|
||||||
|
<td><strong>Features</strong></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`example1` <br>([PDF](./gallery/example1.pdf)|[Typst](./gallery/example1.typ))
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>Simple cases, color sequences, groups, separators, gaps, self-sequences</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`example2` <br>([PDF](./gallery/example2.pdf)|[Typst](./gallery/example2.typ))
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>Lifelines, found/lost messages, synchronized sequences, slanted sequences</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`example3` <br>([PDF](./gallery/example3.pdf)|[Typst](./gallery/example3.typ))
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>Participant shapes, sequence tips, hidden partipicant ends</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
`notes` <br>([PDF](./gallery/notes.pdf)|[Typst](./gallery/notes.typ))
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td>Notes (duh), deferred participant creation</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
>
|
||||||
|
> Many examples were taken/adapted from the PlantUML [documentation](https://plantuml.com/sequence-diagram) on sequence diagrams
|
11
gallery.bash
11
gallery.bash
@ -14,3 +14,14 @@ do
|
|||||||
typst c --root ./ "$f" "$f2"
|
typst c --root ./ "$f" "$f2"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
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
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
gallery/readme/boilerplate.pdf
Normal file
BIN
gallery/readme/boilerplate.pdf
Normal file
Binary file not shown.
BIN
gallery/readme/boilerplate.png
Normal file
BIN
gallery/readme/boilerplate.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
13
gallery/readme/boilerplate.typ
Normal file
13
gallery/readme/boilerplate.typ
Normal file
@ -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")
|
||||||
|
})
|
BIN
gallery/readme/lifelines.pdf
Normal file
BIN
gallery/readme/lifelines.pdf
Normal file
Binary file not shown.
BIN
gallery/readme/lifelines.png
Normal file
BIN
gallery/readme/lifelines.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 96 KiB |
24
gallery/readme/lifelines.typ
Normal file
24
gallery/readme/lifelines.typ
Normal file
@ -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)
|
||||||
|
})
|
BIN
gallery/readme/simple_sequence.pdf
Normal file
BIN
gallery/readme/simple_sequence.pdf
Normal file
Binary file not shown.
BIN
gallery/readme/simple_sequence.png
Normal file
BIN
gallery/readme/simple_sequence.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
17
gallery/readme/simple_sequence.typ
Normal file
17
gallery/readme/simple_sequence.typ
Normal file
@ -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")
|
||||||
|
})
|
@ -11,4 +11,4 @@ categories = ["visualization"]
|
|||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
description = "A package to draw sequence diagrams with CeTZ"
|
description = "A package to draw sequence diagrams with CeTZ"
|
||||||
keywords = ["sequence", "diagram", "plantuml"]
|
keywords = ["sequence", "diagram", "plantuml"]
|
||||||
exclude = [ "/gallery/*" ]
|
exclude = [ "/gallery/*", "/gallery.bash", "/TODO.md" ]
|
||||||
|
Loading…
Reference in New Issue
Block a user