fix(core): prevent expandParent from moving parent node while expanding

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2022-12-20 00:17:54 +01:00
committed by Braks
parent 20682800e8
commit b4daeb6d8d
+20 -11
View File
@@ -1,3 +1,4 @@
import { isFunction, isString } from '@vueuse/core'
import type { import type {
Edge, Edge,
EdgeAddChange, EdgeAddChange,
@@ -22,14 +23,15 @@ function handleParentExpand(updateItem: GraphNode, parent: GraphNode) {
const extendHeight = updateItem.position.y + updateItem.dimensions.height - parent.dimensions.height const extendHeight = updateItem.position.y + updateItem.dimensions.height - parent.dimensions.height
if (extendWidth > 0 || extendHeight > 0 || updateItem.position.x < 0 || updateItem.position.y < 0) { if (extendWidth > 0 || extendHeight > 0 || updateItem.position.x < 0 || updateItem.position.y < 0) {
parent.style = { ...parent.style } || {} if (!parent.style) parent.style = {}
else if (isFunction(parent.style)) parent.style = { ...parent.style(parent) }
parent.style.width = parent.style.width ?? parent.dimensions.width parent.style.width = parent.style.width ?? parent.dimensions.width
parent.style.height = parent.style.height ?? parent.dimensions.height parent.style.height = parent.style.height ?? parent.dimensions.height
if (extendWidth > 0) { if (extendWidth > 0) {
if (typeof parent.style.width === 'string') { if (isString(parent.style.width)) {
const currWidth = parseInt(parent.style.width, 10) const currWidth = Number(parent.style.width.replace('px', ''))
parent.style.width = `${currWidth + extendWidth}px` parent.style.width = `${currWidth + extendWidth}px`
} else { } else {
parent.style.width += extendWidth parent.style.width += extendWidth
@@ -37,8 +39,8 @@ function handleParentExpand(updateItem: GraphNode, parent: GraphNode) {
} }
if (extendHeight > 0) { if (extendHeight > 0) {
if (typeof parent.style.height === 'string') { if (isString(parent.style.height)) {
const currWidth = parseInt(parent.style.height, 10) const currWidth = Number(parent.style.height.replace('px', ''))
parent.style.height = `${currWidth + extendHeight}px` parent.style.height = `${currWidth + extendHeight}px`
} else { } else {
parent.style.height += extendHeight parent.style.height += extendHeight
@@ -48,26 +50,33 @@ function handleParentExpand(updateItem: GraphNode, parent: GraphNode) {
if (updateItem.position.x < 0) { if (updateItem.position.x < 0) {
const xDiff = Math.abs(updateItem.position.x) const xDiff = Math.abs(updateItem.position.x)
parent.position.x = parent.position.x - xDiff parent.position.x = parent.position.x - xDiff
if (typeof parent.style.width === 'string') {
const currWidth = parseInt(parent.style.width, 10) if (isString(parent.style.width)) {
const currWidth = Number(parent.style.width.replace('px', ''))
parent.style.width = `${currWidth + xDiff}px` parent.style.width = `${currWidth + xDiff}px`
} else { } else {
;(parent.style as any).width += xDiff parent.style.width += xDiff
} }
updateItem.position.x = 0 updateItem.position.x = 0
} }
if (updateItem.position.y < 0) { if (updateItem.position.y < 0) {
const yDiff = Math.abs(updateItem.position.y) const yDiff = Math.abs(updateItem.position.y)
parent.position.y = parent.position.y - yDiff parent.position.y = parent.position.y - yDiff
if (typeof parent.style.height === 'string') {
const currWidth = parseInt(parent.style.height, 10) if (isString(parent.style.height)) {
const currWidth = Number(parent.style.height.replace('px', ''))
parent.style.height = `${currWidth + yDiff}px` parent.style.height = `${currWidth + yDiff}px`
} else { } else {
;(parent.style as any).height += yDiff parent.style.height += yDiff
} }
updateItem.position.y = 0 updateItem.position.y = 0
} }
parent.dimensions.width = Number(parent.style.width.toString().replace('px', ''))
parent.dimensions.height = Number(parent.style.height.toString().replace('px', ''))
} }
} }
} }