TreeView package release for visualizing syntax trees


I have just released the first version of the TreeView package, which makes it easy to visualize the syntax tree of a Julia Expression as a graph.

It is as simple as typing

using TreeView
@tree x^2 + y^2

in an IJulia notebook.
You can see a couple of examples here.

This uses the nice TikzGraphs package, so requires LaTeX to be installed on your system, as well as pdf2svg. (See the README of TikzGraphs.)

Apart from being useful for visualization purposes, it is also intended as a pedagogical example of how to walk a syntax tree and do basic metaprogramming.

Suggestions and Pull Requests are, of course, welcome.


Thanks @dpsanders, it can be very useful for people playing with Deep Learning or Mathematical Optimization. It would be great if all Julia packages that manipulate Julia expressions somehow used the same visualization API.


I believe there’s already a plot recipe for handling something like this. I wonder how it’s different. This does look nice though.


Which other APIs do you in this area?


There is indeed a recipe, I actually suggested the recipe to be part of Documenter.jl to have type DAGs a la Doxygen:


@lobingera I am not following the development of the Deep Learning frameworks in Julia closely, but I am sure they have a representation of the computation in graph form that can be visualized somewhere.


I forgot to say that apart from being useful in itself, it is also intended as a pedagogical example of how to walk a syntax tree and do basic metaprogramming.


It’s indeed a great pedagogical tool. I also needed to install pdf2svg (which wasn’t part of TeXLive on OSX). In the example with functions f and g, is it possible to go recursively into the functions?


I’m not quite sure what you mean by “recursively” here.
The package will just display a literal tree of the expression itself; no evaluation is carried out.
Can you give an example of what you had in mind?


What I mean is descend recursively into functions. f itself has an expression graph associated to it. For example instead of

Can we get


That seems quite difficult to do in general. In the case you show it may not be hard, but what if you have eg f(1,y)? This is getting into parser territory. Maybe use Sugar.jl?


Note to myself: Ask concrete and understandable questions.

What i actually wanted to ask was: Have you seen other visualisation APIs in use here? Going to Tikz and LaTeX in the background sounds too heavy for drawing “simple” trees. I always wondered if Compose’s introspect could be reused here:


Here’s an example:


That is precisely what you are looking for @dpo


How hard might it be to get a style more like the tikz trees shown? (ie black and wite without boxes etc) To my eye they look much nicer, but I would rather use Plots.jl


It just requires rewriting the plot recipe.


lol. Good point … looking at the code for the recipe, I realize I don’t really understand how it works … so installing tikz it is … Thanks for the cool package.


As far as I can tell, the Plots recipe doesn’t do it either. Anyways, it was just curiosity.


You could try passing arguments such as method = :tree, markercolor = :white, markerstrokewidth = 0 to the plot recipe?