all-in-one-graph.component.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Component, OnInit} from '@angular/core';
  2. import {SdmDihService} from '../../sdm-dih.service';
  3. @Component({
  4. selector: 'all-in-one-graph',
  5. templateUrl: './all-in-one-graph.component.html',
  6. styleUrls: ['./all-in-one-graph.component.scss'],
  7. })
  8. export class AllInOneGraphComponent implements OnInit {
  9. dataLoaded = false;
  10. data = [];
  11. layout = {
  12. height: '20rem',
  13. //width: '100%',
  14. };
  15. constructor(public sdmDihService: SdmDihService) {
  16. this.sdmDihService.dataLoads.subscribe(() => {
  17. this.processData();
  18. this.dataLoaded = true;
  19. });
  20. }
  21. ngOnInit(): void {
  22. this.processData();
  23. this.dataLoaded = true;
  24. }
  25. processData() {
  26. //TODO: parametrize the PARAM_TO_COMPARE
  27. const PARAM_TO_COMPARE = 'aggregated';
  28. const years = [];
  29. const regions = [];
  30. const colors = [];
  31. for (const yearData of Object.values<any[]>(this.sdmDihService.sdmData)) {
  32. for (const regionData of yearData) {
  33. years.push(regionData['TIME_STEP']);
  34. regions.push(regionData['MODEL']);
  35. colors.push(regionData[PARAM_TO_COMPARE]);
  36. }
  37. }
  38. const trace1 = {
  39. x: years,
  40. y: regions,
  41. mode: 'markers',
  42. marker: {
  43. size: 10,
  44. color: colors,
  45. colorscale: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1].map(
  46. (perc) => {
  47. return [perc, this.sdmDihService.perc2color(perc)];
  48. }
  49. ),
  50. },
  51. type: 'scatter',
  52. };
  53. this.data = [trace1];
  54. }
  55. }