fix(nodes): properly calculate node extent
Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
|
import { isNumber } from '@vueuse/shared'
|
||||||
import type { ComputedGetters, CoordinateExtent, Getters, GraphNode, NodeDragItem, XYPosition } from '~/types'
|
import type { ComputedGetters, CoordinateExtent, Getters, GraphNode, NodeDragItem, XYPosition } from '~/types'
|
||||||
|
|
||||||
export function hasSelector(target: Element, selector: string, node: Ref<Element>): boolean {
|
export function hasSelector(target: Element, selector: string, node: Ref<Element>): boolean {
|
||||||
@@ -59,27 +60,38 @@ export function getEventHandlerParams({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function applyExtent<T extends NodeDragItem | GraphNode>(item: T, extent?: CoordinateExtent, parent?: GraphNode) {
|
export function applyExtent<T extends NodeDragItem | GraphNode>(item: T, extent?: CoordinateExtent, parent?: GraphNode) {
|
||||||
const currentExtent = item.extent ?? extent
|
let currentExtent = item.extent || extent
|
||||||
let nextExtent = currentExtent
|
|
||||||
|
|
||||||
if (currentExtent === 'parent' && parent) {
|
if (item.extent === 'parent') {
|
||||||
nextExtent = [
|
if (item.parentNode && parent && item.dimensions.width && item.dimensions.height) {
|
||||||
[parent.computedPosition.x, parent.computedPosition.y],
|
currentExtent =
|
||||||
[
|
parent &&
|
||||||
parent.computedPosition.x + parent.dimensions.width - item.dimensions.width,
|
isNumber(parent.computedPosition.x) &&
|
||||||
parent.computedPosition.y + parent.dimensions.height - item.dimensions.height,
|
isNumber(parent.computedPosition.y) &&
|
||||||
],
|
isNumber(parent.dimensions.width) &&
|
||||||
]
|
isNumber(parent.dimensions.height)
|
||||||
} else if (currentExtent !== 'parent' && currentExtent && parent) {
|
? [
|
||||||
const itemExtent = currentExtent
|
[parent.computedPosition.x + item.dimensions.width, parent.computedPosition.y + item.dimensions.height],
|
||||||
|
[
|
||||||
|
parent.computedPosition.x + parent.dimensions.width - item.dimensions.width + item.dimensions.width,
|
||||||
|
parent.computedPosition.y + parent.dimensions.height - item.dimensions.height + item.dimensions.height,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
: currentExtent
|
||||||
|
} else {
|
||||||
|
warn('Only child nodes can use a parent extent.')
|
||||||
|
|
||||||
|
currentExtent = extent
|
||||||
|
}
|
||||||
|
} else if (item.extent && parent) {
|
||||||
const parentX = parent.computedPosition.x
|
const parentX = parent.computedPosition.x
|
||||||
const parentY = parent.computedPosition.y
|
const parentY = parent.computedPosition.y
|
||||||
|
|
||||||
nextExtent = [
|
currentExtent = [
|
||||||
[itemExtent[0][0] + parentX, itemExtent[0][1] + parentY],
|
[item.extent[0][0] + parentX, item.extent[0][1] + parentY],
|
||||||
[itemExtent[1][0] + parentX, itemExtent[1][1] + parentY],
|
[item.extent[1][0] + parentX, item.extent[1][1] + parentY],
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextExtent as CoordinateExtent
|
return currentExtent as CoordinateExtent
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user