From ad6577b024a1d0a03faaf209c1a026ac6023d1f4 Mon Sep 17 00:00:00 2001 From: Hamza Date: Tue, 28 Mar 2023 17:41:03 +0300 Subject: [PATCH] update the initialization method --- src/hyse-layout.ts | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/hyse-layout.ts b/src/hyse-layout.ts index 221c90d..47736f8 100644 --- a/src/hyse-layout.ts +++ b/src/hyse-layout.ts @@ -345,42 +345,50 @@ export class HySELayout extends CoSELayout { let randomChildY= 0; if(left && up){ if(distanceUp < distanceLeft){ - randomChildY = mostTopNode.getCenterY() + (newNode.rect.y - Math.floor(Math.random() * newNode.rect.height)); - randomChildX = seedCenter.x + (newNode.rect.x - Math.floor(Math.random() * newNode.rect.width)); + //up + randomChildY = mostTopNode.rect.y - Math.floor(Math.random() * newNode.rect.height) -50; + randomChildX = seedCenter.x - (newNode.rect.width/2) + Math.floor(Math.random() * newNode.rect.width); } else{ - randomChildX = mostLeftNode.getCenterX() + (newNode.rect.x - Math.floor(Math.random() * newNode.rect.width)); - randomChildY = seedCenter.y ; + //left + randomChildX = mostLeftNode.rect.x - Math.floor(Math.random() * newNode.rect.width) -50; + randomChildY = seedCenter.y - (newNode.rect.height/2) + Math.floor(Math.random() * newNode.rect.height); } } else if(left && !up){ if(distanceDown < distanceLeft){ - randomChildY = mostBottomNode.getCenterY() + (newNode.rect.y + Math.floor(Math.random() * newNode.rect.height)); - randomChildX = seedCenter.x + (newNode.rect.x - Math.floor(Math.random() * newNode.rect.width)); + //down + randomChildY = mostBottomNode.rect.y + mostBottomNode.rect.height + Math.floor(Math.random() * newNode.rect.height) +50; + randomChildX = seedCenter.x - (newNode.rect.width/2) + Math.floor(Math.random() * newNode.rect.width); } else{ - randomChildX = mostLeftNode.getCenterX() + (newNode.rect.x - Math.floor(Math.random() * newNode.rect.width)); - randomChildY = seedCenter.y ; + //left + randomChildX = mostLeftNode.rect.x - Math.floor(Math.random() * newNode.rect.width) -100; + randomChildY = seedCenter.y - (newNode.rect.height/2) + Math.floor(Math.random() * newNode.rect.height); } } else if(!left && up){ if(distanceUp < distanceRight){ - randomChildY = mostTopNode.getCenterY() + (newNode.rect.y - Math.floor(Math.random() * newNode.rect.height)); - randomChildX = seedCenter.x + (newNode.rect.x + Math.floor(Math.random() * newNode.rect.width)); + //up + randomChildY = mostTopNode.rect.y - Math.floor(Math.random() * newNode.rect.height) -50; + randomChildX = seedCenter.x - (newNode.rect.width/2) + Math.floor(Math.random() * newNode.rect.width); } else{ - randomChildX = mostRightNode.getCenterX() + (newNode.rect.x + Math.floor(Math.random() * newNode.rect.width)); - randomChildY = seedCenter.y ; + //right + randomChildX = mostRightNode.rect.x + mostRightNode.rect.width + Math.floor(Math.random() * newNode.rect.width) +100; + randomChildY = seedCenter.y - (newNode.rect.height/2) + Math.floor(Math.random() * newNode.rect.height); } } else{ if(distanceDown < distanceRight){ - randomChildY = mostBottomNode.getCenterY() + (newNode.rect.y + Math.floor(Math.random() * newNode.rect.height)); - randomChildX = seedCenter.x + (newNode.rect.x + Math.floor(Math.random() * newNode.rect.width)); + //down + randomChildY = mostBottomNode.rect.y + mostBottomNode.rect.height + Math.floor(Math.random() * newNode.rect.height) +50; + randomChildX = seedCenter.x - (newNode.rect.width/2) + Math.floor(Math.random() * newNode.rect.width); } else{ - randomChildX = mostRightNode.getCenterX() + (newNode.rect.x + Math.floor(Math.random() * newNode.rect.width)); - randomChildY = seedCenter.y ; + //right + randomChildX = mostRightNode.rect.x + mostRightNode.rect.width + Math.floor(Math.random() * newNode.rect.width) +100; + randomChildY = seedCenter.y - (newNode.rect.height/2) + Math.floor(Math.random() * newNode.rect.height); } } //randomChildY = newNode.rect.height*Math.random() + seedCenter.y - newNode.rect.height/2;