Convert DOT to SVG
Mix.install([
{:libgraph, "~> 0.16.0"},
{:kino, "~> 0.12.3"},
{:ex_dot, "~> 0.1.0"},
{:req, "~> 0.4.11"}
])
Render a DOT graph
This demo uses the https://crates.io/crates/layout-rs crate (src: https://github.com/nadavrot/layout), wraps it using Rustler, and allows to convert text in DOT Language to SVG.
render = fn file ->
%Req.Response{status: 200, body: dot_file} =
Req.get!("https://raw.githubusercontent.com/nadavrot/layout/master/inputs/#{file}")
dot_file
|> Dot.to_svg()
|> Kino.Image.new(:svg)
end
file_selector =
Kino.Input.select(
"Please select the file",
[
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"bk", "diamond", "ella", "expr", "heb", "noa",
"prof", "sched0", "sched1", "self", "small"
]
|> Enum.map(fn u -> {"#{u}.dot", u} end)
)
render.(Kino.Input.read(file_selector))