Skip to content
This repository has been archived by the owner on Jun 15, 2019. It is now read-only.

Commit

Permalink
Merge d797a38 into 6b07944
Browse files Browse the repository at this point in the history
  • Loading branch information
realityking committed Jul 7, 2017
2 parents 6b07944 + d797a38 commit 40fd014
Showing 1 changed file with 17 additions and 10 deletions.
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

0 comments on commit 40fd014

Please sign in to comment.