From d797a38d63d18442e578a6a7e369ddb2a1bad670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Fri, 7 Jul 2017 21:28:59 +0200 Subject: [PATCH] Fixes #21 rowSpan on first two columns causes extra cells on the right --- src/layout-manager.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/layout-manager.js b/src/layout-manager.js index 098df3a..e02973d 100644 --- a/src/layout-manager.js +++ b/src/layout-manager.js @@ -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); }); }); }