|
|
@@ -1,13 +1,13 @@
|
|
|
-import { Component, OnInit } from "@angular/core";
|
|
|
-import { select } from "d3";
|
|
|
+import {Component} from '@angular/core';
|
|
|
+import {select} from 'd3';
|
|
|
|
|
|
-import { SdmDihService } from "../sdm-dih.service";
|
|
|
+import {SdmDihService} from '../sdm-dih.service';
|
|
|
|
|
|
@Component({
|
|
|
- selector: "year-graph",
|
|
|
- templateUrl: "year-graph.component.html",
|
|
|
+ selector: 'year-graph',
|
|
|
+ templateUrl: 'year-graph.component.html',
|
|
|
})
|
|
|
-export class YearGraphComponent implements OnInit {
|
|
|
+export class YearGraphComponent {
|
|
|
firstYear: string;
|
|
|
lastYear: string;
|
|
|
regions = [];
|
|
|
@@ -21,56 +21,63 @@ export class YearGraphComponent implements OnInit {
|
|
|
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']))];
|
|
|
+ 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);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- ngOnInit() {}
|
|
|
-
|
|
|
drawGraph(region: string) {
|
|
|
- const regionData = this.sdmDihService.aggregatedData[this.selectedYear].find((row) => row['MODEL'] === region);
|
|
|
+ const regionData = this.sdmDihService.aggregatedData[
|
|
|
+ this.selectedYear
|
|
|
+ ].find((row) => row['MODEL'] === region);
|
|
|
const width = 200;
|
|
|
const height = 200;
|
|
|
//select("#year-graph-place").select("svg")?.remove();
|
|
|
// 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("g")
|
|
|
+ const svg = select('#year-graph-place')
|
|
|
+ .append('svg')
|
|
|
+ .attr('width', width)
|
|
|
+ .attr('height', height)
|
|
|
+ .append('g')
|
|
|
.data([regionData])
|
|
|
- .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
|
|
+ .attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')');
|
|
|
//const yearData = this.sdmDihService.aggregatedData[this.selectedYear];
|
|
|
//const color = `rgba(100, 200, 100, ${yearData[0]['Natural_Capital']})`;
|
|
|
svg
|
|
|
- .append("circle")
|
|
|
- .attr("cx", 0)
|
|
|
- .attr("cy", 0)
|
|
|
- .attr("r", 50)
|
|
|
- .attr("stroke", "black")
|
|
|
- .attr("fill", (d) => {
|
|
|
+ .append('circle')
|
|
|
+ .attr('cx', 0)
|
|
|
+ .attr('cy', 0)
|
|
|
+ .attr('r', 50)
|
|
|
+ .attr('stroke', 'black')
|
|
|
+ .attr('fill', (d) => {
|
|
|
console.log(d);
|
|
|
return this.getColor(d['Natural_Capital']);
|
|
|
});
|
|
|
- svg.append("text")
|
|
|
- .attr("x", 50)
|
|
|
- .attr("y", 50)
|
|
|
- .attr("dy", ".35em")
|
|
|
+ svg
|
|
|
+ .append('text')
|
|
|
+ .attr('x', 50)
|
|
|
+ .attr('y', 50)
|
|
|
+ .attr('dy', '.35em')
|
|
|
.text((d) => d['MODEL']);
|
|
|
}
|
|
|
|
|
|
redrawGraphs() {
|
|
|
const width = 200;
|
|
|
const height = 200;
|
|
|
- select("#year-graph-place").selectAll("svg")?.remove();
|
|
|
+ select('#year-graph-place').selectAll('svg')?.remove();
|
|
|
for (const region of this.regions) {
|
|
|
this.drawGraph(region);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
getColor(value) {
|
|
|
- return `rgba(100, 200, 100, ${value})`
|
|
|
+ return `rgba(100, 200, 100, ${value})`;
|
|
|
}
|
|
|
}
|