|
|
@@ -0,0 +1,61 @@
|
|
|
+import {Component, Input, OnInit} from '@angular/core';
|
|
|
+
|
|
|
+import {SdmDihService} from '../../sdm-dih.service';
|
|
|
+import {YearGraphService} from '../year-graph.service';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'scenario-factor-year-graph',
|
|
|
+ templateUrl: './scenario-factor-year-graph.component.html',
|
|
|
+ styleUrls: ['./scenario-factor-year-graph.component.scss'],
|
|
|
+})
|
|
|
+export class ScenarioFactorYearGraphComponent implements OnInit {
|
|
|
+ @Input() region: string;
|
|
|
+ @Input() domain: string;
|
|
|
+ constructor(
|
|
|
+ public sdmDihService: SdmDihService,
|
|
|
+ public yearGraphService: YearGraphService
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ ngOnInit() {
|
|
|
+ this.sdmDihService.dataLoads.subscribe((loaded) => {
|
|
|
+ if (!loaded) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.yearGraphService.graphRefreshes.subscribe(() => {
|
|
|
+ //unused
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ animateGraphs() {
|
|
|
+ const MILLISECONDS_TO_ANIMATE = 100 as const;
|
|
|
+ let i = 1;
|
|
|
+ for (const year of this.sdmDihService.years) {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.yearGraphService.selectedYear = year;
|
|
|
+ this.yearGraphService.redrawGraphs();
|
|
|
+ }, MILLISECONDS_TO_ANIMATE * i);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ nextYear() {
|
|
|
+ const selectedYearIndex = this.sdmDihService.years.findIndex(
|
|
|
+ (val) => val == this.yearGraphService.selectedYear
|
|
|
+ );
|
|
|
+ this.yearGraphService.selectedYear =
|
|
|
+ this.sdmDihService.years[selectedYearIndex + 1] ??
|
|
|
+ this.yearGraphService.selectedYear;
|
|
|
+ this.yearGraphService.redrawGraphs();
|
|
|
+ }
|
|
|
+
|
|
|
+ prevYear() {
|
|
|
+ const selectedYearIndex = this.sdmDihService.years.findIndex(
|
|
|
+ (val) => val == this.yearGraphService.selectedYear
|
|
|
+ );
|
|
|
+ this.yearGraphService.selectedYear =
|
|
|
+ this.sdmDihService.years[selectedYearIndex - 1] ??
|
|
|
+ this.yearGraphService.selectedYear;
|
|
|
+ this.yearGraphService.redrawGraphs();
|
|
|
+ }
|
|
|
+}
|