diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-04-26 15:33:15 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-04-26 18:03:56 +1000 |
| commit | 46891ca052e6049252a560895af55301f5e37b19 (patch) | |
| tree | 5dcac087c16845f02a10af36ebdbb34871e55fb1 /src/layout.ts | |
| parent | de55b59141a82c68b6a5b360d6f57a7e760e2fd6 (diff) | |
Add small sqrLayout optimisation
Diffstat (limited to 'src/layout.ts')
| -rw-r--r-- | src/layout.ts | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/layout.ts b/src/layout.ts index 6f1fd77..fd65b87 100644 --- a/src/layout.ts +++ b/src/layout.ts @@ -8,7 +8,7 @@ import {TolNode} from './tol'; import type {TolMap} from './tol'; -import {range, arraySum, limitVals, updateAscSeq} from './util'; +import {range, arraySum, linspace, limitVals, updateAscSeq} from './util'; // Represents a node/tree that holds layout data for a TolNode node/tree export class LayoutNode { @@ -276,7 +276,10 @@ let sqrLayout: LayoutFn = function (node, pos, dims, showHeader, allowCollapse, let numChildren = node.children.length; let areaAR = newDims[0] / newDims[1]; // Aspect ratio let lowestEmpSpc = Number.POSITIVE_INFINITY, usedNumCols = 0, usedNumRows = 0, usedTileSz = 0; - for (let numCols = 1; numCols <= numChildren; numCols++){ + const MAX_TRIES = 10; // If there are many possibilities, skip some + let ptlNumCols = numChildren == 1 ? [1] : + linspace(1, numChildren, Math.min(numChildren, MAX_TRIES)).map(n => Math.floor(n)); + for (let numCols of ptlNumCols){ let numRows = Math.ceil(numChildren / numCols); let gridAR = numCols / numRows; let usedFrac = // Fraction of area occupied by maximally-fitting grid |
