|
7 | 7 | ElementRef, |
8 | 8 | inject, |
9 | 9 | Injector, |
| 10 | + signal, |
10 | 11 | viewChild, |
11 | 12 | } from '@angular/core'; |
12 | 13 | import { NgtArgs, NgtHTML } from 'angular-three'; |
@@ -35,17 +36,20 @@ export class ChartContainer extends NgtHTML { |
35 | 36 | // NOTE: I'm doing this dirty because I am lazy. |
36 | 37 | const injector = inject(Injector); |
37 | 38 | afterNextRender(() => { |
38 | | - const chart = new Chart(this.chartContainer().nativeElement, { |
39 | | - type: 'bar', |
40 | | - data: { |
41 | | - labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], |
42 | | - datasets: [{ label: '# of Votes', data: this.data, borderWidth: 1 }], |
43 | | - }, |
44 | | - options: { scales: { y: { beginAtZero: true } } }, |
45 | | - }); |
46 | | - |
47 | 39 | effect( |
48 | 40 | (onCleanup) => { |
| 41 | + const chartReady = Experience.chartReady(); |
| 42 | + if (!chartReady) return; |
| 43 | + |
| 44 | + const chart = new Chart(this.chartContainer().nativeElement, { |
| 45 | + type: 'bar', |
| 46 | + data: { |
| 47 | + labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'], |
| 48 | + datasets: [{ label: '# of Votes', data: this.data, borderWidth: 1 }], |
| 49 | + }, |
| 50 | + options: { scales: { y: { beginAtZero: true } } }, |
| 51 | + }); |
| 52 | + |
49 | 53 | const id = setInterval(() => { |
50 | 54 | // randomize the data |
51 | 55 | this.data.forEach((_, index) => { |
@@ -88,4 +92,6 @@ export class ChartContainer extends NgtHTML { |
88 | 92 | }) |
89 | 93 | export class Experience { |
90 | 94 | protected readonly Math = Math; |
| 95 | + |
| 96 | + static chartReady = signal(false); |
91 | 97 | } |
0 commit comments