Update FloatingObject.js

This commit is contained in:
Luis Fernando Molina committed 2020-04-03 09:27:34 +02:00
1 parent 26194bee1e
commit bba470b075
1 file changed
+53 -19
+53 -19
View File
@@ -285,6 +285,8 @@ function newFloatingObject () {
}
function positionContraintsPhysics () {
const MAX_DISTANCE_TO_PARENT = 3000
if (thisObject.angleToParent !== ANGLE_TO_PARENT.NOT_FIXED && thisObject.isOnFocus !== true) {
let parent = thisObject.payload.chainParent
if (parent === undefined) { return }
@@ -318,6 +320,10 @@ function newFloatingObject () {
}
}
if (distanceToParent > MAX_DISTANCE_TO_PARENT) {
distanceToParent = MAX_DISTANCE_TO_PARENT
}
switch (thisObject.angleToParent) {
case ANGLE_TO_PARENT.RANGE_360:
angleToParentAngle = 360
@@ -361,53 +367,81 @@ function newFloatingObject () {
thisObject.payload.distance = distanceToParent
if (distanceToParent > 3000 || thisObject.isPinned === true) { return } // this is introduced to avoid edges cases when importing workspaces.
if (thisObject.isPinned === true) {
/* When an object is pinned, its angle to its parent needs to be calculated since it depends on where the user places the node. */
if (thisObject.payload.chainParent !== undefined) {
let x = thisObject.container.frame.position.x - thisObject.payload.chainParent.payload.floatingObject.container.frame.position.x
let y = thisObject.container.frame.position.y - thisObject.payload.chainParent.payload.floatingObject.container.frame.position.y
thisObject.payload.angle = Math.atan(y / x)
}
return
}
let newPosition = {
x: parent.payload.position.x,
y: parent.payload.position.y
}
let displacement
switch (thisObject.arrangementStyle) {
case ARRANGEMENT_STYLE.CONCAVE: {
newPosition = {
x: parent.payload.position.x + distanceToParent * Math.cos(toRadians(thisObject.payload.angle)),
y: parent.payload.position.y + distanceToParent * Math.sin(toRadians(thisObject.payload.angle))
displacement = {
x: distanceToParent * Math.cos(toRadians(thisObject.payload.angle)),
y: distanceToParent * Math.sin(toRadians(thisObject.payload.angle))
}
break
}
case ARRANGEMENT_STYLE.CONVEX: {
newPosition = {
x: parent.payload.position.x + 2 * distanceToParent * Math.cos(toRadians(lastParentAngle)) + distanceToParent * Math.cos(toRadians(thisObject.payload.angle + 180)),
y: parent.payload.position.y + 2 * distanceToParent * Math.sin(toRadians(lastParentAngle)) + distanceToParent * Math.sin(toRadians(thisObject.payload.angle + 180))
displacement = {
x: 2 * distanceToParent * Math.cos(toRadians(lastParentAngle)) + distanceToParent * Math.cos(toRadians(thisObject.payload.angle + 180)),
y: 2 * distanceToParent * Math.sin(toRadians(lastParentAngle)) + distanceToParent * Math.sin(toRadians(thisObject.payload.angle + 180))
}
break
}
case ARRANGEMENT_STYLE.HORIZONTAL_BOTTOM: {
newPosition = {
x: parent.payload.position.x + distanceToParent * Math.tan(toRadians(thisObject.payload.angle)),
y: parent.payload.position.y + distanceToParent
displacement = {
x: distanceToParent * Math.tan(toRadians(thisObject.payload.angle)),
y: distanceToParent
}
break
}
case ARRANGEMENT_STYLE.HORIZONTAL_TOP: {
newPosition = {
x: parent.payload.position.x - distanceToParent * Math.tan(toRadians(thisObject.payload.angle)),
y: parent.payload.position.y - distanceToParent
displacement = {
x: -distanceToParent * Math.tan(toRadians(thisObject.payload.angle)),
y: -distanceToParent
}
break
}
case ARRANGEMENT_STYLE.VERTICAL_RIGHT: {
newPosition = {
x: parent.payload.position.x + distanceToParent,
y: parent.payload.position.y + distanceToParent * Math.tan(toRadians(thisObject.payload.angle))
displacement = {
x: distanceToParent,
y: distanceToParent * Math.tan(toRadians(thisObject.payload.angle))
}
break
}
case ARRANGEMENT_STYLE.VERTICAL_LEFT: {
newPosition = {
x: parent.payload.position.x - distanceToParent,
y: parent.payload.position.y - distanceToParent * Math.tan(toRadians(thisObject.payload.angle))
displacement = {
x: -distanceToParent,
y: -distanceToParent * Math.tan(toRadians(thisObject.payload.angle))
}
break
}
}
if (displacement.x > MAX_DISTANCE_TO_PARENT) {
displacement.x = MAX_DISTANCE_TO_PARENT
}
if (displacement.y > MAX_DISTANCE_TO_PARENT) {
displacement.y = MAX_DISTANCE_TO_PARENT
}
newPosition.x = newPosition.x + displacement.x
newPosition.y = newPosition.y + displacement.y
if (isNaN(newPosition.x) === false) {
thisObject.container.frame.position.x = newPosition.x
}