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 (†))
The code above defines:
- a board
b(thing which contains objects)
- a slider with a specific position which goes from value
- a parametrized function which depends upon the value of the slider via
- a plot which is appended to the board with
++(you could also do
plot(...) |> bdepending on your preferences).
is a monstrosity defines an object that wraps around the function
@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).
Everything that appears in the body of a
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).
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: https://tlienart.github.io/JSXGraphWeb/