sort.js 1.1 KB

1234567891011121314151617181920212223242526
  1. export function quickSort(a) {
  2. 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]; })));
  3. }
  4. export var sortLayout = function (layout) {
  5. return [].concat(layout).sort(function (a, b) {
  6. if (a.GridY > b.GridY || (a.GridY === b.GridY && a.GridX > b.GridX)) {
  7. if (a.static)
  8. return 0; //为了静态,排序的时候尽量把静态的放在前面
  9. return 1;
  10. }
  11. else if (a.GridY === b.GridY && a.GridX === b.GridX) {
  12. return 0;
  13. }
  14. return -1;
  15. });
  16. };
  17. export var getMaxContainerHeight = function (layout, elementHeight, elementMarginBottom) {
  18. if (elementHeight === void 0) { elementHeight = 30; }
  19. if (elementMarginBottom === void 0) { elementMarginBottom = 10; }
  20. var ar = layout.map(function (item) {
  21. return item.GridY + item.h;
  22. });
  23. var h = quickSort(ar)[ar.length - 1];
  24. var height = h * (elementHeight + elementMarginBottom) + elementMarginBottom;
  25. return height;
  26. };