Merge pull request #176 from kberg/add-per-series-to-tests
authorRobert Konigsberg <konigsberg@gmail.com>
Thu, 22 Nov 2012 16:29:05 +0000 (08:29 -0800)
committerRobert Konigsberg <konigsberg@gmail.com>
Thu, 22 Nov 2012 16:29:05 +0000 (08:29 -0800)
Add missing tests to local.html, organize.

1  2 
dygraph.js

diff --combined dygraph.js
@@@ -437,6 -437,8 +437,8 @@@ Dygraph.prototype.__init__ = function(d
    this.registeredEvents_ = [];
    this.eventListeners_ = {};
  
+   this.attributes_ = new DygraphOptions(this);
    // Create the containing DIV and other interactive elements
    this.createInterface_();
  
@@@ -568,6 -570,12 +570,12 @@@ Dygraph.prototype.attr_ = function(name
    }
  // </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_) {
        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);
        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);
+   }
+   var USE_NEW_VALUE = true;
+   return USE_NEW_VALUE ? computedValue : ret;
  };
  
  /**
@@@ -1670,7 -1687,7 +1687,7 @@@ Dygraph.prototype.findClosestPoint = fu
    var minDist = Infinity;
    var idx = -1;
    var dist, dx, dy, point, closestPoint, closestSeries;
 -  for (var setIdx = 0; setIdx < this.layout_.datasets.length; ++setIdx) {
 +  for ( var setIdx = this.layout_.datasets.length - 1 ; setIdx >= 0 ; --setIdx ) {
      var points = this.layout_.points[setIdx];
      for (var i = 0; i < points.length; ++i) {
        var point = points[i];
@@@ -1771,7 -1788,7 +1788,7 @@@ Dygraph.prototype.mouseMove_ = function
  
    var highlightSeriesOpts = this.attr_("highlightSeriesOpts");
    var selectionChanged = false;
 -  if (highlightSeriesOpts && !this.lockedSet_) {
 +  if (highlightSeriesOpts && !this.isSeriesLocked()) {
      var closest;
      if (this.attr_("stackedGraph")) {
        closest = this.findStackedPoint(canvasx, canvasy);
@@@ -2064,14 -2081,6 +2081,14 @@@ Dygraph.prototype.getHighlightSeries = 
  };
  
  /**
 + * Returns true if the currently-highlighted series was locked
 + * via setSelection(..., seriesName, true).
 + */
 +Dygraph.prototype.isSeriesLocked = function() {
 +  return this.lockedSet_;
 +};
 +
 +/**
   * Fires when there's data available to be graphed.
   * @param {String} data Raw CSV data to be plotted
   * @private
@@@ -2187,7 -2196,8 +2204,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);
@@@ -2960,6 -2970,7 +2978,7 @@@ Dygraph.prototype.parseCSV_ = function(
      // User hasn't explicitly set labels, so they're (presumably) in the CSV.
      start = 1;
      this.attrs_.labels = lines[0].split(delim);  // NOTE: _not_ user_attrs_.
+     this.attributes_.reparseSeries();
    }
    var line_no = 0;
  
@@@ -3096,8 -3107,9 +3115,9 @@@ Dygraph.prototype.parseArray_ = functio
                "in the options parameter");
      this.attrs_.labels = [ "X" ];
      for (i = 1; i < data[0].length; i++) {
-       this.attrs_.labels.push("Y" + i);
+       this.attrs_.labels.push("Y" + i); // Not user_attrs_.
      }
+     this.attributes_.reparseSeries();
    } else {
      var num_labels = this.attr_("labels");
      if (num_labels.length != data[0].length) {