 (def ^:private bar-th-style  (str font-style "font-size: 10px; font-weight: 400; color: rgb(57,67,64); border-bottom: 4px solid rgb(248, 248, 248); padding-top: 0px; padding-bottom: 10px;"))
 (def ^:private bar-td-style  (str font-style "font-size: 16px; font-weight: 400; text-align: left; padding-right: 1em; padding-top: 8px;"))
 
-(defn format-number
+(defn- format-number
   [n]
   (if (integer? n) (cl-format nil "~:d" n) (cl-format nil "~,2f" n)))
+
+(defn- format-number-short
+  [n]
+  (cond
+    (>= n 1000000000) (str (cl-format nil "~,1f" (/ n 1000000000.0)) "B")
+    (>= n 1000000) (str (cl-format nil "~,1f" (/ n 1000000.0)) "M")
+    (>= n 1000) (str (cl-format nil "~,1f" (/ n 1000.0)) "K")
+    :else (str (cl-format nil "~,1f" n))))
+
+(defn- format-timestamp
+  [timestamp]
+  (let [date (c/from-long timestamp)
+        today (t/today-at 0 00)]
+    (cond
+      (t/within? (t/interval today (t/plus today (t/days 1))) date) "Today"
+      (t/within? (t/interval (t/minus today (t/days 1)) today) date) "Yesterday"
+      :else (f/unparse (f/formatter "MMM d, YYYY") date))))
 
 (defn render-bar-chart-row
   [index row max-value]

(ns metabase.pulse
  (:require [hiccup.core :refer [html]]
            [clojure.tools.logging :as log]
            [clojure.pprint :refer [cl-format]]
            [clojure.string :refer [upper-case]]

          ymax (apply max ys)
          yrange (- ymax ymin)
          ys' (map #(/ (- % ymin) yrange) ys)]
      [:div {:style "color: rgb(214,214,214);" }
        [:div {:style "display: inline-block; position: relative; margin-left: 30px;" }
          [:div {:style "position: relative;"}
            [:div {:style "position: absolute; height: 100%; text-align: right; background-color: red;"}
              [:div {:style "position: absolute; top: 0; right: 0;"} (format-number-short ymax)]
              [:div {:style "position: absolute; top: 150px; right: 0;"} (format-number-short ymin)]]
            [:img {:style "display: block; left: 20px;" :src (generate-data-uri (render-sparkline-to-png xs' ys' 285 150) "image/png")}]
          ]
          [:div
            [:div {:style "height: 15px; margin-left: 10px; margin-right: 10px; border: 4px solid rgb(233,233,233); border-top: none; border-bottom: none;"} "&#160;"]
            [:div {:style "height: 15px; margin-left: 10px; margin-right: 10px;"}
              [:div {:style "float: left;"} (format-timestamp xmin)]
              [:div {:style "float: right;"} (format-timestamp xmax)]]
          ]]]))

(defn render-pulse-card
  [card data include-title]
