Dynamic Diagrams
Mix.install([{:kino, "~> 0.7.0"}])
Section
defmodule GraphvizEx do
def new(source) do
{body, _} =
System.shell("echo '#{source}' | /usr/local/bin/dot -Tpng", stderr_to_stdout: true)
Kino.Image.new(body, :png)
end
end
defmodule PlantUmlEx do
def new(source) do
{body, _} =
System.shell("echo '#{source}' | /usr/local/bin/plantuml -p", stderr_to_stdout: true)
Kino.Image.new(body, :png)
end
end
data = """
digraph architecture {
rankdir=LR;
subgraph client_side_apps {
front_end -> {auth_api, my_app_api};
extension -> {auth_api, my_app_api};
{rank=same; front_end, extension, auth_api};
}
subgraph api_gateways {
my_app_api -> {photos_ms, chats_ms, friends_ms};
}
subgraph microservices {
photos_ms -> {database};
chats_ms -> {database, cache};
friends_ms -> {database, facebook_api};
}
}
"""
GraphvizEx.new(data)
PlantUmlEx.new("""
@startuml
Title "This is an activity diagram"
Actor A
Database B
A -> B: send
@enduml
""")