Just a small thing, not really worth of a git repo, but...
A reusable OM component to wrap a Flot chart object:
(defn flot
"node-name is the id for the DOM node of the flot chart
chart-options is a clojure nested map of options for flot (see flot docs)
data is clojure vector of vectors or maps, with the data series (see flot
docs)"
[{:keys [node-name chart-options data]} owner]
(reify
om/IInitState
(init-state [_]
{:flot nil})
om/IDidMount
(did-mount [this]
(let [g (.plot js/jQuery (js/document.getElementById node-name)
(clj->js data)
(clj->js chart-options))]
(om/set-state! owner :flot g)))
om/IDidUpdate
(did-update [this prev-props {:keys [flot] :as prev-state}]
(when (not= (:data prev-props) data)
(doto flot
(.setData (clj->js data))
.setupGrid
.draw)))
om/IRender
(render [this]
(dom/div #js {:react-key node-name
:ref node-name
:id node-name}))))
I enjoyed being able to abstract out all the flot machinery, and just add new,
live incoming data to the state map, in a callback or go loop, i.e.:
(swap! app-state update-in [:some-chart :data 0] conj new-datapoint)
-ken
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.