aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-03-16 13:24:16 +1100
committerTerry Truong <terry06890@gmail.com>2022-03-16 13:51:35 +1100
commitdf3f3cfbd130e3fec4edfe9f1e2bcb041e349101 (patch)
tree478e2609fe3627796492f107ce48c54726f18000 /src/lib.ts
parent96b9af4919e6f7eeeae1b5ae123f54bbbfad5a2f (diff)
Add swept-nodes-priority option
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/lib.ts b/src/lib.ts
index b23ccc0..e27b7d1 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -90,6 +90,7 @@ export type LayoutOptions = {
rectMode: 'horz' | 'vert' | 'linear' | 'auto';
rectSpaceShifting: boolean;
sweepMode: 'left' | 'top' | 'shorter' | 'auto';
+ sweptNodesPrio: 'linear' | 'sqrt' | 'sqrt-when-high';
sweepingToParent: boolean;
};
export class LayoutNode {
@@ -359,7 +360,17 @@ let sweepLayoutFn: LayoutFn = function (node, pos, dims, showHeader, opts, ownOp
} else if (leaves.length == 0){
return rectLayoutFn(node, pos, dims, showHeader, opts, {subLayoutFn:sweepLayoutFn});
} else {
- let ratio = leaves.length / (leaves.length + nonLeaves.map(n => n.dCount).reduce((x,y) => x+y));
+ let ratio: number, numNonLeaves = nonLeaves.map(n => n.dCount).reduce((x,y) => x+y);
+ if (opts.sweptNodesPrio == 'linear'){
+ ratio = leaves.length / (leaves.length + numNonLeaves);
+ } else if (opts.sweptNodesPrio == 'sqrt'){
+ ratio = Math.sqrt(leaves.length) / (Math.sqrt(leaves.length) + Math.sqrt(numNonLeaves));
+ } else {
+ ratio = (leaves.length < nonLeaves.length) ?
+ leaves.length / (leaves.length + numNonLeaves) :
+ Math.sqrt(leaves.length) / (Math.sqrt(leaves.length) + Math.sqrt(numNonLeaves));
+ }
+ //
let headerSz = showHeader ? opts.headerSz : 0;
let sweptLayout = null, nonLeavesLayout = null, sweptLeft = false;
//get swept-area layout