🌳 Bintreeviz

Bintreeviz is a binary tree visualizer for Elixir. Its main purpose is to convert a given tree structure into a string representation. Out of the box it supports the Wetherell and Shannon alhorithm as described in their 1979 publication of Tidy Drawings of Trees in IEEE and renders to ASCII characters using the Box Drawing Character set, but all of these are configurable options.

Example

Building the tree

alias Bintreeviz.Node

root = Node.new("Root",
  left_child: Node.new("Node A",
    left_child: Node.new("Node C"),
    right_child: Node.new("Node D")
  ),
  right_child: Node.new("Node B",
    left_child: Node.new("Node E"),
    right_child: Node.new("Node F")
  )
)

Rendering the tree

root
|> Bintreeviz.render()
|> IO.puts()

The result:

                   ┏━━━━━━┓
                   ┃ Root ┃
                   ┗━━━┳━━┛
           ┏━━━━━━━━━━━┻━━━━━━━━━━━┓
      ┏━━━━┻━━━┓              ┏━━━━┻━━━┓
      ┃ Node A ┃              ┃ Node B ┃
      ┗━━━━┳━━━┛              ┗━━━━┳━━━┛
     ┏━━━━━┻━━━━━┓           ┏━━━━━┻━━━━━┓
┏━━━━┻━━━┓  ┏━━━━┻━━━┓  ┏━━━━┻━━━┓  ┏━━━━┻━━━┓
┃ Node C ┃  ┃ Node D ┃  ┃ Node E ┃  ┃ Node F ┃
┗━━━━━━━━┛  ┗━━━━━━━━┛  ┗━━━━━━━━┛  ┗━━━━━━━━┛

Installation

If available in Hex, the package can be installed by adding bintreeviz to your list of dependencies in mix.exs:

def deps do
  [
    {:bintreeviz, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/bintreeviz.