From ae7a1618e819d7aea63bd43428f1feb4d02e4f27 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 15:16:47 -0800 Subject: [PATCH] [Plot] Listen for domain/range changes nasa/openmctweb#218 --- platform/features/plot/src/PlotController.js | 50 ++++++++++++++------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index cf6bfcf581..3cc5392049 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -78,6 +78,8 @@ define( cachedObjects = [], updater, lastBounds, + lastRange, + lastDomain, handle; // Populate the scope with axis information (specifically, options @@ -120,16 +122,16 @@ define( // Reinstantiate the plot updater (e.g. because we have a // new subscription.) This will clear the plot. function recreateUpdater() { - updater = new PlotUpdater( - handle, - ($scope.axes[0].active || {}).key, - ($scope.axes[1].active || {}).key, - PLOT_FIXED_DURATION - ); - self.limitTracker = new PlotLimitTracker( - handle, - ($scope.axes[1].active || {}).key - ); + var domain = ($scope.axes[0].active || {}).key, + range = ($scope.axes[1].active || {}).key, + duration = PLOT_FIXED_DURATION; + + updater = new PlotUpdater(handle, domain, range, duration); + lastDomain = domain; + lastRange = range; + + self.limitTracker = new PlotLimitTracker(handle, range); + // Keep any externally-provided bounds if (lastBounds) { setBasePanZoom(lastBounds); @@ -201,6 +203,24 @@ define( } } + function requery() { + self.pending = true; + releaseSubscription(); + subscribe($scope.domainObject); + } + + function domainRequery(newDomain) { + if (newDomain !== lastDomain) { + requery(); + } + } + + function rangeRequery(newRange) { + if (newRange !== lastRange) { + requery(); + } + } + // Respond to a display bounds change (requery for data) function changeDisplayBounds(event, bounds) { var domainAxis = $scope.axes[0]; @@ -208,13 +228,11 @@ define( domainAxis.chooseOption(bounds.domain); plotTelemetryFormatter .setDomainFormat(domainAxis.active.format); - - self.pending = true; - releaseSubscription(); - subscribe($scope.domainObject); setBasePanZoom(bounds); + requery(); } + function updateDomainFormat(format) { plotTelemetryFormatter.setDomainFormat(format); } @@ -237,6 +255,10 @@ define( new PlotAxis("ranges", [], AXIS_DEFAULTS[1]) ]; + // Watch for changes to the selected axis + $scope.$watch("axes[0].active.key", domainRequery); + $scope.$watch("axes[1].active.key", rangeRequery); + // Subscribe to telemetry when a domain object becomes available $scope.$watch('domainObject', subscribe);