mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 21:58:13 +00:00
[Plot] Amend plot updater
Amend plot updater to correctly expose information for real-time plotting without history, allowing removal of cache to free memory; WTD-751.
This commit is contained in:
@ -31,7 +31,8 @@ define(
|
|||||||
domainOffset,
|
domainOffset,
|
||||||
buffers = {},
|
buffers = {},
|
||||||
lengths = {},
|
lengths = {},
|
||||||
bufferArray;
|
lengthArray = [],
|
||||||
|
bufferArray = [];
|
||||||
|
|
||||||
function ensureBufferSize(buffer, id, index) {
|
function ensureBufferSize(buffer, id, index) {
|
||||||
// Check if we don't have enough room
|
// Check if we don't have enough room
|
||||||
@ -52,11 +53,16 @@ define(
|
|||||||
|
|
||||||
function addData(obj) {
|
function addData(obj) {
|
||||||
var id = obj.getId(),
|
var id = obj.getId(),
|
||||||
index = lengths[id],
|
index = lengths[id] || 0,
|
||||||
buffer = buffers[id],
|
buffer = buffers[id],
|
||||||
domainValue = subscription.getDomainValue(obj),
|
domainValue = subscription.getDomainValue(obj),
|
||||||
rangeValue = subscription.getRangeValue(obj);
|
rangeValue = subscription.getRangeValue(obj);
|
||||||
|
|
||||||
|
if (!buffer) {
|
||||||
|
buffer = new Float32Array(INITIAL_SIZE);
|
||||||
|
buffers[id] = buffer;
|
||||||
|
}
|
||||||
|
|
||||||
if (domainValue !== undefined && rangeValue !== undefined &&
|
if (domainValue !== undefined && rangeValue !== undefined &&
|
||||||
(index < 1 || domainValue !== buffer[index * 2 - 2])) {
|
(index < 1 || domainValue !== buffer[index * 2 - 2])) {
|
||||||
// Use the first observed domain value as a domainOffset
|
// Use the first observed domain value as a domainOffset
|
||||||
@ -86,31 +92,28 @@ define(
|
|||||||
var id = obj.getId(),
|
var id = obj.getId(),
|
||||||
buffer = buffers[id],
|
buffer = buffers[id],
|
||||||
length = lengths[id],
|
length = lengths[id],
|
||||||
value = buffer[length * 2 - 2] + domainOffset;
|
low = buffer[0] + domainOffset,
|
||||||
max[0] = Math.max(value, max[0]);
|
high = buffer[length * 2 - 2] + domainOffset;
|
||||||
min[0] = Math.min(value, min[0]);
|
max[0] = Math.max(high, max[0]);
|
||||||
|
min[0] = Math.min(low, min[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function padRange() {
|
|
||||||
// If range is empty, add some padding
|
|
||||||
if (max[1] === min[1]) {
|
|
||||||
max[1] = max[1] + 1.0;
|
|
||||||
min[1] = min[1] - 1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
var objects = subscription.getTelemetryObjects();
|
var objects = subscription.getTelemetryObjects();
|
||||||
bufferArray = objects.map(addData);
|
bufferArray = objects.map(addData);
|
||||||
|
lengthArray = objects.map(function (obj) {
|
||||||
|
return lengths[obj.getId()];
|
||||||
|
});
|
||||||
updateDomainExtrema(objects);
|
updateDomainExtrema(objects);
|
||||||
padRange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare(telemetryObject) {
|
function prepare(telemetryObject) {
|
||||||
var id = telemetryObject.getId();
|
var id = telemetryObject.getId();
|
||||||
lengths[id] = 0;
|
lengths[id] = 0;
|
||||||
buffers[id] = new Float32Array(INITIAL_SIZE);
|
buffers[id] = new Float32Array(INITIAL_SIZE);
|
||||||
|
lengthArray.push(lengths[id]);
|
||||||
|
bufferArray.push(buffers[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscription.getTelemetryObjects().forEach(prepare);
|
subscription.getTelemetryObjects().forEach(prepare);
|
||||||
@ -123,7 +126,10 @@ define(
|
|||||||
* @returns {number[]} the dimensions which bound this data set
|
* @returns {number[]} the dimensions which bound this data set
|
||||||
*/
|
*/
|
||||||
getDimensions: function () {
|
getDimensions: function () {
|
||||||
return [max[0] - min[0], max[1] - min[1]];
|
// Pad range if necessary
|
||||||
|
return (max[1] === min[1]) ?
|
||||||
|
[max[0] - min[0], 2.0 ] :
|
||||||
|
[max[0] - min[0], max[1] - min[1]];
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get the origin of this data set's boundary.
|
* Get the origin of this data set's boundary.
|
||||||
@ -133,7 +139,8 @@ define(
|
|||||||
* @returns {number[]} the origin of this data set's boundary
|
* @returns {number[]} the origin of this data set's boundary
|
||||||
*/
|
*/
|
||||||
getOrigin: function () {
|
getOrigin: function () {
|
||||||
return min;
|
// Pad range if necessary
|
||||||
|
return (max[1] === min[1]) ? [ min[0], min[1] - 1.0 ] : min;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get the domain offset; this offset will have been subtracted
|
* Get the domain offset; this offset will have been subtracted
|
||||||
@ -163,7 +170,10 @@ define(
|
|||||||
* @returns {Float32Array[]} the buffers for these traces
|
* @returns {Float32Array[]} the buffers for these traces
|
||||||
*/
|
*/
|
||||||
getBuffers: function () {
|
getBuffers: function () {
|
||||||
return buffers;
|
return bufferArray;
|
||||||
|
},
|
||||||
|
getLength: function (index) {
|
||||||
|
return lengthArray;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Update with latest data.
|
* Update with latest data.
|
||||||
|
Reference in New Issue
Block a user