|
|
@@ -9,29 +9,11 @@ import {SdmDihService} from '../sdm-dih.service';
|
|
|
styleUrls: ['./year-graph.component.scss'],
|
|
|
})
|
|
|
export class YearGraphComponent {
|
|
|
- firstYear: string;
|
|
|
- lastYear: string;
|
|
|
- regions = [];
|
|
|
selectedYear = '';
|
|
|
- years = [];
|
|
|
- yearsLoaded = false;
|
|
|
|
|
|
- constructor(private sdmDihService: SdmDihService) {
|
|
|
+ constructor(public sdmDihService: SdmDihService) {
|
|
|
this.sdmDihService.dataLoads.subscribe(() => {
|
|
|
- this.years = Object.keys(this.sdmDihService.sdmData);
|
|
|
- this.yearsLoaded = true;
|
|
|
- console.log(this.years);
|
|
|
- this.firstYear = this.years[0];
|
|
|
- this.lastYear = this.years[this.years.length - 1];
|
|
|
- this.regions = [
|
|
|
- ...new Set(
|
|
|
- this.sdmDihService.sdmData[this.firstYear].map(
|
|
|
- (yearData) => yearData['MODEL']
|
|
|
- )
|
|
|
- ),
|
|
|
- ];
|
|
|
- console.log(this.regions);
|
|
|
- this.selectedYear = this.firstYear;
|
|
|
+ this.selectedYear = this.sdmDihService.firstYear;
|
|
|
this.redrawGraphs();
|
|
|
this.drawLegend();
|
|
|
});
|
|
|
@@ -44,8 +26,8 @@ export class YearGraphComponent {
|
|
|
const regionData = this.sdmDihService.sdmData[year].find(
|
|
|
(row) => row['MODEL'] === region
|
|
|
);
|
|
|
- const width = 100 / this.regions.length;
|
|
|
- const height = 100 / this.regions.length;
|
|
|
+ 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')
|
|
|
@@ -163,7 +145,7 @@ export class YearGraphComponent {
|
|
|
const width = 200;
|
|
|
const height = 200;
|
|
|
select('#year-graph-place').selectAll('svg')?.remove();
|
|
|
- for (const region of this.regions) {
|
|
|
+ for (const region of this.sdmDihService.regions) {
|
|
|
this.drawGraph(region);
|
|
|
}
|
|
|
}
|