Skip to content

Commit

Permalink
chore: code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Jan 17, 2024
1 parent 3cf4cd9 commit 31b4140
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export class ClimateChartService {

private pointRadius = 8;

/** List of month names translated */
private monthNames: string[] = [];

constructor(
private translateService: PicsaTranslateService,
private dataService: ClimateDataService,
Expand All @@ -70,6 +73,8 @@ export class ClimateChartService {
this.station = station;
this.station$.next(station);
this.stationData = station?.data || [];
// ensure month names are translated
this.monthNames = await this.translateService.translateArray(MONTH_NAMES.map((m) => m.labelShort));
return this.station;
}

Expand Down Expand Up @@ -360,15 +365,15 @@ export class ClimateChartService {
if (isAxisLabel) {
const monthNumber = Math.round(dayNumber / yMajor) % 12;
// just want nearest month name
label = MONTH_NAMES[monthNumber].labelShort;
label = this.monthNames[monthNumber];
} else {
//simply converts number to day rough date value (same method as local met office)
//initialise year from a year with 365 days
const d = new Date(2015, 0);
d.setDate(dayNumber);

// just take first 3 letters
label = `${d.getDate()}-${MONTH_NAMES[d.getMonth() % 12].labelShort}`;
label = `${d.getDate()}-${this.monthNames[d.getMonth() % 12]}`;
}
return label;
}
Expand Down

0 comments on commit 31b4140

Please sign in to comment.