3 Emmy-viewers
This namespace discusses Clay’s support for Emmy-viewers.
ns clay-book.emmy-viewers
(:require
(:as kind]
[scicloj.kindly.v4.kind :as e :refer :all #_[D square cube tanh cos sin up down]]
[emmy.env :as ev]
[emmy.viewer :as mafs]
[emmy.mafs :as plot]
[emmy.mathbox.plot :as leva])) [emmy.leva
3.1 Usage
Here, we will not explain the full usage of Emmy-viewers. It is recommended to look into the project’ docs.
In Clay, forms generated by emmy-viewers are recognized and displayed accordingly.
:color :blue}) (mafs/of-x e/sin {
3.2 A few detials behind the scenes
In the example above, we used emmy-viewers to generate a Clojurescript expression that can be interpreted as a Reagent component. Here is the actual expression:
(kind/pprint (mafs/of-x e/sin))
(reagent.core/with-let"y0001" " return Math.sin(y0001);")]
[G__84727 (js/Function. :y G__84727}]) [mafs.plot/OfX {
By default, it is inferred to be of :kind/emmy-viewers
, and is handle accordingly.
Equivalently, we could also handle it more explicitly with :kind/reagent
:
(kind/reagentfn []
[`(
~(ev/expand (mafs/of-x e/sin)))]:html/deps [:emmy-viewers]}) {
3.3 More examples
0 0]]
(ev/with-let [!phase [let [shifted (ev/with-params {:atom !phase :params [0]}
(fn [shift]
(fn [x]
(
(((cube D) tanh) (e/- x shift)))))]
(mafs/mafs:height 400}
{
(mafs/cartesian)
(mafs/of-x shifted)
(mafs/movable-point:atom !phase :constrain "horizontal"})
{
(mafs/inequality:y {:<= shifted :> cos} :color :blue})))) {
Try moving the pink mark. 👆