11import { Component , Input , OnChanges , EventEmitter , Output , ViewChild } from '@angular/core' ;
2- import { Chart , ChartConfiguration , LineController } from 'chart.js' ;
2+ import type { ChartConfiguration } from 'chart.js' ;
3+ import { loadChart } from '../../shared/chart-utils' ;
34import { StateService } from '../../shared/state.service' ;
45import { HealthService } from '../../health/health.service' ;
5- import { generateWeeksArray , filterByDate , weekDataLabels , scaleLabel } from './reports.utils' ;
6+ import { generateWeeksArray , filterByDate , weekDataLabels } from './reports.utils' ;
67import { ReportsService } from './reports.service' ;
78import { millisecondsToDay } from '../../meetups/constants' ;
89import { dedupeShelfReduce , styleVariables } from '../../shared/utils' ;
@@ -14,8 +15,6 @@ import { MatSelect } from '@angular/material/select';
1415import { MatOption } from '@angular/material/autocomplete' ;
1516import { ReportsDetailActivitiesComponent } from './reports-detail-activities.component' ;
1617
17- Chart . register ( LineController ) ;
18-
1918@Component ( {
2019 selector : 'planet-reports-health' ,
2120 templateUrl : './reports-health.component.html' ,
@@ -130,7 +129,10 @@ export class ReportsHealthComponent implements OnChanges {
130129 } ) ;
131130 }
132131
133- setChart ( { data, chartName } ) {
132+ async setChart ( { data, chartName } ) {
133+ const { Chart } = await loadChart ( [
134+ 'LineController' , 'LineElement' , 'PointElement' , 'CategoryScale' , 'LinearScale' , 'Title' , 'Tooltip'
135+ ] ) ;
134136 const updateChart = this . charts . find ( chart => chart . canvas . id === chartName ) ;
135137 if ( updateChart ) {
136138 updateChart . data = data ;
@@ -141,6 +143,7 @@ export class ReportsHealthComponent implements OnChanges {
141143 setTimeout ( ( ) => this . setChart ( { data, chartName } ) ) ;
142144 return ;
143145 }
146+ const axisTitleFont = { size : 12 , weight : 'bold' as const } ;
144147 const chartConfig : ChartConfiguration < 'line' > = {
145148 type : 'line' ,
146149 data,
@@ -153,9 +156,13 @@ export class ReportsHealthComponent implements OnChanges {
153156 scales : {
154157 y : {
155158 type : 'linear' ,
156- ticks : { precision : 0 }
159+ ticks : { precision : 0 } ,
160+ title : { display : true , text : $localize `Diagnoses` , font : axisTitleFont }
157161 } ,
158- x : { title : { display : true , text : 'Week of' } }
162+ x : {
163+ type : 'category' ,
164+ title : { display : true , text : $localize `Week of` , font : axisTitleFont }
165+ }
159166 } ,
160167 }
161168 } ;
0 commit comments