[Time Controller] Fix sine wave generation

Generate sine wave correctly when start time has been specified,
WTD-1515
This commit is contained in:
Victor Woeltjen 2015-09-04 14:24:45 -07:00
parent d158aa6028
commit 77d11e1bcf

View File

@ -29,31 +29,34 @@ define(
function () { function () {
"use strict"; "use strict";
var firstObservedTime = Date.now(); var firstObservedTime = Math.floor(Date.now() / 1000);
/** /**
* *
* @constructor * @constructor
*/ */
function SinewaveTelemetrySeries(request) { function SinewaveTelemetrySeries(request) {
var firstTime = (request || {}).start || firstObservedTime, var latestObservedTime = Math.floor(Date.now() / 1000),
latestObservedTime = Date.now(), count = latestObservedTime - firstObservedTime,
count = Math.floor((latestObservedTime - firstTime) / 1000),
period = request.period || 30, period = request.period || 30,
generatorData = {}; generatorData = {},
offset = (request.start !== undefined) ?
Math.floor(request.start / 1000) - firstObservedTime :
0;
generatorData.getPointCount = function () { generatorData.getPointCount = function () {
return count; return count - offset;
}; };
generatorData.getDomainValue = function (i, domain) { generatorData.getDomainValue = function (i, domain) {
return i * 1000 + return (i + offset) * 1000 +
(domain !== 'delta' ? firstTime : 0); (domain !== 'delta' ?
(firstObservedTime * 1000) : 0);
}; };
generatorData.getRangeValue = function (i, range) { generatorData.getRangeValue = function (i, range) {
range = range || "sin"; range = range || "sin";
return Math[range](i * Math.PI * 2 / period); return Math[range]((i + offset) * Math.PI * 2 / period);
}; };
return generatorData; return generatorData;