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.3.1 #1562

Merged
merged 61 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 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
f887648
Upload diagraph v0.2.2
Robotechnic Mar 13, 2024
2ef12bd
Merge branch 'typst:main' into main
Robotechnic Mar 13, 2024
74a70f1
Merge branch 'typst:main' into main
Robotechnic Mar 15, 2024
bad3d82
Update README.md
Robotechnic Mar 15, 2024
b26451b
Merge branch 'typst:main' into main
Robotechnic May 9, 2024
c6fc718
Upload diagraph v0.2.3
Robotechnic May 9, 2024
333f07a
update README
Robotechnic May 9, 2024
6e7d155
update exclude
Robotechnic May 13, 2024
1ccfca0
Merge branch 'main' of https://github.com/typst/packages
Robotechnic May 13, 2024
2e9266f
update README
Robotechnic May 16, 2024
b1d3318
Merge branch 'typst:main' into main
Robotechnic May 16, 2024
7b7054e
Update packages/preview/diagraph/0.2.3/README.md
Robotechnic May 16, 2024
19516fa
Update README.md
Robotechnic May 16, 2024
2207c84
Upload diagraph v0.2.4
Robotechnic May 22, 2024
9555c2b
Merge branch 'typst:main' into main
Robotechnic May 22, 2024
6299481
Upload diagraph v0.2.5
Robotechnic Jun 10, 2024
a796d77
Merge branch 'typst:main' into main
Robotechnic Jun 10, 2024
465c6e2
update README
Robotechnic Jun 10, 2024
4d1f44c
Upload diagraph v0.3.0
Robotechnic Sep 2, 2024
406a22a
Merge branch 'typst:main' into main
Robotechnic Sep 2, 2024
c4cc1b3
Merge branch 'typst:main' into main
Robotechnic Nov 1, 2024
db2f31e
fixed empty readme
Robotechnic Nov 1, 2024
37ba376
Upload diagraph v0.3.1
Robotechnic Jan 13, 2025
dad6656
Merge branch 'typst:main' into main
Robotechnic Jan 13, 2025
494258e
upated LICENCE file
Robotechnic Jan 13, 2025
39fec1c
added forgotten adjacency matrix file
Robotechnic Jan 13, 2025
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.3.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2025 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.
100 changes: 100 additions & 0 deletions packages/preview/diagraph/0.3.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# diagraph

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

## Usage

### Basic usage


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:

<!--EXAMPLE(raw-render)-->
````typ
#raw-render(
```dot
digraph {
a -> b
}
```
)
````
![raw-render](https://raw.githubusercontent.com/Robotechnic/diagraph/main/images/raw-render1.png)

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

### Advanced usage

Check the [manual](https://raw.githubusercontent.com/Robotechnic/diagraph/main/doc/manual.pdf) for more information about the plugin.


## License

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

## Changelog

### 0.3.1

- Updated graphviz version to 12.2.1
- Fixed a bug with the font being incorrectly set
- Added adjacency lists to the graph rendering possibilities

### 0.3.0

- Added support for edge labels
- Added a manual generated with Typst
- Updated graphviz version
- Fix an error in math mode detection

### 0.2.5

- If the shape is point, the label isn't displayed
- Now a minimum size is not enforced if the node label is empty
- Added support for font alternatives

### 0.2.4

- Added support for xlabels which are now rendered by Typst
- Added support for cluster labels which are now rendered by Typst
- Fix a margin problem with the clusters

### 0.2.3

- Updated to typst 0.11.0
- Added support for `fontcolor`, `fontsize` and `fontname` nodes attributes
- Diagraph now uses a protocol generator to generate the wasm interface

### 0.2.2

- Fix an alignment issue
- Added a better mathematic formula recognition for node labels

### 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
191 changes: 191 additions & 0 deletions packages/preview/diagraph/0.3.1/adjacency.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#import "internals.typ": render

#let inches = (
"width",
"height",
"len",
"lheight",
"lwidth",
"margin",
"nodesep",
"page",
"size",
"vertices",
)

#let value-to-str(key, value) = {
if type(value) == length {
if key in inches {
str(value.to-absolute().inches())
} else {
str(value.to-absolute().pt())
}
} else if type(value) == color {
"\"" + value.to-hex() + "\""
} else if value == none {
"none"
} else if value == true {
"true"
} else if value == false {
"false"
} else {
"\"" + str(value) + "\""
}
}

#let dict-to-graph-args(args, sep: ";", parent: "") = {
for (key, value) in args {
if type(value) == dictionary {
if sep == "," {
panic("Invalid argument for " + parent + "[" + key + "=...]")
}
key + "[" + dict-to-graph-args(value, sep: ",", parent: key) + "]"
} else {
key + "=" + if type(value) == array {
"\"(" + value.map(value-to-str.with(key)).join(",") + ")\""
} else {
value-to-str(key, value)
}
} + sep
}
}

#let create-nodes(min, max) = {
range(min, max).map(str).join(";")
}

#let create-attributes(labels) = {
labels
.enumerate()
.map(label => {
if type(label.at(1)) == dictionary {
let _ = label.at(1).remove("label", default: "")
_ = label.at(1).remove("xlabel", default: "")
str(label.at(0)) + "[" + dict-to-graph-args(label.at(1), sep: ",") + "]"
}
})
.join("")
}

#let create-clusters(clusters) = {
clusters
.enumerate()
.map(cluster => {
let id = str(cluster.at(0))
let nodes = cluster.at(1)
"subgraph cluster_" + id + "{"
if type(nodes) == dictionary {
let _ = nodes.remove("label", default: "")
let subnodes = nodes.remove("nodes")
dict-to-graph-args(nodes)
subnodes.map(str).join(";")
} else {
nodes.map(str).join(";")
}
"};"
})
.join("")
}

#let build-edges(adjacency, directed) = {
adjacency
.enumerate()
.map(edges-list => {
edges-list
.at(1)
.enumerate()
.map(edge => {
if edge.at(1) == none {
""
} else {
str(edges-list.at(0))
if directed {
" -> "
} else {
" -- "
}
str(edge.at(0)) + ";"
}
})
.join("")
})
.join("")
}

#let adjacency(..args) = context {
if args.pos().len() != 1 {
panic("adjacency() requires one argument: an adjacency matrix")
}
let adjacency = args.at(0)
let graph-params = args.named()
let vertex-labels = graph-params.remove("vertex-labels", default: ())
let directed = graph-params.remove("directed", default: true)
let clusters = graph-params.remove("clusters", default: ())
let debug = graph-params.remove("debug", default: false)
let clip = graph-params.remove("clip", default: true)

render(
if directed {
"digraph"
} else {
"graph"
} + "{" + dict-to-graph-args(graph-params) + create-nodes(
0,
adjacency.len(),
) + ";" + create-clusters(clusters) + create-attributes(vertex-labels) + build-edges(adjacency, directed) + "}",
debug: debug,
clip: clip,
labels: name => {
let id = int(name)
if id < vertex-labels.len() {
let label = vertex-labels.at(id)
if type(label) == dictionary {
label.at("label", default: "")
} else {
label
}
} else {
""
}
},
xlabels: name => {
let id = int(name)
if id < vertex-labels.len() {
let label = vertex-labels.at(id)
if type(label) == dictionary {
label.at("xlabel", default: none)
} else {
none
}
} else {
none
}
},
edges: (name, edges) => {
let id = int(name)
let result = (:)
for edge in edges {
let edge-id = int(edge)
let label = adjacency.at(id).at(edge-id)
if label != none {
result.insert(edge, [#label])
}
}
result
},
clusters: (name) => {
let id = int(name.split("_").at(1))
if id < clusters.len() {
let cluster = clusters.at(id)
if type(cluster) == dictionary {
cluster.at("label", default: none)
} else {
none
}
} else {
none
}
}
)
}

Binary file not shown.
Loading
Loading