Merge branch 'master' into remove-old-options
authorRobert Konigsberg <konigsberg@google.com>
Sat, 24 Nov 2012 15:45:26 +0000 (10:45 -0500)
committerRobert Konigsberg <konigsberg@google.com>
Sat, 24 Nov 2012 15:46:38 +0000 (10:46 -0500)
Conflicts:
dygraph-options.js
dygraph.js

1  2 
dygraph-options.js
dygraph.js

@@@ -9,11 -9,11 +9,11 @@@
  /*
   * Interesting member variables:
   * dygraph_ - the graph.
 - * global - global attributes (common among all graphs, AIUI)
 + * global_ - global attributes (common among all graphs, AIUI)
-  * user_ - attributes set by the user
+  * user - attributes set by the user
 - * axes - map of options specific to the axis.
 - * series - { seriesName -> { idx, yAxis, options }
 - * labels - used as mapping from index to series name.
 + * axes_ - array of axis index to { series : [ series names ] , options : { axis-specific options. }
-  * series_ - { seriesName -> { idx, yAxis, options }
++ * series_ - { seriesName -> { idx, yAxis, options }}
 + * labels_ - used as mapping from index to series name.
   */
  
  /**
@@@ -32,21 -35,27 +35,27 @@@ var DygraphOptions = function(dygraph) 
    this.global_ = this.dygraph_.attrs_;
    this.user_ = this.dygraph_.user_attrs_ || {};
  
-   this.highlightSeries_ = this.find("highlightSeriesOpts") || {};
+   this.highlightSeries_ = this.get("highlightSeriesOpts") || {};
    // Get a list of series names.
  
-   var labels = this.find("labels");
+   var labels = this.get("labels");
    if (!labels) {
      return; // -- can't do more for now, will parse after getting the labels.
-   };
+   }
  
    this.reparseSeries();
- }
+ };
  
+ /**
+  * Reparses options that are all related to series. This typically occurs when
+  * options are either updated, or source data has been made avaialble.
+  *
+  * TODO(konigsberg): The method name is kind of weak; fix.
+  */
  DygraphOptions.prototype.reparseSeries = function() {
-   this.labels = this.find("labels").slice(1);
+   this.labels = this.get("labels").slice(1);
  
 -  this.axes_ = [ {} ]; // Always one axis at least.
 +  this.axes_ = [ { series : [], options : {}} ]; // Always one axis at least.
    this.series_ = {};
  
    var axisId = 0; // 0-offset; there's always one.
@@@ -114,12 -120,26 +128,26 @@@ DygraphOptions.prototype.get = function
      return this.global_[name];
    }
    return null;
- }
+ };
  
- DygraphOptions.prototype.findForAxis = function(name, axis) {
-   var axisIdx = (axis == "y2" || axis == "y2" || axis == 1) ? 1 : 0;
+ /**
+  * Get a value for a specific axis. If there is no specific value for the axis,
+  * the global value is returned.
+  *
+  * @param {String} name the name of the option.
+  * @param {String|number} axis the axis to search. Can be the string representation
+  * ("y", "y2") or the axis number (0, 1).
+  */
+ DygraphOptions.prototype.getForAxis = function(name, axis) {
+   var axisIdx = 0;
+   if (typeof(axis) == 'number') {
+     axisIdx = axis;
+   } else {
+     // TODO(konigsberg): Accept only valid axis strings?
+     axisIdx = (axis == "y2") ? 1 : 0;
+   }
  
 -  var axisOptions = this.axes_[axisIdx];
 +  var axisOptions = this.axes_[axisIdx].options;
    if (axisOptions.hasOwnProperty(name)) {
      return axisOptions[name];
    }
@@@ -146,34 -174,6 +182,34 @@@ DygraphOptions.prototype.getForSeries 
      return seriesOptions[name];
    }
  
-   return this.findForAxis(name, seriesObj["yAxis"]);
- }
+   return this.getForAxis(name, seriesObj["yAxis"]);
+ };
  
 +/**
 + * Returns the number of y-axes on the chart.
 + * @return {Number} the number of axes.
 + */
 +DygraphOptions.prototype.numAxes = function() {
 +  return this.axes_.length;
 +}
 +
 +/**
 + * Return the y-axis for a given series, specified by name.
 + */
 +DygraphOptions.prototype.axisForSeries = function(seriesName) {
 +  return this.series_[seriesName].yAxis;
 +}
 +
 +/**
 + * Returns the options for the specified axis.
 + */
 +DygraphOptions.prototype.axisOptions = function(yAxis) {
 +  return this.axes_[yAxis].options;
 +}
 +
 +/**
 + * Return the series associated with an axis.
 + */
 +DygraphOptions.prototype.seriesForAxis = function(yAxis) {
 +  return this.axes_[yAxis].series;
 +}
diff --cc dygraph.js
@@@ -569,7 -573,8 +573,12 @@@ Dygraph.prototype.attr_ = function(name
      Dygraph.OPTIONS_REFERENCE[name] = true;
    }
  // </REMOVE_FOR_COMBINED>
++<<<<<<< HEAD
 +  return seriesName ? this.attributes_.findForSeries(name, seriesName) : this.attributes_.find(name);
++=======
+   return seriesName ? this.attributes_.getForSeries(name, seriesName) : this.attributes_.get(name);
++>>>>>>> 5daa462d93e850a64a7f6644afb8122336ccf84d
  };
  
  /**