|
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'; |
3 | 10 | import { NgForOf } from '@angular/common'; |
4 | 11 | 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'; |
5 | 15 |
|
6 | 16 | @Component({ |
7 | 17 | selector: 'stress-test', |
8 | 18 | styleUrls: ['./stress-test.component.scss'], |
9 | 19 | templateUrl: './stress-test.component.html', |
10 | 20 | changeDetection: ChangeDetectionStrategy.OnPush, |
11 | 21 | standalone: true, |
12 | | - imports: [FFlowModule, NgForOf, FZoomDirective], |
| 22 | + imports: [FFlowModule, NgForOf, FZoomDirective, MatFormField, MatLabel, MatOption, MatSelect], |
13 | 23 | }) |
14 | | -export class StressTestComponent implements OnInit { |
| 24 | +export class StressTestComponent { |
15 | 25 | private readonly _canvas = viewChild.required(FCanvasComponent); |
| 26 | + private readonly _flow = viewChild(FFlowComponent); |
16 | 27 |
|
17 | | - protected columns: number[][] | undefined; |
| 28 | + protected readonly totals = [500, 1000, 2000, 5000]; |
18 | 29 |
|
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); |
22 | 35 |
|
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), |
26 | 41 | ); |
27 | | - } |
| 42 | + }); |
28 | 43 |
|
29 | 44 | protected loaded(): void { |
30 | 45 | this._canvas()?.fitToScreen(PointExtensions.initialize(20, 20), false); |
|
0 commit comments