Fork me on GitHub
#nextjournal
<
2022-02-18
>
mkvlr07:02:21

@carsten.behring don’t see why not but also not likely that I will spend time on. OTOH search and column sorting is something we planned (and spent some time on in the past) already.

Carsten Behring11:02:39

I see that. I am completely new to Clojurescript, and I was just wondering if the "viewer API" of Clerk is powerful enough to even included rather easely a complex java script package such as datatables. Or ask the other way around. The R community has developed over time and this has let to the creation of many powerful wrappers of existing java script libraries. Would you see that the "viewer" component of Clerk could go in this direction ?

mkvlr12:02:44

if it’s not working yet it’s just a matter of exposing a few more vars to Clerk’s viewer api via sci, a tiny thing. And then there’s improving the docs and making it more obvious how to actually do it.

👍 1
mkvlr15:02:03

I tried it, it works today but will get easier when we expose this stuff properly:

mkvlr15:02:05

(ns d3-require
  (:require [nextjournal.clerk :as clerk]))


(clerk/with-viewer {:fetch-fn (fn [_ x] x)
                    :render-fn '(fn [value]
                                  (v/html
                                   (when value
                                     [js/nextjournal.ui.components.d3_require.with$ {:package ["[email protected]"]}
                                      (fn [vega]
                                        (let [embed (.-embed vega)]
                                          [:div {:style {:overflow-x "auto"}} ;; TODO: figure out how to make options customizable
                                           [:div.vega-lite {:ref #(when % (embed % (clj->js value) (clj->js {:actions false})))}]]))])))}
  {:width 650 :height 400 :data {:url ""
                                 :format {:type "topojson" :feature "counties"}}
   :transform [{:lookup "id" :from {:data {:url ""}
                                    :key "id" :fields ["rate"]}}]
   :projection {:type "albersUsa"} :mark "geoshape" :encoding {:color {:field "rate" :type "quantitative"}}})

mkvlr07:02:08

the upside of Clerk’s table is that it works with Clerk’s viewer api, here’s an example of a table with a sparkline vega plot in one of the columns (https://snapshots.nextjournal.com/clerk/build/b9f35eb58a32f9b13d50d74143b9e2418dd2d1db/index.html#/notebooks/viewers_nested.clj, https://github.com/nextjournal/clerk/pull/63):

👍 1
1