ソースを参照

🐛 fix layer pop-up information

jmacura 4 年 前
コミット
c13575aead

+ 1 - 1
src/adjuster/adjuster-event.service.ts

@@ -7,7 +7,7 @@ export class AdjusterEventService {
   layerReady: Subject<{name: string}> = new Subject();
   loaded: Subject<{success: boolean; type: string; err?}> = new Subject();
   loaderReady: Subject<void> = new Subject();
-  methodChanged: Subject<string> = new Subject();
+  methodChanges: Subject<string> = new Subject();
   ontologyLoads: Subject<Array<RDFSubject>> = new Subject();
   constructor() {}
 }

+ 25 - 2
src/adjuster/adjuster-legend.service.ts

@@ -1,7 +1,8 @@
 import hsv2rgb from 'hsv2rgb';
 import {Injectable} from '@angular/core';
 
-import {perc2color} from '../app.config';
+import {decimal2prettyPerc, obceIndexLayer, perc2color} from '../app.config';
+import {AdjusterPresetsService, Factor} from './adjuster-presets.service';
 
 @Injectable({providedIn: 'root'})
 export class AdjusterLegendService {
@@ -20,7 +21,9 @@ export class AdjusterLegendService {
     '#ffff99',
     '#b15928',
   ];
-  constructor() {}
+  constructor(
+    public adjusterPresetsService: AdjusterPresetsService,
+    ) {}
 
   createIndexLegend(): FakeLegend {
     return [
@@ -42,6 +45,26 @@ export class AdjusterLegendService {
     return legend;
   }
 
+  updateIndexLayerPopUps(factors: Factor[]) {
+    const attrs = [
+      {
+        attribute: 'aggregate',
+        label: 'agregovaný index',
+        displayFunction: decimal2prettyPerc,
+      }
+    ];
+    for (const factor of factors) {
+      attrs.push({
+        attribute: factor.id,
+        label: this.adjusterPresetsService.getLabelInCurrentLang(factor.labels),
+        displayFunction: decimal2prettyPerc,
+      })
+    }
+    obceIndexLayer.set('popUp', {
+      attributes: attrs
+    });
+  }
+
   refreshColorPalette(count: number): void {
     this.colorPalette = this.generateRandomColorPalette(count);
   }

+ 10 - 1
src/adjuster/adjuster-presets.service.ts

@@ -1,6 +1,8 @@
 import {Injectable} from '@angular/core';
 import {Subject} from 'rxjs';
 
+import {HsLanguageService} from 'hslayers-ng';
+
 import attractivenessConfig from '../attractiveness.config.json';
 import {AdjusterEventService} from './adjuster-event.service';
 import {RDFSubject} from './ontology.model';
@@ -19,7 +21,10 @@ export class AdjusterPresetsService {
   roles: Role[] = [];
   schemas: Schema[] = [];
 
-  constructor(public adjusterEventService: AdjusterEventService) {
+  constructor(
+    public adjusterEventService: AdjusterEventService,
+    private hsLanguageService: HsLanguageService
+    ) {
     this.defaultSchemaId = attractivenessConfig?.defaultClassificationSchema;
     this.adjusterEventService.ontologyLoads.subscribe((ontology) => {
       this.ontology = ontology;
@@ -61,6 +66,10 @@ export class AdjusterPresetsService {
       }) ?? [];
   }
 
+  getLabelInCurrentLang(labels: Label[]) {
+    return this.getLabelInLang(labels, this.hsLanguageService.getCurrentLanguageCode());
+  }
+
   getLabelInLang(labels: Label[], lang: string) {
     return labels.find((labelEntity) => labelEntity['@language'] == lang)?.['@value'] ?? labels[0]['@value'];
   }

+ 2 - 4
src/adjuster/adjuster.component.ts

@@ -1,7 +1,6 @@
 import {Component, OnInit, ViewRef} from '@angular/core';
 
 import {HsDialogContainerService} from 'hslayers-ng';
-import {HsLanguageService} from 'hslayers-ng';
 import {HsLayoutService} from 'hslayers-ng';
 import {HsPanelComponent} from 'hslayers-ng';
 
@@ -28,7 +27,6 @@ export class AdjusterComponent implements HsPanelComponent, OnInit {
     public adjusterService: AdjusterService,
     public adjusterPresetsService: AdjusterPresetsService,
     public hsDialogContainerService: HsDialogContainerService,
-    public hsLanguageService: HsLanguageService,
     public hsLayoutService: HsLayoutService
   ) {
     //this.descriptionVisible = false;
@@ -49,7 +47,7 @@ export class AdjusterComponent implements HsPanelComponent, OnInit {
   }
 
   getLabelInCurrentLang(labels) {
-    return this.adjusterPresetsService.getLabelInLang(labels, this.hsLanguageService.getCurrentLanguageCode());
+    return this.adjusterPresetsService.getLabelInCurrentLang(labels);
   }
 
   isVisible(): boolean {
@@ -81,6 +79,6 @@ export class AdjusterComponent implements HsPanelComponent, OnInit {
 
   /*selectMethod(): void {
     this.adjusterService.method = this.method;
-    this.adjusterEventService.methodChanged.next(this.method);
+    this.adjusterEventService.methodChanges.next(this.method);
   }*/
 }

+ 3 - 1
src/adjuster/adjuster.service.ts

@@ -111,8 +111,9 @@ export class AdjusterService {
         id: 'others',
         labels: [{'@value': 'Ostatní', '@language': 'cs'}, {'@value': 'Others', '@language': 'en'}],
         weight: this.resetFactorWeights('others'),
-        datasets: orphanedDatasets
+        datasets: orphanedDatasets,
       })
+      this.adjusterLegendService.updateIndexLayerPopUps(this.factors);
     });
 
     /* Listen to problem changes so the datasets can be turned on/off */
@@ -160,6 +161,7 @@ export class AdjusterService {
       })
       .toPromise()
       .then((attractivenessData: any[]) => {
+        console.log("attractivenessData", attractivenessData)
         /* Spread the 'aggregate' value between 0 and 1 */
         const min = attractivenessData.reduce((a, b) =>
           a.aggregate < b.aggregate ? a : b

+ 1 - 3
src/adjuster/dataset-list/dataset-list.component.ts

@@ -2,7 +2,6 @@ import {Component, Input, OnInit} from '@angular/core';
 
 import {
   HsDialogContainerService,
-  HsLanguageService
 } from 'hslayers-ng';
 
 import {AdjusterPresetsService} from '../adjuster-presets.service';
@@ -20,13 +19,12 @@ export class DatasetListComponent implements OnInit {
   constructor(
     public adjusterPresetsService: AdjusterPresetsService,
     public hsDialogContainerService: HsDialogContainerService,
-    public hsLanguageService: HsLanguageService
   ) {}
 
   ngOnInit() {}
 
   getLabelInCurrentLang(labels) {
-    return this.adjusterPresetsService.getLabelInLang(labels, this.hsLanguageService.getCurrentLanguageCode());
+    return this.adjusterPresetsService.getLabelInCurrentLang(labels);
   }
 
   showMetadataWindow(dataset) {

+ 1 - 25
src/app.config.ts

@@ -153,7 +153,7 @@ export const perc2color = (perc: number): string => {
   return `rgba(${r}, ${g}, ${b}, 0.7)`;
 };
 
-const decimal2prettyPerc = (x) => {
+export const decimal2prettyPerc = (x) => {
   return `${(x * 100).toFixed(2)}&nbsp;%`;
 };
 
@@ -209,30 +209,6 @@ obceIndexLayer.set('popUp', {
       label: 'agregovaný index',
       displayFunction: decimal2prettyPerc,
     },
-    { //FIXME: This needs to be made versite to schemas
-      attribute: 'Konec chudoby',
-      displayFunction: decimal2prettyPerc,
-    },
-    {
-      attribute: 'Zdraví a kvalitní život',
-      displayFunction: decimal2prettyPerc,
-    },
-    {
-      attribute: 'Kvalitní vzdělání',
-      displayFunction: decimal2prettyPerc,
-    },
-    {
-      attribute: 'Důstojná práce a ekonomický růst',
-      displayFunction: decimal2prettyPerc,
-    },
-    {
-      attribute: 'Udržitelná města a obce',
-      displayFunction: decimal2prettyPerc,
-    },
-    {
-      attribute: 'Ostatní',
-      displayFunction: decimal2prettyPerc,
-    },
   ],
 });
 obceIndexLayer.set('editable', false);