Merge remote-tracking branch 'origin/open1273' into open-1340

This commit is contained in:
larkin
2015-06-26 15:03:19 -07:00
10 changed files with 176 additions and 44 deletions

View File

@ -51,7 +51,13 @@ define(
*
* @constructor
*/
function PlotController($scope, telemetryFormatter, telemetryHandler, throttle) {
function PlotController(
$scope,
telemetryFormatter,
telemetryHandler,
throttle,
PLOT_FIXED_DURATION
) {
var subPlotFactory = new SubPlotFactory(telemetryFormatter),
modeOptions = new PlotModeOptions([], subPlotFactory),
subplots = [],
@ -99,7 +105,8 @@ define(
updater = new PlotUpdater(
handle,
($scope.axes[0].active || {}).key,
($scope.axes[1].active || {}).key
($scope.axes[1].active || {}).key,
PLOT_FIXED_DURATION
);
}
@ -161,7 +168,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 +255,4 @@ define(
return PlotController;
}
);
);

View File

@ -56,6 +56,9 @@ define(
domainOffset,
mousePosition,
marqueeStart,
panStart,
panStartBounds,
subPlotBounds,
hoverCoordinates,
isHovering = false;
@ -88,8 +91,7 @@ define(
// pixel coordinates in the canvas area) from a mouse
// event object.
function toMousePosition($event) {
var target = $event.target,
bounds = target.getBoundingClientRect();
var bounds = subPlotBounds;
return {
x: $event.clientX - bounds.left,
@ -155,6 +157,25 @@ define(
tickGenerator.generateRangeTicks(RANGE_TICKS);
}
function updatePan() {
var start, current, delta, nextOrigin;
// Clear the previous panning pan-zoom state
panZoomStack.popPanZoom();
// Calculate what the new resulting pan-zoom should be
start = mousePositionToDomainRange(panStart);
current = mousePositionToDomainRange(mousePosition);
delta = [ current[0] - start[0], current[1] - start[1] ];
nextOrigin = [
panStartBounds.origin[0] - delta[0],
panStartBounds.origin[1] - delta[1]
];
// ...and push a new one at the current mouse position
panZoomStack.pushPanZoom(nextOrigin, panStartBounds.dimensions);
}
// Perform a marquee zoom.
function marqueeZoom(start, end) {
@ -241,31 +262,77 @@ define(
*/
hover: function ($event) {
isHovering = true;
subPlotBounds = $event.target.getBoundingClientRect();
mousePosition = toMousePosition($event);
updateHoverCoordinates();
if (marqueeStart) {
updateMarqueeBox();
}
if (panStart) {
updatePan();
updateDrawingBounds();
updateTicks();
}
},
/**
* Continue a previously-start pan or zoom gesture.
* @param $event the mouse event
*/
continueDrag: function ($event) {
mousePosition = toMousePosition($event);
if (marqueeStart) {
updateMarqueeBox();
}
if (panStart) {
updatePan();
updateDrawingBounds();
updateTicks();
}
},
/**
* Initiate a marquee zoom action.
* @param $event the mouse event
*/
startMarquee: function ($event) {
mousePosition = marqueeStart = toMousePosition($event);
updateMarqueeBox();
startDrag: function ($event) {
subPlotBounds = $event.target.getBoundingClientRect();
mousePosition = toMousePosition($event);
// Treat any modifier key as a pan
if ($event.altKey || $event.shiftKey || $event.ctrlKey) {
// Start panning
panStart = mousePosition;
panStartBounds = panZoomStack.getPanZoom();
// We're starting a pan, so add this back as a
// state on the stack; it will get replaced
// during the pan.
panZoomStack.pushPanZoom(
panStartBounds.origin,
panStartBounds.dimensions
);
$event.preventDefault();
} else {
// Start marquee zooming
marqueeStart = mousePosition;
updateMarqueeBox();
}
},
/**
* Complete a marquee zoom action.
* @param $event the mouse event
*/
endMarquee: function ($event) {
endDrag: function ($event) {
mousePosition = toMousePosition($event);
subPlotBounds = undefined;
if (marqueeStart) {
marqueeZoom(marqueeStart, mousePosition);
marqueeStart = undefined;
updateMarqueeBox();
updateDrawingBounds();
updateTicks();
}
if (panStart) {
// End panning
panStart = undefined;
panStartBounds = undefined;
}
},
/**
@ -311,4 +378,4 @@ define(
return SubPlot;
}
);
);

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 =
@ -133,7 +136,7 @@ define(
}
// Update dimensions and origin based on extrema of plots
function updateExtrema() {
function updateBounds() {
if (bufferArray.length > 0) {
domainExtrema = bufferArray.map(function (lineBuffer) {
return lineBuffer.getDomainExtrema();
@ -143,10 +146,40 @@ define(
return lineBuffer.getRangeExtrema();
}).reduce(reduceExtrema);
// Calculate best-fit dimensions
dimensions = (rangeExtrema[0] === rangeExtrema[1]) ?
[dimensionsOf(domainExtrema), 2.0 ] :
[dimensionsOf(domainExtrema), dimensionsOf(rangeExtrema)];
origin = [originOf(domainExtrema), originOf(rangeExtrema)];
// ...then enforce a fixed duration if needed
if (fixedDuration !== undefined) {
origin[0] = origin[0] + dimensions[0] - fixedDuration;
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) {
// Leave one point untrimmed, such that line will
// continue off left edge of visible plot area.
plotLineBuffer.trim(index - 1);
}
}
if (fixedDuration !== undefined &&
domainExtrema !== undefined &&
(domainExtrema[1] - domainExtrema[0] > fixedDuration)) {
cutoff = domainExtrema[1] - fixedDuration;
bufferArray.forEach(enforceDurationForBuffer);
updateBounds(); // Extrema may have changed now
}
}
@ -180,8 +213,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 +246,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 +323,4 @@ define(
return PlotUpdater;
}
);
);