From c2985d61b7723b0fab74d4343d90aa05018afdbf Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 4 Sep 2015 13:57:26 -0700 Subject: [PATCH] [Plot] Follow universal time controller Follow displayable area of universal time controller, WTD-1515 --- platform/features/plot/src/PlotController.js | 15 ++++++- .../src/elements/PlotPanZoomStackGroup.js | 3 +- .../features/plot/src/elements/PlotUpdater.js | 41 ++++++++++++++++--- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index a54fff83dd..be126e2ed2 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -138,6 +138,16 @@ define( } } + // Change the displayable bounds + function setBasePanZoom(event, bounds) { + var start = bounds.start, + end = bounds.end; + if (updater) { + updater.setDomainBounds(start, end); + self.update(); + } + } + // Create a new subscription; telemetrySubscriber gets // to do the meaningful work here. function subscribe(domainObject) { @@ -172,11 +182,14 @@ define( this.scheduleUpdate = throttle(function () { self.modeOptions.getModeHandler().getSubPlots() .forEach(updateSubplot); - }); + }, 50); // Subscribe to telemetry when a domain object becomes available $scope.$watch('domainObject', subscribe); + // Respond to external bounds changes + $scope.$on("telemetry:display:bounds", setBasePanZoom); + // Unsubscribe when the plot is destroyed $scope.$on("$destroy", releaseSubscription); diff --git a/platform/features/plot/src/elements/PlotPanZoomStackGroup.js b/platform/features/plot/src/elements/PlotPanZoomStackGroup.js index 3746958ecb..e1b61a06eb 100644 --- a/platform/features/plot/src/elements/PlotPanZoomStackGroup.js +++ b/platform/features/plot/src/elements/PlotPanZoomStackGroup.js @@ -143,8 +143,7 @@ define( PlotPanZoomStackGroup.prototype.getDepth = function () { // All stacks are kept in sync, so look up depth // from the first one. - return this.stacks.length > 0 ? - this.stacks[0].getDepth() : 0; + return this.stacks.length > 0 ? this.stacks[0].getDepth() : 0; }; /** diff --git a/platform/features/plot/src/elements/PlotUpdater.js b/platform/features/plot/src/elements/PlotUpdater.js index 851fa56096..c30786986d 100644 --- a/platform/features/plot/src/elements/PlotUpdater.js +++ b/platform/features/plot/src/elements/PlotUpdater.js @@ -141,10 +141,10 @@ define( PlotUpdater.prototype.initializeDomainOffset = function (values) { this.domainOffset = ((this.domainOffset === undefined) && (values.length > 0)) ? - (values.reduce(function (a, b) { - return (a || 0) + (b || 0); - }, 0) / values.length) : - this.domainOffset; + (values.reduce(function (a, b) { + return (a || 0) + (b || 0); + }, 0) / values.length) : + this.domainOffset; }; // Expand range slightly so points near edges are visible @@ -159,7 +159,10 @@ define( // Update dimensions and origin based on extrema of plots PlotUpdater.prototype.updateBounds = function () { - var bufferArray = this.bufferArray; + var bufferArray = this.bufferArray, + priorDomainOrigin = this.origin[0], + priorDomainDimensions = this.dimensions[0]; + if (bufferArray.length > 0) { this.domainExtrema = bufferArray.map(function (lineBuffer) { return lineBuffer.getDomainExtrema(); @@ -178,6 +181,18 @@ define( // Enforce some minimum visible area this.expandRange(); + // Suppress domain changes when pinned + if (this.hasSpecificDomainBounds) { + this.origin[0] = priorDomainOrigin; + this.dimensions[0] = priorDomainDimensions; + if (this.following) { + this.origin[0] = Math.max( + this.domainExtrema[1] - this.dimensions[0], + this.origin[0] + ); + } + } + // ...then enforce a fixed duration if needed if (this.fixedDuration !== undefined) { this.origin[0] = this.origin[0] + this.dimensions[0] - @@ -281,6 +296,22 @@ define( return this.bufferArray; }; + /** + * Set the start and end boundaries (usually time) for the + * domain axis of this updater. + */ + PlotUpdater.prototype.setDomainBounds = function (start, end) { + this.fixedDuration = end - start; + this.origin[0] = start; + this.dimensions[0] = this.fixedDuration; + + // Suppress follow behavior if we have windowed in on the past + this.hasSpecificDomainBounds = true; + this.following = end >= this.domainExtrema[1]; + + this.updateBounds(); + }; + /** * Fill in historical data. */