Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chgeuer/ex_dot
A little Elixir package to convert DOT language into SVG
https://github.com/chgeuer/ex_dot
elixir-lang graphviz-dot graphviz-dot-language livebook rustler rustler-precompiled svg
Last synced: about 2 months ago
JSON representation
A little Elixir package to convert DOT language into SVG
- Host: GitHub
- URL: https://github.com/chgeuer/ex_dot
- Owner: chgeuer
- License: apache-2.0
- Created: 2024-02-20T21:42:58.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-03-04T20:29:14.000Z (10 months ago)
- Last Synced: 2024-10-20T10:20:10.919Z (2 months ago)
- Topics: elixir-lang, graphviz-dot, graphviz-dot-language, livebook, rustler, rustler-precompiled, svg
- Language: Elixir
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dot for Elixir
> **This library renders graphs in [DOT Language](https://graphviz.org/doc/info/lang.html) to SVG.**
It is a tiny ([Rustler](https://github.com/rusterlium/rustler)-based) wrapper around the [`layout-rs`](https://crates.io/crates/layout-rs). I initially used a local copy of `dot.exe` from the [Graphviz](https://graphviz.org/) package, and launched `dot` using [rambo](https://github.com/jayjun/rambo). However, I didn't want to spin up a console executable for each conversion, so looked for alternatives. Luckily, I found [`nadavrot/layout`](ttps://github.com/nadavrot/layout), which seems to do what I wanted. *I haven't checked whether that Rust crate can do *everything* that the full dot executable can do.*
Try this [demo](livebook://github.com/chgeuer/ex_dot/blob/main/demo.livemd).
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `ex_dot` to your list of dependencies in `mix.exs`:```elixir
def deps do
[
#{:ex_dot, github: "chgeuer/ex_dot"} # If you do this, you must set the environment variable EX_DOT_BUILD=true
{:ex_dot, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) and published on [HexDocs](https://hexdocs.pm). Once published, the docs can be found at .## Local build
You must set the environment variable `EX_DOT_BUILD` to `true`, otherwise it will try to pull the [`rustler_precompiled`](https://github.com/philss/rustler_precompiled) bits.
## Using it in LiveBook
```elixir
Mix.install([
{:libgraph, "~> 0.16.0"},
{:kino, "~> 0.12.3"},
{:ex_dot, "~> 0.1.0"}
])"""
digraph R {
node [shape=record];{ rank=same rA sA tA }
{ rank=same uB vB wB }rA -> sA;
sA -> vB;
t -> rA;
uB -> vB;
wB -> u;
wB -> tA;
}
"""
|> Dot.to_svg()
|> Kino.Image.new(:svg)
```