Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Restrict when the collision avoidance algorithm is used #10755

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,25 @@ describe('CanvasConnectionLine', () => {
'M0 0L 32,0Q 40,0 40,8L 40,132Q 40,140 32,140L1 140L0 140M0 140L-40 140L -132,140Q -140,140 -140,132L -140,-92Q -140,-100 -132,-100L-100 -100',
);
});

it('should only avoid obstacles when the edge intersects the nodes ', () => {
const { container } = renderComponent({
props: {
...DEFAULT_PROPS,
sourceX: -72,
sourceY: -290,
sourcePosition: Position.Right,
targetX: -344,
targetY: -30,
targetPosition: Position.Left,
},
});

const edge = container.querySelector('.vue-flow__edge-path');

expect(edge).toHaveAttribute(
'd',
'M-72 -290L -57,-290Q -52,-290 -52,-285L -52,-165Q -52,-160 -57,-160L -359,-160Q -364,-160 -364,-155L -364,-35Q -364,-30 -359,-30L-344 -30',
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ const EDGE_PADDING_Y = 140;
const EDGE_PADDING_Y_TOP = 80;
const EDGE_BORDER_RADIUS = 8;
const EDGE_OFFSET = 40;
const HANDLE_SIZE = 16;
// const HANDLE_SIZE = 16;

const isTargetHandlePositionedLeftOfSourceTarget = (sourceX: number, targetX: number) =>
sourceX > targetX;

const pathIntersectsNodes = (targetY: number, sourceY: number) =>
Math.abs(targetY - sourceY) < EDGE_PADDING_Y;

export function getCustomPath(
props: Pick<
Expand All @@ -14,12 +20,15 @@ export function getCustomPath(
>,
) {
const { targetX, targetY, sourceX, sourceY, sourcePosition, targetPosition } = props;
const xDiff = targetX - sourceX;
const yDiff = targetY - sourceY;

if (!isTargetHandlePositionedLeftOfSourceTarget(sourceX, targetX)) {
return getBezierPath(props);
}

// Connection is backwards and the source is on the right side
// -> We need to avoid overlapping the source node
if (xDiff < -HANDLE_SIZE && sourcePosition === Position.Right) {
if (pathIntersectsNodes(targetY, sourceY)) {
const direction = yDiff < -EDGE_PADDING_Y || yDiff > 0 ? 'up' : 'down';
const firstSegmentTargetX = sourceX;
const firstSegmentTargetY =
Expand Down Expand Up @@ -49,5 +58,5 @@ export function getCustomPath(
return path;
}

return getBezierPath(props);
return getSmoothStepPath(props);
}
Loading