|
|
@@ -11,6 +11,13 @@ import {YearGraphService} from '../year-graph.service';
|
|
|
})
|
|
|
export class FactorYearGraphComponent implements OnInit {
|
|
|
@Input() region: string;
|
|
|
+ factors = [
|
|
|
+ 'aggregated',
|
|
|
+ 'http://www.semanticweb.org/attractiveness/anthropic',
|
|
|
+ 'http://www.semanticweb.org/attractiveness/economic',
|
|
|
+ 'http://www.semanticweb.org/attractiveness/natural',
|
|
|
+ 'http://www.semanticweb.org/attractiveness/social',
|
|
|
+ ];
|
|
|
|
|
|
constructor(
|
|
|
public sdmDihService: SdmDihService,
|
|
|
@@ -24,6 +31,11 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
}
|
|
|
this.redrawGraphs();
|
|
|
this.drawLegend();
|
|
|
+ console.log('data loads true');
|
|
|
+ });
|
|
|
+ this.yearGraphService.graphRefreshes.subscribe(() => {
|
|
|
+ this.redrawGraphs();
|
|
|
+ this.drawLegend();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -39,8 +51,8 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
);
|
|
|
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-${region}`)
|
|
|
+ // append the svg object to the div called 'year-graph-place-Apulia' or alike
|
|
|
+ const svg = select(`#year-graph-place-${region.replace(' ', '-')}`)
|
|
|
.append('svg')
|
|
|
.attr('width', `${width}%`)
|
|
|
.attr('height', `${height}%`)
|
|
|
@@ -86,7 +98,7 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
.attr('r', 50)
|
|
|
.attr('stroke', 'black')
|
|
|
.attr('fill', (d) => {
|
|
|
- return this.sdmDihService.perc2color(d[factor]?.index);
|
|
|
+ return this.sdmDihService.perc2color(d[factor]?.index ?? d[factor]);
|
|
|
});
|
|
|
svgContent
|
|
|
.append('text')
|
|
|
@@ -101,7 +113,10 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
.attr('y', 60)
|
|
|
.attr('dy', '.35em')
|
|
|
.text(
|
|
|
- (d) => `${(Number.parseFloat(d[factor]?.index) * 100).toFixed(2)} %`
|
|
|
+ (d) =>
|
|
|
+ `${(Number.parseFloat(d[factor]?.index ?? d[factor]) * 100).toFixed(
|
|
|
+ 2
|
|
|
+ )} %`
|
|
|
)
|
|
|
.style('text-anchor', 'middle');
|
|
|
svgContent
|
|
|
@@ -113,14 +128,25 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
'transform',
|
|
|
// rotation is defined clockwise, hence -45 deg will turn the arrow up
|
|
|
(d) =>
|
|
|
- `rotate(${-45 * this.yearGraphService.getRegionProgress(d)}, 0, 0)`
|
|
|
+ `rotate(${
|
|
|
+ -45 * this.yearGraphService.getRegionProgress(d, {factor})
|
|
|
+ }, 0, 0)`
|
|
|
);
|
|
|
+ console.log(
|
|
|
+ 'drawing finished'
|
|
|
+ //select(`#year-graph-place-${region.replace(' ', '-')}`)
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
drawLegend() {
|
|
|
+ select(
|
|
|
+ `#year-graph-legend-place-${this.region.replace(' ', '-')}`
|
|
|
+ ).remove();
|
|
|
const width = 200;
|
|
|
const height = 20;
|
|
|
- const g = select(`#year-graph-legend-place-${this.region}`)
|
|
|
+ const g = select(
|
|
|
+ `#year-graph-legend-place-${this.region.replace(' ', '-')}`
|
|
|
+ )
|
|
|
.append('svg')
|
|
|
.attr('width', width)
|
|
|
.attr('height', height)
|
|
|
@@ -151,11 +177,13 @@ export class FactorYearGraphComponent implements OnInit {
|
|
|
redrawGraphs() {
|
|
|
const width = 200;
|
|
|
const height = 200;
|
|
|
- select(`#year-graph-place-${this.region}`).selectAll('svg')?.remove();
|
|
|
- //for (const region of this.sdmDihService.regions) {
|
|
|
- this.drawGraph(this.region, {
|
|
|
- factor: 'http://www.semanticweb.org/attractiveness/economic',
|
|
|
- });
|
|
|
- //}
|
|
|
+ select(`#year-graph-place-${this.region.replace(' ', '-')}`)
|
|
|
+ .selectAll('svg')
|
|
|
+ ?.remove();
|
|
|
+ for (const factor of this.factors) {
|
|
|
+ this.drawGraph(this.region, {
|
|
|
+ factor: factor,
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|