Skip to content

Commit 0fc9da4

Browse files
feat: improve stress-test example and performance for large-scale node dragging
1 parent 53fce94 commit 0fc9da4

File tree

8 files changed

+54
-27
lines changed

8 files changed

+54
-27
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@if (columns) {
1+
@if (columns()) {
22
<f-flow fDraggable (fLoaded)="loaded()">
33
<f-canvas fZoom>
4-
@for (column of columns; track column; let cIndex = $index) {
4+
@for (column of columns(); track column; let cIndex = $index) {
55
<div
66
fNode
77
*ngFor="let node of column; let rIndex = index"
@@ -13,4 +13,14 @@
1313
}
1414
</f-canvas>
1515
</f-flow>
16+
<div class="examples-toolbar">
17+
<mat-form-field>
18+
<mat-label>Number</mat-label>
19+
<mat-select [(value)]="totalNodes">
20+
@for (option of totals; track option) {
21+
<mat-option [value]="option">{{ option }}</mat-option>
22+
}
23+
</mat-select>
24+
</mat-form-field>
25+
</div>
1626
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
@include flow-common.node;
55
width: unset;
66
}
7+
8+
@include flow-common.examples-toolbar;

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,45 @@
1-
import { ChangeDetectionStrategy, Component, OnInit, viewChild } from '@angular/core';
2-
import { FCanvasComponent, FFlowModule, FZoomDirective } from '@foblex/flow';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
computed,
5+
signal,
6+
untracked,
7+
viewChild,
8+
} from '@angular/core';
9+
import { FCanvasComponent, FFlowComponent, FFlowModule, FZoomDirective } from '@foblex/flow';
310
import { NgForOf } from '@angular/common';
411
import { PointExtensions } from '@foblex/2d';
12+
import { MatFormField, MatLabel } from '@angular/material/form-field';
13+
import { MatOption } from '@angular/material/core';
14+
import { MatSelect } from '@angular/material/select';
515

616
@Component({
717
selector: 'stress-test',
818
styleUrls: ['./stress-test.component.scss'],
919
templateUrl: './stress-test.component.html',
1020
changeDetection: ChangeDetectionStrategy.OnPush,
1121
standalone: true,
12-
imports: [FFlowModule, NgForOf, FZoomDirective],
22+
imports: [FFlowModule, NgForOf, FZoomDirective, MatFormField, MatLabel, MatOption, MatSelect],
1323
})
14-
export class StressTestComponent implements OnInit {
24+
export class StressTestComponent {
1525
private readonly _canvas = viewChild.required(FCanvasComponent);
26+
private readonly _flow = viewChild(FFlowComponent);
1627

17-
protected columns: number[][] | undefined;
28+
protected readonly totals = [500, 1000, 2000, 5000];
1829

19-
public ngOnInit(): void {
20-
const totalNodes = 500;
21-
const nodesPerColumn = Math.ceil(totalNodes / 25);
30+
protected readonly totalNodes = signal(1000);
31+
protected readonly columns = computed(() => {
32+
const total = this.totalNodes();
33+
const cols = Math.ceil(Math.sqrt(total));
34+
const nodesPerCol = Math.ceil(total / cols);
2235

23-
const numbers = Array.from({ length: totalNodes }, (_, i) => i + 1);
24-
this.columns = Array.from({ length: 25 }, (_, i) =>
25-
numbers.slice(i * nodesPerColumn, (i + 1) * nodesPerColumn),
36+
untracked(() => this._flow()?.reset());
37+
const numbers = Array.from({ length: total }, (_, i) => i + 1);
38+
39+
return Array.from({ length: cols }, (_, i) =>
40+
numbers.slice(i * nodesPerCol, (i + 1) * nodesPerCol),
2641
);
27-
}
42+
});
2843

2944
protected loaded(): void {
3045
this._canvas()?.fitToScreen(PointExtensions.initialize(20, 20), false);

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.8.5",
3+
"version": "17.8.6",
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/src/f-canvas/f-canvas.component.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
top: 0;
88
transform-origin: 0 0;
99
pointer-events: none;
10+
will-change: transform;
11+
transform: translateZ(0);
1012
}

projects/f-flow/src/f-flow/f-flow.component.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@
1818
transform-origin: 50% 50%;
1919
will-change: transform;
2020
}
21+
22+
.f-node,
23+
.f-group {
24+
position: absolute;
25+
transform-origin: center;
26+
user-select: none;
27+
pointer-events: all;
28+
left: 0;
29+
top: 0;
30+
}
2131
}

projects/f-flow/src/f-node/f-group.directive.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ export class FGroupDirective
106106
}
107107

108108
public ngOnInit(): void {
109-
this.setStyle('position', 'absolute');
110-
this.setStyle('transform-origin', 'center');
111-
this.setStyle('user-select', 'none');
112-
this.setStyle('pointer-events', 'all');
113-
this.setStyle('left', '0');
114-
this.setStyle('top', '0');
115109
super.redraw();
116110

117111
this._mediator.execute<void>(new AddNodeToStoreRequest(this));

projects/f-flow/src/f-node/f-node.directive.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ export class FNodeDirective
110110
}
111111

112112
public ngOnInit(): void {
113-
this.setStyle('position', 'absolute');
114-
this.setStyle('transform-origin', 'center');
115-
this.setStyle('user-select', 'none');
116-
this.setStyle('pointer-events', 'all');
117-
this.setStyle('left', '0');
118-
this.setStyle('top', '0');
119113
super.redraw();
120114

121115
this._mediator.execute<void>(new AddNodeToStoreRequest(this));

0 commit comments

Comments
 (0)