Skip to content

Commit d15883f

Browse files
authored
diagraph-layout:0.0.1 (#3073)
1 parent 4c2ea1f commit d15883f

File tree

8 files changed

+742
-0
lines changed

8 files changed

+742
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Robotechnic
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# diagraph-layout
2+
3+
A layout engine for directed graphs that uses graphviz algorithms.
4+
5+
> [!NOTE]
6+
> This project only exposes the layout engines and provides no means of rendering the graphs itself. You must use a separate library for rendering the graphs. If you are looking for a complete solution for rendering graphs, you might want to check out [diagraph](https://github.com/Robotechnic/diagraph).
7+
8+
> [!CAUTION]
9+
> This is still a work in progress. The API is not stable yet and might change in the future. Any feedback is welcome!
10+
11+
## API Reference
12+
13+
The api beeing quite simple, there is no need for a separate documentation. Everithing is documented in the following. For more detailed resources on graphviz check their [official documentation](https://graphviz.org/documentation/).
14+
15+
### layout-graph
16+
17+
```typ
18+
#let layout-graph(engine: "dot", directed: false, ..graph)
19+
```
20+
21+
Layouts a graph using the specified layout engine. The default engine is `dot`. Other supported engines are listed by the function `engine-list`. The graph can be either directed or undirected. The default is undirected. The rest of the arguments are element functions. See the following for more details.
22+
23+
### engine-list
24+
25+
```typ
26+
#let engine-list()
27+
```
28+
29+
Returns a list of supported layout engines. The list can change in the future and this is hence the most reliable way to get the supported engines. But as of now, the supported engines are:
30+
31+
- `circo`
32+
- `dot`
33+
- `fdp`
34+
- `neato`
35+
- `nop`
36+
- `nop1`
37+
- `nop2`
38+
- `osage`
39+
- `patchwork`
40+
- `sfdp`
41+
- `twopi`
42+
43+
### node
44+
45+
```typ
46+
#let node(name, width: 0.75 * 75pt, height: 0.5 * 75pt, xlabel: none)
47+
```
48+
49+
Defines a new node with the given name. `width` and `height` define the size of the node in points. The default size is the graphviz default size of `0.75in` x `0.5in`. The `xlabel` argument is the size of the xlabel of the node. This argument takes a `dict` with the keys `width` and `height` in points.
50+
51+
### edge
52+
53+
```typ
54+
#let edge(head, tail, label: none, xlabel: none, taillabel: none, headlabel: none, ..args)
55+
```
56+
57+
Defines a new edge between the nodes `head` and `tail`. The `label`, `xlabel`, `taillabel` and `headlabel` arguments are optional labels for the edge. They take a `dict` with the keys `width` and `height` in points. The rest of the arguments are the edge attributes in the form of named arguments. See [here](https://graphviz.org/docs/edges/) for a list of supported attributes.
58+
59+
> [!NOTE]
60+
> Only the arguments that have an influence on the layout are supported. For example, the `color` won't have any effect as it does not influence the layout.
61+
62+
### graph-attribute
63+
64+
```typ
65+
#let graph-attribute(type, key, value)
66+
```
67+
68+
This function lets you set global graph attributes. The `type` argument can be either `"GRAPH"`, `"NODE"` or `"EDGE"`. The `key` and `value` arguments are the attribute key and value. See [here](https://graphviz.org/doc/info/attrs.html) for a list of supported attributes.
69+
70+
### subgraph
71+
72+
```typ
73+
#let subgraph(...args)
74+
```
75+
76+
Defines a new subgraph. The positional arguments are nodes names. The rest of the named arguments are the subgraph attributes. See [here](https://graphviz.org/docs/graph/) for a list of supported attributes.
77+
This function is made to be used as a separated context for attributes. For instance, you can use it to add `rank=same` to a group of nodes.
78+
79+
## Output format
80+
81+
```typ
82+
#(
83+
"errored": bool,
84+
"scale": length,
85+
"width": length,
86+
"height": length,
87+
"nodes": (
88+
(
89+
"name": str,
90+
"x": length,
91+
"y": length,
92+
"width": length,
93+
"height": length,
94+
"xlabel": (
95+
"x": length,
96+
"y": length,
97+
"width": length,
98+
"height": length
99+
)
100+
),
101+
),
102+
"edges": (
103+
(
104+
"head": str,
105+
"tail": str,
106+
"points": (
107+
("x": length, "y": length),
108+
),
109+
"label": (
110+
"x": length,
111+
"y": length,
112+
"width": length,
113+
"height": length
114+
),
115+
"xlabel": (
116+
"x": length,
117+
"y": length,
118+
"width": length,
119+
"height": length
120+
),
121+
"headlabel": (
122+
"x": length,
123+
"y": length,
124+
"width": length,
125+
"height": length
126+
),
127+
"taillabel": (
128+
"x": length,
129+
"y": length,
130+
"width": length,
131+
"height": length,
132+
)
133+
)
134+
)
135+
)
136+
```
137+
138+
Coordinates are given in graphviz coordinates, meaning that they represent the center of the object. If you want to see how it translates in cetz coordinates, look at the [renderer used in tests](src/renderer.typ).
139+
140+
The `errored` field indicates if the layouting was successful or not. If it is `true`, the rest of the fields are not valid. The `scale` field indicates the scale used by graphviz to convert points to inches, usually `1`. Except for very advanced things, you can just ignore it completely. The `width` and `height` fields indicate the size of the whole graph.
141+
142+
> [!WARNING]
143+
> The outputting order of nodes and edges is not guaranteed to be the same as the inputting order, this can change because of graphviz internals.
144+
145+
## Change Log
146+
147+
### 0.0.1
148+
149+
- Initial release
Binary file not shown.

0 commit comments

Comments
 (0)