sort.js 1.2 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. function quickSort(a) {
  4. return a.length <= 1 ? a : quickSort(a.slice(1).filter(function (item) { return item <= a[0]; })).concat(a[0], quickSort(a.slice(1).filter(function (item) { return item > a[0]; })));
  5. }
  6. exports.quickSort = quickSort;
  7. exports.sortLayout = function (layout) {
  8. return [].concat(layout).sort(function (a, b) {
  9. if (a.GridY > b.GridY || (a.GridY === b.GridY && a.GridX > b.GridX)) {
  10. if (a.static)
  11. return 0; //为了静态,排序的时候尽量把静态的放在前面
  12. return 1;
  13. }
  14. else if (a.GridY === b.GridY && a.GridX === b.GridX) {
  15. return 0;
  16. }
  17. return -1;
  18. });
  19. };
  20. exports.getMaxContainerHeight = function (layout, elementHeight, elementMarginBottom) {
  21. if (elementHeight === void 0) { elementHeight = 30; }
  22. if (elementMarginBottom === void 0) { elementMarginBottom = 10; }
  23. var ar = layout.map(function (item) {
  24. return item.GridY + item.h;
  25. });
  26. var h = quickSort(ar)[ar.length - 1];
  27. var height = h * (elementHeight + elementMarginBottom) + elementMarginBottom;
  28. return height;
  29. };