svgmap 2.17.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/{src/js/svgMap.js → dist/index.cjs} +225 -188
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2350 -0
- package/dist/index.js.map +1 -0
- package/dist/svg-map.css +309 -0
- package/dist/svg-map.min.css +1 -0
- package/dist/svg-map.umd.js +2358 -0
- package/dist/svg-map.umd.js.map +1 -0
- package/dist/svg-map.umd.min.js +1 -0
- package/dist/svgMap.css +2 -4
- package/dist/svgMap.js +2192 -2167
- package/dist/svgMap.js.map +1 -0
- package/dist/svgMap.min.css +1 -2
- package/dist/svgMap.min.js +1 -2
- package/package.json +31 -19
- package/.editorconfig +0 -11
- package/.prettierrc +0 -13
- package/assets/countries.js +0 -247
- package/assets/create-map-paths.html +0 -1029
- package/assets/localize.html +0 -35
- package/assets/map-optimized.svg +0 -986
- package/demo/es6/data/gdp.js +0 -1755
- package/demo/es6/data/personHeight.js +0 -211
- package/demo/es6/data/population.js +0 -267
- package/demo/es6/demo.css +0 -41
- package/demo/es6/index.html +0 -49
- package/demo/es6/index.js +0 -142
- package/demo/es6/local/countriesAR.js +0 -247
- package/demo/es6/local/countriesDE.js +0 -247
- package/demo/es6/local/countriesEN.js +0 -247
- package/demo/es6/local/countriesES.js +0 -247
- package/demo/es6/local/countriesFR.js +0 -247
- package/demo/es6/local/countriesHI.js +0 -247
- package/demo/es6/local/countriesPT.js +0 -247
- package/demo/es6/local/countriesRU.js +0 -247
- package/demo/es6/local/countriesUR.js +0 -247
- package/demo/es6/local/countriesZH.js +0 -247
- package/demo/es6/package-lock.json +0 -4466
- package/demo/es6/package.json +0 -17
- package/demo/html/data/gdp.js +0 -1755
- package/demo/html/data/personHeight.js +0 -211
- package/demo/html/data/population.js +0 -267
- package/demo/html/demo.css +0 -41
- package/demo/html/index.html +0 -192
- package/demo/html/local/countriesAR.js +0 -247
- package/demo/html/local/countriesDE.js +0 -247
- package/demo/html/local/countriesEN.js +0 -247
- package/demo/html/local/countriesES.js +0 -247
- package/demo/html/local/countriesFR.js +0 -247
- package/demo/html/local/countriesHI.js +0 -247
- package/demo/html/local/countriesPT.js +0 -247
- package/demo/html/local/countriesRU.js +0 -247
- package/demo/html/local/countriesUR.js +0 -247
- package/demo/html/local/countriesZH.js +0 -247
- package/demo/react/app/README.md +0 -70
- package/demo/react/app/package-lock.json +0 -17448
- package/demo/react/app/package.json +0 -39
- package/demo/react/app/public/favicon.ico +0 -0
- package/demo/react/app/public/index.html +0 -43
- package/demo/react/app/public/logo192.png +0 -0
- package/demo/react/app/public/logo512.png +0 -0
- package/demo/react/app/public/manifest.json +0 -25
- package/demo/react/app/public/robots.txt +0 -3
- package/demo/react/app/src/App.css +0 -4
- package/demo/react/app/src/App.js +0 -54
- package/demo/react/app/src/App.test.js +0 -8
- package/demo/react/app/src/index.css +0 -13
- package/demo/react/app/src/index.js +0 -17
- package/demo/react/app/src/logo.svg +0 -1
- package/demo/react/app/src/reportWebVitals.js +0 -13
- package/demo/react/app/src/setupTests.js +0 -5
- package/gulpfile.js +0 -139
- package/src/js/umd.js +0 -14
- package/src/scss/main.scss +0 -2
- package/src/scss/map.scss +0 -257
- package/src/scss/tooltip.scss +0 -128
- package/src/scss/variables.scss +0 -31
- package/test/assets.test.js +0 -19
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
function svgMapWrapper(svgPanZoom) {
|
|
3
|
-
var svgMap = function (options) {
|
|
4
|
-
this.init(options);
|
|
5
|
-
};
|
|
1
|
+
'use strict';
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var defaultOptions = {
|
|
3
|
+
class svgMap {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
const defaultOptions = {
|
|
11
6
|
// The element to render the map in
|
|
12
7
|
targetElementID: '',
|
|
13
8
|
|
|
@@ -93,11 +88,16 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
93
88
|
showContinentSelector: false,
|
|
94
89
|
|
|
95
90
|
// Reset zoom on resize
|
|
96
|
-
resetZoomOnResize: false
|
|
91
|
+
resetZoomOnResize: false
|
|
97
92
|
};
|
|
98
93
|
|
|
99
|
-
this.options = Object.assign({}, defaultOptions, options
|
|
94
|
+
this.options = Object.assign({}, defaultOptions, options);
|
|
95
|
+
|
|
96
|
+
this.init();
|
|
97
|
+
}
|
|
100
98
|
|
|
99
|
+
// Initialize
|
|
100
|
+
init() {
|
|
101
101
|
// Abort if target element not found
|
|
102
102
|
if (
|
|
103
103
|
!this.options.targetElementID ||
|
|
@@ -143,11 +143,11 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
143
143
|
|
|
144
144
|
// Apply map data
|
|
145
145
|
this.applyData(this.options.data);
|
|
146
|
-
}
|
|
146
|
+
}
|
|
147
147
|
|
|
148
148
|
// Countries
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
countries = {
|
|
151
151
|
AF: 'Afghanistan',
|
|
152
152
|
AX: 'Åland Islands',
|
|
153
153
|
AL: 'Albania',
|
|
@@ -397,7 +397,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
397
397
|
|
|
398
398
|
// Apply the data to the map
|
|
399
399
|
|
|
400
|
-
|
|
400
|
+
applyData(data) {
|
|
401
401
|
var max = null;
|
|
402
402
|
var min = null;
|
|
403
403
|
|
|
@@ -411,9 +411,9 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
411
411
|
});
|
|
412
412
|
|
|
413
413
|
data.data[data.applyData].thresholdMax &&
|
|
414
|
-
|
|
414
|
+
(max = Math.min(max, data.data[data.applyData].thresholdMax));
|
|
415
415
|
data.data[data.applyData].thresholdMin &&
|
|
416
|
-
|
|
416
|
+
(min = Math.max(min, data.data[data.applyData].thresholdMin));
|
|
417
417
|
|
|
418
418
|
// Loop through countries and set colors
|
|
419
419
|
Object.keys(this.countries).forEach(
|
|
@@ -425,11 +425,17 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
425
425
|
return;
|
|
426
426
|
}
|
|
427
427
|
if (!data.values[countryID]) {
|
|
428
|
-
element.
|
|
428
|
+
element.style.setProperty(
|
|
429
|
+
'--svg-map-country-fill',
|
|
430
|
+
this.toHex(this.options.colorNoData)
|
|
431
|
+
);
|
|
429
432
|
return;
|
|
430
433
|
}
|
|
431
434
|
if (typeof data.values[countryID].color != 'undefined') {
|
|
432
|
-
element.
|
|
435
|
+
element.style.setProperty(
|
|
436
|
+
'--svg-map-country-fill',
|
|
437
|
+
data.values[countryID].color
|
|
438
|
+
);
|
|
433
439
|
return;
|
|
434
440
|
}
|
|
435
441
|
var value = Math.max(
|
|
@@ -442,12 +448,12 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
442
448
|
this.toHex(this.options.colorMin),
|
|
443
449
|
this.calculateColorRatio(value, min, max, this.options.ratioType)
|
|
444
450
|
);
|
|
445
|
-
element.
|
|
451
|
+
element.style.setProperty('--svg-map-country-fill', color);
|
|
446
452
|
}.bind(this)
|
|
447
453
|
);
|
|
448
|
-
}
|
|
454
|
+
}
|
|
449
455
|
|
|
450
|
-
|
|
456
|
+
calculateColorRatio(value, min, max, ratioType) {
|
|
451
457
|
var range = max - min;
|
|
452
458
|
var positionInRange = value - min;
|
|
453
459
|
|
|
@@ -459,7 +465,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
459
465
|
var logValue = Math.log(positionInRange + 1);
|
|
460
466
|
var logMin = Math.log(1);
|
|
461
467
|
var logMax = Math.log(range + 1);
|
|
462
|
-
var ratio = Math.max(
|
|
468
|
+
var ratio = Math.max(
|
|
469
|
+
0,
|
|
470
|
+
Math.min(1, (logValue - logMin) / (logMax - logMin))
|
|
471
|
+
);
|
|
463
472
|
return ratio || ratio === 0 ? ratio : 1;
|
|
464
473
|
}
|
|
465
474
|
|
|
@@ -477,7 +486,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
477
486
|
|
|
478
487
|
// Emoji flags
|
|
479
488
|
|
|
480
|
-
|
|
489
|
+
emojiFlags = {
|
|
481
490
|
AF: '🇦🇫',
|
|
482
491
|
AX: '🇦🇽',
|
|
483
492
|
AL: '🇦🇱',
|
|
@@ -725,72 +734,79 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
725
734
|
ZW: '🇿🇼'
|
|
726
735
|
};
|
|
727
736
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
},
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
x: 454,
|
|
737
|
+
continents = {
|
|
738
|
+
EA: {
|
|
739
|
+
iso: 'EA',
|
|
740
|
+
name: 'World'
|
|
741
|
+
},
|
|
742
|
+
AF: {
|
|
743
|
+
iso: 'AF',
|
|
744
|
+
name: 'Africa',
|
|
745
|
+
pan: {
|
|
746
|
+
x: 454,
|
|
747
|
+
y: 250
|
|
738
748
|
},
|
|
739
|
-
|
|
740
|
-
},
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
x: 904,
|
|
749
|
+
zoom: 1.9
|
|
750
|
+
},
|
|
751
|
+
AS: {
|
|
752
|
+
iso: 'AS',
|
|
753
|
+
name: 'Asia',
|
|
754
|
+
pan: {
|
|
755
|
+
x: 904,
|
|
756
|
+
y: 80
|
|
746
757
|
},
|
|
747
|
-
|
|
748
|
-
},
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
x: 404,
|
|
758
|
+
zoom: 1.8
|
|
759
|
+
},
|
|
760
|
+
EU: {
|
|
761
|
+
iso: 'EU',
|
|
762
|
+
name: 'Europe',
|
|
763
|
+
pan: {
|
|
764
|
+
x: 404,
|
|
765
|
+
y: 80
|
|
754
766
|
},
|
|
755
|
-
|
|
756
|
-
},
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
x: 104,
|
|
767
|
+
zoom: 5
|
|
768
|
+
},
|
|
769
|
+
NA: {
|
|
770
|
+
iso: 'NA',
|
|
771
|
+
name: 'North America',
|
|
772
|
+
pan: {
|
|
773
|
+
x: 104,
|
|
774
|
+
y: 55
|
|
762
775
|
},
|
|
763
|
-
|
|
776
|
+
zoom: 2.6
|
|
764
777
|
},
|
|
765
778
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
x: 104,
|
|
779
|
+
MA: {
|
|
780
|
+
iso: 'MA',
|
|
781
|
+
name: 'Middle America',
|
|
782
|
+
pan: {
|
|
783
|
+
x: 104,
|
|
784
|
+
y: 200
|
|
771
785
|
},
|
|
772
|
-
|
|
773
|
-
},
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
x: 104,
|
|
786
|
+
zoom: 2.6
|
|
787
|
+
},
|
|
788
|
+
SA: {
|
|
789
|
+
iso: 'SA',
|
|
790
|
+
name: 'South America',
|
|
791
|
+
pan: {
|
|
792
|
+
x: 104,
|
|
793
|
+
y: 340
|
|
779
794
|
},
|
|
780
|
-
|
|
781
|
-
},
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
x: 954,
|
|
795
|
+
zoom: 2.2
|
|
796
|
+
},
|
|
797
|
+
OC: {
|
|
798
|
+
iso: 'OC',
|
|
799
|
+
name: 'Oceania',
|
|
800
|
+
pan: {
|
|
801
|
+
x: 954,
|
|
802
|
+
y: 350
|
|
787
803
|
},
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
}
|
|
804
|
+
zoom: 1.9
|
|
805
|
+
}
|
|
806
|
+
};
|
|
791
807
|
// Create the SVG map
|
|
792
808
|
|
|
793
|
-
|
|
809
|
+
createMap() {
|
|
794
810
|
// Create the tooltip
|
|
795
811
|
this.createTooltip();
|
|
796
812
|
|
|
@@ -808,14 +824,15 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
808
824
|
this.mapImage.classList.add('svgMap-map-image');
|
|
809
825
|
this.mapWrapper.appendChild(this.mapImage);
|
|
810
826
|
|
|
811
|
-
|
|
812
827
|
// Add controls
|
|
813
828
|
var mapControlsWrapper = this.createElement(
|
|
814
829
|
'div',
|
|
815
830
|
'svgMap-map-controls-wrapper',
|
|
816
831
|
this.mapWrapper
|
|
817
832
|
);
|
|
818
|
-
mapControlsWrapper.classList.add(
|
|
833
|
+
mapControlsWrapper.classList.add(
|
|
834
|
+
'svgMap-controls-position-' + this.options.zoomButtonsPosition
|
|
835
|
+
);
|
|
819
836
|
var zoomContainer = this.createElement(
|
|
820
837
|
'div',
|
|
821
838
|
'svgMap-map-controls-zoom',
|
|
@@ -823,20 +840,23 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
823
840
|
);
|
|
824
841
|
['in', 'out', 'reset'].forEach(
|
|
825
842
|
function (item) {
|
|
826
|
-
if (
|
|
843
|
+
if (
|
|
844
|
+
(item === 'reset' && this.options.showZoomReset) ||
|
|
845
|
+
item !== 'reset'
|
|
846
|
+
) {
|
|
827
847
|
var zoomControlName =
|
|
828
848
|
'zoomControl' + item.charAt(0).toUpperCase() + item.slice(1);
|
|
829
849
|
this[zoomControlName] = this.createElement(
|
|
830
850
|
'button',
|
|
831
851
|
'svgMap-control-button svgMap-zoom-button svgMap-zoom-' +
|
|
832
|
-
|
|
833
|
-
|
|
852
|
+
item +
|
|
853
|
+
'-button',
|
|
834
854
|
zoomContainer
|
|
835
855
|
);
|
|
836
856
|
this[zoomControlName].type = 'button';
|
|
837
857
|
this[zoomControlName].addEventListener(
|
|
838
858
|
'click',
|
|
839
|
-
function() {
|
|
859
|
+
function () {
|
|
840
860
|
if (this.options.allowInteraction) {
|
|
841
861
|
this.zoomMap(item);
|
|
842
862
|
}
|
|
@@ -863,23 +883,22 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
863
883
|
'svgMap-map-continent-controls-wrapper',
|
|
864
884
|
this.mapWrapper
|
|
865
885
|
);
|
|
866
|
-
this[
|
|
886
|
+
this['continentSelect'] = this.createElement(
|
|
867
887
|
'select',
|
|
868
888
|
'svgMap-continent-select',
|
|
869
889
|
mapContinentControlsWrapper
|
|
870
890
|
);
|
|
871
891
|
var that = this;
|
|
872
|
-
Object.keys(svgMap.prototype.continents).forEach(
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
);
|
|
892
|
+
Object.keys(svgMap.prototype.continents).forEach(function (item) {
|
|
893
|
+
let element = that.createElement(
|
|
894
|
+
'option',
|
|
895
|
+
'svgMap-continent-option svgMap-continent-iso-' +
|
|
896
|
+
svgMap.prototype.continents[item].iso,
|
|
897
|
+
that['continentSelect'],
|
|
898
|
+
svgMap.prototype.continents[item].name
|
|
899
|
+
);
|
|
900
|
+
element.value = item;
|
|
901
|
+
});
|
|
883
902
|
|
|
884
903
|
this.continentSelect.addEventListener(
|
|
885
904
|
'change',
|
|
@@ -889,7 +908,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
889
908
|
}.bind(that),
|
|
890
909
|
{ passive: true }
|
|
891
910
|
);
|
|
892
|
-
mapContinentControlsWrapper.setAttribute(
|
|
911
|
+
mapContinentControlsWrapper.setAttribute(
|
|
912
|
+
'aria-label',
|
|
913
|
+
'Select continent'
|
|
914
|
+
);
|
|
893
915
|
}
|
|
894
916
|
// Fix countries
|
|
895
917
|
var mapPaths = Object.assign({}, this.mapPaths);
|
|
@@ -1000,10 +1022,18 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1000
1022
|
}
|
|
1001
1023
|
|
|
1002
1024
|
let dragged = false;
|
|
1003
|
-
countryElement.addEventListener('mousedown', function () {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
countryElement.addEventListener('
|
|
1025
|
+
countryElement.addEventListener('mousedown', function () {
|
|
1026
|
+
dragged = false;
|
|
1027
|
+
});
|
|
1028
|
+
countryElement.addEventListener('touchstart', function () {
|
|
1029
|
+
dragged = false;
|
|
1030
|
+
});
|
|
1031
|
+
countryElement.addEventListener('mousemove', function () {
|
|
1032
|
+
dragged = true;
|
|
1033
|
+
});
|
|
1034
|
+
countryElement.addEventListener('touchmove', function () {
|
|
1035
|
+
dragged = true;
|
|
1036
|
+
});
|
|
1007
1037
|
const clickHandler = function (e) {
|
|
1008
1038
|
if (dragged) {
|
|
1009
1039
|
return;
|
|
@@ -1017,7 +1047,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1017
1047
|
} else {
|
|
1018
1048
|
window.location.href = link;
|
|
1019
1049
|
}
|
|
1020
|
-
}
|
|
1050
|
+
};
|
|
1021
1051
|
|
|
1022
1052
|
countryElement.addEventListener('click', clickHandler);
|
|
1023
1053
|
countryElement.addEventListener('touchend', clickHandler);
|
|
@@ -1027,9 +1057,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1027
1057
|
countryElement.addEventListener(
|
|
1028
1058
|
'mouseleave',
|
|
1029
1059
|
function () {
|
|
1030
|
-
this.
|
|
1031
|
-
this.hideTooltip();
|
|
1032
|
-
}.bind(this), 300);
|
|
1060
|
+
this.hideTooltip();
|
|
1033
1061
|
countryElement.classList.remove('svgMap-active');
|
|
1034
1062
|
countryElement.removeEventListener(
|
|
1035
1063
|
'mousemove',
|
|
@@ -1075,7 +1103,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1075
1103
|
document.addEventListener(
|
|
1076
1104
|
'touchend',
|
|
1077
1105
|
function (e) {
|
|
1078
|
-
if (
|
|
1106
|
+
if (
|
|
1107
|
+
e.target.closest('.svgMap-country') ||
|
|
1108
|
+
e.target.closest('.svgMap-tooltip')
|
|
1109
|
+
) {
|
|
1079
1110
|
return;
|
|
1080
1111
|
}
|
|
1081
1112
|
this.hideTooltip();
|
|
@@ -1097,7 +1128,10 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1097
1128
|
document.addEventListener(
|
|
1098
1129
|
'click',
|
|
1099
1130
|
function (e) {
|
|
1100
|
-
if (
|
|
1131
|
+
if (
|
|
1132
|
+
e.target.closest('.svgMap-country') ||
|
|
1133
|
+
e.target.closest('.svgMap-tooltip')
|
|
1134
|
+
) {
|
|
1101
1135
|
return;
|
|
1102
1136
|
}
|
|
1103
1137
|
this.hideTooltip();
|
|
@@ -1128,8 +1162,12 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1128
1162
|
maxZoom: this.options.maxZoom,
|
|
1129
1163
|
zoomScaleSensitivity: this.options.zoomScaleSensitivity,
|
|
1130
1164
|
controlIconsEnabled: false,
|
|
1131
|
-
dblClickZoomEnabled: this.options.allowInteraction
|
|
1132
|
-
|
|
1165
|
+
dblClickZoomEnabled: this.options.allowInteraction
|
|
1166
|
+
? this.options.dblClickZoomEnabled
|
|
1167
|
+
: false,
|
|
1168
|
+
mouseWheelZoomEnabled: this.options.allowInteraction
|
|
1169
|
+
? this.options.mouseWheelZoomEnabled
|
|
1170
|
+
: false,
|
|
1133
1171
|
preventMouseEventsDefault: true,
|
|
1134
1172
|
onZoom: function () {
|
|
1135
1173
|
me.setControlStatuses();
|
|
@@ -1174,11 +1212,11 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1174
1212
|
const resizeObserver = new ResizeObserver(() => this.mapReset());
|
|
1175
1213
|
resizeObserver.observe(this.mapWrapper);
|
|
1176
1214
|
}
|
|
1177
|
-
}
|
|
1215
|
+
}
|
|
1178
1216
|
|
|
1179
1217
|
// Create the tooltip content
|
|
1180
1218
|
|
|
1181
|
-
|
|
1219
|
+
getTooltipContent(countryID) {
|
|
1182
1220
|
// Custom tooltip
|
|
1183
1221
|
if (this.options.onGetTooltip) {
|
|
1184
1222
|
var customDiv = this.options.onGetTooltip(
|
|
@@ -1202,7 +1240,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1202
1240
|
var flagContainer = this.createElement(
|
|
1203
1241
|
'div',
|
|
1204
1242
|
'svgMap-tooltip-flag-container svgMap-tooltip-flag-container-' +
|
|
1205
|
-
|
|
1243
|
+
this.options.flagType,
|
|
1206
1244
|
tooltipContentWrapper
|
|
1207
1245
|
);
|
|
1208
1246
|
|
|
@@ -1245,15 +1283,22 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1245
1283
|
function (key) {
|
|
1246
1284
|
var item = this.options.data.data[key];
|
|
1247
1285
|
var value = this.options.data.values[countryID][key];
|
|
1248
|
-
if (
|
|
1286
|
+
if (
|
|
1287
|
+
(value !== undefined && this.options.hideMissingData === true) ||
|
|
1288
|
+
this.options.hideMissingData === false
|
|
1289
|
+
) {
|
|
1249
1290
|
item.floatingNumbers && (value = value.toFixed(1));
|
|
1250
1291
|
item.thousandSeparator &&
|
|
1251
|
-
|
|
1292
|
+
(value = this.numberWithCommas(value, item.thousandSeparator));
|
|
1252
1293
|
value = item.format
|
|
1253
1294
|
? item.format.replace('{0}', '<span>' + value + '</span>')
|
|
1254
1295
|
: '<span>' + value + '</span>';
|
|
1255
1296
|
tooltipContentTable +=
|
|
1256
|
-
'<tr><td>' +
|
|
1297
|
+
'<tr><td>' +
|
|
1298
|
+
(item.name || '') +
|
|
1299
|
+
'</td><td>' +
|
|
1300
|
+
value +
|
|
1301
|
+
'</td></tr>';
|
|
1257
1302
|
}
|
|
1258
1303
|
}.bind(this)
|
|
1259
1304
|
);
|
|
@@ -1261,11 +1306,11 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1261
1306
|
tooltipContent.innerHTML = tooltipContentTable;
|
|
1262
1307
|
}
|
|
1263
1308
|
return tooltipContentWrapper;
|
|
1264
|
-
}
|
|
1309
|
+
}
|
|
1265
1310
|
|
|
1266
1311
|
// Set the disabled statuses for buttons
|
|
1267
1312
|
|
|
1268
|
-
|
|
1313
|
+
setControlStatuses() {
|
|
1269
1314
|
this.zoomControlIn.classList.remove('svgMap-disabled');
|
|
1270
1315
|
this.zoomControlIn.setAttribute('aria-disabled', 'false');
|
|
1271
1316
|
this.zoomControlOut.classList.remove('svgMap-disabled');
|
|
@@ -1283,19 +1328,22 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1283
1328
|
this.zoomControlIn.classList.add('svgMap-disabled');
|
|
1284
1329
|
this.zoomControlIn.setAttribute('aria-disabled', 'true');
|
|
1285
1330
|
}
|
|
1286
|
-
if (
|
|
1331
|
+
if (
|
|
1332
|
+
this.options.showZoomReset &&
|
|
1333
|
+
this.mapPanZoom.getZoom().toFixed(3) == this.options.initialZoom
|
|
1334
|
+
) {
|
|
1287
1335
|
this.zoomControlReset.classList.add('svgMap-disabled');
|
|
1288
1336
|
this.zoomControlReset.setAttribute('aria-disabled', 'true');
|
|
1289
1337
|
}
|
|
1290
|
-
}
|
|
1338
|
+
}
|
|
1291
1339
|
|
|
1292
1340
|
// Zoom map
|
|
1293
1341
|
|
|
1294
|
-
|
|
1342
|
+
zoomMap(direction) {
|
|
1295
1343
|
if (
|
|
1296
1344
|
this[
|
|
1297
|
-
|
|
1298
|
-
|
|
1345
|
+
'zoomControl' + direction.charAt(0).toUpperCase() + direction.slice(1)
|
|
1346
|
+
].classList.contains('svgMap-disabled')
|
|
1299
1347
|
) {
|
|
1300
1348
|
return false;
|
|
1301
1349
|
}
|
|
@@ -1314,29 +1362,28 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1314
1362
|
} else {
|
|
1315
1363
|
this.mapPanZoom[direction == 'in' ? 'zoomIn' : 'zoomOut']();
|
|
1316
1364
|
}
|
|
1317
|
-
}
|
|
1365
|
+
}
|
|
1318
1366
|
|
|
1319
1367
|
// Zoom reset
|
|
1320
|
-
|
|
1321
|
-
this.mapPanZoom.resize()
|
|
1322
|
-
this.zoomMap('reset')
|
|
1368
|
+
mapReset() {
|
|
1369
|
+
this.mapPanZoom.resize();
|
|
1370
|
+
this.zoomMap('reset');
|
|
1323
1371
|
}
|
|
1324
1372
|
|
|
1325
1373
|
// Zoom to Contient
|
|
1326
1374
|
|
|
1327
|
-
|
|
1328
|
-
|
|
1375
|
+
zoomContinent(contientIso) {
|
|
1329
1376
|
const continent = this.continents[contientIso];
|
|
1330
|
-
if (continent.iso ==
|
|
1377
|
+
if (continent.iso == 'EA') this.mapPanZoom.reset();
|
|
1331
1378
|
else if (continent.pan) {
|
|
1332
|
-
this.mapPanZoom.reset()
|
|
1379
|
+
this.mapPanZoom.reset();
|
|
1333
1380
|
this.mapPanZoom.zoomAtPoint(continent.zoom, continent.pan);
|
|
1334
1381
|
}
|
|
1335
|
-
}
|
|
1382
|
+
}
|
|
1336
1383
|
|
|
1337
1384
|
// Add elements to show the zoom with keys notice
|
|
1338
1385
|
|
|
1339
|
-
|
|
1386
|
+
addMouseWheelZoomNotice() {
|
|
1340
1387
|
var noticeWrapper = document.createElement('div');
|
|
1341
1388
|
noticeWrapper.classList.add('svgMap-block-zoom-notice');
|
|
1342
1389
|
|
|
@@ -1348,17 +1395,17 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1348
1395
|
|
|
1349
1396
|
noticeWrapper.append(noticeContainer);
|
|
1350
1397
|
this.wrapper.append(noticeWrapper);
|
|
1351
|
-
}
|
|
1398
|
+
}
|
|
1352
1399
|
|
|
1353
1400
|
// Show the zoom with keys notice
|
|
1354
1401
|
|
|
1355
|
-
|
|
1402
|
+
showMouseWheelZoomNotice(duration) {
|
|
1356
1403
|
if (this.mouseWheelNoticeJustHidden) {
|
|
1357
1404
|
return;
|
|
1358
1405
|
}
|
|
1359
1406
|
|
|
1360
1407
|
this.autoHideMouseWheelNoticeTimeout &&
|
|
1361
|
-
|
|
1408
|
+
clearTimeout(this.autoHideMouseWheelNoticeTimeout);
|
|
1362
1409
|
this.autoHideMouseWheelNoticeTimeout = setTimeout(
|
|
1363
1410
|
function () {
|
|
1364
1411
|
this.hideMouseWheelZoomNotice();
|
|
@@ -1367,33 +1414,33 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1367
1414
|
);
|
|
1368
1415
|
|
|
1369
1416
|
this.wrapper.classList.add('svgMap-block-zoom-notice-active');
|
|
1370
|
-
}
|
|
1417
|
+
}
|
|
1371
1418
|
|
|
1372
1419
|
// Hide the zoom with keys notice
|
|
1373
1420
|
|
|
1374
|
-
|
|
1421
|
+
hideMouseWheelZoomNotice() {
|
|
1375
1422
|
this.wrapper.classList.remove('svgMap-block-zoom-notice-active');
|
|
1376
1423
|
this.autoHideMouseWheelNoticeTimeout &&
|
|
1377
|
-
|
|
1378
|
-
}
|
|
1424
|
+
clearTimeout(this.autoHideMouseWheelNoticeTimeout);
|
|
1425
|
+
}
|
|
1379
1426
|
|
|
1380
1427
|
// Block shing the zoom wheel notice for some time
|
|
1381
1428
|
|
|
1382
|
-
|
|
1429
|
+
blockMouseWheelZoomNotice(duration) {
|
|
1383
1430
|
this.mouseWheelNoticeJustHidden = true;
|
|
1384
1431
|
this.mouseWheelNoticeJustHiddenTimeout &&
|
|
1385
|
-
|
|
1432
|
+
clearTimeout(this.mouseWheelNoticeJustHiddenTimeout);
|
|
1386
1433
|
this.mouseWheelNoticeJustHiddenTimeout = setTimeout(
|
|
1387
1434
|
function () {
|
|
1388
1435
|
this.mouseWheelNoticeJustHidden = false;
|
|
1389
1436
|
}.bind(this),
|
|
1390
1437
|
duration || 600
|
|
1391
1438
|
);
|
|
1392
|
-
}
|
|
1439
|
+
}
|
|
1393
1440
|
|
|
1394
1441
|
// Add the events when you are only allowed to scrool with a key pressed
|
|
1395
1442
|
|
|
1396
|
-
|
|
1443
|
+
addMouseWheelZoomWithKeyEvents() {
|
|
1397
1444
|
// Add events to wrapper
|
|
1398
1445
|
this.wrapper.addEventListener(
|
|
1399
1446
|
'wheel',
|
|
@@ -1452,11 +1499,11 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
1452
1499
|
document.body.classList.remove('svgMap-zoom-key-pressed');
|
|
1453
1500
|
}
|
|
1454
1501
|
});
|
|
1455
|
-
}
|
|
1502
|
+
}
|
|
1456
1503
|
|
|
1457
1504
|
// Map paths
|
|
1458
1505
|
|
|
1459
|
-
|
|
1506
|
+
mapPaths = {
|
|
1460
1507
|
'AF': {
|
|
1461
1508
|
d: 'M1369.9,333.8h-5.4l-3.8-0.5l-2.5,2.9l-2.1,0.7l-1.5,1.3l-2.6-2.1l-1-5.4l-1.6-0.3v-2l-3.2-1.5l-1.7,2.3l0.2,2.6 l-0.6,0.9l-3.2-0.1l-0.9,3l-2.1-1.3l-3.3,2.1l-1.8-0.8l-4.3-1.4h-2.9l-1.6-0.2l-2.9-1.7l-0.3,2.3l-4.1,1.2l0.1,5.2l-2.5,2l-4,0.9 l-0.4,3l-3.9,0.8l-5.9-2.4l-0.5,8l-0.5,4.7l2.5,0.9l-1.6,3.5l2.7,5.1l1.1,4l4.3,1.1l1.1,4l-3.9,5.8l9.6,3.2l5.3-0.9l3.3,0.8l0.9-1.4 l3.8,0.5l6.6-2.6l-0.8-5.4l2.3-3.6h4l0.2-1.7l4-0.9l2.1,0.6l1.7-1.8l-1.1-3.8l1.5-3.8l3-1.6l-3-4.2l5.1,0.2l0.9-2.3l-0.8-2.5l2-2.7 l-1.4-3.2l-1.9-2.8l2.4-2.8l5.3-1.3l5.8-0.8l2.4-1.2l2.8-0.7L1369.9,333.8L1369.9,333.8z'
|
|
1462
1509
|
},
|
|
@@ -2109,7 +2156,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2109
2156
|
|
|
2110
2157
|
// Create the tooltip
|
|
2111
2158
|
|
|
2112
|
-
|
|
2159
|
+
createTooltip() {
|
|
2113
2160
|
if (this.tooltip) {
|
|
2114
2161
|
return false;
|
|
2115
2162
|
}
|
|
@@ -2129,13 +2176,9 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2129
2176
|
this.tooltip
|
|
2130
2177
|
);
|
|
2131
2178
|
|
|
2132
|
-
this.tooltip.addEventListener(
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
clearTimeout(this.tooltipTimeout);
|
|
2136
|
-
}.bind(this),
|
|
2137
|
-
{ passive: true }
|
|
2138
|
-
);
|
|
2179
|
+
this.tooltip.addEventListener('mouseenter', function () {}.bind(this), {
|
|
2180
|
+
passive: true
|
|
2181
|
+
});
|
|
2139
2182
|
|
|
2140
2183
|
this.tooltip.addEventListener(
|
|
2141
2184
|
'mouseleave',
|
|
@@ -2144,34 +2187,34 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2144
2187
|
}.bind(this),
|
|
2145
2188
|
{ passive: true }
|
|
2146
2189
|
);
|
|
2147
|
-
}
|
|
2190
|
+
}
|
|
2148
2191
|
|
|
2149
2192
|
// Set the tooltips content
|
|
2150
2193
|
|
|
2151
|
-
|
|
2194
|
+
setTooltipContent(content) {
|
|
2152
2195
|
if (!this.tooltip) {
|
|
2153
2196
|
return;
|
|
2154
2197
|
}
|
|
2155
2198
|
this.tooltipContent.innerHTML = '';
|
|
2156
2199
|
this.tooltipContent.append(content);
|
|
2157
|
-
}
|
|
2200
|
+
}
|
|
2158
2201
|
|
|
2159
2202
|
// Show the tooltip
|
|
2160
2203
|
|
|
2161
|
-
|
|
2204
|
+
showTooltip(e) {
|
|
2162
2205
|
this.tooltip.classList.add('svgMap-active');
|
|
2163
2206
|
this.moveTooltip(e);
|
|
2164
|
-
}
|
|
2207
|
+
}
|
|
2165
2208
|
|
|
2166
2209
|
// Hide the tooltip
|
|
2167
2210
|
|
|
2168
|
-
|
|
2211
|
+
hideTooltip() {
|
|
2169
2212
|
this.tooltip.classList.remove('svgMap-active');
|
|
2170
|
-
}
|
|
2213
|
+
}
|
|
2171
2214
|
|
|
2172
2215
|
// Move the tooltip
|
|
2173
2216
|
|
|
2174
|
-
|
|
2217
|
+
moveTooltip(e) {
|
|
2175
2218
|
var x = e.pageX || (e.touches && e.touches[0] ? e.touches[0].pageX : null);
|
|
2176
2219
|
var y = e.pageY || (e.touches && e.touches[0] ? e.touches[0].pageY : null);
|
|
2177
2220
|
|
|
@@ -2212,24 +2255,19 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2212
2255
|
|
|
2213
2256
|
this.tooltip.style.left = x + 'px';
|
|
2214
2257
|
this.tooltip.style.top = y + 'px';
|
|
2215
|
-
}
|
|
2258
|
+
}
|
|
2216
2259
|
|
|
2217
2260
|
// Log error to console
|
|
2218
2261
|
|
|
2219
|
-
|
|
2262
|
+
error(error) {
|
|
2220
2263
|
(console.error || console.log)(
|
|
2221
2264
|
'svgMap error: ' + (error || 'Unknown error')
|
|
2222
2265
|
);
|
|
2223
|
-
}
|
|
2266
|
+
}
|
|
2224
2267
|
|
|
2225
2268
|
// Helper to create an element with a class name
|
|
2226
2269
|
|
|
2227
|
-
|
|
2228
|
-
type,
|
|
2229
|
-
className,
|
|
2230
|
-
appendTo,
|
|
2231
|
-
innerhtml
|
|
2232
|
-
) {
|
|
2270
|
+
createElement(type, className, appendTo, innerhtml) {
|
|
2233
2271
|
var element = document.createElement(type);
|
|
2234
2272
|
if (className) {
|
|
2235
2273
|
className = className.split(' ');
|
|
@@ -2240,34 +2278,34 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2240
2278
|
innerhtml && (element.innerHTML = innerhtml);
|
|
2241
2279
|
appendTo && appendTo.appendChild(element);
|
|
2242
2280
|
return element;
|
|
2243
|
-
}
|
|
2281
|
+
}
|
|
2244
2282
|
|
|
2245
2283
|
// Print numbers with commas
|
|
2246
2284
|
|
|
2247
|
-
|
|
2285
|
+
numberWithCommas(nr, separator) {
|
|
2248
2286
|
return nr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator || ',');
|
|
2249
|
-
}
|
|
2287
|
+
}
|
|
2250
2288
|
|
|
2251
2289
|
// Get a color between two other colors
|
|
2252
2290
|
|
|
2253
|
-
|
|
2291
|
+
getColor(color1, color2, ratio) {
|
|
2254
2292
|
color1 = color1.slice(-6);
|
|
2255
2293
|
color2 = color2.slice(-6);
|
|
2256
2294
|
ratio = parseFloat(ratio).toFixed(1);
|
|
2257
2295
|
var r = Math.ceil(
|
|
2258
2296
|
parseInt(color1.substring(0, 2), 16) * ratio +
|
|
2259
|
-
|
|
2297
|
+
parseInt(color2.substring(0, 2), 16) * (1 - ratio)
|
|
2260
2298
|
);
|
|
2261
2299
|
var g = Math.ceil(
|
|
2262
2300
|
parseInt(color1.substring(2, 4), 16) * ratio +
|
|
2263
|
-
|
|
2301
|
+
parseInt(color2.substring(2, 4), 16) * (1 - ratio)
|
|
2264
2302
|
);
|
|
2265
2303
|
var b = Math.ceil(
|
|
2266
2304
|
parseInt(color1.substring(4, 6), 16) * ratio +
|
|
2267
|
-
|
|
2305
|
+
parseInt(color2.substring(4, 6), 16) * (1 - ratio)
|
|
2268
2306
|
);
|
|
2269
2307
|
return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
|
|
2270
|
-
}
|
|
2308
|
+
}
|
|
2271
2309
|
|
|
2272
2310
|
/**
|
|
2273
2311
|
* convert color to hex to allow users of the map to pass in
|
|
@@ -2276,8 +2314,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2276
2314
|
* @param element
|
|
2277
2315
|
* @returns {string}
|
|
2278
2316
|
*/
|
|
2279
|
-
|
|
2280
|
-
|
|
2317
|
+
toHex(color, element = document.documentElement) {
|
|
2281
2318
|
// Resolve CSS variables
|
|
2282
2319
|
if (color.startsWith('var(')) {
|
|
2283
2320
|
const cssVar = color.slice(4, -1).trim().replaceAll(/["']+/g, '');
|
|
@@ -2292,24 +2329,24 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2292
2329
|
ctx.fillStyle = color;
|
|
2293
2330
|
|
|
2294
2331
|
// computed color is full hex code in the case of one color only
|
|
2295
|
-
return ctx.fillStyle
|
|
2332
|
+
return ctx.fillStyle;
|
|
2296
2333
|
}
|
|
2297
2334
|
|
|
2298
|
-
|
|
2299
2335
|
// Get a hex value
|
|
2300
2336
|
|
|
2301
|
-
|
|
2337
|
+
getHex(value) {
|
|
2302
2338
|
value = value.toString(16);
|
|
2303
2339
|
return ('0' + value).slice(-2);
|
|
2304
|
-
}
|
|
2340
|
+
}
|
|
2305
2341
|
|
|
2306
2342
|
// Get the name of a country by its ID
|
|
2307
2343
|
|
|
2308
|
-
|
|
2344
|
+
getCountryName(countryID) {
|
|
2309
2345
|
return this.options.countryNames && this.options.countryNames[countryID]
|
|
2310
2346
|
? this.options.countryNames[countryID]
|
|
2311
2347
|
: this.countries[countryID];
|
|
2312
|
-
}
|
|
2313
|
-
|
|
2314
|
-
return svgMap;
|
|
2348
|
+
}
|
|
2315
2349
|
}
|
|
2350
|
+
|
|
2351
|
+
module.exports = svgMap;
|
|
2352
|
+
//# sourceMappingURL=index.cjs.map
|