 (defonce app-state (atom {:nodes []
                           :timer nil
                           :map (js/Image.)
-                          :locations {"temp-1a:fe:34:fa:b2:af" [50 50]
+                          :locations {"temp-1a:fe:34:fa:b2:af" [500 500]
                                       "temp-1a:fe:34:fa:b2:bf" [100 100]}}))
 
 (def r (t/reader :json))

      (fetch-events)
      (. timer (start))
      (swap! app-state assoc :timer timer)
      (events/listen timer goog.Timer/TICK fetch-events))))

(if (-> (:timer @app-state) nil? not)
  (.stop (:timer @app-state)))

                                             (Math/pow (- (-> node :location second) y) 2.0)))})

(defn draw-map [canvas mapImage]
  (let [context (.getContext canvas "2d")
        gridSize 40
        imageWidth (.-width mapImage)
        imageHeight (.-height mapImage)
        boxWidth (/ (.-width canvas) gridSize)
        boxHeight (/ (.-height canvas) gridSize)
        values (-> (:nodes @app-state) vals)
        temp (-> (temp-for-locations boxWidth boxHeight) seq)
        grid (apply merge
                    (for
                     [x (range 0 gridSize)
                      y (range 0 gridSize)
                      :let [rangeVals (map #(rangeValues % (* (+ .5 x) imageWidth) (* (+ .5 y) imageHeight)) temp)]]
                      {[x y] {:average (weighted-average rangeVals)
                              :blend (alpha-blend rangeVals)}}))
        minTemp (apply min (vals grid))
        maxTemp (apply max (vals grid))]
    (set! (.-width canvas) imageWidth)
    (set! (.-height canvas) imageHeight)
    (.log js/console "image" imageWidth imageHeight)
    (.drawImage context mapImage 0 0)
    (doall (for [key (keys grid)
                 :let [value (get grid key)
                       x (first key)
                       y (second key)]]
             (do
               ;(.log js/console "grid" (first key) (second key) (:blend value))
               (set! (.-fillStyle context) "#ff0000")
               (set! (.-globalAlpha context) (:blend value))
               (.fillRect context (* x boxWidth) (* y boxHeight) boxWidth boxHeight))))))

(def canvas-dom (.getElementById js/document "map"))

