Browse Source

feat(lib): make chartCanvas a view child signal

pull/6491/head
KenTandrian 4 weeks ago
parent
commit
2ad9109024
  1. 10
      libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts

10
libs/ui/src/lib/portfolio-proportion-chart/portfolio-proportion-chart.component.ts

@ -18,7 +18,7 @@ import {
OnChanges, OnChanges,
OnDestroy, OnDestroy,
Output, Output,
ViewChild viewChild
} from '@angular/core'; } from '@angular/core';
import { DataSource } from '@prisma/client'; import { DataSource } from '@prisma/client';
import { Big } from 'big.js'; import { Big } from 'big.js';
@ -83,11 +83,11 @@ export class GfPortfolioProportionChartComponent
@Output() proportionChartClicked = new EventEmitter<AssetProfileIdentifier>(); @Output() proportionChartClicked = new EventEmitter<AssetProfileIdentifier>();
@ViewChild('chartCanvas') chartCanvas: ElementRef<HTMLCanvasElement>;
public chart: Chart<'doughnut'>; public chart: Chart<'doughnut'>;
public isLoading = true; public isLoading = true;
private readonly chartCanvas =
viewChild.required<ElementRef<HTMLCanvasElement>>('chartCanvas');
private readonly OTHER_KEY = 'OTHER'; private readonly OTHER_KEY = 'OTHER';
private colorMap: { private colorMap: {
@ -336,7 +336,6 @@ export class GfPortfolioProportionChartComponent
labels labels
}; };
if (this.chartCanvas) {
if (this.chart) { if (this.chart) {
this.chart.data = data; this.chart.data = data;
this.chart.options.plugins ??= {}; this.chart.options.plugins ??= {};
@ -345,7 +344,7 @@ export class GfPortfolioProportionChartComponent
this.chart.update(); this.chart.update();
} else { } else {
this.chart = new Chart<'doughnut'>(this.chartCanvas.nativeElement, { this.chart = new Chart<'doughnut'>(this.chartCanvas().nativeElement, {
data, data,
options: { options: {
animation: false, animation: false,
@ -406,7 +405,6 @@ export class GfPortfolioProportionChartComponent
type: 'doughnut' type: 'doughnut'
}); });
} }
}
this.isLoading = false; this.isLoading = false;
} }

Loading…
Cancel
Save