added more function definitions, added small hack to make randomWalk and countLine that do not take any series work with the parser and target editor (the whole target editor and parsing & back to target rendering needs to be rewritten to handle functions that take multiple series)

This commit is contained in:
Torkel Ödegaard
2014-01-20 14:31:00 +01:00
parent 203b8df7f8
commit ad4c0ab5b6
4 changed files with 112 additions and 20 deletions

View File

@@ -31,13 +31,6 @@ function (_) {
defaultParams: [1],
});
addFuncDef({
name: "alias",
category: categories.Special,
params: [ { name: "alias", type: 'string' } ],
defaultParams: ['alias']
});
addFuncDef({
name: "holtWintersForecast",
category: categories.Calculate,
@@ -69,6 +62,20 @@ function (_) {
category: categories.Combine,
});
addFuncDef({
name: "alias",
category: categories.Special,
params: [ { name: "alias", type: 'string' } ],
defaultParams: ['alias']
});
addFuncDef({
name: "aliasSub",
category: categories.Special,
params: [ { name: "search", type: 'string' }, { name: "replace", type: 'string' } ],
defaultParams: ['', '']
});
addFuncDef({
name: "groupByNode",
category: categories.Special,
@@ -94,6 +101,30 @@ function (_) {
defaultParams: [3]
});
addFuncDef({
name: 'aliasByMetric',
category: categories.Special,
});
addFuncDef({
name: 'randomWalk',
category: categories.Special,
params: [ { name: "name", type: "string", } ],
defaultParams: ['randomWalk']
});
addFuncDef({
name: 'countSeries',
category: categories.Special
});
addFuncDef({
name: 'constantLine',
category: categories.Special,
params: [ { name: "value", type: "int", } ],
defaultParams: [10]
});
addFuncDef({
name: 'scale',
category: categories.Transform,
@@ -125,6 +156,25 @@ function (_) {
defaultParams: ['1h']
});
addFuncDef({
name: 'absolute',
category: categories.Transform,
});
addFuncDef({
name: 'averageAbove',
category: categories.Filter,
params: [ { name: "n", type: "int", } ],
defaultParams: [25]
});
addFuncDef({
name: 'averageBelow',
category: categories.Filter,
params: [ { name: "n", type: "int", } ],
defaultParams: [25]
});
_.each(categories, function(funcList, catName) {
categories[catName] = _.sortBy(funcList, 'name');
});
@@ -135,6 +185,19 @@ function (_) {
this.updateText();
}
FuncInstance.prototype.render = function (metricExp) {
var str = this.def.name + '(';
var parameters = _.map(this.params, function(value) {
return _.isString(value) ? "'" + value + "'" : value;
});
if (metricExp !== undefined) {
parameters.unshift(metricExp);
}
return str + parameters.join(',') + ')';
};
FuncInstance.prototype.updateText = function () {
if (this.params.length === 0) {
this.text = this.def.name + '()';