svgmap 2.11.1 → 2.12.2

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/gulpfile.js CHANGED
@@ -22,8 +22,6 @@ var scripts = [{
22
22
  name: 'svgMap',
23
23
  src: [
24
24
  './src/js/svgMap.js',
25
- './src/js/data/**/*.js',
26
- './src/js/svgMap/**/*.js',
27
25
  './src/js/umd.js'
28
26
  ],
29
27
  dest: './dist/'
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.11.1",
4
+ "version": "2.12.2",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "main": "dist/svgMap.min.js",
@@ -20,14 +20,14 @@
20
20
  "gulp-concat": "^2.6.1",
21
21
  "gulp-header": "^2.0.9",
22
22
  "gulp-rename": "^2.0.0",
23
- "gulp-sass": "^5.1.0",
23
+ "gulp-sass": "^6.0.0",
24
24
  "gulp-sourcemaps": "^3.0.0",
25
25
  "gulp-uglify": "^3.0.2",
26
- "jest": "^28.1.1",
27
- "sass": "^1.53.0"
26
+ "jest": "^29.7.0",
27
+ "sass": "^1.83.1"
28
28
  },
29
29
  "dependencies": {
30
- "svg-pan-zoom": "^3.6.1"
30
+ "svg-pan-zoom": "^3.6.2"
31
31
  },
32
32
  "scripts": {
33
33
  "watch": "gulp watch",
package/src/js/svgMap.js CHANGED
@@ -412,7 +412,7 @@ function svgMapWrapper(svgPanZoom) {
412
412
  return;
413
413
  }
414
414
  if (!data.values[countryID]) {
415
- element.setAttribute('fill', this.options.colorNoData);
415
+ element.setAttribute('fill', this.toHex(this.options.colorNoData));
416
416
  return;
417
417
  }
418
418
  if (typeof data.values[countryID].color != 'undefined') {
@@ -425,8 +425,8 @@ function svgMapWrapper(svgPanZoom) {
425
425
  );
426
426
  var ratio = Math.max(0, Math.min(1, (value - min) / (max - min)));
427
427
  var color = this.getColor(
428
- this.options.colorMax,
429
- this.options.colorMin,
428
+ this.toHex(this.options.colorMax),
429
+ this.toHex(this.options.colorMin),
430
430
  ratio || ratio === 0 ? ratio : 1
431
431
  );
432
432
  element.setAttribute('fill', color);
@@ -2126,6 +2126,33 @@ function svgMapWrapper(svgPanZoom) {
2126
2126
  return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
2127
2127
  };
2128
2128
 
2129
+ /**
2130
+ * convert color to hex to allow users of the map to pass in
2131
+ * colors in formats other than full hex value.
2132
+ * @param color
2133
+ * @param element
2134
+ * @returns {string}
2135
+ */
2136
+ svgMap.prototype.toHex = function (color, element = document.documentElement) {
2137
+
2138
+ // Resolve CSS variables
2139
+ if (color.startsWith('var(')) {
2140
+ const cssVar = color.slice(4, -1).trim().replaceAll(/["']+/g, '');
2141
+ color = getComputedStyle(element).getPropertyValue(cssVar).trim();
2142
+ }
2143
+
2144
+ // Create an offscreen canvas
2145
+ const canvas = new OffscreenCanvas(1, 1);
2146
+ const ctx = canvas.getContext('2d');
2147
+
2148
+ // Use canvas to parse the color
2149
+ ctx.fillStyle = color;
2150
+
2151
+ // computed color is full hex code in the case of one color only
2152
+ return ctx.fillStyle
2153
+ }
2154
+
2155
+
2129
2156
  // Get a hex value
2130
2157
 
2131
2158
  svgMap.prototype.getHex = function (value) {
@@ -1,3 +1,2 @@
1
- @import 'variables.scss';
2
- @import 'map.scss';
3
- @import 'tooltip.scss';
1
+ @use 'map';
2
+ @use 'tooltip';
package/src/scss/map.scss CHANGED
@@ -1,3 +1,5 @@
1
+ @use 'variables' as *;
2
+
1
3
  .svgMap-wrapper,
2
4
  .svgMap-container {
3
5
  position: relative;
@@ -1,3 +1,5 @@
1
+ @use 'variables' as *;
2
+
1
3
  .svgMap-tooltip {
2
4
  box-shadow: 0 0 3px $mapTooltipBoxShadowColor;
3
5
  position: absolute;