Merge branch 'master' of github.com:danvk/dygraphs
authorRobert Konigsberg <konigsberg@gmail.com>
Sun, 30 Dec 2012 16:07:00 +0000 (11:07 -0500)
committerRobert Konigsberg <konigsberg@gmail.com>
Sun, 30 Dec 2012 16:07:00 +0000 (11:07 -0500)
Conflicts:
auto_tests/tests/Util.js
auto_tests/tests/axis_labels.js

auto_tests/tests/Util.js
auto_tests/tests/axis_labels.js
dygraph-options.js

index 6469bc6..3eb59e3 100644 (file)
@@ -19,7 +19,7 @@ Util.getYLabels = function(axis_num, parent) {
     ary.push(y_labels[i].innerHTML);
   }
   return ary;
-}
+};
 
 /**
  * Get the x-labels for a given axis.
@@ -34,7 +34,7 @@ Util.getXLabels = function(parent) {
     ary.push(x_labels[i].innerHTML);
   }
   return ary;
-}
+};
 
 /**
  * Returns all text in tags w/ a given css class, sorted.
@@ -49,13 +49,36 @@ Util.getClassTexts = function(css_class, parent) {
   }
   texts.sort();
   return texts;
-}
+};
 
 Util.getLegend = function(parent) {
   parent = parent || document;
   var legend = parent.getElementsByClassName("dygraph-legend")[0];
   return legend.textContent;
-}
+};
+
+/**
+ * Assert that all the elements in 'parent' with class 'className' is
+ * the expected font size.
+ */
+Util.assertFontSizes = function(parent, className, expectedSize) {
+  var expectedSizePx = expectedSize + "px";
+  var labels = parent.getElementsByClassName(className);
+  assertTrue(labels.length > 0);
+
+  // window.getComputedStyle is apparently compatible with all browsers
+  // (IE first became compatible with IE9.)
+  // If this test fails on earlier browsers, then enable something like this,
+  // because the font size is set by the parent div.
+  // if (!window.getComputedStyle) {
+  //   fontSize = label.parentElement.style.fontSize;
+  // }
+  for (var idx = 0; idx < labels.length; idx++) {
+    var label = labels[idx];
+    var fontSize = window.getComputedStyle(label).fontSize;
+    assertEquals(expectedSizePx, fontSize);
+  }
+};
 
 
 /**
@@ -67,4 +90,4 @@ Util.makeNumbers = function(ary) {
     ret.push(parseFloat(ary[i]));
   }
   return ret;
-}
+};
index 2eb7f4d..56ddf3d 100644 (file)
@@ -637,37 +637,16 @@ AxisLabelsTestCase.prototype.testAxisLabelFontSize = function() {
 */
 }
 
-/*
- * This test will pass when
- * https://code.google.com/p/dygraphs/issues/detail?id=413
- * is fixed.
-AxisLabelsTestCase.prototype.testAxisLabelFontSize2 = function() {
+AxisLabelsTestCase.prototype.testAxisLabelFontSizeNull = function() {
   var graph = document.getElementById("graph");
   var g = new Dygraph(graph, AxisLabelsTestCase.simpleData,
-    {axisLabelFontSize: undefined});
-  var assertSize = function(className, size) {
-    var sizePx = size + "px";
-    var labels = graph.getElementsByClassName(className);
-    assertTrue(labels.length > 0);
-    // window.getComputedStyle is apparently compatible with all browsers
-    // (IE first became compatible with IE9.)
-    // If this test fails on earlier browsers, then enable something like this,
-    // because the font size is set by the parent div.
-    // if (!window.getComputedStyle) {
-    //   fontSize = label.parentElement.style.fontSize;
-    // }
-    for (var idx = 0; idx < labels.length; idx++) {
-      var label = labels[idx];
-      var fontSize = window.getComputedStyle(label).fontSize;
-      assertEquals(sizePx, fontSize);
-    }
-  }
+    {
+      axisLabelFontSize: null
+    });
 
   // Be sure we're dealing with a 14-point default.
   assertEquals(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
 
-  assertSize("dygraph-axis-label-x", 14);
-  assertSize("dygraph-axis-label-y", 14);
+  Util.assertFontSizes(graph, "dygraph-axis-label-x", 14);
+  Util.assertFontSizes(graph, "dygraph-axis-label-y", 14);
 }
-*/
index 815a893..f059ff9 100644 (file)
@@ -193,14 +193,29 @@ DygraphOptions.prototype.reparseSeries = function() {
  * @param {String} name the name of the option.
  */
 DygraphOptions.prototype.get = function(name) {
+  var result = this.getGlobalUser_(name);
+  if (result != null) {
+    return result;
+  }
+  return this.getGlobalDefault_(name);
+};
+
+DygraphOptions.prototype.getGlobalUser_ = function(name) {
   if (this.user_.hasOwnProperty(name)) {
     return this.user_[name];
   }
+  return null;
+};
+
+DygraphOptions.prototype.getGlobalDefault_ = function(name) {
   if (this.global_.hasOwnProperty(name)) {
     return this.global_[name];
   }
+  if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(name)) {
+    return Dygraph.DEFAULT_ATTRS[name];
+  }
   return null;
-};
+}
 
 /**
  * Get a value for a specific axis. If there is no specific value for the axis,
@@ -218,12 +233,29 @@ DygraphOptions.prototype.getForAxis = function(name, axis) {
     // TODO(konigsberg): Accept only valid axis strings?
     axisIdx = (axis == "y2") ? 1 : 0;
   }
+  // Search the user-specified axis option first.
+  if (this.axes_[axisIdx]) {
+    var axisOptions = this.axes_[axisIdx].options;
+    if (axisOptions.hasOwnProperty(name)) {
+      return axisOptions[name];
+    }
+  }
 
-  var axisOptions = this.axes_[axisIdx].options;
-  if (axisOptions.hasOwnProperty(name)) {
-    return axisOptions[name];
+  // User-specified global options second.
+  var result = this.getGlobalUser_(name);
+  if (result != null) {
+    return result;
   }
-  return this.get(name);
+
+  // Default axis options third.
+  var axisString = axis == 0 ? "y" : "y2";
+  var defaultAxisOptions = Dygraph.DEFAULT_ATTRS.axes[axisString];
+  if (defaultAxisOptions.hasOwnProperty(name)) {
+    return defaultAxisOptions[name];
+  }
+
+  // Default global options last.
+  return this.getGlobalDefault_(name);
 };
 
 /**