( compareWith: Layout, l: LayoutItem, cols: number, fullLayout: Layout )
| 129 | * @returns The compacted item |
| 130 | */ |
| 131 | export function compactItemHorizontal( |
| 132 | compareWith: Layout, |
| 133 | l: LayoutItem, |
| 134 | cols: number, |
| 135 | fullLayout: Layout |
| 136 | ): LayoutItem { |
| 137 | // Correct negative positions first |
| 138 | (l as Mutable<LayoutItem>).x = Math.max(l.x, 0); |
| 139 | (l as Mutable<LayoutItem>).y = Math.max(l.y, 0); |
| 140 | |
| 141 | // Move left as far as possible |
| 142 | while (l.x > 0 && !getFirstCollision(compareWith, l)) { |
| 143 | (l as Mutable<LayoutItem>).x--; |
| 144 | } |
| 145 | |
| 146 | // Resolve collisions |
| 147 | let collision: LayoutItem | undefined; |
| 148 | while ((collision = getFirstCollision(compareWith, l)) !== undefined) { |
| 149 | resolveCompactionCollision(fullLayout, l, collision.x + collision.w, "x"); |
| 150 | |
| 151 | // Horizontal overflow: wrap to next row |
| 152 | if (l.x + l.w > cols) { |
| 153 | (l as Mutable<LayoutItem>).x = cols - l.w; |
| 154 | (l as Mutable<LayoutItem>).y++; |
| 155 | |
| 156 | while (l.x > 0 && !getFirstCollision(compareWith, l)) { |
| 157 | (l as Mutable<LayoutItem>).x--; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | (l as Mutable<LayoutItem>).x = Math.max(l.x, 0); |
| 163 | return l; |
| 164 | } |
| 165 | |
| 166 | // ============================================================================ |
| 167 | // Vertical Compactor |
no test coverage detected
searching dependent graphs…