From: Dan Vanderkam Date: Tue, 21 Apr 2015 20:15:15 +0000 (-0400) Subject: Set `this` for tickers X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a436656270def97bf7ac89ec3cfd6e3b7bd99e12;p=dygraphs.git Set `this` for tickers --- diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index abff8b2..dfa7ef1 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -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. diff --git a/src/dygraph.js b/src/dygraph.js index 878a747..4d7ff74 100644 --- a/src/dygraph.js +++ b/src/dygraph.js @@ -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); } } };