ary.push(y_labels[i].innerHTML);
}
return ary;
-}
+};
/**
* Get the x-labels for a given axis.
ary.push(x_labels[i].innerHTML);
}
return ary;
-}
+};
/**
* Returns all text in tags w/ a given css class, sorted.
}
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);
+ }
+};
AxisLabelsTestCase.prototype.tearDown = function() {
};
+AxisLabelsTestCase.simpleData =
+ "X,Y,Y2\n" +
+ "0,-1,0.25\n" +
+ "1,0,0.5\n" +
+ "2,1,0.9\n" +
+ "3,0,0.7\n";
+
/**
* Takes in an array of strings and returns an array of floats.
*/
g.updateOptions({ includeZero : false });
assertEquals(['500','600','700','800','900','1000'], Util.getYLabels());
}
+
+AxisLabelsTestCase.prototype.testAxisLabelFontSizeNull = function() {
+ var graph = document.getElementById("graph");
+ var g = new Dygraph(graph, AxisLabelsTestCase.simpleData,
+ {
+ axisLabelFontSize: null
+ });
+
+ // Be sure we're dealing with a 14-point default.
+ assertEquals(14, Dygraph.DEFAULT_ATTRS.axisLabelFontSize);
+
+ Util.assertFontSizes(graph, "dygraph-axis-label-x", 14);
+ Util.assertFontSizes(graph, "dygraph-axis-label-y", 14);
+}
* @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,
// 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);
};
/**