Packages
Bintreeviz renders binary tree structures to string. Out of the box it supports positioning using the WS algorithm and renders to ASCII.
Current section
Files
Jump to
Current section
Files
bintreeviz
README.md
README.md

# π³ 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](https://en.wikipedia.org/wiki/Box-drawing_character) set, but all of these are configurable options.
## Example
Building the tree
```elixir
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
```elixir
root
|> Bintreeviz.render()
|> IO.puts()
```
The result:
```text
ββββββββ
β Root β
βββββ³βββ
βββββββββββββ»ββββββββββββ
ββββββ»ββββ ββββββ»ββββ
β Node A β β Node B β
ββββββ³ββββ ββββββ³ββββ
βββββββ»ββββββ βββββββ»ββββββ
ββββββ»ββββ ββββββ»ββββ ββββββ»ββββ ββββββ»ββββ
β Node C β β Node D β β Node E β β Node F β
ββββββββββ ββββββββββ ββββββββββ ββββββββββ
```
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `bintreeviz` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:bintreeviz, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/bintreeviz](https://hexdocs.pm/bintreeviz).