Merge remote-tracking branch 'nasa/open-master' into open-master

This commit is contained in:
Victor Woeltjen 2015-06-29 15:10:02 -07:00
commit 87f982b03e
3 changed files with 29 additions and 78 deletions

View File

@ -20,14 +20,13 @@
at runtime from the About dialog for additional information.
-->
<div class="t-fixed-position l-fixed-position"
ng-controller="FixedController as controller"
mct-resize="controller.setBounds(bounds)">
ng-controller="FixedController as controller">
<!-- Background grid -->
<div class="l-grid-holder" ng-click="controller.clearSelection()">
<div class="l-grid l-grid-x"
<div class="l-grid l-grid-x"
ng-style="{ 'background-size': controller.getGridSize() [0] + 'px 100%' }"></div>
<div class="l-grid l-grid-y"
<div class="l-grid l-grid-y"
ng-style="{ 'background-size': '100% ' + controller.getGridSize() [1] + 'px' }"></div>
</div>
@ -60,4 +59,4 @@
</div>
</span>
</div>
</div>

View File

@ -27,8 +27,7 @@ define(
"use strict";
var DEFAULT_DIMENSIONS = [ 2, 1 ],
DEFAULT_GRID_SIZE = [64, 16],
DEFAULT_GRID_EXTENT = [4, 4];
DEFAULT_GRID_SIZE = [64, 16];
/**
* The FixedController is responsible for supporting the
@ -40,10 +39,8 @@ define(
*/
function FixedController($scope, $q, dialogService, telemetrySubscriber, telemetryFormatter) {
var gridSize = DEFAULT_GRID_SIZE,
gridExtent = DEFAULT_GRID_EXTENT,
dragging,
subscription,
cellStyles = [],
elementProxies = [],
names = {}, // Cache names by ID
values = {}, // Cache values by ID
@ -52,29 +49,6 @@ define(
moveHandle,
selection;
// Refresh cell styles (e.g. because grid extent changed)
function refreshCellStyles() {
var x, y;
// Clear previous styles
cellStyles = [];
// Update grid size from model
gridSize = ($scope.model || {}).layoutGrid || gridSize;
for (x = 0; x < gridExtent[0]; x += 1) {
for (y = 0; y < gridExtent[1]; y += 1) {
// Position blocks; subtract out border size from w/h
cellStyles.push({
left: x * gridSize[0] + 'px',
top: y * gridSize[1] + 'px',
width: gridSize[0] - 1 + 'px',
height: gridSize[1] - 1 + 'px'
});
}
}
}
// Convert from element x/y/width/height to an
// apropriate ng-style argument, to position elements.
function convertPosition(elementProxy) {
@ -143,6 +117,16 @@ define(
}
}
// Update element positions when grid size changes
function updateElementPositions(layoutGrid) {
// Update grid size from model
gridSize = layoutGrid || DEFAULT_GRID_SIZE;
elementProxies.forEach(function (elementProxy) {
elementProxy.style = convertPosition(elementProxy);
});
}
// Update telemetry values based on new data available
function updateValues() {
if (subscription) {
@ -289,6 +273,9 @@ define(
// Position panes when the model field changes
$scope.$watch("model.composition", updateComposition);
// Detect changes to grid size
$scope.$watch("model.layoutGrid", updateElementPositions);
// Subscribe to telemetry when an object is available
$scope.$watch("domainObject", subscribe);
@ -298,19 +285,7 @@ define(
// Position panes where they are dropped
$scope.$on("mctDrop", handleDrop);
// Initialize styles (position etc.) for cells
refreshCellStyles();
return {
/**
* Get styles for all background cells, as will populate the
* ng-style tag.
* @memberof FixedController#
* @returns {Array} cell styles
*/
getCellStyles: function () {
return cellStyles;
},
/**
* Get the size of the grid, in pixels. The returned array
* is in the form `[x, y]`.
@ -319,19 +294,6 @@ define(
getGridSize: function () {
return gridSize;
},
/**
* Set the size of the viewable fixed position area.
* @memberof FixedController#
* @param bounds the width/height, as reported by mct-resize
*/
setBounds: function (bounds) {
var w = Math.ceil(bounds.width / gridSize[0]),
h = Math.ceil(bounds.height / gridSize[1]);
if (w !== gridExtent[0] || h !== gridExtent[1]) {
gridExtent = [w, h];
refreshCellStyles();
}
},
/**
* Get an array of elements in this panel; these are
* decorated proxies for both selection and display.

View File

@ -142,11 +142,6 @@ define(
);
});
it("provides styles for cells", function () {
expect(controller.getCellStyles())
.toEqual(jasmine.any(Array));
});
it("subscribes when a domain object is available", function () {
mockScope.domainObject = mockDomainObject;
findWatch("domainObject")(mockDomainObject);
@ -271,25 +266,19 @@ define(
expect(elements[2].value).toEqual("Formatted 31.42");
});
it("adds grid cells to fill boundaries", function () {
var s1 = {
width: testGrid[0] * 8,
height: testGrid[1] * 4
},
s2 = {
width: testGrid[0] * 10,
height: testGrid[1] * 6
};
it("updates elements styles when grid size changes", function () {
var originalLeft;
mockScope.domainObject = mockDomainObject;
mockScope.model = testModel;
findWatch("domainObject")(mockDomainObject);
findWatch("model.modified")(1);
findWatch("model.composition")(mockScope.model.composition);
// Set first bounds
controller.setBounds(s1);
expect(controller.getCellStyles().length).toEqual(32); // 8 * 4
// Set new bounds
controller.setBounds(s2);
expect(controller.getCellStyles().length).toEqual(60); // 10 * 6
findWatch("model.layoutGrid")([10, 10]);
originalLeft = controller.getElements()[0].style.left;
findWatch("model.layoutGrid")([20, 20]);
expect(controller.getElements()[0].style.left)
.not.toEqual(originalLeft);
});
it("listens for drop events", function () {
@ -352,6 +341,7 @@ define(
});
it("exposes its grid size", function () {
findWatch('model.layoutGrid')(testGrid);
// Template needs to be able to pass this into line
// elements to size SVGs appropriately
expect(controller.getGridSize()).toEqual(testGrid);