|
|
@@ -8,40 +8,68 @@ import { SdmDihService } from "../sdm-dih.service";
|
|
|
templateUrl: "year-graph.component.html",
|
|
|
})
|
|
|
export class YearGraphComponent implements OnInit {
|
|
|
- years = [];
|
|
|
+ firstYear: string;
|
|
|
+ lastYear: string;
|
|
|
regions = [];
|
|
|
+ selectedYear = '';
|
|
|
+ years = [];
|
|
|
yearsLoaded = false;
|
|
|
- selectedYear = "";
|
|
|
|
|
|
constructor(private 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);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
- drawGraph() {
|
|
|
+ drawGraph(region: string) {
|
|
|
const width = 200;
|
|
|
const height = 200;
|
|
|
- select("#year-graph-place").select("svg")?.remove();
|
|
|
+ //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")
|
|
|
+ .data(this.sdmDihService.aggregatedData[this.selectedYear])
|
|
|
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
|
|
|
- const yearData = this.sdmDihService.aggregatedData[this.selectedYear];
|
|
|
- const color = `rgba(100, 200, 100, ${yearData[0]['Natural_Capital']})`;
|
|
|
+ //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", color);
|
|
|
+ .attr("fill", (d) => {
|
|
|
+ console.log(d);
|
|
|
+ return this.getColor(d['Natural_Capital']);
|
|
|
+ });
|
|
|
+ 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();
|
|
|
+ for (const region of this.regions) {
|
|
|
+ this.drawGraph(region);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getColor(value) {
|
|
|
+ return `rgba(100, 200, 100, ${value})`
|
|
|
}
|
|
|
}
|