Skip to content
This repository was archived by the owner on Jun 15, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/layout-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ var RowSpanCell = Cell.RowSpanCell;
var ColSpanCell = Cell.ColSpanCell;

(function(){
function scanForConflict(table, rowIndex, columnIndex, cell) {
for(var y = rowIndex; y >= 0; y--){
var row2 = table[y];
var xMax = (y === rowIndex) ? columnIndex : row2.length;
for(var x = 0; x < xMax; x++){
var cell2 = row2[x];
while(cellsConflict(cell,cell2)){
cell.x++;
}
}
}
}

function layoutTable(table){
table.forEach(function(row,rowIndex){
row.forEach(function(cell,columnIndex){
cell.y = rowIndex;
cell.x = columnIndex;
for(var y = rowIndex; y >= 0; y--){
var row2 = table[y];
var xMax = (y === rowIndex) ? columnIndex : row2.length;
for(var x = 0; x < xMax; x++){
var cell2 = row2[x];
while(cellsConflict(cell,cell2)){
cell.x++;
}
}
}

// Because the initial scan may leave some cells with the same coordinates we scan twice
scanForConflict(table, rowIndex, columnIndex, cell);
scanForConflict(table, rowIndex, columnIndex, cell);
});
});
}
Expand Down