 
       :reagent-render
       (fn []
-        (watch :series-pane-reagent-render (dom-width (:dom-node @pane-state)))
         @window-width
         [:div.series-pane
          [:div.series-pane-header

  (ajax-get (str "/latest/" series-name) cb))

(defn fetch-series-data [ series-name query-window-secs cb ]
  (watch [:fetch series-name])
  (ajax-get (str "/data/" series-name "?query-window-secs=" query-window-secs)
            (fn [ data ]
              (watch [:response series-name])
              (cb data))))

(defn tsplot-fetch-and-draw [ canvas series-name width ]
  (let [ ctx (.getContext canvas "2d")]
    (go
      (tsplot/draw ctx width 180 (<! (<<< fetch-series-data
                                         series-name
                                         @query-window-secs))))))

(defn dom-width [ node ]
  (if node

     {:display-name (str "series-tsplot-" (:name series))
      :component-did-update
      (fn [ this ]
        (tsplot-fetch-and-draw (reagent/dom-node this) (:name series) (dom-width (:dom-node @series-state))))
      
      :component-did-mount
      (fn [ this ]
        (swap! series-state assoc :dom-node (.-parentNode (reagent/dom-node this)))        
        (tsplot-fetch-and-draw (reagent/dom-node this) (:name series) (dom-width (.-parentNode (reagent/dom-node this)))))

      :reagent-render
      (fn [ width ]
        @window-width
        [:canvas { :width (dom-width (:dom-node @series-state)) :height 180}])})))

(defn series-pane [ series ]
  (let [ pane-state (atom {})]
