From ae7a1618e819d7aea63bd43428f1feb4d02e4f27 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 15:16:47 -0800 Subject: [PATCH 1/7] [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); From a88fadcb491bb1a942c34501ca8dfbebb73903d4 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 16:02:18 -0800 Subject: [PATCH 2/7] [Plot] Allow lookup of alternate ranges --- .../telemetry/src/TelemetrySubscription.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/platform/telemetry/src/TelemetrySubscription.js b/platform/telemetry/src/TelemetrySubscription.js index 5dcab54b94..71e1273dec 100644 --- a/platform/telemetry/src/TelemetrySubscription.js +++ b/platform/telemetry/src/TelemetrySubscription.js @@ -287,9 +287,12 @@ define( * @param {DomainObject} domainObject the object of interest * @returns the most recent domain value observed */ - TelemetrySubscription.prototype.getDomainValue = function (domainObject) { - var id = domainObject.getId(); - return (this.latestValues[id] || {}).domain; + TelemetrySubscription.prototype.getDomainValue = function (domainObject, key) { + var id = domainObject.getId(), + latestValue = this.latestValues[id]; + return latestValue && (key ? + latestValue.datum[key] : + latestValue.domain); }; /** @@ -304,9 +307,12 @@ define( * @param {DomainObject} domainObject the object of interest * @returns the most recent range value observed */ - TelemetrySubscription.prototype.getRangeValue = function (domainObject) { - var id = domainObject.getId(); - return (this.latestValues[id] || {}).range; + TelemetrySubscription.prototype.getRangeValue = function (domainObject, key) { + var id = domainObject.getId(), + latestValue = this.latestValues[id]; + return latestValue && (key ? + latestValue.datum[key] : + latestValue.range); }; /** From d60bf94501d6e5be971f9334c89437156a2092e9 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 16:03:42 -0800 Subject: [PATCH 3/7] [Plot] Remove unnecessary fallback --- platform/features/plot/src/PlotController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index 3cc5392049..84350fe646 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -122,8 +122,8 @@ define( // Reinstantiate the plot updater (e.g. because we have a // new subscription.) This will clear the plot. function recreateUpdater() { - var domain = ($scope.axes[0].active || {}).key, - range = ($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); From b30e72081cc61c075a0ae0b7a1cddd801de6f053 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 16:12:16 -0800 Subject: [PATCH 4/7] [Plot] Update domain format ...on change in user's domain selection. --- platform/features/plot/src/PlotController.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index 84350fe646..4789f4c682 100644 --- a/platform/features/plot/src/PlotController.js +++ b/platform/features/plot/src/PlotController.js @@ -209,8 +209,15 @@ define( subscribe($scope.domainObject); } + function updateDomainFormat() { + var domainAxis = $scope.axes[0]; + plotTelemetryFormatter + .setDomainFormat(domainAxis.active.format); + } + function domainRequery(newDomain) { if (newDomain !== lastDomain) { + updateDomainFormat(); requery(); } } @@ -226,17 +233,11 @@ define( var domainAxis = $scope.axes[0]; domainAxis.chooseOption(bounds.domain); - plotTelemetryFormatter - .setDomainFormat(domainAxis.active.format); + updateDomainFormat(); setBasePanZoom(bounds); requery(); } - - function updateDomainFormat(format) { - plotTelemetryFormatter.setDomainFormat(format); - } - this.modeOptions = new PlotModeOptions([], subPlotFactory); this.updateValues = updateValues; From 7dc6f553ac22ab7fed73d844b4947b8fa5ff657e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 16:12:34 -0800 Subject: [PATCH 5/7] [Plot] Expose alternate domain values correctly ...from example telemetry (sine wave generator), to support testing of switching among domains within plot. --- example/generator/src/SinewaveTelemetrySeries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/generator/src/SinewaveTelemetrySeries.js b/example/generator/src/SinewaveTelemetrySeries.js index fa47f8f59a..8643b0429b 100644 --- a/example/generator/src/SinewaveTelemetrySeries.js +++ b/example/generator/src/SinewaveTelemetrySeries.js @@ -62,7 +62,7 @@ define( // so it's not checked for here, just formatted for display // differently. return (i + offset) * 1000 + firstTime * 1000 - - (domain === 'yesterday' ? ONE_DAY : 0); + (domain === 'yesterday' ? (ONE_DAY * 1000) : 0); }; generatorData.getRangeValue = function (i, range) { From 93d969ad671636ff9b81d2ad7d71fb556dc4044f Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 10 Nov 2015 16:17:43 -0800 Subject: [PATCH 6/7] [Plot] Add tests ...to verify that data is requeried when user changes domain or range selection. --- .../features/plot/test/PlotControllerSpec.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/platform/features/plot/test/PlotControllerSpec.js b/platform/features/plot/test/PlotControllerSpec.js index addbdf5032..8edab2fc6d 100644 --- a/platform/features/plot/test/PlotControllerSpec.js +++ b/platform/features/plot/test/PlotControllerSpec.js @@ -53,6 +53,14 @@ define( }); } + function fireWatch(expr, value) { + mockScope.$watch.calls.forEach(function (call) { + if (call.args[0] === expr) { + call.args[1].apply(null, [value]); + } + }); + } + beforeEach(function () { mockScope = jasmine.createSpyObj( @@ -263,6 +271,20 @@ define( ]); expect(mockHandle.request.calls.length).toEqual(2); }); + + it("requeries when user changes domain selection", function () { + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + expect(mockHandle.request.calls.length).toEqual(1); + fireWatch("axes[0].active.key", 'someNewKey'); + expect(mockHandle.request.calls.length).toEqual(2); + }); + + it("requeries when user changes range selection", function () { + mockScope.$watch.mostRecentCall.args[1](mockDomainObject); + expect(mockHandle.request.calls.length).toEqual(1); + fireWatch("axes[1].active.key", 'someNewKey'); + expect(mockHandle.request.calls.length).toEqual(2); + }); }); } ); From a9518e9890cb53353da550b3cb9b32075a908833 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 18 Nov 2015 10:50:32 -0800 Subject: [PATCH 7/7] [Telemetry] Add missing JSDoc ...for new parameters added to support domain/range switching in plots, per code review on nasa/openmctweb#288 --- platform/telemetry/src/TelemetrySubscription.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/telemetry/src/TelemetrySubscription.js b/platform/telemetry/src/TelemetrySubscription.js index 71e1273dec..3de00e4c37 100644 --- a/platform/telemetry/src/TelemetrySubscription.js +++ b/platform/telemetry/src/TelemetrySubscription.js @@ -285,6 +285,9 @@ define( * domain objects returned by `getTelemetryObjects()`. * * @param {DomainObject} domainObject the object of interest + * @param {string} [key] the symbolic identifier of the domain + * to look up; if omitted, the value for this object's + * default domain will be used * @returns the most recent domain value observed */ TelemetrySubscription.prototype.getDomainValue = function (domainObject, key) { @@ -305,6 +308,9 @@ define( * domain objects returned by `getTelemetryObjects()`. * * @param {DomainObject} domainObject the object of interest + * @param {string} [key] the symbolic identifier of the range + * to look up; if omitted, the value for this object's + * default range will be used * @returns the most recent range value observed */ TelemetrySubscription.prototype.getRangeValue = function (domainObject, key) {