From 1f8c95d80d5de7423de7536cea42753e03bbb450 Mon Sep 17 00:00:00 2001 From: craigj Date: Thu, 29 Aug 2013 16:32:31 -0400 Subject: [PATCH] Fix for issue with log scale and toDataYCoord. This is a fix for issue 454: https://code.google.com/p/dygraphs/issues/detail?id=454 Squashed commit of the following: commit 795eaa7bb3fcf65ae13c861dd8c034583009516e Author: craigj Date: Thu Aug 29 07:21:56 2013 -0500 Adding back in comment that explains calculation that was removed in a previous commit. commit fc837121be749eefc41c2af0f5b376dd593bedb6 Author: craigj Date: Tue Aug 27 13:54:27 2013 -0500 Adding test testChartLogarithmic to auto_test. commit 3e1f6af6a79517fce4b88d59def0d05e4ac90920 Author: craigj Date: Tue Aug 13 14:19:09 2013 -0500 ISSUE-454: Fixing issue with log scale and toDataYCoord per issue 454. https://code.google.com/p/dygraphs/issues/detail?id=454 commit 7ea65b58b912714594f5f9382464167f34dfd03a Author: craigj Date: Tue Aug 13 14:16:59 2013 -0500 ISSUE-454: Fixing issue with log scale and toDataYCoord per issue 454. https://code.google.com/p/dygraphs/issues/detail?id=454 commit d509655be656940deaec9a06cdab35c451e708d5 Author: craigj Date: Tue Aug 13 14:11:35 2013 -0500 ISSUE-454: Fixing issue with log scale and toDataYCoord per issue 454. https://code.google.com/p/dygraphs/issues/detail?id=454 --- auto_tests/tests/to_dom_coords.js | 29 +++++++++++++++++++++++++++++ dygraph.js | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/auto_tests/tests/to_dom_coords.js b/auto_tests/tests/to_dom_coords.js index dae4f44..5da5869 100644 --- a/auto_tests/tests/to_dom_coords.js +++ b/auto_tests/tests/to_dom_coords.js @@ -165,3 +165,32 @@ ToDomCoordsTestCase.prototype.testAxisTickSize = function() { assertEquals([200, 0], g.toDomCoords(0, 100)); assertEquals([500, 386], g.toDomCoords(100, 0)); } + +ToDomCoordsTestCase.prototype.testChartLogarithmic = function() { + var opts = { + drawXAxis: false, + drawYAxis: false, + drawXGrid: false, + drawYGrid: false, + logscale: true, + rightGap: 0, + valueRange: [10, 100], + dateWindow: [10, 100], + width: 400, + height: 400, + colors: ['#ff0000'] + } + + var graph = document.getElementById("graph"); + g = new Dygraph(graph, [ [10,10], [100,100] ], opts); + + assertEquals([10, 100], g.toDataCoords(0, 0)); + assertEquals([10, 10], g.toDataCoords(0, 400)); + assertEquals([100, 100], g.toDataCoords(400, 0)); + assertEquals([100, 10], g.toDataCoords(400, 400)); + + assertEquals([0, 0], g.toDomCoords(10, 100)); + assertEquals([0, 400], g.toDomCoords(10, 10)); + assertEquals([400, 0], g.toDomCoords(100, 100)); + assertEquals([400, 400], g.toDomCoords(100, 10)); +} diff --git a/dygraph.js b/dygraph.js index b9f08dc..1d33570 100644 --- a/dygraph.js +++ b/dygraph.js @@ -857,7 +857,7 @@ Dygraph.prototype.toDataYCoord = function(y, axis) { var yRange = this.yAxisRange(axis); if (typeof(axis) == "undefined") axis = 0; - if (!this.axes_[axis].logscale) { + if (!this.attributes_.getForAxis("logscale", axis)) { return yRange[0] + (area.y + area.h - y) / area.h * (yRange[1] - yRange[0]); } else { // Computing the inverse of toDomCoord. -- 2.7.4