From: Robert Konigsberg Date: Thu, 13 Dec 2012 23:57:20 +0000 (-0500) Subject: Fix logscale. Also fix includeZero (and add tests for it.) Probably fixes all those... X-Git-Tag: v1.0.0~143 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=478b866bb009c2bd3dca3330df76cfc5ad727860;p=dygraphs.git Fix logscale. Also fix includeZero (and add tests for it.) Probably fixes all those special per axis options which should now use the other axis-property specification. --- diff --git a/auto_tests/tests/axis_labels.js b/auto_tests/tests/axis_labels.js index a52030a..ddb7a0f 100644 --- a/auto_tests/tests/axis_labels.js +++ b/auto_tests/tests/axis_labels.js @@ -536,3 +536,14 @@ AxisLabelsTestCase.prototype.testLogScale = function() { g.updateOptions({ logscale : false }); assertEquals(['0','200','400','600','800','1000'], Util.getYLabels()); } + +/** + * Verify that include zero range is properly specified. + */ +AxisLabelsTestCase.prototype.testIncludeZero = function() { + var g = new Dygraph("graph", [[0, 500], [1, 1000]], { includeZero : true }); + assertEquals(['0','200','400','600','800','1000'], Util.getYLabels()); + + g.updateOptions({ includeZero : false }); + assertEquals(['500','600','700','800','900','1000'], Util.getYLabels()); +} diff --git a/auto_tests/tests/range_tests.js b/auto_tests/tests/range_tests.js index bc333f9..4fcb822 100644 --- a/auto_tests/tests/range_tests.js +++ b/auto_tests/tests/range_tests.js @@ -150,3 +150,14 @@ RangeTestCase.prototype.testLogScaleExcludesZero = function() { g.updateOptions({ logscale : false }); assertEquals([0, 1099], g.yAxisRange(0)); } + +/** + * Verify that includeZero range is properly specified. + */ +RangeTestCase.prototype.testIncludeZeroIncludesZero = function() { + var g = new Dygraph("graph", [[0, 500], [500, 1000]], { includeZero : true }); + assertEquals([0, 1100], g.yAxisRange(0)); + + g.updateOptions({ includeZero : false }); + assertEquals([450, 1050], g.yAxisRange(0)); +} diff --git a/dygraph.js b/dygraph.js index 3612c11..9c6b3cf 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2427,6 +2427,7 @@ Dygraph.prototype.renderGraph_ = function(is_initial_draw) { * indices are into the axes_ array. */ Dygraph.prototype.computeYAxes_ = function() { + // Preserve valueWindow settings if they exist, and if the user hasn't // specified a new valueRange. var i, valueWindows, seriesName, axis, index, opts, v; @@ -2449,6 +2450,31 @@ Dygraph.prototype.computeYAxes_ = function() { this.axes_[axis] = opts; } + // TODO(konigsberg): REMOVE THIS SILLINESS this should just come from DygraphOptions. + // TODO(konigsberg): Add tests for all of these. Currently just tests for + // includeZero and logscale. + + // all options which could be applied per-axis: + var axisOptions = [ + 'includeZero', + 'valueRange', + 'labelsKMB', + 'labelsKMG2', + 'pixelsPerYLabel', + 'yAxisLabelWidth', + 'axisLabelFontSize', + 'axisTickSize', + 'logscale' + ]; + + // Copy global axis options over to the first axis. + for (i = 0; i < axisOptions.length; i++) { + var k = axisOptions[i]; + v = this.attr_(k); + if (v) this.axes_[0][k] = v; + } + // TODO(konigsberg): end of REMOVE THIS SILLINESS + if (valueWindows !== undefined) { // Restore valueWindow settings. for (index = 0; index < valueWindows.length; index++) {