Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diagraph 0.2.1 #346

Merged
merged 35 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3868ce3
Upload graphviz-typst v0.1.0
Robotechnic Sep 22, 2023
de63269
Upload graphviz-typst v0.1.0
Robotechnic Sep 22, 2023
9f3853f
Upload graphviz-typst v0.1.0
Robotechnic Sep 22, 2023
d70a9f7
Update README.MD
Robotechnic Sep 22, 2023
955ad9c
Change package name to folow guidelines
Robotechnic Sep 22, 2023
b72e34e
Change package name to folow guidelines
Robotechnic Sep 22, 2023
ea20dd0
Fix the licence and fix some typos
Robotechnic Sep 22, 2023
824dbf1
Delete packages/preview/graphviz-typst directory
Robotechnic Sep 22, 2023
a1c516a
Rename the package to diagraph
Robotechnic Sep 22, 2023
996a39f
Merge branch 'typst:main' into main
Robotechnic Sep 23, 2023
7b24175
Rename the package to diagraph
Robotechnic Sep 23, 2023
acc3a36
fix README
Robotechnic Sep 23, 2023
38e4363
fix README
Robotechnic Sep 23, 2023
0c4fdcc
rename gaph-render to raw-dotrender-rule
Robotechnic Sep 23, 2023
bbc984b
Upload diagraph v0.1.1
Robotechnic Sep 26, 2023
02533bb
Merge branch 'typst:main' into main
Robotechnic Sep 26, 2023
0533346
Upload diagraph v0.1.1
Robotechnic Sep 26, 2023
7ea32c3
Upload diagraph v0.1.2
Robotechnic Nov 2, 2023
655a973
Merge branch 'typst:main' into main
Robotechnic Nov 2, 2023
cfe3e5e
Upload diagraph v0.1.2
Robotechnic Nov 2, 2023
5397407
Upload diagraph v0.1.2
Robotechnic Nov 3, 2023
91b1ed7
rename REAMDE.MD to REAMDE.md
Robotechnic Nov 6, 2023
81c82bb
rename REAMDE.MD to REAMDE.md
Robotechnic Nov 6, 2023
79b3457
Upload diagraph v0.2.0
Robotechnic Nov 17, 2023
d984409
Merge branch 'typst:main' into main
Robotechnic Nov 17, 2023
60fe9f2
add internals.typ
Robotechnic Nov 17, 2023
ee42fef
removed a duplicate README
Robotechnic Nov 17, 2023
b3c7147
rename README
Robotechnic Nov 17, 2023
ef6f472
Revert "rename README"
Robotechnic Nov 17, 2023
57fd860
correct README naming
Robotechnic Nov 17, 2023
5ba3672
Revert "removed a duplicate README"
Robotechnic Nov 18, 2023
35577b6
Upload diagraph v0.2.1
Robotechnic Jan 15, 2024
c3b2eb8
Upload diagraph v0.2.1
Robotechnic Jan 15, 2024
c2d7f6a
Merge branch 'typst:main' into main
Robotechnic Jan 15, 2024
122f198
update version and licence
Robotechnic Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/preview/diagraph/0.2.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2024 Robotechnic

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
122 changes: 122 additions & 0 deletions packages/preview/diagraph/0.2.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# diagraph

A simple Graphviz binding for Typst using the WebAssembly plugin system.

## Usage

### Basic usage

This plugin is quite simple to use, you just need to import it:

```typ
#import "@preview/diagraph:0.2.1": *
```

You can render a Graphviz Dot string to a SVG image using the `render` function:

```typ
#render("digraph { a -> b }")
```

Alternatively, you can use `raw-render` to pass a `raw` instead of a string:

````typ
#raw-render(
```dot
digraph {
a -> b
}
```
)
````

You can see an example of this in [`examples/`](https://github.com/Robotechnic/diagraph/tree/main/examples).

For more information about the Graphviz Dot language, you can check the [official documentation](https://graphviz.org/documentation/).

### Arguments

`render` and `raw-render` accept multiple arguments that help you customize your graphs.

- `engine` (`str`) is the name of the engine to generate the graph with. Available engines are circo, dot, fdp, neato, nop, nop1, nop2, osage, patchwork, sfdp, and twopi. Defaults to `"dot"`.

- `width` and `height` (`length` or `auto`) are the dimensions of the image to display. If set to `auto` (the default), will be the dimensions of the generated SVG. If a `length`, cannot be expressed in `em`.

- `clip` (`bool`) determines whether to hide parts of the graph that extend beyond its frame. Defaults to `true`.

- `background` (`none` or `color` or `gradient`) describes how to fill the background. If set to `none` (the default), the background will be transparent.

- `labels` (`dict`) is a list of labels to use to override the defaults labels. This is discussed in depth in the next section. Defaults to `(:)`.

### Labels

By default, all node labels are rendered by Typst. If a node has no explicitly set label (using the `[label="..."]` syntax), its name is used as its label, and interpreted as math if possible. This means a node named `n_0` will render as 𝑛<sub>0</sub>.

If you want a node label to contain a more complex mathematical equation, or more complex markup, you can use the `labels` argument: pass a dictionary that maps node names to Typst `content`. Each node with a name within the dictionary will have its label overridden by the corresponding content.

````typ
#raw-render(
```
digraph {
rankdir=LR
node[shape=circle]
Hmm -> a_0
Hmm -> big
a_0 -> "a'" -> big [style="dashed"]
big -> sum
}
```,
labels: (:
big: [_some_#text(2em)[ big ]*text*],
sum: $ sum_(i=0)^n 1/i $,
),
)
````

See [`examples/`](https://github.com/Robotechnic/diagraph/tree/main/examples) for the rendered graph.

## Build

This project was built with emscripten `3.1.46`. Apart from that, you just need to run `make wasm` to build the wasm file. All libraries are downloaded and built automatically to get the right version that works.

There are also some other make commands:

- `make link`: Link the project to the typst plugin folder
- `make clean`: Clean the build folder and the link
- `make clean-link`: Only clean the link
- `make compile_database`: Generate the compile_commands.json file
- `make module`: It copy the files needed to run the plugin in a folder called `graphviz` in the current directory
- `make wasi-stub`: Build the wasi stub executable, it require a rust toolchain properly configured

### Wasi stub

Somme functions need to be stubbed to work with the webassembly plugin system. The `wasi-stub` executable is a spetial one fitting the needs of the typst plugin system. You can find the source code [here](https://github.com/astrale-sharp/wasm-minimal-protocol/tree/master). It is important to use this one as the default subbed functions are not the same and the makefile is suited for this one.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

## Changelog

### 0.2.1

- Added support for relative lenghts in the `width` and `height` arguments
- Fix various bugs

### 0.2.0

- Node labels are now handled by Typst

### 0.1.2

- Graphs are now scaled to make the graph text size match the document text size

### 0.1.1

- Remove the `raw-render-rule` show rule because it doesn't allow use of custom font and the `render` / `raw-render` functions are more flexible
- Add the `background` parameter to the `render` and `raw-render` typst functions and default it to `transparent` instead of `white`
- Add center attribute to draw graph in the center of the svg in the `render` c function

### 0.1.0

Initial working version
Binary file added packages/preview/diagraph/0.2.1/diagraph.wasm
Binary file not shown.
Loading