svgmap 2.12.2 → 2.14.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svgmap",
3
3
  "description": "svgMap is a JavaScript library that lets you easily create an interactable world map comparing customizable data for each country.",
4
- "version": "2.12.2",
4
+ "version": "2.14.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "main": "dist/svgMap.min.js",
@@ -15,16 +15,16 @@
15
15
  "url": "https://github.com/StephanWagner/svgMap.git"
16
16
  },
17
17
  "devDependencies": {
18
- "gulp": "^5.0.0",
18
+ "gulp": "^5.0.1",
19
19
  "gulp-clean-css": "^4.3.0",
20
20
  "gulp-concat": "^2.6.1",
21
21
  "gulp-header": "^2.0.9",
22
- "gulp-rename": "^2.0.0",
23
- "gulp-sass": "^6.0.0",
22
+ "gulp-rename": "^2.1.0",
23
+ "gulp-sass": "^6.0.1",
24
24
  "gulp-sourcemaps": "^3.0.0",
25
25
  "gulp-uglify": "^3.0.2",
26
- "jest": "^29.7.0",
27
- "sass": "^1.83.1"
26
+ "jest": "^30.0.5",
27
+ "sass": "^1.90.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "svg-pan-zoom": "^3.6.2"
package/src/js/svgMap.js CHANGED
@@ -11,6 +11,9 @@ function svgMapWrapper(svgPanZoom) {
11
11
  // The element to render the map in
12
12
  targetElementID: '',
13
13
 
14
+ // Allow user to zoom and pan
15
+ allowInteraction: true,
16
+
14
17
  // Minimum and maximum zoom
15
18
  minZoom: 1,
16
19
  maxZoom: 25,
@@ -27,6 +30,9 @@ function svgMapWrapper(svgPanZoom) {
27
30
  // Zoom sensitivity
28
31
  zoomScaleSensitivity: 0.2,
29
32
 
33
+ // Zoom with double-click
34
+ dblClickZoomEnabled: true,
35
+
30
36
  // Zoom with mousewheel
31
37
  mouseWheelZoomEnabled: true,
32
38
 
@@ -44,8 +50,8 @@ function svgMapWrapper(svgPanZoom) {
44
50
  colorMin: '#FFE5D9',
45
51
  colorNoData: '#E2E2E2',
46
52
 
47
- // Color attribute for setting a manual color in the data object
48
- manualColorAttribute: 'color',
53
+ // Ratio type for the color scale, can be 'linear' or 'log' for logarithmic or a custom function (value, min, max) => ratio
54
+ ratioType: 'linear',
49
55
 
50
56
  // The flag type can be 'image' or 'emoji'
51
57
  flagType: 'image',
@@ -113,6 +119,7 @@ function svgMapWrapper(svgPanZoom) {
113
119
 
114
120
  // Block scrolling when option is enabled
115
121
  if (
122
+ this.options.allowInteraction &&
116
123
  this.options.mouseWheelZoomEnabled &&
117
124
  this.options.mouseWheelZoomWithKey
118
125
  ) {
@@ -423,17 +430,45 @@ function svgMapWrapper(svgPanZoom) {
423
430
  min,
424
431
  parseInt(data.values[countryID][data.applyData], 10)
425
432
  );
426
- var ratio = Math.max(0, Math.min(1, (value - min) / (max - min)));
433
+
427
434
  var color = this.getColor(
428
435
  this.toHex(this.options.colorMax),
429
436
  this.toHex(this.options.colorMin),
430
- ratio || ratio === 0 ? ratio : 1
437
+ this.calculateColorRatio(value, min, max, this.options.ratioType)
431
438
  );
432
439
  element.setAttribute('fill', color);
433
440
  }.bind(this)
434
441
  );
435
442
  };
436
443
 
444
+ svgMap.prototype.calculateColorRatio = function (value, min, max, ratioType) {
445
+ var range = max - min;
446
+ var positionInRange = value - min;
447
+
448
+ if (range === 0 || positionInRange === 0) {
449
+ return 0;
450
+ }
451
+
452
+ if (ratioType === 'log') {
453
+ var logValue = Math.log(positionInRange + 1);
454
+ var logMin = Math.log(1);
455
+ var logMax = Math.log(range + 1);
456
+ var ratio = Math.max(0, Math.min(1, (logValue - logMin) / (logMax - logMin)));
457
+ return ratio || ratio === 0 ? ratio : 1;
458
+ }
459
+
460
+ if (ratioType === 'linear') {
461
+ var ratio = Math.max(0, Math.min(1, positionInRange / range));
462
+ return ratio || ratio === 0 ? ratio : 1;
463
+ }
464
+
465
+ if (typeof ratioType === 'function') {
466
+ return ratioType(value, min, max);
467
+ }
468
+
469
+ return 1;
470
+ }
471
+
437
472
  // Emoji flags
438
473
 
439
474
  svgMap.prototype.emojiFlags = {
@@ -794,8 +829,10 @@ function svgMapWrapper(svgPanZoom) {
794
829
  this[zoomControlName].type = 'button';
795
830
  this[zoomControlName].addEventListener(
796
831
  'click',
797
- function () {
798
- this.zoomMap(item);
832
+ function() {
833
+ if (this.options.allowInteraction) {
834
+ this.zoomMap(item);
835
+ }
799
836
  }.bind(this),
800
837
  { passive: true }
801
838
  );
@@ -803,11 +840,16 @@ function svgMapWrapper(svgPanZoom) {
803
840
  }.bind(this)
804
841
  );
805
842
 
843
+ if (!this.options.allowInteraction) {
844
+ mapControlsWrapper.classList.add('svgMap-disabled');
845
+ mapControlsWrapper.setAttribute('aria-disabled', 'true');
846
+ }
847
+
806
848
  // Add accessible names to zoom controls
807
849
  this.zoomControlIn.setAttribute('aria-label', 'Zoom in');
808
850
  this.zoomControlOut.setAttribute('aria-label', 'Zoom out');
809
851
 
810
- if (this.options.showContinentSelector) {
852
+ if (this.options.allowInteraction && this.options.showContinentSelector) {
811
853
  // Add continent controls
812
854
  var mapContinentControlsWrapper = this.createElement(
813
855
  'div',
@@ -1007,14 +1049,16 @@ function svgMapWrapper(svgPanZoom) {
1007
1049
 
1008
1050
  // Init pan zoom
1009
1051
  this.mapPanZoom = svgPanZoom(this.mapImage, {
1010
- zoomEnabled: true,
1052
+ zoomEnabled: this.options.allowInteraction,
1053
+ panEnabled: this.options.allowInteraction,
1011
1054
  fit: true,
1012
1055
  center: true,
1013
1056
  minZoom: this.options.minZoom,
1014
1057
  maxZoom: this.options.maxZoom,
1015
1058
  zoomScaleSensitivity: this.options.zoomScaleSensitivity,
1016
1059
  controlIconsEnabled: false,
1017
- mouseWheelZoomEnabled: this.options.mouseWheelZoomEnabled,
1060
+ dblClickZoomEnabled: this.options.allowInteraction ? this.options.dblClickZoomEnabled : false,
1061
+ mouseWheelZoomEnabled: this.options.allowInteraction ? this.options.mouseWheelZoomEnabled : false,
1018
1062
  preventMouseEventsDefault: true,
1019
1063
  onZoom: function () {
1020
1064
  me.setControlStatuses();
package/src/scss/map.scss CHANGED
@@ -77,6 +77,10 @@
77
77
  overflow: hidden;
78
78
  border-radius: 2px;
79
79
  box-shadow: $mapControlsBoxShadow;
80
+
81
+ &.svgMap-disabled {
82
+ display: none;
83
+ }
80
84
  }
81
85
 
82
86
  .svgMap-map-controls-zoom,
@@ -10,7 +10,7 @@ $blockZoomNoticeColor: #fff !default;
10
10
  $blockZoomNoticeBackgroundColor: rgba(0, 0, 0, 0.8) !default;
11
11
 
12
12
  // Map Controls
13
- $mapControlsColor: #fff;
13
+ $mapControlsColor: #fff !default;
14
14
  $mapControlsBackgroundColor: #fff !default;
15
15
  $mapControlsIconColor: #ccc !default;
16
16
  $mapControlsIconColorActive: #000 !default;