alex-tan / elm-tree-diagram / TreeDiagram

This library provides functions drawing diagrams of trees.

Building a tree


type Tree a

A tree data structure

node : a -> List (Tree a) -> Tree a

Constructs a tree out of a root value and a list of subtrees

Drawing a tree


type alias Coord =
( Basics.Float, Basics.Float )

2D coordinate


type alias Drawable fmt out =
{ position : Coord -> fmt -> fmt
, compose : Basics.Int -> Basics.Int -> List fmt -> out
, transform : Basics.Int -> Basics.Int -> Coord -> Coord 
}

Functions for moving around and composing drawings


type alias NodeDrawer a fmt =
a -> fmt

Alias for functions that draw nodes


type alias EdgeDrawer fmt =
Coord -> fmt

Alias for functions that draw edges between nodes

draw_ : Drawable fmt out -> TreeLayout -> NodeDrawer a fmt -> EdgeDrawer fmt -> Tree a -> out

Draws the tree using the provided functions for drawings nodes and edges. TreeLayout contains some more options for positioning the tree.

Tree layout options


type alias TreeLayout =
{ orientation : TreeOrientation
, levelHeight : Basics.Int
, siblingDistance : Basics.Int
, subtreeDistance : Basics.Int
, padding : Basics.Int 
}

Options to be passed to draw_ for laying out the tree:

defaultTreeLayout : TreeLayout

A set of default values that should be modified to create your TreeLayout


type TreeOrientation

Direction of the tree from root to leaves

leftToRight : TreeOrientation

Left-to-right tree orientation

rightToLeft : TreeOrientation

Right-to-left tree orientation

bottomToTop : TreeOrientation

Bottom-to-top tree orientation

topToBottom : TreeOrientation

Top-to-bottom tree orientation