perSeriesTestCase.prototype.tearDown = function() {
};
-
perSeriesTestCase.prototype.testPerSeriesFill = function() {
var opts = {
width: 480,
assertEquals(5, g.getOption("pointSize", "Y"));
};
+perSeriesTestCase.prototype.testAxisInNewSeries = function() {
+ var opts = {
+ logscale: true,
+ series : {
+ D : { axis : 'y2' },
+ C : { axis : 1 },
+ B : { axis : 0 },
+ E : { axis : 'y' }
+ }
+ };
+ var graph = document.getElementById("graph");
+ var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
+ g = new Dygraph(graph, data, opts);
+
+ assertEquals(5, g.getOption("pointSize"));
+ assertEquals(4, g.getOption("pointSize", "Y"));
+ assertEquals(5, g.getOption("pointSize", "Z"));
+};
+
+perSeriesTestCase.prototype.testAxisInNewSeries_withAxes = function() {
+ var opts = {
+ series : {
+ D : { axis : 'y2' },
+ C : { axis : 1 },
+ B : { axis : 0 },
+ E : { axis : 'y' }
+ },
+ axes : {
+ y : {},
+ y2 : {}
+ }
+ };
+ var graph = document.getElementById("graph");
+ var data = "X,A,B,C,D,E\n0,1,2,3,4,5\n";
+ g = new Dygraph(graph, data, opts);
+
+ assertEquals(5, g.getOption("pointSize"));
+ assertEquals(4, g.getOption("pointSize", "Y"));
+ assertEquals(5, g.getOption("pointSize", "Z"));
+};
this.reparseSeries();
};
+/*
+ * Not optimal, but does the trick when you're only using two axes.
+ * If we move to more axes, this can just become a function.
+ */
+DygraphOptions.AXIS_STRING_MAPPINGS_ = {
+ 'y' : 0,
+ 'Y' : 0,
+ 'y1' : 0,
+ 'Y1' : 0,
+ 'y2' : 1,
+ 'Y2' : 1
+}
+
+DygraphOptions.axisToIndex_ = function(axis) {
+ if (typeof(axis) == "string") {
+ if (DygraphOptions.AXIS_STRING_MAPPINGS_.hasOwnProperty(axis)) {
+ return DygraphOptions.AXIS_STRING_MAPPINGS_[axis];
+ }
+ throw "Unknown axis : " + text;
+ }
+ if (typeof(axis) == "number") {
+ if (axis == 0 || axis == 1) {
+ return axis;
+ }
+ throw "Dygraphs only supports two y-axes, indexed from 0-1."
+ }
+ if (axis) {
+ throw "Unknown axis : " + axis;
+ }
+ // No axis specification means axis 0.
+ return 0;
+};
+
/**
* Reparses options that are all related to series. This typically occurs when
* options are either updated, or source data has been made avaialble.
//
// So, if series is found, it's expected to contain per-series data, otherwise we fall
// back.
- var allseries = this.user_["series"] ? this.user_.series : this.user_;
+ var oldStyleSeries = !this.user_["series"];
+
+ if (oldStyleSeries) {
+ var axisId = 0; // 0-offset; there's always one.
+ // Go through once, add all the series, and for those with {} axis options, add a new axis.
+ for (var idx = 0; idx < this.labels.length; idx++) {
+ var seriesName = this.labels[idx];
+
+ var optionsForSeries = this.user_[seriesName] || {};
+
+ var yAxis = 0;
+ var axis = optionsForSeries["axis"];
+ if (typeof(axis) == 'object') {
+ yAxis = ++axisId;
+ this.axes_[yAxis] = axis;
+ }
+ this.series_[seriesName] = { idx: idx, yAxis: yAxis, options : optionsForSeries };
+ }
+
+ // Go through one more time and assign series to an axis defined by another
+ // series, e.g. { 'Y1: { axis: {} }, 'Y2': { axis: 'Y1' } }
+ for (var idx = 0; idx < this.labels.length; idx++) {
+ var seriesName = this.labels[idx];
+ var optionsForSeries = this.series_[seriesName]["options"];
+ var axis = optionsForSeries["axis"];
+
+ if (typeof(axis) == 'string') {
+ if (!this.series_.hasOwnProperty(axis)) {
+ this.dygraph_.error("Series " + seriesName + " wants to share a y-axis with " +
+ "series " + axis + ", which does not define its own axis.");
+ return null;
+ }
+ this.series_[seriesName].yAxis = this.series_[axis].yAxis;
+ }
+ }
+ } else {
+ var maxYAxis = 0;
- var axisId = 0; // 0-offset; there's always one.
- // Go through once, add all the series, and for those with {} axis options, add a new axis.
- for (var idx = 0; idx < this.labels.length; idx++) {
- var seriesName = this.labels[idx];
+ for (var idx = 0; idx < this.labels.length; idx++) {
+ var seriesName = this.labels[idx];
+ var optionsForSeries = this.user_.series[seriesName] || {};
+ var yAxis = DygraphOptions.axisToIndex_(optionsForSeries["axis"]);
- var optionsForSeries = allseries[seriesName] || {};
- var yAxis = 0;
+ maxYAxis = Math.max(yAxis, maxYAxis);
- var axis = optionsForSeries["axis"];
- if (typeof(axis) == 'object') {
- yAxis = ++axisId;
- this.axes_[yAxis] = axis;
+ this.series_[seriesName] = {
+ idx: idx,
+ yAxis: yAxis,
+ options : optionsForSeries };
}
- this.series_[seriesName] = { idx: idx, yAxis: yAxis, options : optionsForSeries };
- }
- // Go through one more time and assign series to an axis defined by another
- // series, e.g. { 'Y1: { axis: {} }, 'Y2': { axis: 'Y1' } }
- for (var idx = 0; idx < this.labels.length; idx++) {
- var seriesName = this.labels[idx];
- var optionsForSeries = this.series_[seriesName]["options"];
- var axis = optionsForSeries["axis"];
-
- if (typeof(axis) == 'string') {
- if (!this.series_.hasOwnProperty(axis)) {
- this.dygraph_.error("Series " + seriesName + " wants to share a y-axis with " +
- "series " + axis + ", which does not define its own axis.");
- return null;
- }
- this.series_[seriesName].yAxis = this.series_[axis].yAxis;
+ for (; maxYAxis >= 0; maxYAxis--) {
+ this.axes_[maxYAxis] = {};
}
}
// This doesn't support reading from the 'x' axis, only 'y' and 'y2.
- // Read from the global "axes" option.
if (this.user_["axes"]) {
var axis_opts = this.user_.axes;
return this.getForAxis(name, seriesObj["yAxis"]);
};
-