@for (label of labels(); let i = $index; track i) {
(false);
- options = signal({});
- data = signal({} as ChartData);
+ options = signal(null);
+ data = signal(null);
platformId = inject(PLATFORM_ID);
- cd = inject(ChangeDetectorRef);
+ readonly PIE_CHART_PALETTE = PIE_CHART_PALETTE;
ngOnInit() {
- this.initChart();
- }
-
- initChart() {
if (isPlatformBrowser(this.platformId)) {
const documentStyle = getComputedStyle(document.documentElement);
const textColorSecondary = documentStyle.getPropertyValue('--dark-blue-1');
@@ -69,8 +56,6 @@ export class BarChartComponent implements OnInit {
this.setChartData(defaultBackgroundColor, defaultBorderColor);
this.setChartOptions(textColorSecondary, surfaceBorder);
-
- this.cd.markForCheck();
}
}
@@ -88,15 +73,12 @@ export class BarChartComponent implements OnInit {
});
}
- getColor(index: number): string {
- return PIE_CHART_PALETTE[index % PIE_CHART_PALETTE.length];
- }
-
private setChartOptions(textColorSecondary: string, surfaceBorder: string) {
this.options.set({
indexAxis: this.orientation() === 'horizontal' ? 'y' : 'x',
maintainAspectRatio: false,
- aspectRatio: 0.8,
+ aspectRatio: 0.9,
+ responsive: true,
plugins: {
legend: {
display: this.showLegend(),
diff --git a/src/app/shared/components/doughnut-chart/doughnut-chart.component.html b/src/app/shared/components/doughnut-chart/doughnut-chart.component.html
index eefcdeccb..e8c487bfc 100644
--- a/src/app/shared/components/doughnut-chart/doughnut-chart.component.html
+++ b/src/app/shared/components/doughnut-chart/doughnut-chart.component.html
@@ -5,24 +5,29 @@
} @else {
-
-
+
{{ label }}
@if (datasets().length) {
diff --git a/src/app/shared/components/bar-chart/bar-chart.component.ts b/src/app/shared/components/bar-chart/bar-chart.component.ts
index e47946b32..297f98779 100644
--- a/src/app/shared/components/bar-chart/bar-chart.component.ts
+++ b/src/app/shared/components/bar-chart/bar-chart.component.ts
@@ -4,16 +4,7 @@ import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from 'pr
import { ChartModule } from 'primeng/chart';
import { isPlatformBrowser } from '@angular/common';
-import {
- ChangeDetectionStrategy,
- ChangeDetectorRef,
- Component,
- inject,
- input,
- OnInit,
- PLATFORM_ID,
- signal,
-} from '@angular/core';
+import { ChangeDetectionStrategy, Component, inject, input, OnInit, PLATFORM_ID, signal } from '@angular/core';
import { PIE_CHART_PALETTE } from '@osf/shared/constants';
import { DatasetInput } from '@osf/shared/models';
@@ -49,17 +40,13 @@ export class BarChartComponent implements OnInit {
orientation = input<'horizontal' | 'vertical'>('horizontal');
showExpandedSection = input{{ title() | translate }}
@if (isLoading()) {
-
-
+
+
+ @if (data() && options() && labels().length) {
+
+ }
@if (showExpandedSection()) {
-
+
-
+
-
{{ title() | translate }}
+
@for (label of labels(); let i = $index; track i) {
(false);
title = input('');
@@ -48,26 +38,18 @@ export class DoughnutChartComponent implements OnInit {
showLegend = input(false);
showExpandedSection = input(false);
- options = signal({});
- data = signal({} as ChartData);
+ options = signal | null>(null);
+ data = signal(null);
- ngOnInit() {
- this.initChart();
- }
+ readonly PIE_CHART_PALETTE = PIE_CHART_PALETTE;
- initChart() {
+ ngOnInit() {
if (isPlatformBrowser(this.platformId)) {
this.setChartData();
this.setChartOptions();
-
- this.cd.markForCheck();
}
}
- getColor(index: number): string {
- return PIE_CHART_PALETTE[index % PIE_CHART_PALETTE.length];
- }
-
private setChartData() {
const chartDatasets = this.datasets().map((dataset) => ({
label: dataset.label,
@@ -84,6 +66,7 @@ export class DoughnutChartComponent implements OnInit {
private setChartOptions() {
this.options.set({
+ cutout: '60%',
maintainAspectRatio: true,
responsive: true,
plugins: {
-
+
{{ label }}
@if (datasets().length) {
diff --git a/src/app/shared/components/doughnut-chart/doughnut-chart.component.ts b/src/app/shared/components/doughnut-chart/doughnut-chart.component.ts
index 718d71c16..88b4f6755 100644
--- a/src/app/shared/components/doughnut-chart/doughnut-chart.component.ts
+++ b/src/app/shared/components/doughnut-chart/doughnut-chart.component.ts
@@ -4,16 +4,7 @@ import { Accordion, AccordionContent, AccordionHeader, AccordionPanel } from 'pr
import { ChartModule } from 'primeng/chart';
import { isPlatformBrowser } from '@angular/common';
-import {
- ChangeDetectionStrategy,
- ChangeDetectorRef,
- Component,
- inject,
- input,
- OnInit,
- PLATFORM_ID,
- signal,
-} from '@angular/core';
+import { ChangeDetectionStrategy, Component, inject, input, OnInit, PLATFORM_ID, signal } from '@angular/core';
import { PIE_CHART_PALETTE } from '@osf/shared/constants';
import { DatasetInput } from '@osf/shared/models';
@@ -39,7 +30,6 @@ import { ChartData, ChartOptions } from 'chart.js';
})
export class DoughnutChartComponent implements OnInit {
private readonly platformId = inject(PLATFORM_ID);
- private readonly cd = inject(ChangeDetectorRef);
isLoading = input