Set `this` for tickers
authorDan Vanderkam <danvdk@gmail.com>
Tue, 21 Apr 2015 20:15:15 +0000 (16:15 -0400)
committerDan Vanderkam <danvdk@gmail.com>
Tue, 21 Apr 2015 20:15:15 +0000 (16:15 -0400)
auto_tests/tests/axis_labels.js
src/dygraph.js

index abff8b2..dfa7ef1 100644 (file)
@@ -1034,6 +1034,26 @@ it('testMaxNumberWidthPerAxis', function() {
   assert.deepEqual(["12401","12402","12403"], Util.getXLabels());
 });
 
+// Regression test for https://github.com/danvk/dygraphs/issues/506
+it('should draw top and bottom ticks', function() {
+  var firstLastTicker = function(a, b, pixels, opts, dygraph) {
+    assert.isTrue(this == dygraph, 'this not set correctly');
+    var formatter = opts('axisLabelFormatter');
+    return [
+      {v: a, label: formatter(a, 0, opts, this)},
+      {v: b, label: formatter(b, 0, opts, this)}
+    ];
+  };
+
+  var g = new Dygraph('graph', simpleData, {
+    valueRange: [0.0, 1.2],
+    axes: {
+      x: { ticker: firstLastTicker },
+      y: { ticker: firstLastTicker }
+    }
+  });
+});
+
 /*
 // Regression test for http://code.google.com/p/dygraphs/issues/detail?id=147
 // Checks that axis labels stay sane across a DST change.
index 878a747..4d7ff74 100644 (file)
@@ -2259,7 +2259,8 @@ Dygraph.prototype.addXTicks_ = function() {
   }
 
   var xAxisOptionsView = this.optionsViewForAxis_('x');
-  var xTicks = xAxisOptionsView('ticker')(
+  var xTicks = xAxisOptionsView('ticker').call(
+      this,
       range[0],
       range[1],
       this.plotter_.area.w,  // TODO(danvk): should be area.width
@@ -2914,7 +2915,7 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
       axis.independentTicks = independentTicks;
       var opts = this.optionsViewForAxis_('y' + (i ? '2' : ''));
       var ticker = opts('ticker');
-      axis.ticks = ticker(axis.computedValueRange[0],
+      axis.ticks = ticker.call(this, axis.computedValueRange[0],
               axis.computedValueRange[1],
               this.plotter_.area.h,
               opts,
@@ -2945,12 +2946,13 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
         tick_values.push(y_val);
       }
 
-      axis.ticks = ticker(axis.computedValueRange[0],
-                          axis.computedValueRange[1],
-                          this.plotter_.area.h,
-                          opts,
-                          this,
-                          tick_values);
+      axis.ticks = ticker.call(this,
+                               axis.computedValueRange[0],
+                               axis.computedValueRange[1],
+                               this.plotter_.area.h,
+                               opts,
+                               this,
+                               tick_values);
     }
   }
 };