refactor(edge-renderer): cleanup

This commit is contained in:
moklick
2021-11-26 07:07:21 +01:00
parent b2ac219912
commit 33255635af
4 changed files with 52 additions and 48 deletions
+34 -1
View File
@@ -4,7 +4,17 @@ import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../compon
import wrapEdge from '../../components/Edges/wrapEdge';
import { rectToBox } from '../../utils';
import { EdgeTypesType, EdgeProps, HandleElement, Position, XYPosition, Transform, Rect } from '../../types';
import {
EdgeTypesType,
EdgeProps,
HandleElement,
Position,
XYPosition,
Transform,
Rect,
NodeInternals,
NodeHandleBounds,
} from '../../types';
export function createEdgeTypes(edgeTypes: EdgeTypesType): EdgeTypesType {
const standardTypes: EdgeTypesType = {
@@ -153,3 +163,26 @@ export function isEdgeVisible({
return overlappingArea > 0;
}
export function getNodeData(nodeInternals: NodeInternals, nodeId: string): [Rect, NodeHandleBounds | null, boolean] {
const node = nodeInternals.get(nodeId);
const handleBounds = node?.handleBounds;
const isInvalid =
!node ||
!node?.handleBounds ||
!node?.width ||
!node?.height ||
typeof node.positionAbsolute?.x === 'undefined' ||
typeof node.positionAbsolute?.y === 'undefined';
return [
{
x: node?.positionAbsolute?.x || 0,
y: node?.positionAbsolute?.y || 0,
width: node?.width || 0,
height: node?.height || 0,
},
handleBounds || null,
!isInvalid,
];
}