aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-03-07 12:04:51 +1100
committerTerry Truong <terry06890@gmail.com>2022-03-07 12:04:51 +1100
commitd5203b2bdf4f479253b5dab7dbb0d42968a64190 (patch)
tree537f08c983c0d933040cbe2c29d927fa79199686
parentebfc9bc988edc4d49807a066df03886269fb7962 (diff)
Enable sweep-to-side to use all four directionsfour-directional-sweep
-rw-r--r--src/layout.js43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/layout.js b/src/layout.js
index 6c86662..a9bbf67 100644
--- a/src/layout.js
+++ b/src/layout.js
@@ -225,20 +225,41 @@ const sweepToSideLayout = {
} else {
let ratio = leaves.length / (leaves.length + nonLeaves.map(e => e.tileCount).reduce((x,y) => x+y));
let hOffset = (hideHeader ? 0 : this.HEADER_SZ);
+ //determine leaf-node average-center-point
+ let rectLayout = staticRectLayout.genLayout(nodes, x0, y0, w, h, hideHeader);
+ let leafNames = leaves.map(node => node.tolNode.name);
+ let leafCenters = leafNames.map(name => {
+ let coords = rectLayout.coords[name];
+ return [coords.x + coords.w/2, coords.y + coords.h/2];
+ });
+ let avgLeafCenter = leafCenters.reduce((x,y) => [x[0]+x[1], y[0]+y[1]]).map(x => x / leafCenters.length);
+ let rightness = (avgLeafCenter[0] - x0) / w;
+ let bottomness = (avgLeafCenter[1] - y0) / h;
//get swept-area layout
let area = {x: x0, y: y0+hOffset, w: w, h: h-hOffset};
- let leftLayout = staticSqrLayout.genLayout(leaves, area.x, area.y, area.w*ratio, area.h, true);
- let topLayout = staticSqrLayout.genLayout(leaves, area.x, area.y, area.w, area.h*ratio, true);
- //let sweptLayout = leftLayout;
- let sweptLayout = (leftLayout.w*leftLayout.h > topLayout.w*topLayout.h) ? leftLayout : topLayout;
- //get remaining-area layout
- if (sweptLayout == leftLayout){
- area.x += leftLayout.w - this.TILE_SPACING;
- area.w += -leftLayout.w + this.TILE_SPACING;
- } else {
- area.y += topLayout.h - this.TILE_SPACING;
- area.h += -topLayout.h + this.TILE_SPACING;
+ let sweptLayout;
+ if (rightness <= 0.5 && rightness <= bottomness){ //sweep left
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x, area.y, area.w*ratio, area.h, true);
+ area.x += sweptLayout.w - this.TILE_SPACING;
+ area.w += -sweptLayout.w + this.TILE_SPACING;
+ } else if (rightness > 0.5 && rightness >= bottomness){ //sweep right
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x + area.w*(1-ratio), area.y,
+ area.w*ratio, area.h, true);
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x + area.w - sweptLayout.w, area.y,
+ sweptLayout.w, area.h, true);
+ area.w += -sweptLayout.w + this.TILE_SPACING;
+ } else if (bottomness <= 0.5){ //sweep upward
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x, area.y, area.w, area.h*ratio, true);
+ area.y += sweptLayout.h - this.TILE_SPACING;
+ area.h += -sweptLayout.h + this.TILE_SPACING;
+ } else { //sweep downward
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x, area.y + area.h*(1-ratio),
+ area.w, area.h*ratio, true);
+ sweptLayout = staticSqrLayout.genLayout(leaves, area.x, area.y + area.h - sweptLayout.h,
+ area.w, sweptLayout.h, true);
+ area.h += -sweptLayout.h + this.TILE_SPACING;
}
+ //get remaining-area layout
let nonLeavesLayout = staticRectLayout.genLayout(nonLeaves, area.x, area.y, area.w, area.h, true);
//return combined layout
return {coords: {...sweptLayout.coords, ...nonLeavesLayout.coords}, w: w, h: h};