/*
* Interesting member variables:
* dygraph_ - the graph.
- * global - global attributes (common among all graphs, AIUI)
+ * global_ - global attributes (common among all graphs, AIUI)
- * user_ - attributes set by the user
+ * user - attributes set by the user
- * axes - map of options specific to the axis.
- * series - { seriesName -> { idx, yAxis, options }
- * labels - used as mapping from index to series name.
+ * axes_ - array of axis index to { series : [ series names ] , options : { axis-specific options. }
- * series_ - { seriesName -> { idx, yAxis, options }
++ * series_ - { seriesName -> { idx, yAxis, options }}
+ * labels_ - used as mapping from index to series name.
*/
/**
this.global_ = this.dygraph_.attrs_;
this.user_ = this.dygraph_.user_attrs_ || {};
- this.highlightSeries_ = this.find("highlightSeriesOpts") || {};
+ this.highlightSeries_ = this.get("highlightSeriesOpts") || {};
// Get a list of series names.
- var labels = this.find("labels");
+ var labels = this.get("labels");
if (!labels) {
return; // -- can't do more for now, will parse after getting the labels.
- };
+ }
this.reparseSeries();
- }
+ };
+ /**
+ * Reparses options that are all related to series. This typically occurs when
+ * options are either updated, or source data has been made avaialble.
+ *
+ * TODO(konigsberg): The method name is kind of weak; fix.
+ */
DygraphOptions.prototype.reparseSeries = function() {
- this.labels = this.find("labels").slice(1);
+ this.labels = this.get("labels").slice(1);
- this.axes_ = [ {} ]; // Always one axis at least.
+ this.axes_ = [ { series : [], options : {}} ]; // Always one axis at least.
this.series_ = {};
var axisId = 0; // 0-offset; there's always one.
return this.global_[name];
}
return null;
- }
+ };
- DygraphOptions.prototype.findForAxis = function(name, axis) {
- var axisIdx = (axis == "y2" || axis == "y2" || axis == 1) ? 1 : 0;
+ /**
+ * 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
+ * ("y", "y2") or the axis number (0, 1).
+ */
+ DygraphOptions.prototype.getForAxis = function(name, axis) {
+ var axisIdx = 0;
+ if (typeof(axis) == 'number') {
+ axisIdx = axis;
+ } else {
+ // TODO(konigsberg): Accept only valid axis strings?
+ axisIdx = (axis == "y2") ? 1 : 0;
+ }
- var axisOptions = this.axes_[axisIdx];
+ var axisOptions = this.axes_[axisIdx].options;
if (axisOptions.hasOwnProperty(name)) {
return axisOptions[name];
}
return seriesOptions[name];
}
- return this.findForAxis(name, seriesObj["yAxis"]);
- }
+ return this.getForAxis(name, seriesObj["yAxis"]);
+ };
+/**
+ * Returns the number of y-axes on the chart.
+ * @return {Number} the number of axes.
+ */
+DygraphOptions.prototype.numAxes = function() {
+ return this.axes_.length;
+}
+
+/**
+ * Return the y-axis for a given series, specified by name.
+ */
+DygraphOptions.prototype.axisForSeries = function(seriesName) {
+ return this.series_[seriesName].yAxis;
+}
+
+/**
+ * Returns the options for the specified axis.
+ */
+DygraphOptions.prototype.axisOptions = function(yAxis) {
+ return this.axes_[yAxis].options;
+}
+
+/**
+ * Return the series associated with an axis.
+ */
+DygraphOptions.prototype.seriesForAxis = function(yAxis) {
+ return this.axes_[yAxis].series;
+}