(layout: Layout, verticalCompact: Boolean, minPositions)
| 79 | * @return {Array} Compacted Layout. |
| 80 | */ |
| 81 | export function compact(layout: Layout, verticalCompact: Boolean, minPositions): Layout { |
| 82 | // Statics go in the compareWith array right away so items flow around them. |
| 83 | const compareWith = getStatics(layout); |
| 84 | // We go through the items by row and column. |
| 85 | const sorted = sortLayoutItemsByRowCol(layout); |
| 86 | // Holding for new items. |
| 87 | const out = Array(layout.length); |
| 88 | |
| 89 | for (let i = 0, len = sorted.length; i < len; i++) { |
| 90 | let l = sorted[i]; |
| 91 | |
| 92 | // Don't move static elements |
| 93 | if (!l.static) { |
| 94 | l = compactItem(compareWith, l, verticalCompact, minPositions); |
| 95 | |
| 96 | // Add to comparison array. We only collide with items before this one. |
| 97 | // Statics are already in this array. |
| 98 | compareWith.push(l); |
| 99 | } |
| 100 | |
| 101 | // Add to output array to make sure they still come out in the right order. |
| 102 | out[layout.indexOf(l)] = l; |
| 103 | |
| 104 | // Clear moved flag, if it exists. |
| 105 | l.moved = false; |
| 106 | } |
| 107 | |
| 108 | return out; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Compact an item in the layout. |
searching dependent graphs…