Treestack

.qp.treestack.layout

Layout for a hierarchical tree. A stack tree layout. Output is x, y, x2, y2 coordinates for .qp.rect.

Useful for weighted trees (trace timelines, etc). When used in polar coordinates, becomes a Sunburst Chart.

Options:

  • [`expand] expand children to take entire width of the parent.
  • [`filldepth] depth at which children are assigned a colour (default 4).
  • [`colours] a list of 0xrrggbb colours to use when filling.

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
weight symbol weight (numeric) column
o dict | null options

Returns:

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

Example: Basic layout


      t: .gg.cheat.i.assemble[];
      t: update w:count each children from t;

      rr: .qp.treestack.layout[t;`id;`children;`w;``expand!(::;1b)];

     .qp.rect[rr;`x__;`y__;`x2__;`y2__] 
         .qp.s.geom[``colour!(::;0xffffff)]

Image

Example: Adding a fill and alpha scale


     .qp.theme[.gg.theme.blank , ``legend_use!(::;0b)]
     .qp.rect[rr;`x__;`y__;`x2__;`y2__] 
         .qp.s.geom[``colour!(::;0xffffff)] ,
         .qp.s.aes[`fill`alpha; `id`d__] ,
         .qp.s.scale[`fill; .gg.scale.colour.cat rr[`id]!rr`fill__]

Image

Example: Sunburst chart


     .qp.theme[.gg.theme.blank]
     .qp.theme[``legend_use!(::;0b)]
     .qp.rect[rr;`y__;`x__;`y2__;`x2__] 
         .qp.s.geom[``colour!(::;0xffffff)] ,
         .qp.s.aes[`fill`alpha; `id`d__] ,
         .qp.s.scale[`fill; .gg.scale.colour.cat rr[`id]!rr`fill__] ,
         .qp.s.coord[.gg.coords.polar]

Image