aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/layout.ts7
-rw-r--r--src/util.ts9
2 files changed, 14 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
diff --git a/src/util.ts b/src/util.ts
index be31102..a698d23 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -10,6 +10,15 @@ export function range(len: number): number[] {
export function arraySum(array: number[]): number {
return array.reduce((x,y) => x+y);
}
+// Returns an array of increasing evenly-spaced numbers from 'start' to 'end' with size 'size'
+export function linspace(start: number, end: number, size: number): number[] {
+ let step = (end - start) / (size - 1);
+ let ar = [];
+ for (let i = 0; i < size; i++){
+ ar.push(start + step * i);
+ }
+ return ar;
+}
// Returns array copy with vals clipped to within [min,max], redistributing to compensate
// Returns null on failure
export function limitVals(arr: number[], min: number, max: number): number[] | null {