refactor(edgeRendererUtils): cleanup
This commit is contained in:
@@ -115,7 +115,7 @@ function renderEdge(
|
||||
targetPosition
|
||||
);
|
||||
|
||||
const isSelected = selectedElements ? selectedElements.some((elm) => isEdge(elm) && elm.id === edge.id) : false;
|
||||
const isSelected = selectedElements?.some((elm) => isEdge(elm) && elm.id === edge.id) || false;
|
||||
|
||||
return (
|
||||
<EdgeComponent
|
||||
|
||||
@@ -29,62 +29,42 @@ export function createEdgeTypes(edgeTypes: EdgeTypesType): EdgeTypesType {
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
const x = handle?.x || 0;
|
||||
const y = handle?.y || 0;
|
||||
const width = handle?.width || node.__rf.width;
|
||||
const height = handle?.height || node.__rf.height;
|
||||
|
||||
switch (position) {
|
||||
case Position.Top:
|
||||
return {
|
||||
x: handle.x + handle.width / 2,
|
||||
y: handle.y,
|
||||
x: x + width / 2,
|
||||
y,
|
||||
};
|
||||
case Position.Right:
|
||||
return {
|
||||
x: handle.x + handle.width,
|
||||
y: handle.y + handle.height / 2,
|
||||
x: x + width,
|
||||
y: y + height / 2,
|
||||
};
|
||||
case Position.Bottom:
|
||||
return {
|
||||
x: handle.x + handle.width / 2,
|
||||
y: handle.y + handle.height,
|
||||
x: x + width / 2,
|
||||
y: y + height,
|
||||
};
|
||||
case Position.Left:
|
||||
return {
|
||||
x: handle.x,
|
||||
y: handle.y + handle.height / 2,
|
||||
x,
|
||||
y: y + height / 2,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | null | undefined {
|
||||
let handle = null;
|
||||
|
||||
export function getHandle(bounds: HandleElement[], handleId: ElementId | null): HandleElement | null {
|
||||
if (!bounds) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let handle = 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) {
|
||||
|
||||
Reference in New Issue
Block a user