mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 13:44:21 +00:00
[Plot] Spec for PlotController
Fill in spec for PlotController, which is the primary handler of logic associated with plot views, transitioned for WTD-533.
This commit is contained in:
parent
c9300e8611
commit
ad802e674e
@ -84,13 +84,26 @@ define(
|
|||||||
tickGenerator.generateRangeTicks(RANGE_TICKS);
|
tickGenerator.generateRangeTicks(RANGE_TICKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
function plotTelemetry(telemetry) {
|
function setupAxes(metadatas) {
|
||||||
var prepared, data;
|
$scope.axes = [
|
||||||
|
new PlotAxis("domain", metadatas, AXIS_DEFAULTS[0]),
|
||||||
|
new PlotAxis("range", metadatas, AXIS_DEFAULTS[1])
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function plotTelemetry() {
|
||||||
|
var prepared, data, telemetry;
|
||||||
|
|
||||||
|
telemetry = $scope.telemetry;
|
||||||
|
|
||||||
if (!telemetry) {
|
if (!telemetry) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$scope.axes) {
|
||||||
|
setupAxes(telemetry.getMetadata());
|
||||||
|
}
|
||||||
|
|
||||||
data = telemetry.getResponse();
|
data = telemetry.getResponse();
|
||||||
|
|
||||||
prepared = new PlotPreparer(
|
prepared = new PlotPreparer(
|
||||||
@ -119,13 +132,6 @@ define(
|
|||||||
updateTicks();
|
updateTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupAxes(metadatas) {
|
|
||||||
$scope.axes = [
|
|
||||||
new PlotAxis("domain", metadatas, AXIS_DEFAULTS[0]),
|
|
||||||
new PlotAxis("range", metadatas, AXIS_DEFAULTS[1])
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
function toMousePosition($event) {
|
function toMousePosition($event) {
|
||||||
var target = $event.target,
|
var target = $event.target,
|
||||||
bounds = target.getBoundingClientRect();
|
bounds = target.getBoundingClientRect();
|
||||||
|
@ -10,13 +10,43 @@ define(
|
|||||||
|
|
||||||
describe("The plot controller", function () {
|
describe("The plot controller", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
|
mockTelemetry, // mock telemetry controller
|
||||||
|
mockData,
|
||||||
|
mockElement,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
|
function echo(i) { return i; }
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockScope = jasmine.createSpyObj(
|
mockScope = jasmine.createSpyObj(
|
||||||
"$scope",
|
"$scope",
|
||||||
[ "$watch", "$on" ]
|
[ "$watch", "$on" ]
|
||||||
);
|
);
|
||||||
|
mockTelemetry = jasmine.createSpyObj(
|
||||||
|
"telemetry",
|
||||||
|
[ "getResponse", "getMetadata" ]
|
||||||
|
);
|
||||||
|
mockData = jasmine.createSpyObj(
|
||||||
|
"data",
|
||||||
|
[ "getPointCount", "getDomainValue", "getRangeValue" ]
|
||||||
|
);
|
||||||
|
mockElement = jasmine.createSpyObj(
|
||||||
|
"element",
|
||||||
|
[ "getBoundingClientRect" ]
|
||||||
|
);
|
||||||
|
|
||||||
|
mockScope.telemetry = mockTelemetry;
|
||||||
|
mockTelemetry.getResponse.andReturn([mockData]);
|
||||||
|
mockData.getPointCount.andReturn(2);
|
||||||
|
mockData.getDomainValue.andCallFake(echo);
|
||||||
|
mockData.getRangeValue.andCallFake(echo);
|
||||||
|
mockElement.getBoundingClientRect.andReturn({
|
||||||
|
left: 0,
|
||||||
|
top: 0,
|
||||||
|
width: 100,
|
||||||
|
height: 100
|
||||||
|
});
|
||||||
|
|
||||||
controller = new PlotController(mockScope);
|
controller = new PlotController(mockScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -27,6 +57,139 @@ define(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides plot colors", function () {
|
||||||
|
// PlotPalette will have its own tests
|
||||||
|
expect(controller.getColor(0))
|
||||||
|
.toEqual(jasmine.any(String));
|
||||||
|
|
||||||
|
// Colors should be unique
|
||||||
|
expect(controller.getColor(0))
|
||||||
|
.not.toEqual(controller.getColor(1));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("draws lines when telemetry data becomes available", function () {
|
||||||
|
// Broadcast data
|
||||||
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
// Should have put some lines in the drawing scope,
|
||||||
|
// which the template should pass along to the renderer
|
||||||
|
expect(mockScope.draw.lines).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not fail if telemetry controller is not in scope", function () {
|
||||||
|
mockScope.telemetry = undefined;
|
||||||
|
|
||||||
|
// Broadcast data
|
||||||
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
|
|
||||||
|
// Just want to not have an exception
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides coordinates on hover", function () {
|
||||||
|
expect(controller.getHoverCoordinates().length).toEqual(0);
|
||||||
|
|
||||||
|
controller.hover({
|
||||||
|
target: mockElement
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(controller.getHoverCoordinates().length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("permits marquee zoom", function () {
|
||||||
|
// Verify pre-condition
|
||||||
|
expect(controller.isZoomed()).toBeFalsy();
|
||||||
|
|
||||||
|
// Simulate a marquee zoom interaction
|
||||||
|
controller.startMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.hover({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.endMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 10,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(controller.isZoomed()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("permits unøom", function () {
|
||||||
|
// Simulate a marquee zoom interaction
|
||||||
|
controller.startMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 10
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.hover({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.endMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 10,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify precondition
|
||||||
|
expect(controller.isZoomed()).toBeTruthy();
|
||||||
|
|
||||||
|
// Perform the unzoom
|
||||||
|
controller.unzoom();
|
||||||
|
|
||||||
|
// Should no longer report as zoomed
|
||||||
|
expect(controller.isZoomed()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("permits unøom", function () {
|
||||||
|
// Simulate two marquee zooms interaction
|
||||||
|
[0, 1].forEach(function (n) {
|
||||||
|
controller.startMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 10 + 10 * n
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.hover({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 0,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
controller.endMarquee({
|
||||||
|
target: mockElement,
|
||||||
|
clientX: 10 + 10 * n,
|
||||||
|
clientY: 0
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Verify precondition
|
||||||
|
expect(controller.isZoomed()).toBeTruthy();
|
||||||
|
|
||||||
|
// Step back...
|
||||||
|
controller.stepBackPanZoom();
|
||||||
|
|
||||||
|
// Should still be zoomed
|
||||||
|
expect(controller.isZoomed()).toBeTruthy();
|
||||||
|
|
||||||
|
// Step back again...
|
||||||
|
controller.stepBackPanZoom();
|
||||||
|
|
||||||
|
// Should no longer report as zoomed
|
||||||
|
expect(controller.isZoomed()).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user