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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {Component} 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 {
  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. processData() {
  22. //TODO: parametrize the PARAM_TO_COMPARE
  23. const PARAM_TO_COMPARE = 'aggregated';
  24. const years = [];
  25. const regions = [];
  26. const colors = [];
  27. for (const yearData of Object.values<any[]>(this.sdmDihService.sdmData)) {
  28. for (const regionData of yearData) {
  29. years.push(regionData['TIME_STEP']);
  30. regions.push(regionData['MODEL']);
  31. colors.push(regionData[PARAM_TO_COMPARE]);
  32. }
  33. }
  34. const trace1 = {
  35. x: years,
  36. y: regions,
  37. mode: 'markers',
  38. marker: {
  39. size: 10,
  40. color: colors,
  41. colorscale: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1].map(
  42. (perc) => {
  43. return [perc, this.sdmDihService.perc2color(perc)];
  44. }
  45. ),
  46. },
  47. type: 'scatter',
  48. };
  49. this.data = [trace1];
  50. }
  51. }