 
 (def tick-observable (js/Rx.Observable.interval update-interval-ms))
 
+;; Resize
+
+(defn sync-on-container-size! [current-state selector]
+  (let [container (.select d3 selector)
+        element (.node container)
+        width (.-clientWidth element)
+        height (.-clientHeight element)
+        svg (:svg @current-state)
+        background (.select svg ".background")]
+    (-> svg (.attr "width" width) (.attr "height" height))
+    (-> background (.attr "width" width) (.attr "height" height))
+    (swap-state! current-state assoc :view-size (v/create width height))))
+
+(def resize-observable
+  (-> rx-observable (.fromEvent js/window "resize")
+      (.map :resize)
+      (.debounce resize-delay-ms)))
+
+(defn respond-to-resize! [current-state selector]
+  (.subscribe resize-observable
+              #(sync-on-container-size! current-state selector)))
+
+;; Animation
+
 (defn animation-subject []
   (js/Rx.BehaviorSubject. :animation-end))
 

(defn hammer-manager [svg]
  (let [manager (js/Hammer.Manager. (.node svg))]
    (.add manager (js/Hammer.Pan.
                    (js-obj "threshold" 10)))
    (-> manager (.add (js/Hammer.Swipe.
                        (js-obj "threshold" 10
                                "velocity" 0)))
        (.recognizeWith (.get manager "pan")))
    (-> manager (.add (js/Hammer.Pinch.))
        (.recognizeWith (.get manager "pan")))
    (.add manager (js/Hammer.Tap.
                    (js-obj "threshold" 10)))
    manager))

(defn gesture-observable [manager gesture]

  (let [element (-> d3 (.select selector) .node)
        width (.-clientWidth element)
        height (.-clientHeight element)
        svg (setup-svg! selector)
        gesture-manager (hammer-manager svg)
        animation-subject (animation-subject)
        node-tap-subject (js/Rx.Subject.)
