diff --git a/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.html b/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.html index e78a293..a1916a3 100644 --- a/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.html +++ b/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.html @@ -8,5 +8,6 @@ [legend]="chartOptions().legend" [states]="chartOptions().states" [dataLabels]="chartOptions().dataLabels" - [tooltip]="chartOptions().tooltip"> + [tooltip]="chartOptions().tooltip" + (chartReady)="onChartReady()"> diff --git a/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.ts b/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.ts index 5cf1e37..0ca37c0 100644 --- a/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.ts +++ b/src/app/carbon-estimation-treemap/carbon-estimation-treemap.component.ts @@ -34,8 +34,9 @@ export class CarbonEstimationTreemapComponent { public chartOptions = computed(() => this.getChartOptions(!this.carbonEstimation())); private tooltipFormatter = tooltipFormatter; + private chartReady = false; - @ViewChild('chart') chart: ChartComponent | undefined; + @ViewChild('chart') private chart: ChartComponent | undefined; constructor(private carbonEstimationUtilService: CarbonEstimationUtilService) { effect(() => { @@ -46,6 +47,18 @@ export class CarbonEstimationTreemapComponent { }); } + public onChartReady() { + this.chartReady = true; + } + + public readyChart(): ChartComponent | undefined { + if (this.chartReady) { + return this.chart; + } + + return undefined; + } + private getChartOptions(isPlaceholder: boolean) { const chartOptions = getBaseChartOptions(isPlaceholder); chartOptions.chart.height = this.chartHeight(); diff --git a/src/app/carbon-estimation/carbon-estimation.component.ts b/src/app/carbon-estimation/carbon-estimation.component.ts index 1569a03..34f16fa 100644 --- a/src/app/carbon-estimation/carbon-estimation.component.ts +++ b/src/app/carbon-estimation/carbon-estimation.component.ts @@ -72,7 +72,7 @@ export class CarbonEstimationComponent implements OnInit, OnDestroy { this.hasResized = false; this.hasEstimationUpdated = false; this.changeDetectorRef.detectChanges(); - this.treemap.chart?.updateOptions({}); + this.treemap.readyChart()?.updateOptions({}); } }