From 46891ca052e6049252a560895af55301f5e37b19 Mon Sep 17 00:00:00 2001 From: Terry Truong Date: Tue, 26 Apr 2022 15:33:15 +1000 Subject: Add small sqrLayout optimisation --- src/layout.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/layout.ts') 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 -- cgit v1.2.3