[Plot] Begin integrating with telemetry handler

Miscellaneous tweaks and fixes to begin showing merged
real-time and historical telemetry, WTD-806.
This commit is contained in:
Victor Woeltjen
2015-04-17 14:53:21 -07:00
parent 5cc89e7983
commit 8ba9c0553a
6 changed files with 54 additions and 30 deletions

View File

@ -22,7 +22,7 @@
{ {
"key": "PlotController", "key": "PlotController",
"implementation": "PlotController.js", "implementation": "PlotController.js",
"depends": [ "$scope", "telemetryFormatter", "telemetrySubscriber" ] "depends": [ "$scope", "telemetryFormatter", "telemetryHandler" ]
} }
] ]
} }

View File

@ -13,8 +13,8 @@ define(
var count = seriesWindow.getPointCount(); var count = seriesWindow.getPointCount();
function doInsert() { function doInsert() {
var firstTimestamp = buffer.getDomainValue(0), var firstTimestamp = seriesWindow.getDomainValue(0),
lastTimestamp = buffer.getDomainValue(count - 1), lastTimestamp = seriesWindow.getDomainValue(count - 1),
startIndex = buffer.findInsertionIndex(firstTimestamp), startIndex = buffer.findInsertionIndex(firstTimestamp),
endIndex = buffer.findInsertionIndex(lastTimestamp); endIndex = buffer.findInsertionIndex(lastTimestamp);
@ -51,8 +51,16 @@ define(
* @param {number} rangeValue the range value * @param {number} rangeValue the range value
*/ */
addPoint: function (domainValue, rangeValue) { addPoint: function (domainValue, rangeValue) {
var index = buffer.findInsertionIndex(domainValue); var index;
if (index > -1) { // Make sure we got real/useful values here...
if (domainValue !== undefined && rangeValue !== undefined) {
index = buffer.findInsertionIndex(domainValue);
// Already in the buffer? Skip insertion
if (index < 0) {
return;
}
// Insert the point // Insert the point
if (!buffer.insertPoint(domainValue, rangeValue, index)) { if (!buffer.insertPoint(domainValue, rangeValue, index)) {
// If insertion failed, trim from the beginning... // If insertion failed, trim from the beginning...

View File

@ -75,10 +75,8 @@ define(
buffer[index * 2 + 1] = rangeValue; buffer[index * 2 + 1] = rangeValue;
// Track min/max of range values (min/max for // Track min/max of range values (min/max for
// domain values can be read directly from buffer) // domain values can be read directly from buffer)
rangeExtrema = [ rangeExtrema[0] = Math.min(rangeExtrema[0], rangeValue);
Math.min(rangeExtrema[0], rangeValue), rangeExtrema[1] = Math.max(rangeExtrema[1], rangeValue);
Math.max(rangeExtrema[1], rangeValue)
];
} }
return { return {

View File

@ -41,5 +41,7 @@ define(
} }
}; };
} }
return PlotSeriesWindow;
} }
); );

View File

@ -58,13 +58,14 @@ define(
return; return;
} }
// Update list of ids in use
ids = nextIds;
// Built up a set of ids. Note that we can only // Built up a set of ids. Note that we can only
// create plot lines after our domain offset has // create plot lines after our domain offset has
// been determined. // been determined.
if (domainOffset !== undefined) { if (domainOffset !== undefined) {
// Update list of ids in use
ids = nextIds;
// Create buffers for these objects
bufferArray = ids.map(function (id) { bufferArray = ids.map(function (id) {
var buffer = new PlotLineBuffer( var buffer = new PlotLineBuffer(
domainOffset, domainOffset,
@ -112,18 +113,31 @@ define(
// Update dimensions and origin based on extrema of plots // Update dimensions and origin based on extrema of plots
function updateExtrema() { function updateExtrema() {
domainExtrema = bufferArray.map(function (lineBuffer) { if (bufferArray.length > 0) {
return lineBuffer.getDomainExtrema(); domainExtrema = bufferArray.map(function (lineBuffer) {
}).reduce(reduceExtrema); return lineBuffer.getDomainExtrema();
}).reduce(reduceExtrema);
rangeExtrema = bufferArray.map(function (lineBuffer) { rangeExtrema = bufferArray.map(function (lineBuffer) {
return lineBuffer.getRangeExtrema(); return lineBuffer.getRangeExtrema();
}).reduce(reduceExtrema); }).reduce(reduceExtrema);
dimensions = (rangeExtrema[0] === rangeExtrema[1]) ? dimensions = (rangeExtrema[0] === rangeExtrema[1]) ?
[dimensionsOf(domainExtrema), 2.0 ] : [dimensionsOf(domainExtrema), 2.0 ] :
[dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)]; [dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)];
origin = [originOf(domainExtrema), originOf(rangeExtrema)]; origin = [originOf(domainExtrema), originOf(rangeExtrema)];
}
}
// Add latest data for this domain object
function addPointFor(domainObject) {
var line = lines[domainObject.getId()];
if (line) {
line.addPoint(
handle.getDomainValue(domainObject, domain),
handle.getRangeValue(domainObject, range)
);
}
} }
// Handle new telemetry data // Handle new telemetry data
@ -134,6 +148,8 @@ define(
if (domainOffset === undefined) { if (domainOffset === undefined) {
initializeDomainOffset(objects.map(function (obj) { initializeDomainOffset(objects.map(function (obj) {
return handle.getDomainValue(obj, domain); return handle.getDomainValue(obj, domain);
}).filter(function (value) {
return typeof value === 'number';
})); }));
} }
@ -141,12 +157,7 @@ define(
prepareLines(objects); prepareLines(objects);
// Add new data // Add new data
objects.forEach(function (obj, index) { objects.forEach(addPointFor);
lines[obj.getId()].addPoint(
handle.getDomainValue(obj, domain),
handle.getRangeValue(obj, range)
);
});
// Finally, update extrema // Finally, update extrema
updateExtrema(); updateExtrema();
@ -154,7 +165,7 @@ define(
// Add historical data for this domain object // Add historical data for this domain object
function setHistorical(domainObject, series) { function setHistorical(domainObject, series) {
var count = series.getPointCount(), var count = series ? series.getPointCount() : 0,
line; line;
// Nothing to do if it's an empty series // Nothing to do if it's an empty series
@ -163,7 +174,7 @@ define(
} }
// Initialize domain offset if necessary // Initialize domain offset if necessary
if (domainOffset === undefined && series) { if (domainOffset === undefined) {
initializeDomainOffset([ initializeDomainOffset([
series.getDomainValue(0, domain), series.getDomainValue(0, domain),
series.getDomainValue(count - 1, domain) series.getDomainValue(count - 1, domain)

View File

@ -43,6 +43,11 @@
"key": "telemetrySubscriber", "key": "telemetrySubscriber",
"implementation": "TelemetrySubscriber.js", "implementation": "TelemetrySubscriber.js",
"depends": [ "$q", "$timeout" ] "depends": [ "$q", "$timeout" ]
},
{
"key": "telemetryHandler",
"implementation": "TelemetryHandler.js",
"depends": [ "$q", "telemetrySubscriber" ]
} }
], ],
"licenses": [ "licenses": [