Code Monkey home page Code Monkey logo

treeview.jl's Introduction

TreeView

Build Status codecov

This is a small package to visualize a graph corresponding to an abstract syntax tree (AST) of a Julia expression. It uses the TikzGraphs.jl package to do the visualization.

Usage

The package is designed to be used within the IJulia notebook.

The simplest usage is @tree <EXPRESSION>, where <EXPRESSION> represents any Julia expression, for example

@tree x^2 + y^2

which gives the following output:

example_tree

See this notebook for usage examples.

Installation prerequisites

You will need to have LaTeX installed on your system, and install the pdf2svg utility; see the TikzGraphs.jl documentation for details.

Author

  • David P. Sanders, Departamento de Física, Facultad de Ciencias, Universidad Nacional Autónoma de México (UNAM)

Acknowledements

Financial support is acknowledged from DGAPA-UNAM PAPIME grants PE-105911 and PE-107114, and DGAPA-UNAM PAPIIT grant IN-117214, and from a CONACYT-Mexico sabbatical fellowship. The author thanks Alan Edelman and the Julia group for hospitality during his sabbatical visit.

In particular, he thanks Jiahao Chen, who, when asked if a package like this existed, replied "why don't you write one?".

treeview.jl's People

Contributors

dpsanders avatar juliatagbot avatar lmondada avatar mykelk avatar racinmat avatar rcnlee avatar rdeits avatar staticfloat avatar tawheeler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

treeview.jl's Issues

Save to SVG file

Is there a way to save the resulting picture as an SVG file? I know that with TikzPictures.jl you can use:

save(SVG("output"), tp)

but I haven't been able to connect this with TreeView.jl. The reason I would like to do this is because I don't use Jupyter notebooks. Instead I use Vim + REPL for writing Julia code.

If there exists an alternative to viewing the picture in a vim + REPL environment other than saving it and opening it with e.g. the browser, I would also be interested in knowing what it is. Thanks in advance.

ERROR: KeyError: key "Artifacts" not found

Version 1.5.2 (2020-09-23)
Stacktrace:
[1] getindex at .\dict.jl:467 [inlined]
[2] #37 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\manifest.jl:215 [inlined]
[3] _all(::Pkg.Types.var"#37#40"{Dict{String,Bool}}, ::Dict{String,Base.UUID}, ::Colon) at .\reduce.jl:828
[4] all at .\reduce.jl:823 [inlined]
[5] destructure(::Dict{Base.UUID,Pkg.Types.PackageEntry}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\manifest.jl:215
[6] write_manifest at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\manifest.jl:233 [inlined]
[7] write_manifest at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\manifest.jl:231 [inlined]
[8] write_env(::Pkg.Types.EnvCache; update_undo::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\Types.jl:1367
[9] write_env at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\Types.jl:1366 [inlined]
[10] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}, ::Array{Base.UUID,1}; preserve::Pkg.Types.PreserveLevel, platform::Pkg.BinaryPlatforms.Windows) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\Operations.jl:1143
[11] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}; preserve::Pkg.Types.PreserveLevel, platform::Pkg.BinaryPlatforms.Windows, kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\API.jl:188
[12] add(::Pkg.Types.Context, ::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\API.jl:139
[13] #add#21 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\API.jl:67 [inlined]
[14] add(::Array{Pkg.Types.PackageSpec,1}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\API.jl:67
[15] do_cmd!(::Pkg.REPLMode.Command, ::REPL.LineEditREPL) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\REPLMode\REPLMode.jl:404
[16] do_cmd(::REPL.LineEditREPL, ::String; do_rethrow::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\REPLMode\REPLMode.jl:382
[17] do_cmd at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\REPLMode\REPLMode.jl:377 [inlined]
[18] (::Pkg.REPLMode.var"#24#27"{REPL.LineEditREPL,REPL.LineEdit.Prompt})(::REPL.LineEdit.MIState, ::Base.GenericIOBuffer{Array{UInt8,1}}, ::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Pkg\src\REPLMode\REPLMode.jl:546
[19] #invokelatest#1 at .\essentials.jl:710 [inlined]
[20] invokelatest at .\essentials.jl:709 [inlined]
[21] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\LineEdit.jl:2355
[22] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\REPL\src\REPL.jl:1144
[23] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at .\task.jl:356

(@v1.5) pkg> ^C

julia> using TreeView
ERROR: ArgumentError: Package TreeView [39424ebd-4cf3-5550-a685-96706a953f40] is required but does not seem to be installed:

  • Run Pkg.instantiate() to install all recorded dependencies.

Stacktrace:
[1] _require(::Base.PkgId) at .\loading.jl:999
[2] require(::Base.PkgId) at .\loading.jl:928
[3] require(::Module, ::Symbol) at .\loading.jl:923

julia>

Tree not shown

Running the example doesn' t work for me. The tree is not shown. While using TikzGraphs works. What could be the reason?

deepinscreenshot_select-area_20181205121221

Error running examples

I get the following error when running the example ipynb. Any ideas? Thanks!

> @tree x^2 + y^2

! Emergency stop.
LabelledTree({7, 6} directed simple Int64 graph, Any[:+, :^, :x, 2, :^, :y, 2])
<everyjob> ...ring \\def\string \\encodingdefault{OT1}')end }
                                                  \let \f@encoding \encoding...
l.1 
  \documentclass[tikz]{standalone}
End of file on the terminal!



Here is how much of LuaTeX's memory you used:
 8 strings out of 494300
 100000,89155 words of node,token memory allocated 241 words of node memory still in use:
   1 dir, 34 glue_spec nodes
   avail lists: 2:12,3:1,4:1
 4357 multiletter control sequences out of 65536+600000
 14 fonts using 591799 bytes
 5i,0n,1p,61b,15s stack positions out of 5000i,500n,10000p,200000b,100000s
!  ==> Fatal error occurred, no output PDF file produced!

LaTeX error in trees that contain generated symbols

This is actually an upstream bug in TikzGraphs: JuliaTeX/TikzGraphs.jl#12 but I figured you might run into it here anyway.

Trying to render an expression that contains symbols generated with gensym() gives a LaTeX error because of the # character in those symbols. Minimal example:

expr = Expr(gensym())
walk_tree(expr)

produces:

! Illegal parameter number in definition of \pgfutil@reserved@a.
<to be read again> 
2
l.13 }
    ;
Error saving as SVG
LaTeX error

Would it be worth just replacing # with another character for now?

artifact download when running `@tree`

Hi,

When executing the simple example

using TreeView

@tree begin
    a = b + c
    d = (a - 2)^2
end

I get an error:

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: LaTeX 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

Move to an org

I would be more than happy for this package to live at a suitable organisation if that would make things easier.

cc @tawheeler

&&

@tree false && true

in a notebook gives the following error:

! Misplaced alignment tab character &.
<recently read> &
 
l.23 }
    ;
Error saving as SVG

LaTeX error

Tree of a symbol doesn't work

julia> @tree x
MethodError: no method matching @tree(::LineNumberNode, ::Module, ::Symbol)
Closest candidates are:
@tree(::LineNumberNode, ::Module, !Matched::Expr) at /Users/dpsanders/.julia/dev/TreeView/src/tree.jl:65

View tree of expression stored in variable

I'm on Julia 1.0.3, TreeView 0.3.1 in an IJulia notebook:

julia> myexpr = :(1.0 * x[1] + -1.0 * x[2] + -1.0 * x[3])
julia> @tree @eval myexpr
LabelledTree({4, 3} directed simple Int64 graph, Any[:macrocall, Symbol("@eval"), :(#= In[21]:1 =#), :objexpr])

On a side note, it took me a moment to realize that I needed @eval here. If this usage is correct, perhaps there could be an example in the README. This may also be related to #19?!

Way to pass nested dict with string leaf nodes

Let's say you have a DAG representing a package and its dependencies, and their dependencies after them (and so forth).

What's the easiest way to hook into TreeView to plot that dependency graph? And is there a way to make the plot interactive with clicking on nodes?

Think it would be cool if you could keep clicking packages and the dag keeps switching root nodes.

// note that dependencies only appear once in a DAG (every other appearance is removed)


[update:] basically trying to replicate JuliaLang/julia#25951 (comment)

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Heads-up: LightGraphs and Julia 0.6

Hi all,

LightGraphs is preparing for a fairly large upgrade with Julia 0.6, and I wanted to make you aware of what we're doing. Very few things are breaking, but there will be some potential performance improvements that you might be able to take advantage of.

In a nutshell: we're abstracting Graph and DiGraph, renaming them to SimpleGraph and SimpleDiGraph*, and parameterizing vertex indices to <: Integer. This will allow you to create, e.g., SimpleGraph{UInt8}s that will be much more space-efficient if you have graphs that are < 256 vertices.

*While we plan on more abstractions (e.g., for weighted graphs) in the future, for now Graph and DiGraph will continue to work and will continue to default to SimpleGraph, and the default parameterization for both Simple(Di)Graphs and (Di)Graphs will be Int.

Feel free to review the (very long) WIP at sbromberger/LightGraphs.jl#541 - your feedback would be greatly appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.