From: Neal Nelson Date: Fri, 18 Jun 2010 09:58:24 +0000 (+0200) Subject: Add avoidMinZero option to disable the Y axis at zero heuristic. X-Git-Tag: v1.0.0~636^2~5 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=00c281d4b022a47936132bd04784db2e59dbc3fa;p=dygraphs.git Add avoidMinZero option to disable the Y axis at zero heuristic. --- diff --git a/docs/index.html b/docs/index.html index e95d540..aba5380 100644 --- a/docs/index.html +++ b/docs/index.html @@ -852,6 +852,17 @@ perl -ne 'BEGIN{print "Month,Nominal,Real\n"} chomp; ($m,$cpi,$low,$close,$high) + + avoidMinZero + boolean + false + + When set, the heuristic that fixes the Y axis at zero for a data set with the minimum Y value of zero is disabled. + This is particularly useful for data sets that contain many zero values, especially for step plots which may otherwise have lines not visible running along the bottom axis. +
Tests: avoidMinZero
+ + + diff --git a/dygraph.js b/dygraph.js index ee08802..896a0f9 100644 --- a/dygraph.js +++ b/dygraph.js @@ -125,7 +125,8 @@ Dygraph.DEFAULT_ATTRS = { stackedGraph: false, hideOverlayOnMouseOut: true, - stepPlot: false + stepPlot: false, + avoidMinZero: false }; // Various logging levels. @@ -1639,8 +1640,10 @@ Dygraph.prototype.drawGraph_ = function(data) { var minAxisY = minY - 0.1 * span; // Try to include zero and make it minAxisY (or maxAxisY) if it makes sense. - if (minAxisY < 0 && minY >= 0) minAxisY = 0; - if (maxAxisY > 0 && maxY <= 0) maxAxisY = 0; + if (!this.attr_("avoidMinZero")) { + if (minAxisY < 0 && minY >= 0) minAxisY = 0; + if (maxAxisY > 0 && maxY <= 0) maxAxisY = 0; + } if (this.attr_("includeZero")) { if (maxY < 0) maxAxisY = 0; diff --git a/tests/avoidMinZero.html b/tests/avoidMinZero.html new file mode 100644 index 0000000..be33df5 --- /dev/null +++ b/tests/avoidMinZero.html @@ -0,0 +1,80 @@ + + + dygraph + + + + + + + +

1: Line chart with axis at zero problem:

+
+ + +

2: Step chart with axis at zero problem:

+
+ + +

3: Line chart with avoidMinZero option:

+
+ + +

4: Step chart with avoidMinZero option:

+
+ + + +