|
|
@@ -0,0 +1,56 @@
|
|
|
+import {Component, Input} from '@angular/core';
|
|
|
+
|
|
|
+import {SdmDihService} from '../sdm-dih.service';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'region-graph',
|
|
|
+ templateUrl: './region-graph.component.html',
|
|
|
+ styleUrls: ['./region-graph.component.scss'],
|
|
|
+})
|
|
|
+export class RegionGraphComponent {
|
|
|
+ @Input() region: string;
|
|
|
+ dataLoaded = false;
|
|
|
+ data = [];
|
|
|
+ layout = {
|
|
|
+ height: 400,
|
|
|
+ //width: '100%',
|
|
|
+ };
|
|
|
+
|
|
|
+ constructor(public sdmDihService: SdmDihService) {
|
|
|
+ this.sdmDihService.dataLoads.subscribe(() => {
|
|
|
+ this.processData();
|
|
|
+ this.dataLoaded = true;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ processData() {
|
|
|
+ //TODO: parametrize the PARAM_TO_COMPARE
|
|
|
+ const PARAM_TO_COMPARE = 'aggregated';
|
|
|
+ const years = [];
|
|
|
+ const regions = [];
|
|
|
+ const colors = [];
|
|
|
+ for (const yearData of Object.values<any[]>(this.sdmDihService.sdmData)) {
|
|
|
+ for (const regionData of yearData) {
|
|
|
+ years.push(regionData['TIME_STEP']);
|
|
|
+ regions.push(regionData['MODEL']);
|
|
|
+ colors.push(regionData[PARAM_TO_COMPARE]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const trace1 = {
|
|
|
+ x: years,
|
|
|
+ y: regions,
|
|
|
+ mode: 'markers',
|
|
|
+ marker: {
|
|
|
+ size: 10,
|
|
|
+ color: colors,
|
|
|
+ colorscale: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1].map(
|
|
|
+ (perc) => {
|
|
|
+ return [perc, this.sdmDihService.perc2color(perc)];
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ type: 'scatter',
|
|
|
+ };
|
|
|
+ this.data = [trace1];
|
|
|
+ }
|
|
|
+}
|