 ;;;;;;;;;; Application state ;;;;;;;;;;;;;;;;;
 
 (def chart-state
-  (atom {:selected #{}
+  (atom {:selected {:left #{}
+                    :right #{}}
          :property "rad003"
          :devices [{:hecuba/name "01"
                     :name "External temperature"}


;;;;;;;;;;; Data ;;;;;;;;;;;

(def mock-data {"01"     [{"device_id" "01" "month" "01/01/2011" "reading" 0.8}
                          {"device_id" "01" "month" "01/02/2011" "reading" 0.9}
                          {"device_id" "01" "month" "01/03/2011" "reading" 0.8}
                          {"device_id" "01" "month" "01/04/2011" "reading" 0.75}
                          {"device_id" "01" "month" "01/05/2011" "reading" 0.65}
                          {"device_id" "01" "month" "01/06/2011" "reading" 0.50}
                          {"device_id" "01" "month" "01/07/2011" "reading" 0.55}
                          {"device_id" "01" "month" "01/08/2011" "reading" 0.6}
                          {"device_id" "01" "month" "01/09/2011" "reading" 0.66}
                          {"device_id" "01" "month" "01/10/2011" "reading" 0.68}
                          {"device_id" "01" "month" "01/11/2011" "reading" 0.71}
                          {"device_id" "01" "month" "01/12/2011" "reading" 0.9}]
                "02"     [{"device_id" "02" "month" "01/01/2011" "reading" 6}
                          {"device_id" "02" "month" "01/02/2011" "reading" 10}
                          {"device_id" "02" "month" "01/03/2011" "reading" 12}
                          {"device_id" "02" "month" "01/04/2011" "reading" 15}
                          {"device_id" "02" "month" "01/05/2011" "reading" 18}
                          {"device_id" "02" "month" "01/06/2011" "reading" 20}
                          {"device_id" "02" "month" "01/07/2011" "reading" 25}
                          {"device_id" "02" "month" "01/08/2011" "reading" 31}
                          {"device_id" "02" "month" "01/09/2011" "reading" 20}
                          {"device_id" "02" "month" "01/10/2011" "reading" 17}
                          {"device_id" "02" "month" "01/11/2011" "reading" 12}
                          {"device_id" "02" "month" "01/12/2011" "reading" 9}]})

;;;;;;;;; Utils ;;;;;;;;;;;;;;;;;;;;;;


        (dom/div nil
                 (dom/div #js {:id "chart" :width 500 :height 450})
                 (dom/table #js {:id "form-table" :cellSpacing "10"}
                            (let [cols {:left "Left axis plots" :right "Right axis plots"}]
                               (dom/tr nil
                                       (for [col cols]
                                         (dom/td nil
                                                 (dom/h4 nil (val col))
                                                 (dom/form nil
                                                           (for [device (get cursor :devices)]
                                                             (let [device-id   (str (:hecuba/name device))
                                                                   device-name (str (:name device))
                                                                   device-ref  (str (:red device))]
                                                               (dom/div nil
                                                                        (dom/input #js {:type "checkbox"
                                                                                        :ref device-ref
                                                                                        :value device-id
                                                                                        :onChange (fn [e]
                                                                                                   (om/update! cursor update-in [:selected (key col)] (if (.. e -target -checked) conj disj) device-id))})
                                                                        (dom/label #js {:htmlFor device-id} device-name)
                                                                        (dom/br #js {}))))))))))))
      om/IDidUpdate
