}
);
- var in_series = g.dataHandler_.extractSeries(data, 1, g.attributes_);
+ var in_series = g.dataHandler_.extractSeries(data, 1, 'A', g.attributes_);
assertEquals(null, in_series[4][1]);
assertEquals(null, in_series[4][2][0]);
assertNaN(in_series[5][2][0]);
assertNaN(in_series[5][2][1]);
- var out_series = g.dataHandler_.rollingAverage(in_series, 1, g.attributes_);
+ var out_series = g.dataHandler_.rollingAverage(in_series, 1, 'A', g.attributes_);
assertNaN(out_series[5][1]);
assertNaN(out_series[5][2][0]);
assertNaN(out_series[5][2][1]);
}
};
-rollingAverageTestCase.prototype.getRolledData = function(g, data, seriesIdx, rollPeriod){
+rollingAverageTestCase.prototype.getRolledData = function(g, data, seriesIdx, rollPeriod) {
+ // TODO(konigsberg): exposure to attributes_.
var options = g.attributes_;
- return g.dataHandler_.rollingAverage(g.dataHandler_.extractSeries(data, seriesIdx, options), rollPeriod, options);
+ var seriesName = g.getLabels()[seriesIdx];
+ var interim = g.dataHandler_.extractSeries(data, seriesIdx, seriesName, options);
+ return g.dataHandler_.rollingAverage(interim, rollPeriod, seriesName, options);
};
CustomBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
// customBars
-CustomBarsHandler.prototype.extractSeries = function(rawData, i, options) {
+CustomBarsHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point;
- var logScale = options.get('logscale');
+ var logScale = options.getForAxis('logscale', options.axisForSeries(seriesName));
for ( var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
return series;
};
-CustomBarsHandler.prototype.rollingAverage = function(originalData, rollPeriod,
- options) {
+CustomBarsHandler.prototype.rollingAverage = function(
+ originalData, rollPeriod, seriesName, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
var y, low, high, mid,count, i, extremes;
ErrorBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
// errorBars
-ErrorBarsHandler.prototype.extractSeries = function(rawData, i, options) {
+ErrorBarsHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, variance, point;
- var sigma = options.get("sigma");
- var logScale = options.get('logscale');
+ var sigma = options.getForSeries('sigma', seriesName);
+ var logScale = options.getForAxis('logscale', options.axisForSeries(seriesName));
for ( var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
return series;
};
-ErrorBarsHandler.prototype.rollingAverage = function(originalData, rollPeriod,
- options) {
+ErrorBarsHandler.prototype.rollingAverage = function(
+ originalData, rollPeriod, seriesName, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
- var sigma = options.get("sigma");
+ var sigma = options.getForSeries('sigma', seriesName);
var i, j, y, v, sum, num_ok, stddev, variance, value;
FractionsBarsHandler.prototype = new Dygraph.DataHandlers.BarsHandler();
// errorBars
-FractionsBarsHandler.prototype.extractSeries = function(rawData, i, options) {
+FractionsBarsHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point, num, den, value, stddev, variance;
var mult = 100.0;
- var sigma = options.get("sigma");
- var logScale = options.get('logscale');
+ var sigma = options.getForSeries('sigma', seriesName);
+ var logScale = options.getForAxis('logscale', options.axisForSeries(seriesName));
for ( var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
return series;
};
-FractionsBarsHandler.prototype.rollingAverage = function(originalData, rollPeriod,
- options) {
+FractionsBarsHandler.prototype.rollingAverage = function(
+ originalData, rollPeriod, seriesName, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
- var sigma = options.get("sigma");
- var wilsonInterval = options.get("wilsonInterval");
+ var sigma = options.getForSeries('sigma', seriesName);
+ var wilsonInterval = options.getForSeries('wilsonInterval', seriesName);
var low, high, i, stddev;
var num = 0;
var BarsHandler = Dygraph.DataHandlers.BarsHandler;
// errorBars
-BarsHandler.prototype.extractSeries = function(rawData, i, options) {
+BarsHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// Not implemented here must be extended
};
}
};
-BarsHandler.prototype.getExtremeYValues = function(series, dateWindow, options) {
+BarsHandler.prototype.getExtremeYValues = function(series, dateWindow, seriesName, options) {
var minY = null, maxY = null, y;
var firstIdx = 0;
* rawData[i] = [x,ySeries1,...,ySeriesN].
* @param seriesIndex {!number} Index of the series to extract. All other series should
* be ignored.
+ * @param {!string} seriesName Name of the series.
* @param options {!DygraphOptions} Dygraph options.
* @returns {Array.<[!number,?number,?]>} The series in the unified data format
* where series[i] = [x,y,{extras}].
* @public
*/
- handler.prototype.extractSeries = function(rawData, seriesIndex, options) {
+ handler.prototype.extractSeries = function(rawData, seriesIndex, seriesName, options) {
};
/**
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
- * @param {!string} setName Name of the series.
+ * @param {!string} seriesName Name of the series.
* @param {!number} boundaryIdStart Index offset of the first point, equal to the
* number of skipped points left of the date window minimum (if any).
* @return {!Array.<Dygraph.PointType>} List of points for this series.
* @public
*/
- handler.prototype.seriesToPoints = function(series, setName, boundaryIdStart) {
+ handler.prototype.seriesToPoints = function(series, seriesName, boundaryIdStart) {
// TODO(bhs): these loops are a hot-spot for high-point-count charts. In
// fact,
// on chrome+linux, they are 6 times more expensive than iterating through
y : NaN,
xval : DygraphLayout.parseFloat_(item[0]),
yval : yval,
- name : setName, // TODO(danvk): is this really necessary?
+ name : seriesName, // TODO(danvk): is this really necessary?
idx : i + boundaryIdStart
};
points.push(point);
*
* @param {!Array.<[!number,?number,?]>} series The series in the unified
* data format where series[i] = [x,y,{extras}].
- * @param {!number} rollPeriod The number of points over which to average the data
+ * @param {!number} rollPeriod The number of points over which to average the data.
+ * @param {!String} seriesName the name of the series.
* @param {!DygraphOptions} options The dygraph options.
* @return the rolled series.
* @public
*/
- handler.prototype.rollingAverage = function(series, rollPeriod, options) {
+ handler.prototype.rollingAverage = function(series, rollPeriod, seriesName, options) {
};
/**
var DefaultFractionHandler = Dygraph.DataHandlers.DefaultFractionHandler;
DefaultFractionHandler.prototype = new Dygraph.DataHandlers.DefaultHandler();
-DefaultFractionHandler.prototype.extractSeries = function(rawData, i, options) {
+DefaultFractionHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
var x, y, point, num, den, value;
var mult = 100.0;
- var logScale = options.get('logscale');
+ var logScale = options.getForAxis('logscale', options.axisForSeries(seriesName));
for ( var j = 0; j < rawData.length; j++) {
x = rawData[j][0];
point = rawData[j][i];
return series;
};
-DefaultFractionHandler.prototype.rollingAverage = function(originalData, rollPeriod,
- options) {
+DefaultFractionHandler.prototype.rollingAverage = function(
+ originalData, rollPeriod, seriesName, options) {
+
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
Dygraph.DataHandlers.DefaultHandler = Dygraph.DataHandler();
var DefaultHandler = Dygraph.DataHandlers.DefaultHandler;
-DefaultHandler.prototype.extractSeries = function(rawData, i, options) {
+DefaultHandler.prototype.extractSeries = function(rawData, i, seriesName, options) {
// TODO(danvk): pre-allocate series here.
var series = [];
- var logScale = options.get('logscale');
+ var logScale = options.getForAxis('logscale', options.axisForSeries(seriesName));
for ( var j = 0; j < rawData.length; j++) {
var x = rawData[j][0];
var point = rawData[j][i];
return series;
};
-DefaultHandler.prototype.rollingAverage = function(originalData, rollPeriod,
- options) {
+DefaultHandler.prototype.rollingAverage = function(
+ originalData, rollPeriod, seriesName, options) {
rollPeriod = Math.min(rollPeriod, originalData.length);
var rollingData = [];
this.registeredEvents_ = [];
this.eventListeners_ = {};
+ // TODO(konigsberg): Rename attributes_ to options_.
this.attributes_ = new DygraphOptions(this);
// Create the containing DIV and other interactive elements
// Convert the raw data (a 2D array) into the internal format and compute
// rolling averages.
this.rolledSeries_ = [null]; // x-axis is the first series and it's special
- for (var i = 1; i < this.numColumns(); i++) {
- // var logScale = this.attr_('logscale', i); // TODO(klausw): this looks wrong // konigsberg thinks so too.
- var series = this.dataHandler_.extractSeries(this.rawData_, i, this.attributes_);
+ for (var seriesIdx = 1; seriesIdx < this.numColumns(); seriesIdx++) {
+ var seriesName = this.attr_('labels')[seriesIdx];
+ var series = this.dataHandler_.extractSeries(this.rawData_, seriesIdx, seriesName, this.attributes_);
if (this.rollPeriod_ > 1) {
- series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, this.attributes_);
+ series = this.dataHandler_.rollingAverage(series, this.rollPeriod_, seriesName, this.attributes_);
}
this.rolledSeries_.push(series);
var seriesName = this.attr_("labels")[seriesIdx];
var seriesExtremes = this.dataHandler_.getExtremeYValues(series,
- dateWindow, this.attr_("stepPlot",seriesName));
+ dateWindow, this.attr_("stepPlot", seriesName));
var seriesPoints = this.dataHandler_.seriesToPoints(series,
seriesName, boundaryIds[seriesIdx-1][0]);