Tree

.qp.tree.layout

Layout for a hierarchical tree. An implementation of Reingold and Tilford's layout.

The layout results in a node table and an edge table. These tables can be used in a point and segment geometry to draw the tree (see the examples below).

Options:

  • [`inverty] whether the y axis should be inverted (useful for plotting horizontally or radially).

Parameter(s):

Name Type Description
t table table of a tree - should contain a scalar id column and a nested child column pointing to other ids
id symbol id column
children symbol children column
o dict | null options

Returns:

Name Type Description
<returns> dict Node and edges layout table
<returns>.nodes table
<returns>.edges table

Example: Basic tree example


     // Data has a nested child column
     t: .gg.cheat.i.assemble[];

     l: .qp.tree.layout[t;`id;`children;::];

     .qp.theme[.gg.theme.blank]
     .qp.stack (
         .qp.segment[l`edges;`x__;`y__;`x2__;`y2__;::]; 
         .qp.point[l`nodes;`x__;`y__;::])

Image

Example: Radial tree (polar coordinates)

     l: .qp.tree.layout[t;`id;`children;``inverty!(::;1b)];

     .qp.theme[.gg.theme.blank]
     .qp.stack (
         .qp.segment[l`edges;`y__;`x__;`y2__;`x2__]
             .qp.s.coord .gg.coords.polar; 
         .qp.point[l`nodes;`y__;`x__;::])

Image

Example: horizontal tree

     l: .qp.tree.layout[t;`id;`children;``inverty!(::;1b)];

     .qp.theme[.gg.theme.blank]
     .qp.stack (
         .qp.segment[l`edges;`y__;`x__;`y2__;`x2__;::]; 
         .qp.point[l`nodes;`y__;`x__;::])

Image