Merge branch 'master' of git://github.com/danvk/dygraphs
[dygraphs.git] / dygraph-canvas.js
index 20e1f8b..ac0e741 100644 (file)
@@ -19,7 +19,7 @@ DygraphLayout = function(dygraph, options) {
   this.options = {};  // TODO(danvk): remove, use attr_ instead.
   Dygraph.update(this.options, options ? options : {});
   this.datasets = new Array();
-  this.annotations = new Array()
+  this.annotations = new Array();
 };
 
 DygraphLayout.prototype.attr_ = function(name) {
@@ -103,13 +103,6 @@ DygraphLayout.prototype._evaluateLineCharts = function() {
         name: setName
       };
 
-      // limit the x, y values so they do not overdraw
-      if (point.y <= 0.0) {
-        point.y = 0.0;
-      }
-      if (point.y >= 1.0) {
-        point.y = 1.0;
-      }
       this.points.push(point);
     }
   }
@@ -202,6 +195,35 @@ DygraphLayout.prototype.updateOptions = function(new_options) {
   Dygraph.update(this.options, new_options ? new_options : {});
 };
 
+/**
+ * Return a copy of the point at the indicated index, with its yval unstacked.
+ * @param int index of point in layout_.points
+ */
+DygraphLayout.prototype.unstackPointAtIndex = function(idx) {
+  var point = this.points[idx];
+  
+  // Clone the point since we modify it
+  var unstackedPoint = {};  
+  for (var i in point) {
+    unstackedPoint[i] = point[i];
+  }
+  
+  if (!this.attr_("stackedGraph")) {
+    return unstackedPoint;
+  }
+  
+  // The unstacked yval is equal to the current yval minus the yval of the 
+  // next point at the same xval.
+  for (var i = idx+1; i < this.points.length; i++) {
+    if (this.points[i].xval == point.xval) {
+      unstackedPoint.yval -= this.points[i].yval; 
+      break;
+    }
+  }
+  
+  return unstackedPoint;
+}  
+
 // Subclass PlotKit.CanvasRenderer to add:
 // 1. X/Y grid overlay
 // 2. Ability to draw error bars (if required)
@@ -754,16 +776,15 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() {
 
   for (var i = 0; i < setCount; i++) {
     var setName = setNames[i];
-    var setIdx = this.dygraph_.indexFromSetName(setName);
     var color = this.colors[setName];
-    var strokeWidth = this.dygraph_.attr_("strokeWidth", setIdx);
+    var strokeWidth = this.dygraph_.attr_("strokeWidth", setName);
 
     // setup graphics context
     context.save();
     var point = this.layout.points[0];
-    var pointSize = this.dygraph_.attr_("pointSize", setIdx);
+    var pointSize = this.dygraph_.attr_("pointSize", setName);
     var prevX = null, prevY = null;
-    var drawPoints = this.dygraph_.attr_("drawPoints", setIdx);
+    var drawPoints = this.dygraph_.attr_("drawPoints", setName);
     var points = this.layout.points;
     for (var j = 0; j < points.length; j++) {
       var point = points[j];