      :min (- (:min range) scaled-delta)}))
 
 (defn draw-xlabel [ ctx text x y left? ]
-  (let [mt (.measureText ctx text)
-        w (.-width mt)]
-    (.fillText ctx text (if left? x (- x w)) (+ 12 y))))
+  (with-preserved-ctx ctx
+    (aset ctx "textBaseline" "top")
+    (aset ctx "textAlign" (if left? "left" "right"))
+    (.fillText ctx text x y)))
 
 (defn draw-ylabel [ ctx text x y ]
-  (let [mt (.measureText ctx text)
-        w (.-width mt)]
-    (.fillText ctx text (- x w) (+ y 4))))
+  (with-preserved-ctx ctx
+    (aset ctx "textBaseline" "middle")
+    (aset ctx "textAlign" "right")
+    (.fillText ctx text x y)))
 
 (defn translate-fn [ range size ]
   (let [min (:min range)

    (aset ctx "font" "12px Arial")
    (let [y-range (rescale-range (s-yrange data) 1.1)]
      (unless (empty? data)
              (draw-y-grid ctx w h y-range)
              (with-preserved-ctx ctx
                (clip-rect ctx 0 0 w h)
                (draw-series-line ctx data x-range y-range w h))
              (draw-xlabel ctx (format-xlabel (:min x-range)) 0 h true)
              (draw-xlabel ctx (format-xlabel (:max x-range)) w h false))))) 

(defn draw-series-background [ ctx w h ]
  (with-preserved-ctx ctx

            (map #(* % (.pow js/Math 10 scale))
                 [ 1 2 5 ]))
          (range -3 3)))

(def x-line-intervals
  (mapcat (fn [ scale ]
            (map #(* % scale)
                 [ 1 2 3 4 5 6 ]))
          [1 60 3600 86400 604800]))

(def stroke-styles
  {:grid
