Skip to content

Commit f9e6603

Browse files
Merge pull request #244 from Foblex/feature/shuzarevich/connection-paint-optimization
Unify installation flow (Angular CLI + Nx) and improve canvas rendering performance
2 parents ded9072 + fad6ead commit f9e6603

22 files changed

+425
-300
lines changed

projects/f-examples/nodes/stress-test-with-connections/stress-test-with-connections.component.html

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<f-flow fDraggable (fLoaded)="onLoaded()">
1+
<f-flow fDraggable (fLoaded)="loaded()">
22
<f-canvas fZoom>
3-
@for (node of nodes; track node.position; let index = $index) {
3+
@for (node of nodes(); track node.id) {
44
<div
55
fNode
66
[fNodePosition]="node.position"
@@ -24,14 +24,16 @@
2424
Move me
2525
</div>
2626

27-
@for (node of nodes; track node.position; let index = $index) {
27+
@for (node of nodes(); track node.position; let index = $index) {
2828
<f-connection
29-
[fType]="type"
30-
[fBehavior]="behavior"
29+
[fType]="type()"
30+
[fBehavior]="behavior()"
3131
fOutputId="0"
3232
[fInputId]="node.id"
3333
fReassignDisabled="true"
3434
fSelectionDisabled="true"
35+
fOutputSide="calculate"
36+
fInputSide="calculate"
3537
>
3638
<svg
3739
viewBox="0 0 700 700"
@@ -67,7 +69,7 @@
6769
<div class="examples-toolbar">
6870
<mat-form-field>
6971
<mat-label>Number</mat-label>
70-
<mat-select [(value)]="count" (selectionChange)="onSelectionChange($event)">
72+
<mat-select [(value)]="count">
7173
@for (option of counts; track option) {
7274
<mat-option [value]="option">{{ option }}</mat-option>
7375
}
@@ -82,7 +84,7 @@
8284
</mat-select>
8385
</mat-form-field>
8486
<mat-form-field>
85-
<mat-label>Select Background</mat-label>
87+
<mat-label>Type</mat-label>
8688
<mat-select [(value)]="type">
8789
@for (option of types; track option) {
8890
<mat-option [value]="option">{{ option }}</mat-option>

projects/f-examples/nodes/stress-test-with-connections/stress-test-with-connections.component.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
1-
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
computed,
5+
signal,
6+
untracked,
7+
viewChild,
8+
} from '@angular/core';
29
import {
310
EFConnectableSide,
411
EFConnectionBehavior,
512
EFConnectionType,
613
EFMarkerType,
714
FCanvasComponent,
8-
FFlowComponent,
915
FFlowModule,
1016
FZoomDirective,
1117
} from '@foblex/flow';
1218
import { IPoint, PointExtensions } from '@foblex/2d';
1319
import { MatFormField, MatLabel } from '@angular/material/form-field';
1420
import { MatOption } from '@angular/material/core';
15-
import { MatSelect, MatSelectChange } from '@angular/material/select';
21+
import { MatSelect } from '@angular/material/select';
1622

1723
@Component({
1824
selector: 'stress-test-with-connections',
1925
styleUrls: ['./stress-test-with-connections.component.scss'],
2026
templateUrl: './stress-test-with-connections.component.html',
27+
changeDetection: ChangeDetectionStrategy.OnPush,
2128
standalone: true,
2229
imports: [FFlowModule, MatFormField, MatLabel, MatOption, MatSelect, FZoomDirective],
2330
})
24-
export class StressTestWithConnectionsComponent implements OnInit, AfterViewInit {
25-
@ViewChild(FFlowComponent, { static: false })
26-
public fFlow!: FFlowComponent;
27-
28-
@ViewChild(FCanvasComponent, { static: false })
29-
public fCanvas!: FCanvasComponent;
30-
31-
public counts: number[] = [25, 50, 75, 100, 150];
32-
public count = 25;
31+
export class StressTestWithConnectionsComponent {
32+
private readonly _canvas = viewChild.required(FCanvasComponent);
3333

34-
public behaviors: string[] = [
34+
protected readonly eMarkerType = EFMarkerType;
35+
protected readonly counts = [25, 50, 75, 100, 150];
36+
protected readonly behaviors: string[] = [
3537
EFConnectionBehavior.FIXED,
3638
EFConnectionBehavior.FIXED_CENTER,
3739
EFConnectionBehavior.FLOATING,
3840
];
39-
public behavior = EFConnectionBehavior.FLOATING;
40-
41-
public types: string[] = [
41+
protected readonly types: string[] = [
4242
EFConnectionType.STRAIGHT,
4343
EFConnectionType.SEGMENT,
4444
EFConnectionType.BEZIER,
45+
EFConnectionType.ADAPTIVE_CURVE,
4546
];
46-
public type = EFConnectionType.STRAIGHT;
4747

48-
public nodes: { id: number; position: IPoint; side: EFConnectableSide }[] = [];
48+
protected readonly count = signal(50);
49+
protected readonly behavior = signal(EFConnectionBehavior.FLOATING);
50+
protected readonly type = signal(EFConnectionType.STRAIGHT);
4951

50-
public onLoaded(): void {
51-
this.fCanvas?.fitToScreen(PointExtensions.initialize(20, 20), false);
52-
}
52+
protected readonly nodes = computed(() => {
53+
const count = this.count();
5354

54-
public ngOnInit(): void {
55-
this.nodes = this._generateNodes(this.count);
56-
}
55+
return untracked(() => this._generateNodes(count));
56+
});
5757

58-
public ngAfterViewInit(): void {
59-
this.fFlow.reset();
58+
protected loaded(): void {
59+
this._canvas()?.fitToScreen(PointExtensions.initialize(20, 20), false);
6060
}
6161

6262
private _generateNodes(
@@ -115,10 +115,4 @@ export class StressTestWithConnectionsComponent implements OnInit, AfterViewInit
115115

116116
return result;
117117
}
118-
119-
protected readonly eMarkerType = EFMarkerType;
120-
121-
public onSelectionChange(event: MatSelectChange): void {
122-
this.nodes = this._generateNodes(event.value);
123-
}
124118
}

projects/f-examples/nodes/stress-test/stress-test.component.html

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
@if (columns()) {
22
<f-flow fDraggable (fLoaded)="loaded()">
33
<f-canvas fZoom>
4-
@for (column of columns(); track column; let cIndex = $index) {
5-
<div
6-
fNode
7-
*ngFor="let node of column; let rIndex = index"
8-
[fNodePosition]="{ x: 120 * cIndex, y: rIndex * 120 }"
9-
fDragHandle
10-
>
11-
Node
12-
</div>
13-
}
4+
<ng-container ngProjectAs="[fNodes]">
5+
@for (column of columns(); track column; let cIndex = $index) {
6+
@for (node of column; track node; let rIndex = $index) {
7+
<div
8+
fNode
9+
[fNodePosition]="{ x: 120 * cIndex, y: rIndex * 120 }"
10+
fDragHandle
11+
fNodeInput
12+
[fInputId]="node"
13+
fNodeOutput
14+
[fOutputId]="node"
15+
>
16+
Node
17+
</div>
18+
}
19+
}
20+
</ng-container>
21+
22+
<ng-container ngProjectAs="[fConnections]">
23+
@if (showConnections()) {
24+
@for (connection of connections(); track connection) {
25+
<f-connection
26+
fType="adaptive-curve"
27+
fBehavior="fixed"
28+
[fInputId]="connection.target"
29+
[fOutputId]="connection.source"
30+
fInputSide="calculate"
31+
fOutputSide="calculate"
32+
/>
33+
}
34+
}
35+
</ng-container>
1436
</f-canvas>
1537
</f-flow>
1638
<div class="examples-toolbar">
39+
<f-checkbox [checked]="showConnections()" (change)="toggleConnections()"
40+
>Show Connections</f-checkbox
41+
>
1742
<mat-form-field>
1843
<mat-label>Number</mat-label>
1944
<mat-select [(value)]="totalNodes">

projects/f-examples/nodes/stress-test/stress-test.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@use '../../flow-common';
22

3+
::ng-deep f-flow {
4+
@include flow-common.connection;
5+
}
6+
37
.f-node {
48
@include flow-common.node;
59
width: unset;

projects/f-examples/nodes/stress-test/stress-test.component.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,35 @@ import { PointExtensions } from '@foblex/2d';
1212
import { MatFormField, MatLabel } from '@angular/material/form-field';
1313
import { MatOption } from '@angular/material/core';
1414
import { MatSelect } from '@angular/material/select';
15+
import { FCheckboxComponent } from '@foblex/m-render';
16+
17+
type Edge = { source: number; target: number };
1518

1619
@Component({
1720
selector: 'stress-test',
1821
styleUrls: ['./stress-test.component.scss'],
1922
templateUrl: './stress-test.component.html',
2023
changeDetection: ChangeDetectionStrategy.OnPush,
2124
standalone: true,
22-
imports: [FFlowModule, NgForOf, FZoomDirective, MatFormField, MatLabel, MatOption, MatSelect],
25+
imports: [
26+
FFlowModule,
27+
NgForOf,
28+
FZoomDirective,
29+
MatFormField,
30+
MatLabel,
31+
MatOption,
32+
MatSelect,
33+
FCheckboxComponent,
34+
],
2335
})
2436
export class StressTestComponent {
2537
private readonly _canvas = viewChild.required(FCanvasComponent);
2638
private readonly _flow = viewChild(FFlowComponent);
2739

28-
protected readonly totals = [500, 1000, 2000, 5000];
40+
protected readonly totals = [200, 500, 1000, 2000];
2941

30-
protected readonly totalNodes = signal(1000);
42+
protected readonly showConnections = signal(false);
43+
protected readonly totalNodes = signal(200);
3144
protected readonly columns = computed(() => {
3245
const total = this.totalNodes();
3346
const cols = Math.ceil(Math.sqrt(total));
@@ -41,7 +54,21 @@ export class StressTestComponent {
4154
);
4255
});
4356

57+
protected readonly connections = computed<Edge[]>(() => {
58+
const total = this.totalNodes();
59+
const edges: Edge[] = [];
60+
for (let i = 1; i < total; i++) {
61+
edges.push({ source: i, target: i + 1 });
62+
}
63+
64+
return edges;
65+
});
66+
4467
protected loaded(): void {
4568
this._canvas()?.fitToScreen(PointExtensions.initialize(20, 20), false);
4669
}
70+
71+
protected toggleConnections(): void {
72+
this.showConnections.update((x) => !x);
73+
}
4774
}

projects/f-flow/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@foblex/flow",
3-
"version": "17.9.0",
3+
"version": "17.9.5",
44
"description": "An Angular library designed to simplify the creation and manipulation of dynamic flow. Provides components for flows, nodes, and connections, automating node manipulation and inter-node connections.",
55
"main": "index.js",
66
"types": "index.d.ts",

projects/f-flow/schematics/collection.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
"factory": "./ng-add/index#ngAdd",
77
"schema": "./ng-add/schema.json"
88
},
9+
"add": {
10+
"description": "Installs @foblex/flow and its dependencies (alias for Nx users)",
11+
"factory": "./ng-add/index#ngAdd",
12+
"schema": "./ng-add/schema.json"
13+
},
914
"ng-update": {
1015
"description": "Updates @foblex/flow to the latest version",
1116
"factory": "./ng-update/index#ngUpdate",
1217
"schema": "./ng-update/schema.json"
13-
},
18+
}
1419
}
1520
}

0 commit comments

Comments
 (0)