|
@@ -1,5 +1,4 @@
|
|
|
-import {Component, OnInit} from '@angular/core';
|
|
|
|
|
-import {interpolate, quantize, select} from 'd3';
|
|
|
|
|
|
|
+import {Component} from '@angular/core';
|
|
|
|
|
|
|
|
import {SdmDihService} from '../../sdm-dih.service';
|
|
import {SdmDihService} from '../../sdm-dih.service';
|
|
|
import {YearGraphService} from '../year-graph.service';
|
|
import {YearGraphService} from '../year-graph.service';
|
|
@@ -9,26 +8,12 @@ import {YearGraphService} from '../year-graph.service';
|
|
|
templateUrl: './year-graph.component.html',
|
|
templateUrl: './year-graph.component.html',
|
|
|
styleUrls: ['./year-graph.component.scss'],
|
|
styleUrls: ['./year-graph.component.scss'],
|
|
|
})
|
|
})
|
|
|
-export class YearGraphComponent implements OnInit {
|
|
|
|
|
|
|
+export class YearGraphComponent {
|
|
|
constructor(
|
|
constructor(
|
|
|
public sdmDihService: SdmDihService,
|
|
public sdmDihService: SdmDihService,
|
|
|
public yearGraphService: YearGraphService
|
|
public yearGraphService: YearGraphService
|
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
- ngOnInit() {
|
|
|
|
|
- this.sdmDihService.dataLoads.subscribe((loaded) => {
|
|
|
|
|
- if (!loaded) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.redrawGraphs();
|
|
|
|
|
- this.drawLegend();
|
|
|
|
|
- });
|
|
|
|
|
- this.yearGraphService.graphRefreshes.subscribe(() => {
|
|
|
|
|
- this.redrawGraphs();
|
|
|
|
|
- this.drawLegend();
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
animateGraphs() {
|
|
animateGraphs() {
|
|
|
const MILLISECONDS_TO_ANIMATE = 100 as const;
|
|
const MILLISECONDS_TO_ANIMATE = 100 as const;
|
|
|
let i = 1;
|
|
let i = 1;
|
|
@@ -41,123 +26,6 @@ export class YearGraphComponent implements OnInit {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- drawGraph(region: string) {
|
|
|
|
|
- const year = this.yearGraphService.selectedYear.toString().includes('.')
|
|
|
|
|
- ? this.yearGraphService.selectedYear
|
|
|
|
|
- : this.yearGraphService.selectedYear + '.0';
|
|
|
|
|
- const regionData = this.sdmDihService.sdmData[year].find(
|
|
|
|
|
- (row) => row['MODEL'] === region
|
|
|
|
|
- );
|
|
|
|
|
- const width = 100 / this.sdmDihService.regions.length;
|
|
|
|
|
- const height = 100 / this.sdmDihService.regions.length;
|
|
|
|
|
- // append the svg object to the div called 'year-graph-place'
|
|
|
|
|
- const svg = select('#year-graph-place')
|
|
|
|
|
- .append('svg')
|
|
|
|
|
- .attr('width', `${width}%`)
|
|
|
|
|
- .attr('height', `${height}%`)
|
|
|
|
|
- .append('svg')
|
|
|
|
|
- .attr('x', '50%')
|
|
|
|
|
- .attr('y', '50%')
|
|
|
|
|
- .attr('overflow', 'visible');
|
|
|
|
|
- // arrow symbol for later re-use
|
|
|
|
|
- const arrow = svg.append('symbol').attr('id', 'arrow');
|
|
|
|
|
- // horizontal line
|
|
|
|
|
- arrow
|
|
|
|
|
- .append('line')
|
|
|
|
|
- .attr('x1', 0)
|
|
|
|
|
- .attr('y1', 30)
|
|
|
|
|
- .attr('x2', 60)
|
|
|
|
|
- .attr('y2', 30)
|
|
|
|
|
- .attr('stroke', 'black')
|
|
|
|
|
- .style('stroke-width', 4);
|
|
|
|
|
- // upper line
|
|
|
|
|
- arrow
|
|
|
|
|
- .append('line')
|
|
|
|
|
- .attr('x1', 40)
|
|
|
|
|
- .attr('y1', 10)
|
|
|
|
|
- .attr('x2', 60)
|
|
|
|
|
- .attr('y2', 30)
|
|
|
|
|
- .attr('stroke', 'black')
|
|
|
|
|
- .style('stroke-width', 4);
|
|
|
|
|
- // bottom line
|
|
|
|
|
- arrow
|
|
|
|
|
- .append('line')
|
|
|
|
|
- .attr('x1', 40)
|
|
|
|
|
- .attr('y1', 50)
|
|
|
|
|
- .attr('x2', 60)
|
|
|
|
|
- .attr('y2', 30)
|
|
|
|
|
- .attr('stroke', 'black')
|
|
|
|
|
- .style('stroke-width', 4);
|
|
|
|
|
- const svgContent = svg.append('g').data([regionData]);
|
|
|
|
|
- //.attr('transform', 'translate(' + width / 2 + '% ,' + height / 2 + '% )');
|
|
|
|
|
- svgContent
|
|
|
|
|
- .append('circle')
|
|
|
|
|
- .attr('cx', 0)
|
|
|
|
|
- .attr('cy', 0)
|
|
|
|
|
- .attr('r', 50)
|
|
|
|
|
- .attr('stroke', 'black')
|
|
|
|
|
- .attr('fill', (d) => {
|
|
|
|
|
- return this.sdmDihService.perc2color(d['aggregated']);
|
|
|
|
|
- });
|
|
|
|
|
- svgContent
|
|
|
|
|
- .append('text')
|
|
|
|
|
- .attr('x', 0)
|
|
|
|
|
- .attr('y', -60)
|
|
|
|
|
- .attr('dy', '.35em')
|
|
|
|
|
- .text((d) => d['MODEL'])
|
|
|
|
|
- .style('text-anchor', 'middle');
|
|
|
|
|
- svgContent
|
|
|
|
|
- .append('text')
|
|
|
|
|
- .attr('x', 0)
|
|
|
|
|
- .attr('y', 60)
|
|
|
|
|
- .attr('dy', '.35em')
|
|
|
|
|
- .text((d) => `${(Number.parseFloat(d['aggregated']) * 100).toFixed(2)} %`)
|
|
|
|
|
- .style('text-anchor', 'middle');
|
|
|
|
|
- svgContent
|
|
|
|
|
- .append('use')
|
|
|
|
|
- .attr('xlink:href', '#arrow')
|
|
|
|
|
- .attr('x', -30)
|
|
|
|
|
- .attr('y', -30)
|
|
|
|
|
- .attr(
|
|
|
|
|
- 'transform',
|
|
|
|
|
- // rotation is defined clockwise, hence -45 deg will turn the arrow up
|
|
|
|
|
- (d) =>
|
|
|
|
|
- `rotate(${-45 * this.yearGraphService.getRegionProgress(d)}, 0, 0)`
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- drawLegend() {
|
|
|
|
|
- select(`#year-graph-legend-place`).remove();
|
|
|
|
|
- const width = 200;
|
|
|
|
|
- const height = 20;
|
|
|
|
|
- const g = select('#year-graph-legend-place')
|
|
|
|
|
- .append('svg')
|
|
|
|
|
- .attr('width', width)
|
|
|
|
|
- .attr('height', height)
|
|
|
|
|
- .attr('viewBox', [0, 0, width, height])
|
|
|
|
|
- .style('overflow', 'visible')
|
|
|
|
|
- .style('display', 'block')
|
|
|
|
|
- .append('g');
|
|
|
|
|
- for (let i = 0; i < 10; i++) {
|
|
|
|
|
- g.append('rect')
|
|
|
|
|
- .attr('x', i * 20)
|
|
|
|
|
- .attr('y', 0)
|
|
|
|
|
- .attr('width', width / 10)
|
|
|
|
|
- .attr('height', height / 2)
|
|
|
|
|
- .attr('fill', this.sdmDihService.perc2color(i / 10));
|
|
|
|
|
- }
|
|
|
|
|
- g.append('text')
|
|
|
|
|
- .attr('x', 0 - 10)
|
|
|
|
|
- .attr('y', 20)
|
|
|
|
|
- .attr('dy', '.5em')
|
|
|
|
|
- .text('0 %');
|
|
|
|
|
- g.append('text')
|
|
|
|
|
- .attr('x', 200 - 10)
|
|
|
|
|
- .attr('y', 20)
|
|
|
|
|
- .attr('dy', '.5em')
|
|
|
|
|
- .text('100 %');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
nextYear() {
|
|
nextYear() {
|
|
|
const selectedYearIndex = this.sdmDihService.years.findIndex(
|
|
const selectedYearIndex = this.sdmDihService.years.findIndex(
|
|
|
(val) => val == this.yearGraphService.selectedYear
|
|
(val) => val == this.yearGraphService.selectedYear
|
|
@@ -177,17 +45,4 @@ export class YearGraphComponent implements OnInit {
|
|
|
this.yearGraphService.selectedYear;
|
|
this.yearGraphService.selectedYear;
|
|
|
this.yearGraphService.redrawGraphs();
|
|
this.yearGraphService.redrawGraphs();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- redrawGraphs() {
|
|
|
|
|
- // Data not loaded yet
|
|
|
|
|
- if (!this.sdmDihService.sdmData) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- const width = 200;
|
|
|
|
|
- const height = 200;
|
|
|
|
|
- select('#year-graph-place').selectAll('svg')?.remove();
|
|
|
|
|
- for (const region of this.sdmDihService.regions) {
|
|
|
|
|
- this.drawGraph(region);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|