From: Klaus Weidner Date: Thu, 1 Mar 2012 03:25:11 +0000 (-0800) Subject: Keep the X axis ticks when logscale is set globally. X-Git-Tag: v1.0.0~314^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=44462ba3fe7f5b70f9a3a896d1e6ef4b33e094d0;p=dygraphs.git Keep the X axis ticks when logscale is set globally. Currently, setting {logscale: true} at the toplevel options with a numeric X axis attempts to use logarithmic ticks for the X axis too, with strange results since the X values aren't scaled logarithmically. This resulted in tests/logscale.html skipping the "6" and "8" numbers on the ticker, and the modified demo with a large X value shows the effect more clearly. This change wraps the numericTicks generator as numericLinearTicks, ignoring 'logscale' in its axis options, and uses that for the X axis numeric ticker. Arguably doing it the other way around would be clearer, but that would be a much larger refactoring. (Note that date-valued X axes as used in the stock demo weren't affected by this issue.) --- diff --git a/dygraph-tickers.js b/dygraph-tickers.js index 64cf59f..b91b82f 100644 --- a/dygraph-tickers.js +++ b/dygraph-tickers.js @@ -62,6 +62,14 @@ /*global Dygraph:false */ "use strict"; +Dygraph.numericLinearTicks = function(a, b, pixels, opts, dygraph, vals) { + var nonLogscaleOpts = function(opt) { + if (opt === 'logscale') return false; + return opts(opt); + }; + return Dygraph.numericTicks(a, b, pixels, nonLogscaleOpts, dygraph, vals); +}; + Dygraph.numericTicks = function(a, b, pixels, opts, dygraph, vals) { var pixels_per_tick = opts('pixelsPerLabel'); var ticks = []; diff --git a/dygraph.js b/dygraph.js index 40f1d11..8d19f23 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2873,7 +2873,7 @@ Dygraph.prototype.detectTypeFromString_ = function(str) { // TODO(danvk): use Dygraph.numberValueFormatter here? /** @private (shut up, jsdoc!) */ this.attrs_.axes.x.valueFormatter = function(x) { return x; }; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter; } }; @@ -3112,7 +3112,7 @@ Dygraph.prototype.parseArray_ = function(data) { /** @private (shut up, jsdoc!) */ this.attrs_.axes.x.valueFormatter = function(x) { return x; }; this.attrs_.axes.x.axisLabelFormatter = Dygraph.numberAxisLabelFormatter; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; return data; } }; @@ -3152,7 +3152,7 @@ Dygraph.prototype.parseDataTable_ = function(data) { } else if (indepType == 'number') { this.attrs_.xValueParser = function(x) { return parseFloat(x); }; this.attrs_.axes.x.valueFormatter = function(x) { return x; }; - this.attrs_.axes.x.ticker = Dygraph.numericTicks; + this.attrs_.axes.x.ticker = Dygraph.numericLinearTicks; this.attrs_.axes.x.axisLabelFormatter = this.attrs_.axes.x.valueFormatter; } else { this.error("only 'date', 'datetime' and 'number' types are supported for " + diff --git a/tests/logscale.html b/tests/logscale.html index 84cc8e3..98193ba 100644 --- a/tests/logscale.html +++ b/tests/logscale.html @@ -51,6 +51,7 @@ "7,0\n"+ "8,100\n"+ "9,500\n"+ + "101,500\n"+ ""; };