 
 (defn add-grid []
   (swap! state (fn [state]
-                 (assoc state :points (for [x (range 10 800 20) y (range 10 400 20)] [x y]))))
+                 (assoc state :points (for [x (range 10 (:width svg-size) 20) y (range 10 (:height svg-size) 20)] [x y]))))
   (enable-buttons true)
   (visualize))
 

(def state (atom initial-state))

(defn random-cluster [n]
  (let [cx (+ 50 (rand 700))
        cy (+ 50 (rand 300))]
    (for [_ (range n)]
      [(+ cx -40 (rand 80)) (+ cy -40 (rand 80))])))


  [:div.topbar
   [:div.topbar-inner [:div.container-fluid [:a.brand "AI Playground"]]]]
  [:div.container-fluid
   [:div.sidebar
    [:div.well
     [:h5 "Unsupervised Learning"]
     [:ul [:li.active "K-Means"]]]]
   [:div.content
    [:div.row
     [:div.span16 [:h2 "K-Means"]]]
    [:div.row
     [:div.span13
      [:svg:svg svg-size]]
     [:div#options.span3 [:h5 "Options"]]]
    [:div.row
     [:a#reset-button.btn.span3.offset2 "Reset"]
     [:a#step-button.btn.span3 "Step"]
     [:a#run-button.btn.span3 "Run"]]]])

(dom/append (dom/query "body") (page))

(pm/defpartial button [text id]
  (let [attr (if id {:id id} {})]
    [:a.btn attr text]))

(defn append-button
  ([parent text fn] (append-button parent text fn nil))
