Skip to content

Commit 74d2d42

Browse files
author
shuzarevich
committed
refactor(connection): replace pivots with waypoints in connection calculations
- Updated tests to use waypoints instead of pivots for path calculations. - Refactored candidate calculation functions to return IPoint instead of IWaypointCandidate. - Adjusted connection-related components to handle waypoints consistently. - Removed unused imports and cleaned up related code for clarity.
1 parent e923fe2 commit 74d2d42

37 files changed

+118
-157
lines changed

projects/f-examples/connections/connection-waypoints/connection-waypoints.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
&:hover {
2222
stroke: #298459;
23-
transform: scale(1.12);
23+
transform: scale(1.1);
2424
}
2525
}
2626

@@ -31,7 +31,7 @@
3131
cursor: grab;
3232

3333
&:hover {
34-
transform: scale(1.10);
34+
transform: scale(1.1);
3535
}
3636
}
3737
}

projects/f-examples/connections/custom-connection-type/custom-connection-type.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class OffsetStraightBuilder implements IFConnectionBuilder {
1717

1818
return {
1919
path,
20-
connectionCenter: { x: 0, y: 0 },
2120
penultimatePoint: PointExtensions.initialize(target.x - 20, target.y),
2221
secondPoint: PointExtensions.initialize(source.x + 20, source.y),
2322
points: [
@@ -39,7 +38,6 @@ class CircleConnectionBuilder implements IFConnectionBuilder {
3938

4039
return {
4140
path,
42-
connectionCenter: { x: 0, y: 0 },
4341
penultimatePoint: d,
4442
secondPoint: d,
4543
points: [source, d, target],

projects/f-flow/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2026 Foblex
3+
Copyright (c) 2026 Foblex Flow
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

projects/f-flow/src/domain/i-map.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

projects/f-flow/src/domain/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export * from './css-cls';
3838

3939
export * from './f-event-trigger';
4040

41-
export * from './i-map';
42-
4341
export * from './is-mobile';
4442

4543
export * from './log-deprecated';

projects/f-flow/src/f-connection-v2/components/connection-waypoints/f-connection-waypoints.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<circle
66
[attr.r]="radius()"
77
class="f-candidate"
8-
[attr.cx]="candidate.point.x"
9-
[attr.cy]="candidate.point.y"
8+
[attr.cx]="candidate.x"
9+
[attr.cy]="candidate.y"
1010
></circle>
1111
}
1212
@for (point of waypoints(); track $index) {

projects/f-flow/src/f-connection-v2/components/connection-waypoints/f-connection-waypoints.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import {
22
booleanAttribute,
33
ChangeDetectionStrategy,
44
Component,
5+
effect,
6+
inject,
7+
Injector,
58
input,
69
model,
710
numberAttribute,
11+
OnDestroy,
12+
OnInit,
13+
untracked,
814
} from '@angular/core';
915
import { F_CONNECTION_WAYPOINTS, FConnectionWaypointsBase } from './models';
1016
import { IPoint } from '@foblex/2d';
17+
import { NotifyDataChangedRequest } from '../../../f-storage';
18+
import { FMediator } from '@foblex/mediator';
1119

1220
@Component({
1321
selector: 'f-connection-waypoints',
@@ -20,7 +28,10 @@ import { IPoint } from '@foblex/2d';
2028
},
2129
providers: [{ provide: F_CONNECTION_WAYPOINTS, useExisting: FConnectionWaypoints }],
2230
})
23-
export class FConnectionWaypoints extends FConnectionWaypointsBase {
31+
export class FConnectionWaypoints extends FConnectionWaypointsBase implements OnInit, OnDestroy {
32+
private readonly _mediator = inject(FMediator);
33+
private readonly _injector = inject(Injector);
34+
2435
public override readonly radius = input(4, {
2536
transform: numberAttribute,
2637
});
@@ -29,4 +40,28 @@ export class FConnectionWaypoints extends FConnectionWaypointsBase {
2940
public override readonly visibility = input(true, {
3041
transform: booleanAttribute,
3142
});
43+
44+
public ngOnInit(): void {
45+
this._listenChanges();
46+
}
47+
48+
private _listenChanges(): void {
49+
effect(
50+
() => {
51+
this.radius();
52+
this.waypoints();
53+
this.visibility();
54+
untracked(() => this._notifyDataChanged());
55+
},
56+
{ injector: this._injector },
57+
);
58+
}
59+
60+
private _notifyDataChanged(): void {
61+
this._mediator.execute(new NotifyDataChangedRequest());
62+
}
63+
64+
public ngOnDestroy(): void {
65+
this._notifyDataChanged();
66+
}
3267
}
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ElementRef, inject, InjectionToken, ModelSignal, signal, Signal } from '@angular/core';
2-
import { IWaypointCandidate } from './i-waypoint-candidate';
32
import { IPoint, PointExtensions } from '@foblex/2d';
43

54
export const F_CONNECTION_WAYPOINTS = new InjectionToken<FConnectionWaypointsBase>(
@@ -9,27 +8,27 @@ export const F_CONNECTION_WAYPOINTS = new InjectionToken<FConnectionWaypointsBas
98
export abstract class FConnectionWaypointsBase {
109
public readonly hostElement = inject(ElementRef<SVGElement>).nativeElement;
1110

12-
public readonly candidates = signal<IWaypointCandidate[]>([]);
11+
public readonly candidates = signal<IPoint[]>([]);
1312

1413
public abstract waypoints: ModelSignal<IPoint[]>;
1514
public abstract radius: Signal<number>;
1615
public abstract visibility: Signal<boolean>;
1716

18-
protected _activeIndex = signal(-1)
17+
private _activeIndex = 0;
1918
private _pivots: IPoint[] = [];
2019

21-
public insert(candidate: IWaypointCandidate): void {
20+
public insert(candidate: IPoint): void {
2221
const current = this.waypoints().slice();
2322

24-
this._activeIndex.set(Math.max(0, Math.min(candidate.chainIndex, current.length)));
23+
this._activeIndex = Math.max(0, Math.min(this.candidates().indexOf(candidate), current.length));
2524

26-
current.splice(this._activeIndex(), 0, { ...candidate.point });
25+
current.splice(this._activeIndex, 0, { ...candidate });
2726
this.waypoints.set(current);
2827
this._pivots = current;
2928
}
3029

3130
public select(pivot: IPoint): void {
32-
this._activeIndex.set(this.waypoints().findIndex((x) => PointExtensions.isEqual(pivot, x)));
31+
this._activeIndex = this.waypoints().findIndex((x) => PointExtensions.isEqual(pivot, x));
3332
this._pivots = this.waypoints();
3433
}
3534

@@ -41,15 +40,13 @@ export abstract class FConnectionWaypointsBase {
4140
const current = this.waypoints().slice();
4241
current.splice(index, 1);
4342
this.waypoints.set(current);
44-
this._activeIndex.set(-1);
4543
}
4644

4745
public move(point: IPoint): void {
48-
this._pivots[this._activeIndex()] = { ...point };
46+
this._pivots[this._activeIndex] = { ...point };
4947
}
5048

5149
public update(): void {
5250
this.waypoints.set([...this._pivots]);
53-
// this._activeIndex.set(-1);
5451
}
5552
}

projects/f-flow/src/f-connection-v2/components/connection-waypoints/models/i-waypoint-candidate.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './f-connection-waypoints-base';
2-
export * from './i-waypoint-candidate';

0 commit comments

Comments
 (0)