Browse Source

feat(ui): implement viewChild signal

pull/7325/head
KenTandrian 2 days ago
parent
commit
4fb435d6cb
  1. 10
      libs/ui/src/lib/treemap-chart/treemap-chart.component.ts

10
libs/ui/src/lib/treemap-chart/treemap-chart.component.ts

@ -20,7 +20,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';
@ -61,11 +61,11 @@ export class GfTreemapChartComponent
@Output() treemapChartClicked = new EventEmitter<AssetProfileIdentifier>(); @Output() treemapChartClicked = new EventEmitter<AssetProfileIdentifier>();
@ViewChild('chartCanvas') private chartCanvas: ElementRef<HTMLCanvasElement>;
protected isLoading = true; protected isLoading = true;
private chart: Chart<'treemap'>; private chart: Chart<'treemap'>;
private readonly chartCanvas =
viewChild.required<ElementRef<HTMLCanvasElement>>('chartCanvas');
public constructor() { public constructor() {
Chart.register(LinearScale, Tooltip, TreemapController, TreemapElement); Chart.register(LinearScale, Tooltip, TreemapController, TreemapElement);
@ -307,7 +307,7 @@ export class GfTreemapChartComponent
] ]
}; };
if (this.chartCanvas) { 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 ??= {};
@ -316,7 +316,7 @@ export class GfTreemapChartComponent
this.chart.update(); this.chart.update();
} else { } else {
this.chart = new Chart<'treemap'>(this.chartCanvas.nativeElement, { this.chart = new Chart<'treemap'>(this.chartCanvas().nativeElement, {
data, data,
options: { options: {
animation: false, animation: false,

Loading…
Cancel
Save