update both linear regression tests; support null as per-series value
[dygraphs.git] / dygraph.js
index 517f0c6..929a9ea 100644 (file)
@@ -243,6 +243,7 @@ Dygraph.prototype.__init__ = function(div, file, attrs) {
 Dygraph.prototype.attr_ = function(name, series) {
   if (series &&
       typeof(this.user_attrs_[series]) != 'undefined' &&
+      this.user_attrs_[series] != null &&
       typeof(this.user_attrs_[series][name]) != 'undefined') {
     return this.user_attrs_[series][name];
   } else if (typeof(this.user_attrs_[name]) != 'undefined') {
@@ -1021,11 +1022,18 @@ Dygraph.prototype.mouseMove_ = function(event) {
  */
 Dygraph.prototype.updateSelection_ = function() {
   // Clear the previously drawn vertical, if there is one
-  var circleSize = this.attr_('highlightCircleSize');
   var ctx = this.canvas_.getContext("2d");
   if (this.previousVerticalX_ >= 0) {
+    // Determine the maximum highlight circle size.
+    var maxCircleSize = 0;
+    var num_series = this.attr_('labels').length;
+    for (var i = 1; i < num_series; i++) {
+      var r = this.attr_('highlightCircleSize', i);
+      if (r > maxCircleSize) maxCircleSize = r;
+    }
     var px = this.previousVerticalX_;
-    ctx.clearRect(px - circleSize - 1, 0, 2 * circleSize + 2, this.height_);
+    ctx.clearRect(px - maxCircleSize - 1, 0,
+                  2 * maxCircleSize + 2, this.height_);
   }
 
   var isOK = function(x) { return x && !isNaN(x); };
@@ -1061,6 +1069,8 @@ Dygraph.prototype.updateSelection_ = function() {
     ctx.save();
     for (var i = 0; i < this.selPoints_.length; i++) {
       if (!isOK(this.selPoints_[i].canvasy)) continue;
+      var setIdx = this.indexFromSetName(this.selPoints_[i].name);
+      var circleSize = this.attr_('highlightCircleSize', setIdx);
       ctx.beginPath();
       ctx.fillStyle = this.plotter_.colors[this.selPoints_[i].name];
       ctx.arc(canvasx, this.selPoints_[i].canvasy, circleSize,
@@ -2312,6 +2322,11 @@ Dygraph.prototype.updateOptions = function(attrs) {
   }
 
   // TODO(danvk): validate per-series options.
+  // Supported:
+  // strokeWidth
+  // pointSize
+  // drawPoints
+  // highlightCircleSize
 
   Dygraph.update(this.user_attrs_, attrs);
   Dygraph.update(this.renderOptions_, attrs);
@@ -2427,6 +2442,18 @@ Dygraph.prototype.annotations = function() {
   return this.annotations_;
 };
 
+/**
+ * Get the index of a series (column) given its name. The first column is the
+ * x-axis, so the data series start with index 1.
+ */
+Dygraph.prototype.indexFromSetName = function(name) {
+  var labels = this.attr_("labels");
+  for (var i = 0; i < labels.length; i++) {
+    if (labels[i] == name) return i;
+  }
+  return null;
+};
+
 Dygraph.addAnnotationRule = function() {
   if (Dygraph.addedAnnotationCSS) return;