Open slwu89 opened 4 months ago
TreeView uses LaTex so I think that is trying to download a complete LaTeX environment...
I think if you do
t = @tree begin
a = b + c
d = (a - 2)^2
end
print(t)
you should get a text representation instead. You could then use Makie or something to plot that.
I believe that there was a way to draw ASTs using Plots.jl too
I see now that the Base.show
method for LabelledTree
will call down to some other packages using tikz/latex, strange that it is trying to download that file. I'm using MacTeX and have all the prerequisites installed (as per the instructions).
Thanks for the advice! I should be able to work with the LabelledTree
object from the macro to get some plotting worked out. I think Graphviz or Mermaid will look nice.
[EDIT] @dpsanders where exactly in the code does it do some processing of the LabelledTree
to get rid of some of the nodes? What I mean is that the tree object from the simple example in the readme is below, but the picture of the resulting tikz graph only has 7 nodes.
julia> t.labels
9-element Vector{Any}:
:block
:(#= /Users/wusea/Desktop/git/dssi-dyve-gcs/dev/country-depot.jl:7 =#)
:+
:^
:x
2
:^
:y
2
julia> t.g
{9, 8} directed simple Int64 graph
t = @tree x^2 + y^2
print(t.labels)
on my machine gives
7-element Vector{Any}:
:+
:^
:x
2
:^
:y
2
Did you add parentheses?
Please let us know if you find a nice solution with other tools!
Curious, on my machine, using the exact same code, I get (removing the long stacktrace from the error I get with Base.show
for labeled trees:
julia> t = @tree begin
x^2 + y^2
end
error: error sending request for url (https://relay.fullyjustified.net/default_bundle_v33.tar): error trying to connect: connection closed via error
caused by: error trying to connect: connection closed via error
caused by: connection closed via error
Error showing value of type LabelledTree:
ERROR: LaTeX error
julia> t.g
{9, 8} directed simple Int64 graph
julia> t.labels
9-element Vector{Any}:
:block
:(#= REPL[148]:2 =#)
:+
:^
:x
2
:^
:y
2
I might look into doing a proper visualization with Graphviz or MMD later, but for now it suits my purposes to just use Catlab's Graphviz interface (LabeledGraph
is a type from Catlab, I'm more familiar with Catlab than the JuliaTeX/Graphs packages). E.g. using the following to get
using Catlab
using Graphs
g = LabeledGraph{Symbol}()
add_vertices!(g, Graphs.nv(t.g), label=Symbol.(t.labels))
add_edges!(g, Graphs.src.(Graphs.edges(t.g)), Graphs.dst.(Graphs.edges(t.g)))
to_graphviz(g, node_labels=:label, graph_attrs=Dict(:rankdir=>"TB"))
Oh I see now that the extra nodes are due to the begin ... end
block. Mystery solved.
Hi,
When executing the simple example
I get an error:
Because I have to work behind a firewall that blocks the URL https://relay.fullyjustified.net. I looked through the src of this package and cannot find anywhere where the code is trying to execute some download. Is there any workaround for this? Thanks!
I'm on
[39424ebd] TreeView v0.5.1