2013-12-06 07:53:05 -06:00
|
|
|
define([
|
2014-08-07 07:35:19 -05:00
|
|
|
'lodash',
|
2014-02-15 03:15:05 -06:00
|
|
|
'kbn'
|
2013-12-06 07:53:05 -06:00
|
|
|
],
|
2014-02-15 03:15:05 -06:00
|
|
|
function (_, kbn) {
|
2013-12-06 07:53:05 -06:00
|
|
|
'use strict';
|
|
|
|
|
2014-08-19 09:22:18 -05:00
|
|
|
function TimeSeries(opts) {
|
2014-02-05 06:03:56 -06:00
|
|
|
this.datapoints = opts.datapoints;
|
2014-02-06 03:19:26 -06:00
|
|
|
this.info = opts.info;
|
|
|
|
this.label = opts.info.alias;
|
2014-08-19 09:22:18 -05:00
|
|
|
}
|
2013-12-06 07:53:05 -06:00
|
|
|
|
2014-08-20 03:27:30 -05:00
|
|
|
function matchSeriesOverride(aliasOrRegex, seriesAlias) {
|
|
|
|
if (aliasOrRegex[0] === '/') {
|
|
|
|
var match = aliasOrRegex.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
|
|
|
|
var regex = new RegExp(match[1], match[2]);
|
|
|
|
return seriesAlias.match(regex) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aliasOrRegex === seriesAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
function translateFillOption(fill) {
|
|
|
|
return fill === 0 ? 0.001 : fill/10;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeSeries.prototype.applySeriesOverrides = function(overrides) {
|
|
|
|
this.lines = {};
|
|
|
|
this.points = {};
|
|
|
|
this.bars = {};
|
|
|
|
this.info.yaxis = 1;
|
|
|
|
delete this.stack;
|
|
|
|
|
|
|
|
for (var i = 0; i < overrides.length; i++) {
|
|
|
|
var override = overrides[i];
|
|
|
|
if (!matchSeriesOverride(override.alias, this.info.alias)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (override.lines !== void 0) { this.lines.show = override.lines; }
|
|
|
|
if (override.points !== void 0) { this.points.show = override.points; }
|
|
|
|
if (override.bars !== void 0) { this.bars.show = override.bars; }
|
|
|
|
if (override.fill !== void 0) { this.lines.fill = translateFillOption(override.fill); }
|
|
|
|
if (override.stack !== void 0) { this.stack = override.stack; }
|
|
|
|
if (override.linewidth !== void 0) { this.lines.lineWidth = override.linewidth; }
|
|
|
|
if (override.pointradius !== void 0) { this.points.radius = override.pointradius; }
|
|
|
|
if (override.steppedLine !== void 0) { this.lines.steps = override.steppedLine; }
|
|
|
|
if (override.yaxis !== void 0) {
|
|
|
|
this.info.yaxis = override.yaxis;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-19 09:22:18 -05:00
|
|
|
TimeSeries.prototype.getFlotPairs = function (fillStyle, yFormats) {
|
2014-02-05 06:03:56 -06:00
|
|
|
var result = [];
|
|
|
|
|
2014-02-07 06:10:35 -06:00
|
|
|
this.color = this.info.color;
|
|
|
|
this.yaxis = this.info.yaxis;
|
|
|
|
|
2014-02-06 03:19:26 -06:00
|
|
|
this.info.total = 0;
|
2014-07-04 04:50:11 -05:00
|
|
|
this.info.max = -212312321312;
|
2014-02-06 03:19:26 -06:00
|
|
|
this.info.min = 212312321312;
|
|
|
|
|
2014-07-04 04:50:11 -05:00
|
|
|
var ignoreNulls = fillStyle === 'connected';
|
|
|
|
var nullAsZero = fillStyle === 'null as zero';
|
|
|
|
var currentTime;
|
|
|
|
var currentValue;
|
|
|
|
|
|
|
|
for (var i = 0; i < this.datapoints.length; i++) {
|
|
|
|
currentValue = this.datapoints[i][0];
|
|
|
|
currentTime = this.datapoints[i][1];
|
|
|
|
|
2014-02-05 06:03:56 -06:00
|
|
|
if (currentValue === null) {
|
2014-07-04 04:50:11 -05:00
|
|
|
if (ignoreNulls) { continue; }
|
|
|
|
if (nullAsZero) {
|
2014-02-05 06:03:56 -06:00
|
|
|
currentValue = 0;
|
|
|
|
}
|
2013-12-06 07:53:05 -06:00
|
|
|
}
|
|
|
|
|
2014-02-06 03:19:26 -06:00
|
|
|
if (_.isNumber(currentValue)) {
|
|
|
|
this.info.total += currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentValue > this.info.max) {
|
|
|
|
this.info.max = currentValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentValue < this.info.min) {
|
|
|
|
this.info.min = currentValue;
|
|
|
|
}
|
|
|
|
|
2014-02-05 06:03:56 -06:00
|
|
|
result.push([currentTime * 1000, currentValue]);
|
2014-07-04 04:50:11 -05:00
|
|
|
}
|
2014-02-06 03:19:26 -06:00
|
|
|
|
2014-03-02 06:26:08 -06:00
|
|
|
if (result.length > 2) {
|
|
|
|
this.info.timeStep = result[1][0] - result[0][0];
|
|
|
|
}
|
|
|
|
|
2014-02-06 06:26:35 -06:00
|
|
|
if (result.length) {
|
2014-03-02 06:26:08 -06:00
|
|
|
|
2014-02-15 03:15:05 -06:00
|
|
|
this.info.avg = (this.info.total / result.length);
|
2014-02-06 06:26:35 -06:00
|
|
|
this.info.current = result[result.length-1][1];
|
2014-02-15 03:15:05 -06:00
|
|
|
|
2014-02-26 12:46:34 -06:00
|
|
|
var formater = kbn.getFormatFunction(yFormats[this.yaxis - 1], 2);
|
2014-06-02 12:28:51 -05:00
|
|
|
this.info.avg = this.info.avg != null ? formater(this.info.avg) : null;
|
|
|
|
this.info.current = this.info.current != null ? formater(this.info.current) : null;
|
|
|
|
this.info.min = this.info.min != null ? formater(this.info.min) : null;
|
|
|
|
this.info.max = this.info.max != null ? formater(this.info.max) : null;
|
|
|
|
this.info.total = this.info.total != null ? formater(this.info.total) : null;
|
2014-02-06 06:26:35 -06:00
|
|
|
}
|
2013-12-06 07:53:05 -06:00
|
|
|
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2014-08-19 09:22:18 -05:00
|
|
|
return TimeSeries;
|
|
|
|
|
|
|
|
});
|