Add delta() series transform function, closes #172.

This commit is contained in:
Alexander Zobnin
2016-09-24 10:33:47 +03:00
parent 8df8e66cbd
commit f44fce8d75
2 changed files with 18 additions and 0 deletions

View File

@@ -151,6 +151,16 @@ export default class DataProcessor {
});
}
static delta(datapoints) {
let newSeries = [];
let deltaValue;
for (var i = 1; i < datapoints.length; i++) {
deltaValue = datapoints[i][0] - datapoints[i - 1][0];
newSeries.push([deltaValue, datapoints[i][1]]);
}
return newSeries;
}
static groupByWrapper(interval, groupFunc, datapoints) {
var groupByCallback = DataProcessor.aggregationFunctions[groupFunc];
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
@@ -181,6 +191,7 @@ export default class DataProcessor {
return {
groupBy: this.groupByWrapper,
scale: this.scale,
delta: this.delta,
aggregateBy: this.aggregateByWrapper,
average: _.partial(this.aggregateWrapper, this.AVERAGE),
min: _.partial(this.aggregateWrapper, this.MIN),

View File

@@ -39,6 +39,13 @@ addFuncDef({
defaultParams: [100],
});
addFuncDef({
name: 'delta',
category: 'Transform',
params: [],
defaultParams: [],
});
addFuncDef({
name: 'sumSeries',
category: 'Aggregate',