Function Repository Resource:

TreeVisualizationGraph

Source Notebook

Generate a graph corresponding to the visualization of a tree

Contributed by: Ian Ford

ResourceFunction["TreeVisualizationGraph"][tree]

gives the Graph object for tree formatted as a Tree.

Details and Options

ResourceFunction["TreeVisualizationGraph"] takes the same options as Graph.
In contrast to TreeGraph, all visualizations options used to construct the formatted Tree are preserved by ResourceFunction["TreeVisualizationGraph"].

Examples

Basic Examples (2) 

Give the graph used to format a tree:

In[1]:=
ResourceFunction["TreeVisualizationGraph"][
 Tree[a, {Tree[b, {c, d}], e, f}]]
Out[1]=

Visually this is identical to the tree itself:

In[2]:=
Tree[a, {Tree[b, {c, d}], e, f}]
Out[2]=

Properties and Relations (2) 

TreeGraph converts a tree to a graph without preserving any visualization options:

In[3]:=
TreeGraph[\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`a, {
Tree[$CellContext`b, {
Tree[$CellContext`c, None], 
Tree[$CellContext`d, None]}], 
Tree[$CellContext`e, None], 
Tree[$CellContext`f, None]}]]}, {
{Hue[0.6, 0.7, 0.7], Opacity[0.7], CapForm["Round"], Arrowheads[{{Medium, 0.8}}], 
StyleBox[{
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            0.4082482904638631, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            1.2247448713915892`, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            2.041241452319315, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{0.4082482904638631, 0.8273371707065537}, {0., 0.}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{0.4082482904638631, 0.8273371707065537}, {
            0.8164965809277261, 0.}}]}},
FontFamily->"Arial"]}, 
{Hue[0.6, 0.5, 1.], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
StyleBox[{InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.2247448713915892, 1.6546743414131073}], InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.4082482904638631, 0.8273371707065537}], InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.}], InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.8164965809277261, 0.}], InsetBox[
FrameBox["e",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.2247448713915892, 0.8273371707065537}], InsetBox[
FrameBox["f",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.041241452319315, 0.8273371707065537}]},
FontFamily->"Arial"]}}]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{FontFamily -> "Arial"},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->None,
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[3]=

TreeVisualizationGraph preserves all visualization options used to format the tree:

In[4]:=
ResourceFunction["TreeVisualizationGraph"][\!\(\*
GraphicsBox[
NamespaceBox["Trees",
DynamicModuleBox[{Typeset`tree = HoldComplete[
Tree[$CellContext`a, {
Tree[$CellContext`b, {
Tree[$CellContext`c, None], 
Tree[$CellContext`d, None]}], 
Tree[$CellContext`e, None], 
Tree[$CellContext`f, None]}]]}, {
{Hue[0.6, 0.7, 0.7], Opacity[0.7], CapForm["Round"], Arrowheads[{{Medium, 0.8}}], 
StyleBox[{
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            0.4082482904638631, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            1.2247448713915892`, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{1.2247448713915892`, 1.6546743414131073`}, {
            2.041241452319315, 0.8273371707065537}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{0.4082482904638631, 0.8273371707065537}, {0., 0.}}]}, 
{RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], AbsoluteThickness[1], LineBox[{{0.4082482904638631, 0.8273371707065537}, {
            0.8164965809277261, 0.}}]}},
FontFamily->"Arial"]}, 
{Hue[0.6, 0.5, 1.], EdgeForm[{GrayLevel[0], Opacity[0.7]}], 
StyleBox[{InsetBox[
FrameBox["a",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {1.2247448713915892, 1.6546743414131073}], InsetBox[
FrameBox["b",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->4,
StripOnInput->False], {0.4082482904638631, 0.8273371707065537}], InsetBox[
FrameBox["c",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0., 0.}], InsetBox[
FrameBox["d",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {0.8164965809277261, 0.}], InsetBox[
FrameBox["e",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {1.2247448713915892, 0.8273371707065537}], InsetBox[
FrameBox["f",
Background->Directive[
RGBColor[0.940307618753161, 0.986938478128161, 0.971679689065661], 
Opacity[1]],
BaseStyle->Directive[
GrayLevel[0.0000999867918018385], FontFamily -> "Arial"],
FrameMargins->{{2, 2}, {1, 1}},
FrameStyle->Directive[
RGBColor[0.3231201179703305, 0.696411134378161, 0.574096681253161], 
AbsoluteThickness[1], 
Opacity[1]],
ImageSize->Automatic,
RoundingRadius->0,
StripOnInput->False], {2.041241452319315, 0.8273371707065537}]},
FontFamily->"Arial"]}}]],
AlignmentPoint->Center,
Axes->False,
AxesLabel->None,
AxesOrigin->Automatic,
AxesStyle->{},
Background->None,
BaseStyle->{FontFamily -> "Arial"},
BaselinePosition->Automatic,
ContentSelectable->Automatic,
DefaultBaseStyle->"TreeGraphics",
Epilog->{},
FormatType->StandardForm,
Frame->False,
FrameLabel->None,
FrameStyle->{},
FrameTicks->None,
FrameTicksStyle->{},
GridLines->None,
GridLinesStyle->{},
ImageMargins->0.,
ImagePadding->All,
LabelStyle->{},
PlotLabel->None,
PlotRange->All,
PlotRangeClipping->False,
PlotRangePadding->Automatic,
PlotRegion->Automatic,
Prolog->{},
RotateLabel->True,
Ticks->Automatic,
TicksStyle->{}]\)]
Out[4]=

Publisher

Ian Ford

Version History

  • 1.0.0 – 07 August 2025

Related Resources

License Information