feature #3748: Add derivative for graphs

This commit is contained in:
Daniel Molina committed 2015-06-09 12:58:09 +02:00
1 parent d9ee6a91d3
commit 3116a6d8db
1 file changed
+19 -2
+19 -2
View File
@@ -14,9 +14,9 @@ define(function(require) {
CONSTRUCTOR
*/
return {
return {
'plot': _plotGraph
}
}
/*
FUNCTION DEFINITIONS
@@ -91,4 +91,21 @@ define(function(require) {
$.plot(info.div_graph, series, options);
};
}
function derivative(data) {
for (var i = 0; i < data.length - 1; i++) {
// Each elem is [timestamp, cumulative value]
var first = data[i];
var second = data[i + 1];
// value now - value before / seconds
var speed = (second[1] - first[1]) / (second[0] - first[0]);
// The first element is replaced with the second one
data[i] = [first[0], speed];
}
// The last elem must be removed
data.pop();
}
});