Hello,
I’d like to announce JSXGraph.jl a wrapper around the javascript library of the same name (jsxgraph.org), in their own words:
JSXGraph is a cross-browser JavaScript library for interactive geometry, function plotting, charting, and data visualization in the web browser.
The aim of the package is to help describe interactive figures simply, using Julia. In a way it’s a bit like Interact.jl except that the output is pluggable javascript that can be used with Documenter.jl or Franklin.jl (or any other static framework that you might be using but you should consider Franklin, cough, cough).
Code looks like this:
using JSXGraph
b = board("brd", xlim=[-2,2], ylim=[-1,2])
b ++ slider("a", [[-1,1.5],[1,1.5],[0,1.5,3]])
@jsf foo(x) = val(a)*x^2 - 1
b ++ plot(foo, dash=2)
b
This basically plots f(x) = ax^2 where a is controlled by a slider.
(if you’re in Juno, a parabola should appear in the plotpane, otherwise it should appear in an independent Blink window (yes, also if you’re in a notebook (†))
†: there’s some dark magic required to load javascript libraries properly with jupyter notebooks, VegaLite.jl has figured it out but I haven’t. If you know how to do it & can show me a working example, you will earn my gratitude and a virtual medal .
The code above defines:
- a board
b
(thing which contains objects) - a slider with a specific position which goes from value
0
to3
- a parametrized function which depends upon the value of the slider via
val
- a plot which is appended to the board with
++
(you could also dob(plot(...))
orplot(...) |> b
depending on your preferences).
The @jsf
macro is a monstrosity defines an object that wraps around the function foo
keeping track of a javascript representation of the function. It is an extension (@travigd would likely say an abuse) of the @js
macro offered by JSExpr.jl.
Comparison with plotly
Plotly is more geared towards showing data. Generally though it has less support for interactivity (e.g. the sliders are very limited). It’s also several times heavier to load than JSXGraph.
If your primary concern is to show pre-computed data, then Plotly is great and should be preferred (or VegaLite, Plots etc).
Limitations
Everything that appears in the body of a @jsf
function has to be understandable by Javascript. JSXGraph.jl helps with this by defining the standard maths functions like sin, cos, tan
etc. However functions from specific packages will not work at this point.
You can still do data plots where you pass an array of pre-computed values (and this could be combined with functions and interactivity).
Next steps
The wrapping is far from complete. I’d like to see if there’s interest from potential users and whether there are some people willing to help me with it (porting more functionalities is not very hard).
More examples: JSXGraph Examples