alex-tan/elm-tree-diagram/1.0.0

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 =
( Float, Float )

2D coordinate

type alias Drawable fmt out =
{ position : Coord -> fmt -> fmt
, compose : Int -> Int -> List fmt -> out
, transform : Int -> 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

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 : Int
, siblingDistance : Int
, subtreeDistance : Int
, padding : Int
}

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

  • orientation: direction of the tree from root to leaves.
  • levelHeight: vertical distance between parent and child nodes.
  • subtreeDistance: horizontal distance between subtrees.
  • siblingDistance: horizontal distance between siblings. This is usually set below subtreeDistance to produce a clearer distinction between sibling nodes and non-siblings on the same level of the tree.
  • padding: amount of space to leave around the edges of the diagram.
defaultTreeLayout : TreeLayout

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

Direction of the tree from root to leaves

Left-to-right tree orientation

Right-to-left tree orientation

Bottom-to-top tree orientation

Top-to-bottom tree orientation