From: Dan Vanderkam Date: Tue, 5 Apr 2011 14:32:44 +0000 (-0400) Subject: general cleanup X-Git-Tag: v1.0.0~536^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=36dfa9583c9b6134a63654c73aded8710aff2779;p=dygraphs.git general cleanup --- diff --git a/dygraph.js b/dygraph.js index 30ea7a8..00af051 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2601,13 +2601,10 @@ Dygraph.prototype.drawGraph_ = function() { this.layout_.addDataset(this.attr_("labels")[i], datasets[i]); } - if (datasets.length > 0) { - // TODO(danvk): this method doesn't need to return anything. - this.computeYAxisRanges_(extremes); - this.layout_.updateOptions( { yAxes: this.axes_, - seriesToAxisMap: this.seriesToAxisMap_ - } ); - } + this.computeYAxisRanges_(extremes); + this.layout_.updateOptions( { yAxes: this.axes_, + seriesToAxisMap: this.seriesToAxisMap_ + } ); this.addXTicks_(); // Save the X axis zoomed status as the updateOptions call will tend to set it errorneously @@ -2793,23 +2790,18 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) { // Only use valid extremes to stop null data series' from corrupting the scale. extremeMinY = extremes[series[j]][0]; if (extremeMinY != null) { - minY = Math.min(extremeMinY, minY); + minY = Math.min(extremeMinY, minY); } extremeMaxY = extremes[series[j]][1]; if (extremeMaxY != null) { - maxY = Math.max(extremeMaxY, maxY); + maxY = Math.max(extremeMaxY, maxY); } } if (axis.includeZero && minY > 0) minY = 0; // Ensure we have a valid scale, otherwise defualt to zero for safety. - if (minY == Infinity) { - minY = 0; - } - - if (maxY == -Infinity) { - maxY = 0; - } + if (minY == Infinity) minY = 0; + if (maxY == -Infinity) maxY = 0; // Add some padding and round up to an integer to be human-friendly. var span = maxY - minY; @@ -3533,11 +3525,6 @@ Dygraph.prototype.start_ = function() { *
  • errorBars: changes whether the data contains stddev
  • * * - * If the dateWindow or valueRange options are specified, the relevant zoomed_x_ - * or zoomed_y_ flags are set, unless the isZoomedIgnoreProgrammaticZoom option is also - * secified. This allows for the chart to be programmatically zoomed without - * altering the zoomed flags. - * * @param {Object} attrs The new properties and values */ Dygraph.prototype.updateOptions = function(attrs) { @@ -4215,7 +4202,7 @@ Dygraph.OPTIONS_REFERENCE = // "default": "false", "labels": ["Zooming"], "type": "boolean", - "description" : "When this flag is passed along with either the dateWindow or valueRange options, the zoom flags are not changed to reflect a zoomed state. This is primarily useful for when the display area of a chart is changed programmatically and also where manual zooming is allowed and use is made of the isZoomed method to determine this." + "description" : "When this option is passed to updateOptions() along with either the dateWindow or valueRange options, the zoom flags are not changed to reflect a zoomed state. This is primarily useful for when the display area of a chart is changed programmatically and also where manual zooming is allowed and use is made of the isZoomed method to determine this." } } ; // @@ -4240,7 +4227,8 @@ Dygraph.OPTIONS_REFERENCE = // 'Legend', 'Overall display', 'Rolling Averages', - 'Value display/formatting' + 'Value display/formatting', + 'Zooming' ]; var cats = {}; for (var i = 0; i < valid_cats.length; i++) cats[valid_cats[i]] = true; diff --git a/tests/is-zoomed-ignore-programmatic-zoom.html b/tests/is-zoomed-ignore-programmatic-zoom.html index 7b2629e..e8ae826 100644 --- a/tests/is-zoomed-ignore-programmatic-zoom.html +++ b/tests/is-zoomed-ignore-programmatic-zoom.html @@ -1,167 +1,168 @@ - - isZoomedIgnoreProgrammaticZoom Flag - - - - - - - - - -

    isZoomedIgnoreProgrammaticZoom Option

    -

    - By default, when the dateWindow or updateOptions - of a chart is changed programmatically by a call to updateOptions - the zoomed flags (isZoomed) are changed. This is the same - as manually zooming in using the mouse. -

    + + + isZoomedIgnoreProgrammaticZoom Flag + + + + + + + + + +

    isZoomedIgnoreProgrammaticZoom Option

    +

    + By default, when the dateWindow or updateOptions + of a chart is changed programmatically by a call to updateOptions + the zoomed flags (isZoomed) are changed. This is the same + as manually zooming in using the mouse. +

    +

    + Sometimes it may be desirable to change the display of the chart by + manipulating the dateWindow and valueRange + options but without changing the zoomed flags, for example where manual + zooming is still required but where it is also desired that the zoomed + flags drive display elements, but only for manual zooming. +

    +

    + In this case isZoomedIgnoreProgrammaticZoom may be specified along with + either the dateWindow or valueRange values to + updateOptions and the zoomed flags will remain unaffected. +

    +

    + The chart below may be manipulated to change the updateOptions + using the Max and Min Y axis buttons and the dateWindow + by using the Max and Min X axis buttons. +

    +

    + Toggle the check box below to determine the difference in operation of the zoom flags + when the date and value windows of the chart are changed using the arrows underneath. +

    +

    Do not change zoom flags (isZoomedIgnoreProgrammaticZoom)

    + +
    +

    - Sometimes it may be desirable to change the display of the chart by - manipulating the dateWindow and valueRange - options but without changing the zoomed flags, for example where manual - zooming is still required but where it is also desired that the zoomed - flags drive display elements, but only for manual zooming. + Max Y Axis: + +

    - In this case isZoomedIgnoreProgrammaticZoom may be specified along with - either the dateWindow or valueRange values to - updateOptions and the zoomed flags will remain unaffected. + Min Y Axis: + +

    - The chart below may be manipulated to change the updateOptions - using the Max and Min Y axis buttons and the dateWindow - by using the Max and Min X axis buttons. + Min X Axis: + +

    - Toggle the check box below to determine the difference in operation of the zoom flags - when the date and value windows of the chart are changed using the arrows underneath. + Max X Axis: + +

    -

    Do not change zoom flags (isZoomedIgnoreProgrammaticZoom)

    - -
    -
    -

    - Max Y Axis: - - -

    -

    - Min Y Axis: - - -

    -

    - Min X Axis: - - -

    -

    - Max X Axis: - - -

    -
    -
    -
    +
    +
    +
    -
    -
    -
    -

    Zoomed Flags

    -

    Zoomed: False

    -

    Zoomed X: False

    -

    Zoomed Y: False

    -

    Window coordinates (in dates and values):

    -
    -
    -
    +
    +
    +
    +

    Zoomed Flags

    +

    Zoomed: False

    +

    Zoomed X: False

    +

    Zoomed Y: False

    +

    Window coordinates (in dates and values):

    +
    +
    +
    - - + + diff --git a/tests/is-zoomed.html b/tests/is-zoomed.html index 50c23f1..1b5db9f 100644 --- a/tests/is-zoomed.html +++ b/tests/is-zoomed.html @@ -1,103 +1,104 @@ - - isZoomedIgnoresProgrammaticZoom Flag - - - - - - - - -

    Determining Zoom

    -

    - It is possible to detect whether a chart has been zoomed in either axis by the use of the isZoomed function. - If called with no argument, it will report whether either axis has been zoomed. - Alternatively it can be called with an argument of either 'x' or 'y' and it will report the status of just that axis. -

    - -

    Here's a simple example using drawCallback to display the various zoom states whenever the chart is zoomed:

    - -
    OUTPUT
    -
    -
    -

    Zoomed: False

    -

    Zoomed X: False

    -

    Zoomed Y: False

    -

    -
    -
    - -
    -
    - -

    -

    HTML
    + + + isZoomedIgnoresProgrammaticZoom Flag + + + + + + + + +

    Determining Zoom

    +

    + It is possible to detect whether a chart has been zoomed in either axis by the use of the isZoomed function. + If called with no argument, it will report whether either axis has been zoomed. + Alternatively it can be called with an argument of either 'x' or 'y' and it will report the status of just that axis. +

    + +

    Here's a simple example using drawCallback to display the various zoom states whenever the chart is zoomed:

    + +
    OUTPUT
    +
    +
    +

    Zoomed: False

    +

    Zoomed X: False

    +

    Zoomed Y: False

    +

    +
    +
    + +
    +
    + +

    +

    HTML
       new Dygraph(
     
    -    // containing div
    -    document.getElementById("zoomdiv"),
    +  // containing div
    +  document.getElementById("zoomdiv"),
     
    -    // CSV or path to a CSV file.
    -    "Date,Temperature\n" +
    -    "2011-01-07,75\n" +
    -    "2011-01-08,70\n" +
    -    "2011-01-09,90\n" +
    -    "2011-01-10,30\n" +
    -    "2011-01-11,40\n" +
    -    "2011-01-12,60\n" +
    -    "2011-01-13,70\n" +
    -    "2011-01-14,40\n",
    -    {
    -      drawCallback: function(me, initial) {
    -        document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
    -        document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
    -        document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
    -      }
    +  // CSV or path to a CSV file.
    +  "Date,Temperature\n" +
    +  "2011-01-07,75\n" +
    +  "2011-01-08,70\n" +
    +  "2011-01-09,90\n" +
    +  "2011-01-10,30\n" +
    +  "2011-01-11,40\n" +
    +  "2011-01-12,60\n" +
    +  "2011-01-13,70\n" +
    +  "2011-01-14,40\n",
    +  {
    +    drawCallback: function(me, initial) {
    +    document.getElementById("zoomed").innerHTML = "" + me.isZoomed();
    +    document.getElementById("zoomedX").innerHTML = "" + me.isZoomed("x");
    +    document.getElementById("zoomedY").innerHTML = "" + me.isZoomed("y");
         }
    +  }
       );
     
    -

    - -

    The Tests for zoom operations show a full example of this in action.

    - -

    Programmatic Zoom

    -

    - When a chart is programmatically zoomed by updating either the dateWindow - or valueRange option, by default the zoomed flags are also updated correspondingly. - It is possible to prevent this by specifying the isZoomedIgnoreProgrammaticZoom in the same - call to the updateOptions method. -

    -

    - The is-zoomed-ignore-programmatic-zoom test shows this in operation. -

    - +

    + +

    The Tests for zoom operations show a full example of this in action.

    + +

    Programmatic Zoom

    +

    + When a chart is programmatically zoomed by updating either the dateWindow + or valueRange option, by default the zoomed flags are also updated correspondingly. + It is possible to prevent this by specifying the isZoomedIgnoreProgrammaticZoom in the same + call to the updateOptions method. +

    +

    + The is-zoomed-ignore-programmatic-zoom test shows this in operation. +

    +