* Get a value for a specific axis. If there is no specific value for the axis,
* the global value is returned.
*
- * @param {String} name the name of the option.
- * @param {String|number} axis the axis to search. Can be the string representation
- * ("x", "y", "y2") or the y-axis number (0, 1). (x-axis can't be specified by number.)
+ * @param {string} name the name of the option.
+ * @param {string|number} axis the axis to search. Can be the string representation
+ * ("y", "y2") or the axis number (0, 1).
*/
DygraphOptions.prototype.getForAxis = function(name, axis) {
- var axisIdx = 0;
+ var axisIdx;
+ var axisString;
+
+ // Since axis can be a number or a string, straighten everything out here.
if (typeof(axis) == 'number') {
axisIdx = axis;
+ axisString = axisIdx == 0 ? "y" : "y2";
} else {
- // TODO(konigsberg): Accept only valid axis strings?
- axisIdx = (axis == "y2") ? 1 : 0;
+ if (axis == "y1") { axis = "y"; } // Standardize on 'y'. Is this bad? I think so.
+ if (axis == "y") {
+ axisIdx = 0;
+ } else if (axis == "y2") {
+ axisIdx = 1;
+ } else if (axis == "x") {
+ axisIdx = -1; // simply a placeholder for below.
+ } else {
+ throw "Unknown axis " + axis;
+ }
+ axisString = axis;
}
+
+ var userAxis = (axisIdx == -1) ? this.xAxis_ : this.yAxes_[axisIdx];
+
// Search the user-specified axis option first.
- if (this.axes_[axisIdx]) {
- var axisOptions = this.axes_[axisIdx].options;
+ if (userAxis) { // This condition could be removed if we always set up this.yAxes_ for y2.
+ var axisOptions = userAxis.options;
if (axisOptions.hasOwnProperty(name)) {
return axisOptions[name];
}