year-graph.component.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {Component} from '@angular/core';
  2. import {SdmDihService} from '../../sdm-dih.service';
  3. import {YearGraphService} from './year-graph.service';
  4. @Component({
  5. selector: 'year-graph',
  6. templateUrl: './year-graph.component.html',
  7. styleUrls: ['./year-graph.component.scss'],
  8. })
  9. export class YearGraphComponent {
  10. constructor(
  11. public sdmDihService: SdmDihService,
  12. public yearGraphService: YearGraphService
  13. ) {}
  14. animateGraphs() {
  15. const MILLISECONDS_TO_ANIMATE = 100 as const;
  16. let i = 1;
  17. for (const year of this.sdmDihService.years) {
  18. setTimeout(() => {
  19. this.yearGraphService.selectedYear = year;
  20. this.yearGraphService.redrawGraphs();
  21. }, MILLISECONDS_TO_ANIMATE * i);
  22. i++;
  23. }
  24. }
  25. nextYear() {
  26. const selectedYearIndex = this.sdmDihService.years.findIndex(
  27. (val) => val == this.yearGraphService.selectedYear
  28. );
  29. this.yearGraphService.selectedYear =
  30. this.sdmDihService.years[selectedYearIndex + 1] ??
  31. this.yearGraphService.selectedYear;
  32. this.yearGraphService.redrawGraphs();
  33. }
  34. prevYear() {
  35. const selectedYearIndex = this.sdmDihService.years.findIndex(
  36. (val) => val == this.yearGraphService.selectedYear
  37. );
  38. this.yearGraphService.selectedYear =
  39. this.sdmDihService.years[selectedYearIndex - 1] ??
  40. this.yearGraphService.selectedYear;
  41. this.yearGraphService.redrawGraphs();
  42. }
  43. }