Add dygraph-options.js. Add code to compare behavior. Looks like it's only working...
[dygraphs.git] / dygraph.js
index 621ea32..4189750 100644 (file)
@@ -437,6 +437,8 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
   this.registeredEvents_ = [];
   this.eventListeners_ = {};
 
+  this.attributes_ = new DygraphOptions(this);
+
   // Create the containing DIV and other interactive elements
   this.createInterface_();
 
@@ -568,6 +570,12 @@ Dygraph.prototype.attr_ = function(name, seriesName) {
   }
 // </REMOVE_FOR_COMBINED>
 
+  // Building an array which we peruse in backwards order to find the correct value.
+  // Options are checked in this order:
+  // series, axis, user attrs, global attrs.
+  // TODO(konigsberg): Can this be made faster by starting with the series and working outward,
+  // rather than building an array?
+
   var sources = [];
   sources.push(this.attrs_);
   if (this.user_attrs_) {
@@ -576,6 +584,8 @@ Dygraph.prototype.attr_ = function(name, seriesName) {
       if (this.user_attrs_.hasOwnProperty(seriesName)) {
         sources.push(this.user_attrs_[seriesName]);
       }
+
+      // TODO(konigsberg): This special case ought to be documented.
       if (seriesName === this.highlightSet_ &&
           this.user_attrs_.hasOwnProperty('highlightSeriesOpts')) {
         sources.push(this.user_attrs_.highlightSeriesOpts);
@@ -591,7 +601,15 @@ Dygraph.prototype.attr_ = function(name, seriesName) {
       break;
     }
   }
-  return ret;
+
+  var computedValue = seriesName ? this.attributes_.findForSeries(name, seriesName) : this.attributes_.find(name);
+
+  if (ret !== computedValue) {
+    console.log("Mismatch", name, seriesName, ret, computedValue);
+  } else {
+    console.log("Match", name, seriesName, ret, computedValue);
+  }
+  return computedValue;
 };
 
 /**
@@ -2179,7 +2197,8 @@ Dygraph.prototype.predraw_ = function() {
   // rolling averages.
   this.rolledSeries_ = [null];  // x-axis is the first series and it's special
   for (var i = 1; i < this.numColumns(); i++) {
-    var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong
+    // var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong // konigsberg thinks so too.
+    var logScale = this.attr_('logscale');
     var series = this.extractSeries_(this.rawData_, i, logScale);
     series = this.rollingAverage(series, this.rollPeriod_);
     this.rolledSeries_.push(series);