mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 05:38:12 +00:00
[Plot] Separate out pan/zoom stack
Create a separate script/class for the pan-zoom stack, to simplify PlotController for testability and maintainability. WTD-533.
This commit is contained in:
@ -4,8 +4,13 @@
|
|||||||
* Module defining PlotController. Created by vwoeltje on 11/12/14.
|
* Module defining PlotController. Created by vwoeltje on 11/12/14.
|
||||||
*/
|
*/
|
||||||
define(
|
define(
|
||||||
["./PlotPreparer", "./PlotPalette", "../lib/moment.min.js"],
|
[
|
||||||
function (PlotPreparer, PlotPalette) {
|
"./PlotPreparer",
|
||||||
|
"./PlotPalette",
|
||||||
|
"./PlotPanZoomStack",
|
||||||
|
"../lib/moment.min.js"
|
||||||
|
],
|
||||||
|
function (PlotPreparer, PlotPalette, PlotPanZoomStack) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var AXIS_DEFAULTS = [
|
var AXIS_DEFAULTS = [
|
||||||
@ -22,10 +27,7 @@ define(
|
|||||||
function PlotController($scope) {
|
function PlotController($scope) {
|
||||||
var mousePosition,
|
var mousePosition,
|
||||||
marqueeStart,
|
marqueeStart,
|
||||||
panZoomStack = [{
|
panZoomStack = new PlotPanZoomStack([], []),
|
||||||
dimensions: [],
|
|
||||||
origin: []
|
|
||||||
}],
|
|
||||||
domainOffset;
|
domainOffset;
|
||||||
|
|
||||||
function formatDomainValue(v) {
|
function formatDomainValue(v) {
|
||||||
@ -44,8 +46,8 @@ define(
|
|||||||
|
|
||||||
|
|
||||||
function pixelToDomainRange(x, y, width, height, domainOffset) {
|
function pixelToDomainRange(x, y, width, height, domainOffset) {
|
||||||
var panZoom = panZoomStack[panZoomStack.length - 1],
|
var panZoom = panZoomStack.getPanZoom(),
|
||||||
offset = [ domainOffset || 0, 0],
|
offset = [ domainOffset || 0, 0 ],
|
||||||
origin = panZoom.origin,
|
origin = panZoom.origin,
|
||||||
dimensions = panZoom.dimensions;
|
dimensions = panZoom.dimensions;
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateDrawingBounds() {
|
function updateDrawingBounds() {
|
||||||
var panZoom = panZoomStack[panZoomStack.length - 1];
|
var panZoom = panZoomStack.getPanZoom();
|
||||||
|
|
||||||
$scope.draw.dimensions = panZoom.dimensions;
|
$scope.draw.dimensions = panZoom.dimensions;
|
||||||
$scope.draw.origin = panZoom.origin;
|
$scope.draw.origin = panZoom.origin;
|
||||||
@ -129,10 +131,10 @@ define(
|
|||||||
formatRangeValue
|
formatRangeValue
|
||||||
);
|
);
|
||||||
|
|
||||||
panZoomStack[0] = {
|
panZoomStack.setBasePanZoom(
|
||||||
origin: prepared.getOrigin(),
|
prepared.getOrigin(),
|
||||||
dimensions: prepared.getDimensions()
|
prepared.getDimensions()
|
||||||
};
|
);
|
||||||
|
|
||||||
domainOffset = prepared.getDomainOffset();
|
domainOffset = prepared.getDomainOffset();
|
||||||
|
|
||||||
@ -207,10 +209,7 @@ define(
|
|||||||
Math.max(a[1], b[1]) - origin[1]
|
Math.max(a[1], b[1]) - origin[1]
|
||||||
];
|
];
|
||||||
|
|
||||||
panZoomStack.push({
|
panZoomStack.pushPanZoom(origin, dimensions);
|
||||||
origin: origin,
|
|
||||||
dimensions: dimensions
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.axes = [ {}, {} ];
|
$scope.axes = [ {}, {} ];
|
||||||
@ -249,16 +248,14 @@ define(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
isZoomed: function () {
|
isZoomed: function () {
|
||||||
return panZoomStack.length > 1;
|
return panZoomStack.getDepth() > 1;
|
||||||
},
|
},
|
||||||
stepBackPanZoom: function () {
|
stepBackPanZoom: function () {
|
||||||
if (panZoomStack.length > 1) {
|
panZoomStack.popPanZoom();
|
||||||
panZoomStack.pop();
|
updateDrawingBounds();
|
||||||
updateDrawingBounds();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
unzoom: function () {
|
unzoom: function () {
|
||||||
panZoomStack = [panZoomStack[0]];
|
panZoomStack.clearPanZoom();
|
||||||
updateDrawingBounds();
|
updateDrawingBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
59
platform/features/plot/src/PlotPanZoomStack.js
Normal file
59
platform/features/plot/src/PlotPanZoomStack.js
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*global define*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
[],
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function PlotPanZoomStack(origin, dimensions) {
|
||||||
|
var stack = [{ origin: origin, dimensions: dimensions }];
|
||||||
|
|
||||||
|
function getDepth() {
|
||||||
|
return stack.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pushPanZoom(origin, dimensions) {
|
||||||
|
stack.push({ origin: origin, dimensions: dimensions });
|
||||||
|
}
|
||||||
|
|
||||||
|
function popPanZoom() {
|
||||||
|
if (stack.length > 1) {
|
||||||
|
stack.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearPanZoom() {
|
||||||
|
stack = [stack[0]];
|
||||||
|
}
|
||||||
|
|
||||||
|
function setBasePanZoom(origin, dimensions) {
|
||||||
|
stack[0] = { origin: origin, dimensions: dimensions };
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPanZoom() {
|
||||||
|
return stack[stack.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getOrigin() {
|
||||||
|
return getPanZoom().origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDimensions() {
|
||||||
|
return getPanZoom().dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getDepth: getDepth,
|
||||||
|
pushPanZoom: pushPanZoom,
|
||||||
|
popPanZoom: popPanZoom,
|
||||||
|
setBasePanZoom: setBasePanZoom,
|
||||||
|
clearPanZoom: clearPanZoom,
|
||||||
|
getPanZoom: getPanZoom,
|
||||||
|
getOrigin: getOrigin,
|
||||||
|
getDimensions: getDimensions
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return PlotPanZoomStack;
|
||||||
|
}
|
||||||
|
);
|
Reference in New Issue
Block a user