              :identifier (:identifier x)
              :val (get-data-type parent type (:totals x))}) data)}))
 
-;(defn get-line-graph-data
-;  [type data]
-;  ;(println "get-line-graph-data: " (count data))
-;  {:title (get-graph-title type)
-;   :data (map (fn [x]
-;          {:month (:month x)
-;            :year (:year x)
-;            :type (:type x)
-;            :identifier (:identifier x)
-;            :val (get-data-type type (:totals x))}) data)})
 
 (defn get-svg
   [selector]
-  (if-let [svg (.select (.select js/d3 selector) "svg")]
-    svg
-    (.append (.select js/d3 selector) "svg")))
+  (let [svg (.select (.select js/d3 selector) "svg")]
+    (if (nil? (first (first (js->clj svg)))) (.append (.select js/d3 selector) "svg") svg)))
 
 (defn get-g
   [selector from-elem]
-  (if-let [g (.select from-elem selector)]
-    g
-    (.append from-elem "g")))
+  (let [g (.select from-elem selector)]
+    (if (nil? (first (first (js->clj g)))) (.append from-elem "g") g)))
 
 (defn set-graph
   [graph-data]

(def tick-padding 5)
(def width (- (- 960 (:left margin)) (:right margin)))
(def height (- (- 640 (:top margin)) (:bottom margin)))

;(defmulti get-data-type (fn [type _] type))

;(defmethod get-data-type :crashes
;  [type totals]
;  (let [type-total (first (filter #(= :crashes (keyword (:type %))) totals))]
;    ; (println "type-total: " (:total-crashes type-total))
;    (:total-crashes type-total)))

;(defmulti get-data-type (fn [parent & _] parent))

(defn get-data-type
  [parent type totals]

                         (.attr "y" 12)
                         (.attr "dx" "-1.5em")
                         (.style "text-anchor" "start"))
        y-axis-group (-> (get-g ".axis.y" line-group)
                         (.attr "transform" (str "translate(0, -25)"))
                         (.attr "class" "y axis")
                         (.call y-axis)
