Browse Source

resolve comments

pull/8017/head
KenTandrian 2 weeks ago
parent
commit
1bd200707e
  1. 28
      libs/ui/src/lib/world-map-chart/world-map-chart.component.ts

28
libs/ui/src/lib/world-map-chart/world-map-chart.component.ts

@ -23,10 +23,10 @@ import svgMap from 'svgmap';
templateUrl: './world-map-chart.component.html' templateUrl: './world-map-chart.component.html'
}) })
export class GfWorldMapChartComponent implements OnChanges, OnDestroy { export class GfWorldMapChartComponent implements OnChanges, OnDestroy {
@Input() public countries?: { @Input() public countries: {
[code: string]: { name?: string; value: number }; [code: string]: { name?: string; value: number };
}; };
@Input() public format?: string; @Input() public format: string;
@Input() public isInPercentage?: boolean = false; @Input() public isInPercentage?: boolean = false;
@Input() public locale?: string = getLocale(); @Input() public locale?: string = getLocale();
@ -53,28 +53,24 @@ export class GfWorldMapChartComponent implements OnChanges, OnDestroy {
} }
private initialize() { private initialize() {
if (!this.countries) {
return;
}
const countries = this.countries;
if (this.isInPercentage) { if (this.isInPercentage) {
// Convert value of countries to percentage // Convert value of countries to percentage
let sum = 0; let sum = 0;
Object.keys(countries).map((country) => { Object.keys(this.countries).map((country) => {
sum += countries[country].value; sum += this.countries[country].value;
}); });
Object.keys(countries).map((country) => { Object.keys(this.countries).map((country) => {
countries[country].value = Number( this.countries[country].value = Number(
((countries[country].value * 100) / sum).toFixed(2) ((this.countries[country].value * 100) / sum).toFixed(2)
); );
}); });
} else { } else {
// Convert value to fixed-point notation // Convert value to fixed-point notation
Object.keys(countries).map((country) => { Object.keys(this.countries).map((country) => {
countries[country].value = Number(countries[country].value.toFixed(2)); this.countries[country].value = Number(
this.countries[country].value.toFixed(2)
);
}); });
} }
@ -90,7 +86,7 @@ export class GfWorldMapChartComponent implements OnChanges, OnDestroy {
thousandSeparator: getNumberFormatGroup(this.locale) thousandSeparator: getNumberFormatGroup(this.locale)
} }
}, },
values: countries values: this.countries
}, },
hideFlag: true, hideFlag: true,
minZoom: 1.06, minZoom: 1.06,

Loading…
Cancel
Save