refactor(onlyRenderVisible): change from nodes to elements #677
This commit is contained in:
@@ -3,7 +3,7 @@ import { ComponentType } from 'react';
|
||||
import { BezierEdge, StepEdge, SmoothStepEdge, StraightEdge } from '../../components/Edges';
|
||||
import wrapEdge from '../../components/Edges/wrapEdge';
|
||||
|
||||
import { EdgeTypesType, EdgeProps } from '../../types';
|
||||
import { EdgeTypesType, EdgeProps, Position, Node, XYPosition, ElementId, HandleElement } from '../../types';
|
||||
|
||||
export function createEdgeTypes(edgeTypes: EdgeTypesType): EdgeTypesType {
|
||||
const standardTypes: EdgeTypesType = {
|
||||
@@ -27,3 +27,75 @@ export function createEdgeTypes(edgeTypes: EdgeTypesType): EdgeTypesType {
|
||||
...specialTypes,
|
||||
};
|
||||
}
|
||||
|
||||
export function getHandlePosition(position: Position, node: Node, handle: any | null = null): XYPosition {
|
||||
if (!handle) {
|
||||
switch (position) {
|
||||
case Position.Top:
|
||||
return {
|
||||
x: node.__rf.width / 2,
|
||||
y: 0,
|
||||
};
|
||||
case Position.Right:
|
||||
return {
|
||||
x: node.__rf.width,
|
||||
y: node.__rf.height / 2,
|
||||
};
|
||||
case Position.Bottom:
|
||||
return {
|
||||
x: node.__rf.width / 2,
|
||||
y: node.__rf.height,
|
||||
};
|
||||
case Position.Left:
|
||||
return {
|
||||
x: 0,
|
||||
y: node.__rf.height / 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
switch (position) {
|
||||
case Position.Top:
|
||||
return {
|
||||
x: handle.x + handle.width / 2,
|
||||
y: handle.y,
|
||||
};
|
||||
case Position.Right:
|
||||
return {
|
||||
x: handle.x + handle.width,
|
||||
y: handle.y + handle.height / 2,
|
||||
};
|
||||
case Position.Bottom:
|
||||
return {
|
||||
x: handle.x + handle.width / 2,
|
||||
y: handle.y + handle.height,
|
||||
};
|
||||
case Position.Left:
|
||||
return {
|
||||
x: handle.x,
|
||||
y: handle.y + handle.height / 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | null | undefined {
|
||||
let handle = null;
|
||||
|
||||
if (!bounds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// there is no handleId when there are no multiple handles/ handles with ids
|
||||
// so we just pick the first one
|
||||
if (bounds.length === 1 || !handleId) {
|
||||
handle = bounds[0];
|
||||
} else if (handleId) {
|
||||
handle = bounds.find((d) => d.id === handleId);
|
||||
}
|
||||
|
||||
if (typeof handle === 'undefined') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user