Fork me on GitHub
#reagent
<
2016-05-17
>
fabrao01:05:26

@gadfly361: Man, you are the best !!! It worked. So, how about

gauge-consumo-did-mount
or
gauge-consumo-render
with parameter? Like updating many gauges in Dashboard page, each with different ids? How to select each gaugue to get reagent/atom like {:ROOM-1 0 :ROOM-2 0} and ROOM-# as parameter?

gadfly36101:05:54

(ns view-fortigate.core
  (:require
     [reagent.core :as reagent]))

(defonce app-state
  (reagent/atom
   {:valor-1 10
    :valor-2 50}))

(defn gauge-consumo-config [vl]
  {:chart {:type "solidgauge"}
   :title {:text "SALA 105"}
   :pane {
          ;:center ["58%" "85%"]
          :size "100%"
          :startAngle -90
          :endAngle 90
          :background {
                       :backgroundColor "#FFF"
                       :innerRadius "60%"
                       :outerRadius "100%"
                       :shape "arc1"
                       }
          }
   :tooltip { :enabled false }
   :credits { :enabled false }
   :yAxis {:stops [[0.1 "#55BF3B"]
                   [0.5 "#DDDF0D"]
                   [0.9 "#DF5353"]]
           :lineWidth 0
           :minorTickInterval nil
           :tickPixelInterval 400
           :tickWidth 0
           :title {:text "" :y -70}
           :labels {:y 16}
           :min 0
           :max 100
           }
   :series [{:name "Consumo"
             :data [vl]
             }]
   :plotOptions {
                 :solidgauge {
                              :dataLabels {:y 15
                                           :borderWidth 0
                                           :useHTML false
                                           :format "{y} %"}
                              }
                 }
   })

(defn gauge-consumo-did-mount [this ratom k]
  (js/Highcharts.Chart. (reagent/dom-node this)
                        (clj->js (gauge-consumo-config (k @ratom)))))

(defn gauge-consumo-render [ratom]
  (let [_ @ratom]
    [:div {:style {:width "200px" :height "200px" :margin "0 auto"}}]))

(defn gauge-consumo [ratom k]
  (reagent/create-class
   {:component-did-mount  #(gauge-consumo-did-mount % ratom k)
    :component-did-update #(gauge-consumo-did-mount % ratom k)
    :reagent-render       #(gauge-consumo-render ratom)}))

(defn home [ratom]
  [:div
   [gauge-consumo ratom :valor-1]
   [gauge-consumo ratom :valor-2]])

(defn reload []
  (reagent/render [home app-state]
                  (.getElementById js/document "app")))

(defn ^:export main []
  (reload))

escherize01:05:18

@gadfly361 is a pillar in the reagent scene. From maintaining reagent templates to always helping out in #C0620C0C8, to maintaining the reagent cookbook. He's the man!!!

gadfly36101:05:19

@fabrao: try something like this 👆

gadfly36101:05:00

ha thanks guys:wink:

fabrao01:05:06

@escherize: @gadfly361 IS MASTER !!! It worked => gadgent simple_smile . Thanks a lot, now I understand how it works.

seantempesta03:05:24

How do you specify the key for an element using (reagent.core/as-element …)?

seantempesta03:05:38

Ah, never mind. It’s just

(r/as-element
      ^{:key (str section-id "-" row-id)}
      [touchable-highlight {:onPress #()}

escherize04:05:29

Why does one use as-element?

seantempesta04:05:12

Well, in my case I’m using react native and the listview component takes a “renderRow” argument that specifies this:

renderRow function 

(rowData, sectionID, rowID, highlightRow) => renderable
https://facebook.github.io/react-native/docs/listview.html

ndroock110:05:54

@ckarlsen: did you find a solution for your the problem you had with reagent and the react draft-js library?