I have a code that generates a tree of graphics objects. The structure can be visualized like this, with each Rule
constituting a parent child relationship:
children[list_] := ReplaceList[list, {a___, x_, b___} :> Rule[x, children[{a, b}]]]
children[{a, b, c}] // TreeForm
A better way of visualizing the result I want, courtesy of Halirutan is this:
children[list_] := ReplaceList[list, {a___, x_, b___} :> (x @@ children[{a, b}])]
children[{a, b, c}] // TreeForm
However my real code like I said has graphics in it. So each symbol in the above image is a graphics object. An example of this:
r[col_] := Graphics[{col, Rectangle[]}]
treeData = children[{r[Red], r[Green], r[Blue]}];
I would like to visualize this tree using TreeGraph
where each VertexShape
is the corresponding graphics object. So for the leftmost branch I expect graphics object a
and from it two arrows one two graphics object b
and one to graphics object c
and so on. Example of expected output from children[{r[Red],r[Blue]}] // renderTree
:
TreeGraph[{
DirectedEdge[1, 2],
DirectedEdge[1, 3],
DirectedEdge[2, 4],
DirectedEdge[3, 5]
}, VertexShape -> {
2 -> r[Red],
3 -> r[Blue],
4 -> r[Blue],
5 -> r[Red]
}, VertexSize -> 0.5]
Speed is not important since I will only be doing this on relatively small trees for visualization purposes. I can change the code that generates the tree data so you are free to do that as well, you don't have to work with the data as it is. You might want to insert custom heads for example. That is one approach I've tried. However I don't have any code to share, I hope that will not cause a riot. But if it does I shall accept it stoically I hope, I know how important showing an effort is to some of you. I don't know what a good start is.