2013-12-06 14:53:05 +01:00
|
|
|
define([
|
2014-08-07 14:35:19 +02:00
|
|
|
'lodash',
|
2014-02-15 10:15:05 +01:00
|
|
|
'kbn'
|
2013-12-06 14:53:05 +01:00
|
|
|
],
|
2014-02-15 10:15:05 +01:00
|
|
|
function (_, kbn) {
|
2013-12-06 14:53:05 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-08-19 16:22:18 +02:00
|
|
|
function TimeSeries(opts) {
|
2014-02-05 13:03:56 +01:00
|
|
|
this.datapoints = opts.datapoints;
|
2014-11-08 19:16:22 +01:00
|
|
|
this.label = opts.alias;
|
|
|
|
|
this.id = opts.alias;
|
|
|
|
|
this.alias = opts.alias;
|
|
|
|
|
this.color = opts.color;
|
2014-10-06 12:17:48 -04:00
|
|
|
this.valueFormater = kbn.valueFormats.none;
|
2014-10-06 12:37:51 -04:00
|
|
|
this.stats = {};
|
2014-08-19 16:22:18 +02:00
|
|
|
}
|
2013-12-06 14:53:05 +01:00
|
|
|
|
2014-08-20 10:27:30 +02:00
|
|
|
function matchSeriesOverride(aliasOrRegex, seriesAlias) {
|
2014-08-20 11:48:00 +02:00
|
|
|
if (!aliasOrRegex) { return false; }
|
|
|
|
|
|
2014-08-20 10:27:30 +02:00
|
|
|
if (aliasOrRegex[0] === '/') {
|
2014-09-01 11:13:18 +02:00
|
|
|
var regex = kbn.stringToJsRegex(aliasOrRegex);
|
2014-08-20 10:27:30 +02:00
|
|
|
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 = {};
|
2014-11-08 19:16:22 +01:00
|
|
|
this.yaxis = 1;
|
2014-08-20 11:31:40 +02:00
|
|
|
this.zindex = 0;
|
2014-08-20 10:27:30 +02:00
|
|
|
delete this.stack;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < overrides.length; i++) {
|
|
|
|
|
var override = overrides[i];
|
2014-11-08 19:16:22 +01:00
|
|
|
if (!matchSeriesOverride(override.alias, this.alias)) {
|
2014-08-20 10:27:30 +02:00
|
|
|
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; }
|
2014-08-20 10:50:26 +02:00
|
|
|
if (override.zindex !== void 0) { this.zindex = override.zindex; }
|
2014-10-15 10:55:46 -04:00
|
|
|
if (override.fillBelowTo !== void 0) { this.fillBelowTo = override.fillBelowTo; }
|
2015-05-14 12:34:30 +02:00
|
|
|
if (override.color !== void 0) { this.color = override.color; }
|
2015-06-12 20:06:47 +02:00
|
|
|
if (override.transform !== void 0) { this.transform = override.transform; }
|
2014-10-15 10:55:46 -04:00
|
|
|
|
2014-08-20 10:27:30 +02:00
|
|
|
if (override.yaxis !== void 0) {
|
2014-11-08 19:16:22 +01:00
|
|
|
this.yaxis = override.yaxis;
|
2014-08-20 10:27:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-29 11:37:56 +02:00
|
|
|
TimeSeries.prototype.getFlotPairs = function (fillStyle) {
|
2014-02-05 13:03:56 +01:00
|
|
|
var result = [];
|
|
|
|
|
|
2014-10-06 12:37:51 -04:00
|
|
|
this.stats.total = 0;
|
2014-11-26 09:34:21 +01:00
|
|
|
this.stats.max = -Number.MAX_VALUE;
|
2014-10-10 10:45:34 -04:00
|
|
|
this.stats.min = Number.MAX_VALUE;
|
|
|
|
|
this.stats.avg = null;
|
|
|
|
|
this.stats.current = null;
|
2014-11-07 13:39:47 +01:00
|
|
|
this.allIsNull = true;
|
2014-02-06 10:19:26 +01:00
|
|
|
|
2014-07-04 11:50:11 +02: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 13:03:56 +01:00
|
|
|
if (currentValue === null) {
|
2014-07-04 11:50:11 +02:00
|
|
|
if (ignoreNulls) { continue; }
|
|
|
|
|
if (nullAsZero) {
|
2014-02-05 13:03:56 +01:00
|
|
|
currentValue = 0;
|
|
|
|
|
}
|
2013-12-06 14:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-13 09:27:08 +01:00
|
|
|
if (currentValue !== null) {
|
|
|
|
|
if (_.isNumber(currentValue)) {
|
|
|
|
|
this.stats.total += currentValue;
|
|
|
|
|
this.allIsNull = false;
|
|
|
|
|
}
|
2014-02-06 10:19:26 +01:00
|
|
|
|
2015-03-13 09:27:08 +01:00
|
|
|
if (currentValue > this.stats.max) {
|
|
|
|
|
this.stats.max = currentValue;
|
|
|
|
|
}
|
2014-02-06 10:19:26 +01:00
|
|
|
|
2015-03-13 09:27:08 +01:00
|
|
|
if (currentValue < this.stats.min) {
|
|
|
|
|
this.stats.min = currentValue;
|
|
|
|
|
}
|
2014-02-06 10:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-12 08:39:04 +01:00
|
|
|
result.push([currentTime, currentValue]);
|
2014-07-04 11:50:11 +02:00
|
|
|
}
|
2014-02-06 10:19:26 +01:00
|
|
|
|
2014-10-10 10:45:34 -04:00
|
|
|
if (this.datapoints.length >= 2) {
|
2014-11-12 08:39:04 +01:00
|
|
|
this.stats.timeStep = this.datapoints[1][1] - this.datapoints[0][1];
|
2014-03-02 13:26:08 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-26 09:34:21 +01:00
|
|
|
if (this.stats.max === -Number.MAX_VALUE) { this.stats.max = null; }
|
2014-10-10 10:45:34 -04:00
|
|
|
if (this.stats.min === Number.MAX_VALUE) { this.stats.min = null; }
|
|
|
|
|
|
2014-02-06 13:26:35 +01:00
|
|
|
if (result.length) {
|
2014-10-06 12:37:51 -04:00
|
|
|
this.stats.avg = (this.stats.total / result.length);
|
|
|
|
|
this.stats.current = result[result.length-1][1];
|
2014-11-12 13:47:06 +01:00
|
|
|
if (this.stats.current === null && result.length > 1) {
|
|
|
|
|
this.stats.current = result[result.length-2][1];
|
|
|
|
|
}
|
2014-02-06 13:26:35 +01:00
|
|
|
}
|
2013-12-06 14:53:05 +01:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-29 11:37:56 +02:00
|
|
|
TimeSeries.prototype.updateLegendValues = function(formater, decimals, scaledDecimals) {
|
2014-10-06 12:17:48 -04:00
|
|
|
this.valueFormater = formater;
|
|
|
|
|
this.decimals = decimals;
|
|
|
|
|
this.scaledDecimals = scaledDecimals;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TimeSeries.prototype.formatValue = function(value) {
|
|
|
|
|
return this.valueFormater(value, this.decimals, this.scaledDecimals);
|
2014-09-19 13:24:15 +02:00
|
|
|
};
|
|
|
|
|
|
2014-08-19 16:22:18 +02:00
|
|
|
return TimeSeries;
|
|
|
|
|
|
|
|
|
|
});
|