Generating Diagrams in Livebook

I have paused working on my kino_wardley component for a while.

Just having a think about how to integrate diagram generation into a livebook.
I came up with this

Here is the code

Mix.install([{:kino, "~> 0.7.0"}])

data = """
digraph architecture {

  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};

{body, _} = "echo '#{data}' | /usr/local/bin/dot -Tpng", stderr_to_stdout: true), :png)

It simply installs Kino and uses the graphviz command line tool dot to build a png which is then displayed in a Kino.Image.

This gives the basis of adding diagrams generated from dot or plantuml straight into a livebook.
These would make very useful as a LiveCell

Sample rendered image

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s