Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Last active January 2, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustingetz/072f598320a217090e79dd4b698e707b to your computer and use it in GitHub Desktop.
Save dustingetz/072f598320a217090e79dd4b698e707b to your computer and use it in GitHub Desktop.
(def mid (reagent.core/atom 2))
(def viz-refs (reagent.core/atom {}))
(def vega-renderer'
(reagent.core/create-class
{:component-did-mount
(fn [this]
(let [[_ vega-spec merchantid] (reagent.core/argv this)]
(println (str "update id: " merchantid))
(js/vegaEmbed (str "#viz-" merchantid) vega-spec)))
:component-did-update
(fn [this old-argv]
(let [[_ vega-spec merchantid] (reagent.core/argv this)]
(println (str "update id: " merchantid))
(js/vegaEmbed (str "#viz-" merchantid) vega-spec)))
:display-name "vega-renderer"
:reagent-render
(fn [vega-spec merchantid]
[:div
[:div {:id (str "viz-" merchantid) :ref (fn [el] (swap! viz-refs update merchantid (constantly el)))}]])}))
(defn vega-renderer [txt merchantid]
(let [vega-spec (-> txt js/JSON.parse (js->clj :keywordize-keys true)
(update-in
[:transform 0 :filter :and 0 :equal]
(constantly merchantid))
clj->js)
#_#_id (str (random-uuid))]
[vega-renderer' vega-spec merchantid]))
(defn vega-dashboard [specs merchantid]
(assert (exists? js/vegaEmbed))
[:div.flexer
[:div.wrapper {:id "row-1"}
[:div.left-pane {:id "cell-1-1"}
[vega-renderer (nth specs 4) merchantid]]
[:div.central-pane {:id "cell-1-2"}]
[:div.right-pane {:id "cell-1-3"}
[vega-renderer (nth specs 5) merchantid]]]
[:div.wrapper {:id "row-2"}
[:div.left-pane {:id "cell-2-1"}
[vega-renderer (nth specs 2) merchantid]]
[:div.central-pane {:id "cell-2-2"}]
[:div.right-pane {:id "cell-2-3"}
[vega-renderer (nth specs 3) merchantid]]]
[:div.wrapper {:id "row-3"}
[:div.left-pane {:id "cell-3-1"}
[vega-renderer (nth specs 1) merchantid]]
[:div.central-pane {:id "cell-3-2"}]
[:div.right-pane {:id "cell-3-3"}
[vega-renderer (nth specs 0) merchantid]]]])
(def scripts-loaded (reagent.core/atom false))
(defn with-loaded [hiccup]
(let [loaded @scripts-loaded]
[:<> {:key loaded}
(if loaded
hiccup
[:p "loading..."])]))
(defn pp [a] [:pre (with-out-str (cljs.pprint/pprint a))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment