|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import {
|
|
|
|
|
ChangeDetectionStrategy,
|
|
|
|
|
ChangeDetectorRef,
|
|
|
|
|
Component,
|
|
|
|
|
Input,
|
|
|
|
|
OnChanges,
|
|
|
|
@ -7,6 +8,8 @@ import {
|
|
|
|
|
OnInit
|
|
|
|
|
} from '@angular/core';
|
|
|
|
|
import { primaryColorHex } from '@ghostfolio/common/config';
|
|
|
|
|
import { getCssVariable, getTextColor } from '@ghostfolio/common/helper';
|
|
|
|
|
import { Currency } from '@prisma/client';
|
|
|
|
|
import svgMap from 'svgmap';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
@ -16,33 +19,40 @@ import svgMap from 'svgmap';
|
|
|
|
|
styleUrls: ['./world-map-chart.component.scss']
|
|
|
|
|
})
|
|
|
|
|
export class WorldMapChartComponent implements OnChanges, OnDestroy, OnInit {
|
|
|
|
|
@Input() baseCurrency: Currency;
|
|
|
|
|
@Input() countries: { [code: string]: { name: string; value: number } };
|
|
|
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
|
public svgMapElement;
|
|
|
|
|
|
|
|
|
|
public constructor() {}
|
|
|
|
|
public constructor(private changeDetectorRef: ChangeDetectorRef) {}
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {}
|
|
|
|
|
|
|
|
|
|
public ngOnChanges() {
|
|
|
|
|
if (this.countries) {
|
|
|
|
|
this.destroySvgMap();
|
|
|
|
|
|
|
|
|
|
this.initialize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {}
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
|
this.destroySvgMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private initialize() {
|
|
|
|
|
new svgMap({
|
|
|
|
|
this.svgMapElement = new svgMap({
|
|
|
|
|
colorMax: primaryColorHex,
|
|
|
|
|
colorMin: '#d3f4f3',
|
|
|
|
|
colorNoData: '#eeeeee',
|
|
|
|
|
colorNoData: `rgba(${getTextColor()}, ${getCssVariable(
|
|
|
|
|
'--palette-foreground-divider-alpha'
|
|
|
|
|
)})`,
|
|
|
|
|
data: {
|
|
|
|
|
applyData: 'value',
|
|
|
|
|
data: {
|
|
|
|
|
value: {
|
|
|
|
|
format: '{0}',
|
|
|
|
|
name: 'Value'
|
|
|
|
|
format: `{0} ${this.baseCurrency}`
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
values: this.countries
|
|
|
|
@ -53,6 +63,17 @@ export class WorldMapChartComponent implements OnChanges, OnDestroy, OnInit {
|
|
|
|
|
targetElementID: 'svgMap'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.isLoading = false;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.isLoading = false;
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
|
}, 500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private destroySvgMap() {
|
|
|
|
|
this.svgMapElement?.mapWrapper?.remove();
|
|
|
|
|
this.svgMapElement?.tooltip?.remove();
|
|
|
|
|
|
|
|
|
|
this.svgMapElement = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|