From: manufitoussi Date: Fri, 25 Jan 2013 15:34:32 +0000 (+0100) Subject: Allows that user specifies only one limit of valueRange and let other one to be calcu... X-Git-Tag: v1.0.0~105^2~8 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=e4ddb639e116ae48dba0ab9c130feae6390eafa3;p=dygraphs.git Allows that user specifies only one limit of valueRange and let other one to be calculated automatically, by exemple [NaN,30]. --- diff --git a/auto_tests/tests/range_tests.js b/auto_tests/tests/range_tests.js index 767206f..96e5eb7 100644 --- a/auto_tests/tests/range_tests.js +++ b/auto_tests/tests/range_tests.js @@ -70,6 +70,14 @@ RangeTestCase.prototype.testRangeSetOperations = function() { assertEquals([12, 18], g.xAxisRange()); assertEquals([10, 40], g.yAxisRange(0)); + g.updateOptions({ valueRange: [10, NaN] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 44.2], g.yAxisRange(0)); + + g.updateOptions({ valueRange: [10, 40] }); + assertEquals([12, 18], g.xAxisRange()); + assertEquals([10, 40], g.yAxisRange(0)); + g.updateOptions({ }); assertEquals([12, 18], g.xAxisRange()); assertEquals([10, 40], g.yAxisRange(0)); diff --git a/dygraph-options-reference.js b/dygraph-options-reference.js index 98cf22f..a6f026f 100644 --- a/dygraph-options-reference.js +++ b/dygraph-options-reference.js @@ -421,7 +421,7 @@ Dygraph.OPTIONS_REFERENCE = // "labels": ["Axis display"], "type": "Array of two numbers", "example": "[10, 110]", - "description": "Explicitly set the vertical range of the graph to [low, high]. This may be set on a per-axis basis to define each y-axis separately." + "description": "Explicitly set the vertical range of the graph to [low, high]. This may be set on a per-axis basis to define each y-axis separately. You can specify only one limit and let other one (replaced by NaN) to be calculated automatically, by exemple [NaN,30]" }, "labelsDivWidth": { "default": "250", diff --git a/dygraph.js b/dygraph.js index fc50740..b516f5e 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2570,7 +2570,10 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { axis.computedValueRange = [axis.valueWindow[0], axis.valueWindow[1]]; } else if (axis.valueRange) { // This is a user-set value range for this axis. - axis.computedValueRange = [axis.valueRange[0], axis.valueRange[1]]; + axis.computedValueRange = [ + !isNaN(axis.valueRange[0]) ? axis.valueRange[0] : axis.extremeRange[0], + !isNaN(axis.valueRange[1]) ? axis.valueRange[1] : axis.extremeRange[1] + ]; } else { axis.computedValueRange = axis.extremeRange; }