Function Repository Resource:

TreeGrid

Source Notebook

Display a tree with a grid

Contributed by: Michael Sollami

ResourceFunction["TreeGrid"][tree]

displays tree as a hierarchical grid.

Details and Options

The tree can be given in two forms:
Nested list of rules{e1{e2,e3{e4,e5,}}}
Tree grapha Graph g such that TreeGraphQ[g] is True
ResourceFunction["TreeGrid"] takes a single option Appearance, which can be set to "Vertical" (default) or "Horizontal".

Examples

Basic Examples (3) 

Display a tree as a Grid:

In[1]:=
ResourceFunction["TreeGrid"][
 1 -> {2 -> {3, 4 -> {5 -> {6, 7}}}, 4 -> {8 -> {9 -> {10}}}}]
Out[1]=

Display a TreeGraph as a hierarchical grid:

In[2]:=
g = TreeGraph[(RandomInteger[#] -> (# + 1)) & /@ Range[0, 6], VertexSize -> 0.1, VertexLabels -> Automatic, GraphRoot -> 0, ImageSize -> {Automatic, 200}];
In[3]:=
Row@{g, Spacer[30], ResourceFunction["TreeGrid"][g, Appearance -> "Horizontal"]}
Out[3]=

Display a tree as a vertically or horizontally aligned Grid:

In[4]:=
Labeled[ResourceFunction["TreeGrid"][1 -> {2 -> {3, 4 -> {5, 6, 7}}}, Appearance -> # ], Text@#] & /@ {"Horizontal", "Vertical"}
Out[4]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 27 May 2020

Related Resources

License Information