Add delta() series transform function, closes #172.
This commit is contained in:
@@ -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) {
|
static groupByWrapper(interval, groupFunc, datapoints) {
|
||||||
var groupByCallback = DataProcessor.aggregationFunctions[groupFunc];
|
var groupByCallback = DataProcessor.aggregationFunctions[groupFunc];
|
||||||
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
|
return DataProcessor.groupBy(interval, groupByCallback, datapoints);
|
||||||
@@ -181,6 +191,7 @@ export default class DataProcessor {
|
|||||||
return {
|
return {
|
||||||
groupBy: this.groupByWrapper,
|
groupBy: this.groupByWrapper,
|
||||||
scale: this.scale,
|
scale: this.scale,
|
||||||
|
delta: this.delta,
|
||||||
aggregateBy: this.aggregateByWrapper,
|
aggregateBy: this.aggregateByWrapper,
|
||||||
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
average: _.partial(this.aggregateWrapper, this.AVERAGE),
|
||||||
min: _.partial(this.aggregateWrapper, this.MIN),
|
min: _.partial(this.aggregateWrapper, this.MIN),
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ addFuncDef({
|
|||||||
defaultParams: [100],
|
defaultParams: [100],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addFuncDef({
|
||||||
|
name: 'delta',
|
||||||
|
category: 'Transform',
|
||||||
|
params: [],
|
||||||
|
defaultParams: [],
|
||||||
|
});
|
||||||
|
|
||||||
addFuncDef({
|
addFuncDef({
|
||||||
name: 'sumSeries',
|
name: 'sumSeries',
|
||||||
category: 'Aggregate',
|
category: 'Aggregate',
|
||||||
|
|||||||
Reference in New Issue
Block a user