Merge branch 'master' into open199

This commit is contained in:
Henry
2015-11-19 14:29:32 -08:00
14 changed files with 216 additions and 51 deletions

View File

@ -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);

View File

@ -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);
});
});
}
);