 
       return clamp(interval, @get_min_interval(), @get_max_interval())
 
+  last_day_no_later_than = (time) ->
+    # FIXME Is this really the best way?
+    d = new Date(time)
+    d.setHours(0)
+    d.setMinutes(0)
+    d.setSeconds(0)
+    d.setMilliseconds(0)
+    return d.getTime()
+
+  add_days = (time, n_days) ->
+    d = new Date(time)
+    d.setDate(d.getDate() + n_days)
+    return d.getTime()
+
+  class DayScale extends AdaptiveScale
+    constructor: () ->
+      super([1.0, 2.0, 5.0], 10.0, ONE_DAY, ONE_DAY)
+
+    get_ticks: (data_low, data_high) ->
+      interval = @get_interval(data_low, data_high)
+
+      # FIXME Ideally we would walk forward using this, but we need to align
+      # the days consistently.
+      n_days_per_tick = interval / ONE_DAY
+
+      tick = last_day_no_later_than(data_low)
+      ticks = [tick]
+      while true
+        tick = add_days(tick, 1)
+        ticks.push(tick)
+        if tick >= data_high
+          break
+
+      console.log(ticks.map((time) -> new Date(time)))
+      return ticks
+
   class SimpleScale extends CompositeScale
     constructor: (intervals) ->
       super(intervals.map((interval) ->

    get_max_interval: () ->
      return _.last(@max_intervals)

    get_interval: (data_low, data_high) ->
      data_range = float(data_high) - float(data_low)
      ideal_interval = @get_ideal_interval(data_low, data_high)
      scale_ixs = [

        return Math.abs(DESIRED_N_TICKS - (data_range / interval)))
      
      best_scale_ix = scale_ixs[argmin(errors)]
      best_scale = @scales[best_scale_ix]

#       console.log("Selected #{best_scale.constructor.name}")

      return best_scale

    get_interval: (data_low, data_high) ->
      best_scale = @get_best_scale(data_low, data_high)
      return best_scale.get_interval(data_low, data_high)

    get_ticks: (data_low, data_high) ->
      best_scale = @get_best_scale(data_low, data_high)
      return best_scale.get_ticks(data_low, data_high)

  class AdaptiveScale extends AbstractScale
    constructor: (mantissas, @base=10.0, @min_magnitude=0.0,
