svgmap 2.13.0 → 2.15.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.13.0",
4
+ "version": "2.15.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "main": "dist/svgMap.min.js",
@@ -18,10 +18,10 @@
18
18
  "gulp": "^5.0.1",
19
19
  "gulp-clean-css": "^4.3.0",
20
20
  "gulp-concat": "^2.6.1",
21
- "gulp-header": "^1.8.9",
21
+ "gulp-header": "^2.0.9",
22
22
  "gulp-rename": "^2.1.0",
23
23
  "gulp-sass": "^6.0.1",
24
- "gulp-sourcemaps": "^2.6.5",
24
+ "gulp-sourcemaps": "^3.0.0",
25
25
  "gulp-uglify": "^3.0.2",
26
26
  "jest": "^30.0.5",
27
27
  "sass": "^1.90.0"
package/src/js/svgMap.js CHANGED
@@ -45,13 +45,16 @@ function svgMapWrapper(svgPanZoom) {
45
45
  // The message to show for MacOS
46
46
  mouseWheelKeyMessageMac: 'Press the [COMMAND] key to zoom',
47
47
 
48
+ // Position of the zoom buttons
49
+ zoomButtonsPosition: 'bottomLeft',
50
+
48
51
  // Data colors
49
52
  colorMax: '#CC0033',
50
53
  colorMin: '#FFE5D9',
51
54
  colorNoData: '#E2E2E2',
52
55
 
53
- // Color attribute for setting a manual color in the data object
54
- manualColorAttribute: 'color',
56
+ // Ratio type for the color scale, can be 'linear' or 'log' for logarithmic or a custom function (value, min, max) => ratio
57
+ ratioType: 'linear',
55
58
 
56
59
  // The flag type can be 'image' or 'emoji'
57
60
  flagType: 'image',
@@ -405,9 +408,9 @@ function svgMapWrapper(svgPanZoom) {
405
408
  });
406
409
 
407
410
  data.data[data.applyData].thresholdMax &&
408
- (max = Math.min(max, data.data[data.applyData].thresholdMax));
411
+ (max = Math.min(max, data.data[data.applyData].thresholdMax));
409
412
  data.data[data.applyData].thresholdMin &&
410
- (min = Math.max(min, data.data[data.applyData].thresholdMin));
413
+ (min = Math.max(min, data.data[data.applyData].thresholdMin));
411
414
 
412
415
  // Loop through countries and set colors
413
416
  Object.keys(this.countries).forEach(
@@ -430,17 +433,45 @@ function svgMapWrapper(svgPanZoom) {
430
433
  min,
431
434
  parseInt(data.values[countryID][data.applyData], 10)
432
435
  );
433
- var ratio = Math.max(0, Math.min(1, (value - min) / (max - min)));
436
+
434
437
  var color = this.getColor(
435
438
  this.toHex(this.options.colorMax),
436
439
  this.toHex(this.options.colorMin),
437
- ratio || ratio === 0 ? ratio : 1
440
+ this.calculateColorRatio(value, min, max, this.options.ratioType)
438
441
  );
439
442
  element.setAttribute('fill', color);
440
443
  }.bind(this)
441
444
  );
442
445
  };
443
446
 
447
+ svgMap.prototype.calculateColorRatio = function (value, min, max, ratioType) {
448
+ var range = max - min;
449
+ var positionInRange = value - min;
450
+
451
+ if (range === 0 || positionInRange === 0) {
452
+ return 0;
453
+ }
454
+
455
+ if (ratioType === 'log') {
456
+ var logValue = Math.log(positionInRange + 1);
457
+ var logMin = Math.log(1);
458
+ var logMax = Math.log(range + 1);
459
+ var ratio = Math.max(0, Math.min(1, (logValue - logMin) / (logMax - logMin)));
460
+ return ratio || ratio === 0 ? ratio : 1;
461
+ }
462
+
463
+ if (ratioType === 'linear') {
464
+ var ratio = Math.max(0, Math.min(1, positionInRange / range));
465
+ return ratio || ratio === 0 ? ratio : 1;
466
+ }
467
+
468
+ if (typeof ratioType === 'function') {
469
+ return ratioType(value, min, max);
470
+ }
471
+
472
+ return 1;
473
+ }
474
+
444
475
  // Emoji flags
445
476
 
446
477
  svgMap.prototype.emojiFlags = {
@@ -781,6 +812,7 @@ function svgMapWrapper(svgPanZoom) {
781
812
  'svgMap-map-controls-wrapper',
782
813
  this.mapWrapper
783
814
  );
815
+ mapControlsWrapper.classList.add('svgMap-controls-position-' + this.options.zoomButtonsPosition);
784
816
  var zoomContainer = this.createElement(
785
817
  'div',
786
818
  'svgMap-map-controls-zoom',
@@ -1143,7 +1175,7 @@ function svgMapWrapper(svgPanZoom) {
1143
1175
  if ((value !== undefined && this.options.hideMissingData === true) || this.options.hideMissingData === false) {
1144
1176
  item.floatingNumbers && (value = value.toFixed(1));
1145
1177
  item.thousandSeparator &&
1146
- (value = this.numberWithCommas(value, item.thousandSeparator));
1178
+ (value = this.numberWithCommas(value, item.thousandSeparator));
1147
1179
  value = item.format
1148
1180
  ? item.format.replace('{0}', '<span>' + value + '</span>')
1149
1181
  : '<span>' + value + '</span>';
@@ -1189,8 +1221,8 @@ function svgMapWrapper(svgPanZoom) {
1189
1221
  svgMap.prototype.zoomMap = function (direction) {
1190
1222
  if (
1191
1223
  this[
1192
- 'zoomControl' + direction.charAt(0).toUpperCase() + direction.slice(1)
1193
- ].classList.contains('svgMap-disabled')
1224
+ 'zoomControl' + direction.charAt(0).toUpperCase() + direction.slice(1)
1225
+ ].classList.contains('svgMap-disabled')
1194
1226
  ) {
1195
1227
  return false;
1196
1228
  }
@@ -1247,7 +1279,7 @@ function svgMapWrapper(svgPanZoom) {
1247
1279
  }
1248
1280
 
1249
1281
  this.autoHideMouseWheelNoticeTimeout &&
1250
- clearTimeout(this.autoHideMouseWheelNoticeTimeout);
1282
+ clearTimeout(this.autoHideMouseWheelNoticeTimeout);
1251
1283
  this.autoHideMouseWheelNoticeTimeout = setTimeout(
1252
1284
  function () {
1253
1285
  this.hideMouseWheelZoomNotice();
@@ -1263,7 +1295,7 @@ function svgMapWrapper(svgPanZoom) {
1263
1295
  svgMap.prototype.hideMouseWheelZoomNotice = function () {
1264
1296
  this.wrapper.classList.remove('svgMap-block-zoom-notice-active');
1265
1297
  this.autoHideMouseWheelNoticeTimeout &&
1266
- clearTimeout(this.autoHideMouseWheelNoticeTimeout);
1298
+ clearTimeout(this.autoHideMouseWheelNoticeTimeout);
1267
1299
  };
1268
1300
 
1269
1301
  // Block shing the zoom wheel notice for some time
@@ -1271,7 +1303,7 @@ function svgMapWrapper(svgPanZoom) {
1271
1303
  svgMap.prototype.blockMouseWheelZoomNotice = function (duration) {
1272
1304
  this.mouseWheelNoticeJustHidden = true;
1273
1305
  this.mouseWheelNoticeJustHiddenTimeout &&
1274
- clearTimeout(this.mouseWheelNoticeJustHiddenTimeout);
1306
+ clearTimeout(this.mouseWheelNoticeJustHiddenTimeout);
1275
1307
  this.mouseWheelNoticeJustHiddenTimeout = setTimeout(
1276
1308
  function () {
1277
1309
  this.mouseWheelNoticeJustHidden = false;
package/src/scss/map.scss CHANGED
@@ -70,14 +70,29 @@
70
70
 
71
71
  .svgMap-map-controls-wrapper {
72
72
  position: absolute;
73
- bottom: 10px;
74
- left: 10px;
75
73
  z-index: 1;
76
74
  display: flex;
77
75
  overflow: hidden;
78
76
  border-radius: 2px;
79
77
  box-shadow: $mapControlsBoxShadow;
80
78
 
79
+ &.svgMap-controls-position-bottomLeft {
80
+ bottom: 10px;
81
+ left: 10px;
82
+ }
83
+ &.svgMap-controls-position-bottomRight {
84
+ bottom: 10px;
85
+ right: 10px;
86
+ }
87
+ &.svgMap-controls-position-topLeft {
88
+ top: 10px;
89
+ left: 10px;
90
+ }
91
+ &.svgMap-controls-position-topRight {
92
+ top: 10px;
93
+ right: 10px;
94
+ }
95
+
81
96
  &.svgMap-disabled {
82
97
  display: none;
83
98
  }
@@ -214,6 +229,7 @@
214
229
  // Countries
215
230
 
216
231
  .svgMap-country {
232
+ fill: $colorNoData;
217
233
  stroke: $countryStrokeColor;
218
234
  stroke-width: 1;
219
235
  stroke-linejoin: round;
@@ -3,6 +3,7 @@ $textColor: #111 !default;
3
3
  $textColorLight: #777 !default;
4
4
 
5
5
  // Map
6
+ $colorNoData: #E2E2E2 !default;
6
7
  $oceanColor: #d9ecff !default;
7
8
  $mapActiveStrokeColor: #333 !default;
8
9
  $mapActiveStrokeWidth: 1.5 !default;