This library renders graphs in DOT Language to SVG.
It is a tiny (Rustler-based) wrapper around the layout-rs. I initially used a local copy of dot.exe from the Graphviz package, and launched dot using rambo. However, I didn't want to spin up a console executable for each conversion, so looked for alternatives. Luckily, I found 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.
If available in Hex, the package can be installed
by adding ex_dot to your list of dependencies in mix.exs:
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"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ex_dot.
You must set the environment variable EX_DOT_BUILD to true, otherwise it will try to pull the rustler_precompiled bits.
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)