Initial implementation
[dygraphs.git] / dygraph.js
index 21079c8..03ee85d 100644 (file)
@@ -193,6 +193,11 @@ Dygraph.DEFAULT_ATTRS = {
   stepPlot: false,
   avoidMinZero: false,
 
+  // Sizes of the various chart labels.
+  titleHeight: 16,
+  xLabelHeight: 16,
+  yLabelWidth: 16,
+
   interactionModel: null  // will be set to Dygraph.defaultInteractionModel.
 };
 
@@ -914,8 +919,9 @@ Dygraph.prototype.createStatusMessage_ = function() {
 };
 
 /**
- * Position the labels div so that its right edge is flush with the right edge
- * of the charting area.
+ * Position the labels div so that:
+ * - its right edge is flush with the right edge of the charting area
+ * - its top edge is flush with the top edge of the charting area
  */
 Dygraph.prototype.positionLabelsDiv_ = function() {
   // Don't touch a user-specified labelsDiv.
@@ -924,6 +930,7 @@ Dygraph.prototype.positionLabelsDiv_ = function() {
   var area = this.plotter_.area;
   var div = this.attr_("labelsDiv");
   div.style.left = area.x + area.w - this.attr_("labelsDivWidth") - 1 + "px";
+  div.style.top = area.y + "px";
 };
 
 /**
@@ -2635,6 +2642,20 @@ Dygraph.prototype.computeYAxisRanges_ = function(extremes) {
     seriesForAxis[idx].push(series);
   }
 
+  // If no series are defined or visible then fill in some reasonable defaults.
+  if (seriesForAxis.length == 0) {
+    var axis = this.axes_[0];
+    axis.computedValueRange = [0, 1];
+    var ret =
+      Dygraph.numericTicks(axis.computedValueRange[0],
+                           axis.computedValueRange[1],
+                           this,
+                           axis);
+    axis.ticks = ret.ticks;
+    this.numYDigits_ = ret.numDigits;
+    return;
+  }
+
   // Compute extreme values, a span and tick marks for each axis.
   for (var i = 0; i < this.axes_.length; i++) {
     var axis = this.axes_[i];
@@ -3240,6 +3261,11 @@ Dygraph.prototype.parseDataTable_ = function(data) {
           annotations.push(ann);
         }
       }
+
+      // Strip out infinities, which give dygraphs problems later on.
+      for (var j = 0; j < row.length; j++) {
+        if (!isFinite(row[j])) row[j] = null;
+      }
     } else {
       for (var j = 0; j < cols - 1; j++) {
         row.push([ data.getValue(i, 1 + 2 * j), data.getValue(i, 2 + 2 * j) ]);
@@ -3248,11 +3274,6 @@ Dygraph.prototype.parseDataTable_ = function(data) {
     if (ret.length > 0 && row[0] < ret[ret.length - 1][0]) {
       outOfOrder = true;
     }
-
-    // Strip out infinities, which give dygraphs problems later on.
-    for (var j = 0; j < row.length; j++) {
-      if (!isFinite(row[j])) row[j] = null;
-    }
     ret.push(row);
   }
 
@@ -3637,12 +3658,6 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "type": "integer",
     "description": "The size of the dot to draw on each point in pixels (see drawPoints). A dot is always drawn when a point is \"isolated\", i.e. there is a missing point on either side of it. This also controls the size of those dots."
   },
-  "annotationMouseOutHandler": {
-    "default": "",
-    "labels": ["Annotations"],
-    "type": "",
-    "description": ""
-  },
   "labelsDivStyles": {
     "default": "null",
     "labels": ["Legend"],
@@ -3735,22 +3750,28 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "description": "Number of pixels to require between each x- and y-label. Larger values will yield a sparser axis with fewer ticks."
   },
   "annotationMouseOverHandler": {
-    "default": "",
+    "default": "null",
     "labels": ["Annotations"],
-    "type": "",
-    "description": ""
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user mouses over an annotation."
+  },
+  "annotationMouseOutHandler": {
+    "default": "null",
+    "labels": ["Annotations"],
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user mouses out of an annotation."
   },
   "annotationClickHandler": {
-    "default": "",
+    "default": "null",
     "labels": ["Annotations"],
-    "type": "",
-    "description": ""
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user clicks on an annotation."
   },
   "annotationDblClickHandler": {
-    "default": "",
+    "default": "null",
     "labels": ["Annotations"],
-    "type": "",
-    "description": ""
+    "type": "function(annotation, point, dygraph, event)",
+    "description": "If provided, this function is called whenever the user double-clicks on an annotation."
   },
   "drawCallback": {
     "default": "null",
@@ -3841,7 +3862,7 @@ Dygraph.OPTIONS_REFERENCE =  // <JSON>
     "default": "false",
     "labels": ["Axis display"],
     "type": "boolean",
-    "description": "When set for a y-axis, the graph shows that axis in y-scale. Any values less than or equal to zero are not displayed.\n\nNot compatible with showZero, and ignores connectSeparatedPoints. Also, showing log scale with valueRanges that are less than zero will result in an unviewable graph."
+    "description": "When set for a y-axis, the graph shows that axis in log scale. Any values less than or equal to zero are not displayed.\n\nNot compatible with showZero, and ignores connectSeparatedPoints. Also, showing log scale with valueRanges that are less than zero will result in an unviewable graph."
   },
   "strokeWidth": {
     "default": "1.0",