Lightweight interface package for defining JSXGraph.jl recipes.
External packages can depend on this package (instead of JSXGraph.jl itself) to define how their custom types are rendered on a JSXGraph board via the @jsxrecipe macro.
using Pkg
Pkg.add("JSXGraphRecipesBase")using JSXGraphRecipesBase
struct Triangle
A::Tuple{Float64, Float64}
B::Tuple{Float64, Float64}
C::Tuple{Float64, Float64}
end
@jsxrecipe function f(t::Triangle; color="blue")
p1 = ElementSpec(:point, t.A[1], t.A[2]; name="A")
p2 = ElementSpec(:point, t.B[1], t.B[2]; name="B")
p3 = ElementSpec(:point, t.C[1], t.C[2]; name="C")
[p1, p2, p3, ElementSpec(:polygon, p1, p2, p3; strokeColor=color)]
endThen in a script or notebook using JSXGraph.jl:
using JSXGraph
b = board("recipe-demo", xlim=(-5, 5), ylim=(-5, 5))
tri = Triangle((0.0, 0.0), (3.0, 0.0), (1.5, 2.5))
plot!(b, tri; color="red")ElementSpec— specification for a single JSXGraph element@jsxrecipe— macro to define a recipe for a custom typeapply_recipe— apply the registered recipe for an objecthas_recipe— check whether a recipe exists for a type
MIT