Skip to content

Commit cbafa5b

Browse files
committed
fix dragging arc endpoint from connected node and updating arc while dragging
1 parent ab25d7a commit cbafa5b

File tree

4 files changed

+368
-71
lines changed

4 files changed

+368
-71
lines changed

libs/visual-programming-system/src/components/arc-connection.ts

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import { thumbHalfWidth, thumbHalfHeight } from '../constants/measures';
2+
import { IBaseFlow } from '../canvas-app/base-flow';
33
import { CanvasAction } from '../enums/canvas-action';
44
import { InteractionStateMachine } from '../interaction-state-machine';
55
import {
@@ -18,7 +18,6 @@ import { BaseNodeInfo } from '../types/base-node-info';
1818
import { LineType } from '../types/line-type';
1919
import { Connection } from './connection';
2020
import {
21-
doRectanglesOverlap,
2221
findCircleCenter,
2322
getPointAngle,
2423
isLargeArc,
@@ -55,7 +54,8 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
5554
containerNode?: IRectNodeComponent<T>,
5655
theme?: Theme,
5756
setCanvasAction?: (canvasAction: CanvasAction, payload?: any) => void,
58-
rootElement?: HTMLElement
57+
rootElement?: HTMLElement,
58+
canvasApp?: IBaseFlow<T>
5959
) {
6060
super(
6161
canvas,
@@ -77,7 +77,8 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
7777
containerNode,
7878
theme,
7979
setCanvasAction,
80-
rootElement
80+
rootElement,
81+
canvasApp
8182
);
8283
if (!this.nodeComponent) {
8384
throw new Error('nodeComponent is undefined');
@@ -133,7 +134,8 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
133134
undefined,
134135
undefined,
135136
rootElement,
136-
this
137+
this,
138+
this.canvasApp
137139
);
138140
if (!startPointNode.nodeComponent) {
139141
throw new Error('startPointNode.nodeComponent is undefined');
@@ -205,7 +207,8 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
205207
undefined,
206208
undefined,
207209
rootElement,
208-
this
210+
this,
211+
this.canvasApp
209212
);
210213
if (!endPointNode.nodeComponent) {
211214
throw new Error('endPointNode.nodeComponent is undefined');
@@ -400,6 +403,7 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
400403

401404
const startNode = this.nodeComponent?.startNode;
402405
const endNode = this.nodeComponent?.endNode;
406+
403407
const halfStartWidth = startNode?.width
404408
? startNode.width / 2 + spacingAABB
405409
: 0;
@@ -462,25 +466,29 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
462466
}
463467

464468
// Find intersection points
465-
const intersections1 = findRectangleIntersections(
466-
startX,
467-
startY,
468-
startWidth,
469-
startHeight,
470-
centerX,
471-
centerY,
472-
radius
473-
);
474-
475-
const intersections2 = findRectangleIntersections(
476-
endX,
477-
endY,
478-
endWidth,
479-
endHeight,
480-
centerX,
481-
centerY,
482-
radius
483-
);
469+
const intersections1 = this.nodeComponent?.startNode
470+
? findRectangleIntersections(
471+
startX,
472+
startY,
473+
startWidth,
474+
startHeight,
475+
centerX,
476+
centerY,
477+
radius
478+
)
479+
: [{ x: x1, y: y1 }];
480+
481+
const intersections2 = this.nodeComponent?.endNode
482+
? findRectangleIntersections(
483+
endX,
484+
endY,
485+
endWidth,
486+
endHeight,
487+
centerX,
488+
centerY,
489+
radius
490+
)
491+
: [{ x: x2, y: y2 }];
484492

485493
// Sort intersection points by angle
486494
const sortedIntersections1 = [...intersections1].sort(
@@ -528,22 +536,22 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
528536
}
529537

530538
if (bestIntersection1 && bestIntersection2) {
531-
const isOverlapping = doRectanglesOverlap(
532-
{
533-
x: startX,
534-
y: startY,
535-
width: startWidth,
536-
height: startHeight,
537-
element: startNode?.domElement as SVGRectElement,
538-
},
539-
{
540-
x: endX,
541-
y: endY,
542-
width: endWidth,
543-
height: endHeight,
544-
element: endNode?.domElement as SVGRectElement,
545-
}
546-
);
539+
// const isOverlapping = doRectanglesOverlap(
540+
// {
541+
// x: startX,
542+
// y: startY,
543+
// width: startWidth,
544+
// height: startHeight,
545+
// element: startNode?.domElement as SVGRectElement,
546+
// },
547+
// {
548+
// x: endX,
549+
// y: endY,
550+
// width: endWidth,
551+
// height: endHeight,
552+
// element: endNode?.domElement as SVGRectElement,
553+
// }
554+
// );
547555

548556
// Calculate angles and determine sweep flag
549557
const angle1 = getPointAngle(bestIntersection1, centerX, centerY);
@@ -553,7 +561,7 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
553561
if (angleDiff > Math.PI) angleDiff -= 2 * Math.PI;
554562

555563
// Calculate if points are on opposite sides
556-
const isOpposite = Math.abs(Math.abs(angleDiff) - Math.PI) < 0.01;
564+
//const isOpposite = Math.abs(Math.abs(angleDiff) - Math.PI) < 0.01;
557565

558566
// Calculate control point position on the actual arc path
559567
const midAngle = angle1 + angleDiff / 2;
@@ -617,6 +625,7 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
617625
} ${angleDiff > 0 ? 1 : 0} ${bestIntersection2.x} ${
618626
bestIntersection2.y
619627
}`;
628+
620629
//canvas.updateTestArcPath(d);
621630
return {
622631
path: d,

libs/visual-programming-system/src/components/geometry/pathCalculation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Point, Node } from './types/types';
1+
import { Point } from './types/types';
22
import { isLargeArc } from './geometry';
33

44
export function createSVGWithArcPoints(

0 commit comments

Comments
 (0)