Skip to content

Commit 663e14b

Browse files
committed
add shadow to paths instead of using an extra transparent path
1 parent b4e0db7 commit 663e14b

File tree

5 files changed

+82
-46
lines changed

5 files changed

+82
-46
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,12 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
376376
'd',
377377
pathInfo.path
378378
);
379-
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
380-
'd',
381-
pathInfo.path
382-
);
379+
if (this.pathTransparentElement) {
380+
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
381+
'd',
382+
pathInfo.path
383+
);
384+
}
383385
return {
384386
startX: pathInfo.startX + bbox.x - startOffsetX,
385387
startY: pathInfo.startY + bbox.y - startOffsetY,

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

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class Connection<T extends BaseNodeInfo> {
104104
) => void,
105105
id?: string,
106106
containerNode?: IRectNodeComponent<T>,
107-
theme?: Theme,
107+
_theme?: Theme,
108108
setCanvasAction?: (canvasAction: CanvasAction, payload?: any) => void,
109109
rootElement?: HTMLElement,
110110
canvasApp?: IBaseFlow<T>
@@ -234,20 +234,20 @@ export class Connection<T extends BaseNodeInfo> {
234234
endOffsetY
235235
);
236236

237-
this.pathTransparentElement = createNSElement(
238-
'path',
239-
{
240-
class: this.cssClasses.pathTransparentCssClasses,
241-
d: path,
242-
stroke: containerNode
243-
? '#94a3b8'
244-
: theme?.backgroundAsHexColor ?? '#1e293b',
245-
'stroke-width': 20,
246-
fill: 'transparent',
247-
pointerdown: this.onPointerDown,
248-
},
249-
this.nodeComponent.domElement
250-
);
237+
// this.pathTransparentElement = createNSElement(
238+
// 'path',
239+
// {
240+
// class: this.cssClasses.pathTransparentCssClasses,
241+
// d: path,
242+
// stroke: containerNode
243+
// ? '#94a3b8'
244+
// : theme?.backgroundAsHexColor ?? '#1e293b',
245+
// 'stroke-width': 20,
246+
// fill: 'transparent',
247+
// pointerdown: this.onPointerDown,
248+
// },
249+
// this.nodeComponent.domElement
250+
// );
251251

252252
this.pathElement = createNSElement(
253253
'path',
@@ -260,14 +260,17 @@ export class Connection<T extends BaseNodeInfo> {
260260
'stroke-width': 3,
261261
...dashedStroke,
262262
fill: 'transparent',
263+
style: {
264+
filter: `url(#${arrowIdPrefix}_shadow)`,
265+
},
263266
},
264267
this.nodeComponent.domElement
265268
);
266269
this.nodeComponent.pathElement = this.pathElement;
267270

268271
if (!this.pathElement) throw new Error('pathElement is undefined');
269-
if (!this.pathTransparentElement)
270-
throw new Error('pathTransparentElement is undefined');
272+
// if (!this.pathTransparentElement)
273+
// throw new Error('pathTransparentElement is undefined');
271274

272275
elements.set(this.nodeComponent.id, this.nodeComponent);
273276
this.nodeComponent.elements.set(this.pathElement.id, this.pathElement);
@@ -504,19 +507,19 @@ export class Connection<T extends BaseNodeInfo> {
504507
let updateThumbs = false;
505508

506509
if (!target || x === undefined || y === undefined || !initiator) {
507-
(
508-
this.pathTransparentElement?.domElement as SVGPathElement
509-
).classList.remove('hidden');
510-
if (this.nodeComponent?.startNode && this.nodeComponent?.endNode) {
511-
if (
512-
this.nodeComponent.startNode.nodeInfo?.isInGroup ||
513-
this.nodeComponent.endNode.nodeInfo?.isInGroup
514-
) {
515-
(
516-
this.pathTransparentElement?.domElement as SVGPathElement
517-
).classList.add('hidden');
518-
}
519-
}
510+
// (
511+
// this.pathTransparentElement?.domElement as SVGPathElement
512+
// ).classList.remove('hidden');
513+
// if (this.nodeComponent?.startNode && this.nodeComponent?.endNode) {
514+
// if (
515+
// this.nodeComponent.startNode.nodeInfo?.isInGroup ||
516+
// this.nodeComponent.endNode.nodeInfo?.isInGroup
517+
// ) {
518+
// (
519+
// this.pathTransparentElement?.domElement as SVGPathElement
520+
// ).classList.add('hidden');
521+
// }
522+
// }
520523
// needed for updating without using parameters (...update() )
521524
if (this.nodeComponent?.startNode) {
522525
const start = this.onCalculateControlPoints(
@@ -1034,6 +1037,31 @@ export class Connection<T extends BaseNodeInfo> {
10341037
},
10351038
markerBegin.domElement
10361039
);
1040+
1041+
const shadowFilter = createNSElement(
1042+
'filter',
1043+
{
1044+
id: `${id}_shadow`,
1045+
x: '-10%',
1046+
y: '-10%',
1047+
height: '120%',
1048+
width: '120%',
1049+
filterUnits: 'userSpaceOnUse',
1050+
},
1051+
defs.domElement
1052+
);
1053+
1054+
if (shadowFilter) {
1055+
createNSElement(
1056+
'feDropShadow',
1057+
{
1058+
dx: '2.0',
1059+
dy: '2.0',
1060+
stdDeviation: '1.0',
1061+
},
1062+
shadowFilter.domElement
1063+
);
1064+
}
10371065
}
10381066

10391067
protected initializeControlPoints(): { x: number; y: number }[] {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,12 @@ export class LineConnection<T extends BaseNodeInfo> extends Connection<T> {
353353
'd',
354354
pathInfo.path
355355
);
356-
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
357-
'd',
358-
pathInfo.path
359-
);
356+
if (this.pathTransparentElement) {
357+
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
358+
'd',
359+
pathInfo.path
360+
);
361+
}
360362
return {
361363
startX: pathInfo.startX + bbox.x,
362364
startY: pathInfo.startY + bbox.y,

libs/visual-programming-system/src/components/quadratic-bezier-connection.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,12 @@ export class QuadraticBezierConnection<
590590
'd',
591591
pathInfo.path
592592
);
593-
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
594-
'd',
595-
pathInfo.path
596-
);
593+
if (this.pathTransparentElement) {
594+
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
595+
'd',
596+
pathInfo.path
597+
);
598+
}
597599
return {
598600
startX: pathInfo.startX + bbox.x, // - startOffsetX,
599601
startY: pathInfo.startY + bbox.y, // - startOffsetY,

libs/visual-programming-system/src/components/qubic-bezier-connection.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,12 @@ export class CubicBezierConnection<
799799
}
800800
(this.pathElement?.domElement as HTMLElement).setAttribute('d', path);
801801

802-
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
803-
'd',
804-
path
805-
);
802+
if (this.pathTransparentElement) {
803+
(this.pathTransparentElement?.domElement as HTMLElement).setAttribute(
804+
'd',
805+
path
806+
);
807+
}
806808

807809
return {
808810
startX: this.points.beginX + startOffsetX, //+ bbox.x - startOffsetX,

0 commit comments

Comments
 (0)