scenario-year-graph.component.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {Component, Input, OnInit} from '@angular/core';
  2. import domain2scenario from '../../../assets/data/domain-scenario.json';
  3. import {SdmDihService} from '../../sdm-dih.service';
  4. import {YearGraphService} from '../year-graph.service';
  5. @Component({
  6. selector: 'scenario-year-graph',
  7. templateUrl: './scenario-year-graph.component.html',
  8. styleUrls: ['./scenario-year-graph.component.scss'],
  9. })
  10. export class ScenarioYearGraphComponent implements OnInit {
  11. @Input() region: string;
  12. @Input() domain: string;
  13. filteredScenarios = [];
  14. constructor(
  15. public sdmDihService: SdmDihService,
  16. public yearGraphService: YearGraphService
  17. ) {}
  18. ngOnInit() {
  19. this.sdmDihService.dataLoads.subscribe((loaded) => {
  20. if (!loaded) {
  21. return;
  22. }
  23. this.filterScenarios();
  24. });
  25. this.yearGraphService.graphRefreshes.subscribe(({domain}) => {
  26. if (domain) {
  27. this.domain = domain;
  28. }
  29. this.filterScenarios();
  30. });
  31. }
  32. filterScenarios(): void {
  33. this.filteredScenarios = this.sdmDihService.scenarios.filter((scenario) => {
  34. return domain2scenario[this.domain].includes(scenario);
  35. });
  36. }
  37. /*animateGraphs() {
  38. const MILLISECONDS_TO_ANIMATE = 100 as const;
  39. let i = 1;
  40. for (const year of this.sdmDihService.years) {
  41. setTimeout(() => {
  42. this.yearGraphService.selectedYear = year;
  43. this.yearGraphService.redrawGraphs();
  44. }, MILLISECONDS_TO_ANIMATE * i);
  45. i++;
  46. }
  47. }*/
  48. /*nextYear() {
  49. const selectedYearIndex = this.sdmDihService.years.findIndex(
  50. (val) => val == this.yearGraphService.selectedYear
  51. );
  52. this.yearGraphService.selectedYear =
  53. this.sdmDihService.years[selectedYearIndex + 1] ??
  54. this.yearGraphService.selectedYear;
  55. this.yearGraphService.redrawGraphs();
  56. }*/
  57. /*prevYear() {
  58. const selectedYearIndex = this.sdmDihService.years.findIndex(
  59. (val) => val == this.yearGraphService.selectedYear
  60. );
  61. this.yearGraphService.selectedYear =
  62. this.sdmDihService.years[selectedYearIndex - 1] ??
  63. this.yearGraphService.selectedYear;
  64. this.yearGraphService.redrawGraphs();
  65. }*/
  66. }