Asymptote as a Julia package?

Based on the follwing data type for trees

type Tree{T} 
    key:: T
    st :: Array{Tree{T},1} 
end

I have written a small program with plots such trees using Asymptote (based on ANDREW J. KENNEDYs algorithm for drawing trees, J. Functional Programming 6 (3): 527–534, May 1996). The program generates a sequence of draw commands, stores them as asy-file and does an external call of Asymptote for this file.
Output can be either eps, png, pdf or svg. (Tikz is still planned. In this case Asymptote isn’t used)

As an example this is the output of a randomly generated tree:

When writing this program I thought having (a reimplementation of) Asymptote as Julia package would be great (provided permission of the developers of Asymptote is given). What are your opinions?

We do have a Cairo.jl package, and there is the Compose.jl package if you want a simpler higher-level graphics interface, and GLVisualize.jl … not sure what re-implementing Asymptote would add? Certainly you would have to re-think the Asymptote syntax (which is C++ like) for Julia’s idioms.

LaTeX typesetting of labels (or is this already in Cairo / Compose? Either way it would probably be easier to add this to existing packages.)

There is
https://github.com/JuliaGraphics/Cairo.jl/blob/master/src/Cairo.jl#L1103
but perhaps rewriting it to render to an intermediate format which is useful for other purposes would be a good project for a library.

How does Asymptote compare to Tikz? The latter is already supported in TikzPictures.jl and uses latex to generate the figures.

Tools to generate inline, potentially interactive graphics in notebooks are a good thing to have for sure.

You’re volunteering? I was active for some time to find a latex-style labeling solution, but did not make real progress. It really look’s like this is missing as independent library. Mathjax looked like a solution, but then i learned, they are not outputting svg, but a special html style where you need a browser rendering entity. The Mozilla MathML project looked also promising, but access to the logic goes via Gecko and that brings in the (whole) C++ API library chaos.
GtkMathView also is mentioned several times, but seems abandoned.

julia-users thread
https://groups.google.com/forum/?fromgroups=#!searchin/julia-users/math$20rendering|sort:relevance/julia-users/VDOPMen0mFE/bCy5ifgKi8kJ

There is also TikzGraphs.jl which does graphs in LaTeX. It is possible that there is already a graph layout that does what you want.

Thanks for all the replies.

There is also TikzGraphs.jl” Unfortunately I wasn’t aware of this package (my fault! ). I like Tikz and I think this package indeed is very useful.
Personally I believe that concerning 3D Asymptote has some advantages over Tikz. However when reading that Asymptote has more than 80.000 lines of low level C++ code (as of June 2010) I have given up the idea of a reimplementation as a Julia package.

80,000 lines of C++ ≈ 8,000 lines of Julia

2 Likes

Coming from C++, I’d say that’s about right. But what really counts is the number of hairs left on your head when you’re finished, I think there it’s the other way around :wink:

2 Likes

As a corollary: years to develop in C++ is one productive weekend in Julia.

2 Likes

This function doesn’t do much more than change font sizes and styles:

julia> Cairo.tex2pango("\$ -b \\pm \\sqrt{b^2 - 4ac} \\over 2a \$", 12)
"\$ −b ±\\sqrtb<sup><span font=\"7.416407813432845\">2</span></sup> − 4ac \\over2a \$"

(Obvious really that it wouldn’t do LaTeX, when you think about it. :))

Oh, i just learned from Chris’ message, that TeX can be redone in Julia in one productive weekend…

1 Like

for inline interactive figures I think D3 is much better & more modern.

This one I suppose?

Is it available for use from within Julia? Looking at the examples, the interface seems very low-level compared to Tikz, but I must say the results are stunning.

yes.
there is a simple julia wrapper : https://github.com/jverzani/DThree.jl but you will still need to write D3 itself.

D3 is basically 2D vector graphics (svg) programming, analog to directly programming openGL for 3D. So it’s good if you want to develop your own custom visualisations. For a stunning example of this: A visual introduction to machine learning

Now if your looking for a more high level plotting lib: use plotlyJS.jl. The 2D plots of plotly are itself based on D3.js (the 3D ones are based on webGL).

How does D3 do TeX labels?

here’s one possible way Redirecting to Google Groups https://groups.google.com/forum/#!topic/d3-js/JzUTJmUBuKQ

MathJax again → browser rendering.