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) { diff --git a/platform/features/plot/src/PlotController.js b/platform/features/plot/src/PlotController.js index cf6bfcf581..4789f4c682 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,22 +203,39 @@ define( } } + function requery() { + self.pending = true; + releaseSubscription(); + subscribe($scope.domainObject); + } + + function updateDomainFormat() { + var domainAxis = $scope.axes[0]; + plotTelemetryFormatter + .setDomainFormat(domainAxis.active.format); + } + + function domainRequery(newDomain) { + if (newDomain !== lastDomain) { + updateDomainFormat(); + 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]; domainAxis.chooseOption(bounds.domain); - plotTelemetryFormatter - .setDomainFormat(domainAxis.active.format); - - self.pending = true; - releaseSubscription(); - subscribe($scope.domainObject); + updateDomainFormat(); setBasePanZoom(bounds); - } - - function updateDomainFormat(format) { - plotTelemetryFormatter.setDomainFormat(format); + requery(); } this.modeOptions = new PlotModeOptions([], subPlotFactory); @@ -237,6 +256,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); 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); + }); }); } ); diff --git a/platform/telemetry/src/TelemetrySubscription.js b/platform/telemetry/src/TelemetrySubscription.js index 5dcab54b94..3de00e4c37 100644 --- a/platform/telemetry/src/TelemetrySubscription.js +++ b/platform/telemetry/src/TelemetrySubscription.js @@ -285,11 +285,17 @@ 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) { - 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); }; /** @@ -302,11 +308,17 @@ 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) { - 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); }; /**