From 0037b2a4ba9a2f8e2825bda8ea1879afe2af8826 Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Tue, 25 Jan 2011 18:49:29 -0500 Subject: [PATCH] First round of fixes of log scaling based on code review from danvk. --- dygraph-canvas.js | 4 ++-- dygraph.js | 8 ++++---- tests/logscale.html | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index fc7ab1d..245dc6f 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -89,7 +89,7 @@ DygraphLayout.prototype._evaluateLimits = function() { axis.yrange = axis.maxyval - axis.minyval; axis.yscale = (axis.yrange != 0 ? 1.0 / axis.yrange : 1.0); - axis.ylogrange = Math.log(axis.maxyval) - Math.log(axis.minyval); + axis.ylogrange = Dygraph.log10(axis.maxyval) - Dygraph.log10(axis.minyval); axis.ylogscale = (axis.ylogrange != 0 ? 1.0 / axis.ylogrange : 1.0); } }; @@ -108,7 +108,7 @@ DygraphLayout.prototype._evaluateLineCharts = function() { var yval; if (this.dygraph_.attr_("logscale")) { - yval = 1.0 - ((Math.log(parseFloat(item[1])) - Math.log(axis.minyval)) * axis.ylogscale); // really should just be yscale. + yval = 1.0 - ((Dygraph.log10(parseFloat(item[1])) - Dygraph.log10(axis.minyval)) * axis.ylogscale); // really should just be yscale. } else { yval = 1.0 - ((parseFloat(item[1]) - axis.minyval) * axis.yscale); } diff --git a/dygraph.js b/dygraph.js index 9826414..5b35b8a 100644 --- a/dygraph.js +++ b/dygraph.js @@ -80,9 +80,9 @@ Dygraph.DEFAULT_HEIGHT = 320; Dygraph.AXIS_LINE_WIDTH = 0.3; Dygraph.LOG_SCALE = 10; -Dygraph.LOG_BASE_E_OF_TEN = Math.log(Dygraph.LOG_SCALE); +Dygraph.LN_TEN = Math.log(Dygraph.LOG_SCALE); Dygraph.log10 = function(x) { - return Math.log(x) / Dygraph.LOG_BASE_E_OF_TEN; + return Math.log(x) / Dygraph.LN_TEN; } // Default attribute values. @@ -372,8 +372,8 @@ Dygraph.prototype.toDomCoords = function(x, y, axis) { /** * Convert from data x coordinates to canvas/div X coordinate. * If specified, do this conversion for the coordinate system of a particular - * axis. Uses the first axis by default. - * returns a single value or null if x is null. + * axis. + * Returns a single value or null if x is null. */ Dygraph.prototype.toDomXCoord = function(x) { if (x == null) { diff --git a/tests/logscale.html b/tests/logscale.html index 9c17ead..30e4a32 100644 --- a/tests/logscale.html +++ b/tests/logscale.html @@ -41,7 +41,7 @@ g.updateOptions({ logscale : true }); } function linearScale() { - g.updateOptions({ logscale : null }); + g.updateOptions({ logscale : false }); } -- 2.7.4