             [sablono.core :refer-macros [html]]
             [rum.core :as rum]
             [goog.string.format]
+            [goog.string :as gstring]
             [clojure.contrib.inflect :as inflect]
             [clojure.contrib.humanize :as humanize]))
 
 (enable-console-print!)
+
+(defn- render-percentage
+  [val]
+  (if (some? val)
+    (str (gstring/format "%.2f" val) "%")
+    "-"))
 
 (defn- node-item-state [value]
   (case value


(defn node-used [stat]
  (cond
    (< stat 75) {:name  "actual"
                 :value stat
                 :color "#43a047"}
    (> stat 90) {:name  "actual"
                 :value stat
                 :color "#d32f2f"}
    :else {:name  "actual"
           :value stat
           :color "#ffa000"}))

(rum/defc node-graph [stat label id]
  (let [data [(node-used stat)
              {:name  "rest"
               :value (- 100 stat)
               :color "#ccc"}]]
    (chart/pie

      label
      "Swarmpit-node-stat-graph"
      id
      {:formatter (fn [value name props]
                    (render-percentage value))})))

(rum/defc node-item < rum/static [item index]
  (let [cpu (-> item :resources :cpu (int))
        memory-bytes (-> item :resources :memory (* 1024 1024))
        disk-bytes (-> item :stats :disk :total)]
