[Plot] Support fixed duration

Support a fixed duration for plots, WTD-1273.
This commit is contained in:
Victor Woeltjen 2015-06-20 10:28:49 -07:00
parent a82fea2166
commit fbf682d5fa
3 changed files with 52 additions and 13 deletions

View File

@ -99,7 +99,8 @@ define(
updater = new PlotUpdater(
handle,
($scope.axes[0].active || {}).key,
($scope.axes[1].active || {}).key
($scope.axes[1].active || {}).key,
15000 // 15 seconds
);
}
@ -161,7 +162,7 @@ define(
// Unsubscribe when the plot is destroyed
$scope.$on("$destroy", releaseSubscription);
// Create a throttled update function
scheduleUpdate = throttle(function () {
modeOptions.getModeHandler().getSubPlots()
@ -248,4 +249,4 @@ define(
return PlotController;
}
);
);

View File

@ -43,9 +43,9 @@ define(
var mid = Math.floor((min + max) / 2),
found = buffer[mid * 2];
// Collisions are not wanted
// On collisions, insert at same index
if (found === value) {
return -1;
return mid;
}
// Otherwise, if we're down to a single index,
@ -258,4 +258,4 @@ define(
return PlotLineBuffer;
}
);
);

View File

@ -42,8 +42,10 @@ define(
* @param {TelemetryHandle} handle the handle to telemetry access
* @param {string} domain the key to use when looking up domain values
* @param {string} range the key to use when looking up range values
* @param {number} maxDuration maximum plot duration to display
* @param {number} maxPoints maximum number of points to display
*/
function PlotUpdater(handle, domain, range, maxPoints) {
function PlotUpdater(handle, domain, range, fixedDuration, maxPoints) {
var ids = [],
lines = {},
dimensions = [0, 0],
@ -107,6 +109,7 @@ define(
lines = next;
}
// Initialize the domain offset, based on these observed values
function initializeDomainOffset(values) {
domainOffset =
@ -147,6 +150,35 @@ define(
[dimensionsOf(domainExtrema), 2.0 ] :
[dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)];
origin = [originOf(domainExtrema), originOf(rangeExtrema)];
if (fixedDuration !== undefined) {
origin[0] = Math.min(
origin[0],
origin[0] + dimensions[0] - fixedDuration
);
dimensions[0] = Math.max(dimensions[0], fixedDuration);
}
}
}
// Enforce maximum duration on all plot lines; not that
// domain extrema must be up-to-date for this to behave correctly.
function enforceDuration() {
var cutoff;
function enforceDurationForBuffer(plotLineBuffer) {
var index = plotLineBuffer.findInsertionIndex(cutoff);
if (index > 0) {
plotLineBuffer.trim(index);
}
}
if (fixedDuration !== undefined &&
domainExtrema !== undefined &&
(domainExtrema[1] - domainExtrema[0] > fixedDuration)) {
cutoff = domainExtrema[1] - fixedDuration;
bufferArray.forEach(enforceDurationForBuffer);
updateExtrema(); // Extrema may have changed now
}
}
@ -161,6 +193,12 @@ define(
}
}
// Update plot extremea and enforce maximum duration
function updateBounds() {
updateExtrema();
enforceDuration();
}
// Handle new telemetry data
function update() {
var objects = handle.getTelemetryObjects();
@ -180,8 +218,8 @@ define(
// Add new data
objects.forEach(addPointFor);
// Finally, update extrema
updateExtrema();
// Then, update extrema
updateBounds();
}
// Add historical data for this domain object
@ -213,12 +251,12 @@ define(
line.addSeries(series, domain, range);
}
// Finally, update extrema
updateExtrema();
// Update extrema
updateBounds();
}
// Use a default MAX_POINTS if none is provided
maxPoints = maxPoints || MAX_POINTS;
maxPoints = maxPoints !== undefined ? maxPoints : MAX_POINTS;
// Initially prepare state for these objects.
// Note that this may be an empty array at this time,
@ -290,4 +328,4 @@ define(
return PlotUpdater;
}
);
);