From 959c1661784a9a4d08c18762aedc69e405e57506 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Mon, 21 Mar 2022 20:24:43 +1100 Subject: Add more adaptive min-cell-size for rect-layout --- src/components/TileTree.vue | 2 +- src/lib.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/TileTree.vue b/src/components/TileTree.vue index bdc3959..c57821d 100644 --- a/src/components/TileTree.vue +++ b/src/components/TileTree.vue @@ -27,7 +27,7 @@ const defaultLayoutOptions: LayoutOptions = { layoutType: 'sweep', //'sqr' | 'rect' | 'sweep' rectMode: 'auto', //'horz' | 'vert' | 'linear' | 'auto' sweepMode: 'left', //'left' | 'top' | 'shorter' | 'auto' - sweptNodesPrio: 'linear', //'linear' | 'sqrt' | 'pow-2/3' + sweptNodesPrio: 'pow-2/3', //'linear' | 'sqrt' | 'pow-2/3' sweepingToParent: true, }; const defaultOtherOptions = { diff --git a/src/lib.ts b/src/lib.ts index bee6c95..ddfc19d 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -276,6 +276,12 @@ let rectLayout: LayoutFn = function (node, pos, dims, showHeader, opts, ownOpts? let rowBrks: number[] = []; // Will hold indices for nodes at which each row starts let lowestEmpSpc = Number.POSITIVE_INFINITY, usedEmpRight = 0, usedEmpBottom = 0; let tempTree: LayoutNode = node.cloneNodeTree(); // Holds tentative layouts for 'node' + const minCellDims = [ // Can situationally assume non-leaf children + opts.minTileSz + opts.tileSpacing + + (opts.layoutType == 'sweep' ? opts.tileSpacing*2 : 0), + opts.minTileSz + opts.tileSpacing + + (opts.layoutType == 'sweep' ? opts.tileSpacing*2 + opts.headerSz : 0) + ]; rowBrksLoop: while (true){ // Update rowBrks or exit loop @@ -334,13 +340,13 @@ let rectLayout: LayoutFn = function (node, pos, dims, showHeader, opts, ownOpts? let cellHs = rowsOfCnts.map(rowOfCnts => arraySum(rowOfCnts) / totalDCount * newDims[1]); // Check min-tile-size, attempting to reallocate space if needed for (let rowIdx = 0; rowIdx < rowsOfCnts.length; rowIdx++){ - let newWs = limitVals(cellWs[rowIdx], opts.minTileSz + opts.tileSpacing, Number.POSITIVE_INFINITY); + let newWs = limitVals(cellWs[rowIdx], minCellDims[0], Number.POSITIVE_INFINITY); if (newWs == null){ continue rowBrksLoop; } cellWs[rowIdx] = newWs; } - cellHs = limitVals(cellHs, opts.minTileSz + opts.tileSpacing, Number.POSITIVE_INFINITY)!; + cellHs = limitVals(cellHs, minCellDims[1], Number.POSITIVE_INFINITY)!; if (cellHs == null){ continue rowBrksLoop; } -- cgit v1.2.3