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/README.md +3 -3
- package/demo/html/index.html +2 -2
- package/demo/react/app/package-lock.json +615 -288
- package/dist/svgMap.js +30 -3
- package/dist/svgMap.min.js +1 -1
- package/gulpfile.js +0 -2
- package/package.json +5 -5
- package/src/js/svgMap.js +30 -3
- package/src/scss/main.scss +2 -3
- package/src/scss/map.scss +2 -0
- package/src/scss/tooltip.scss +2 -0
package/dist/svgMap.js
CHANGED
|
@@ -413,7 +413,7 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
413
413
|
return;
|
|
414
414
|
}
|
|
415
415
|
if (!data.values[countryID]) {
|
|
416
|
-
element.setAttribute('fill', this.options.colorNoData);
|
|
416
|
+
element.setAttribute('fill', this.toHex(this.options.colorNoData));
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
419
|
if (typeof data.values[countryID].color != 'undefined') {
|
|
@@ -426,8 +426,8 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
426
426
|
);
|
|
427
427
|
var ratio = Math.max(0, Math.min(1, (value - min) / (max - min)));
|
|
428
428
|
var color = this.getColor(
|
|
429
|
-
this.options.colorMax,
|
|
430
|
-
this.options.colorMin,
|
|
429
|
+
this.toHex(this.options.colorMax),
|
|
430
|
+
this.toHex(this.options.colorMin),
|
|
431
431
|
ratio || ratio === 0 ? ratio : 1
|
|
432
432
|
);
|
|
433
433
|
element.setAttribute('fill', color);
|
|
@@ -2127,6 +2127,33 @@ function svgMapWrapper(svgPanZoom) {
|
|
|
2127
2127
|
return '#' + this.getHex(r) + this.getHex(g) + this.getHex(b);
|
|
2128
2128
|
};
|
|
2129
2129
|
|
|
2130
|
+
/**
|
|
2131
|
+
* convert color to hex to allow users of the map to pass in
|
|
2132
|
+
* colors in formats other than full hex value.
|
|
2133
|
+
* @param color
|
|
2134
|
+
* @param element
|
|
2135
|
+
* @returns {string}
|
|
2136
|
+
*/
|
|
2137
|
+
svgMap.prototype.toHex = function (color, element = document.documentElement) {
|
|
2138
|
+
|
|
2139
|
+
// Resolve CSS variables
|
|
2140
|
+
if (color.startsWith('var(')) {
|
|
2141
|
+
const cssVar = color.slice(4, -1).trim().replaceAll(/["']+/g, '');
|
|
2142
|
+
color = getComputedStyle(element).getPropertyValue(cssVar).trim();
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
// Create an offscreen canvas
|
|
2146
|
+
const canvas = new OffscreenCanvas(1, 1);
|
|
2147
|
+
const ctx = canvas.getContext('2d');
|
|
2148
|
+
|
|
2149
|
+
// Use canvas to parse the color
|
|
2150
|
+
ctx.fillStyle = color;
|
|
2151
|
+
|
|
2152
|
+
// computed color is full hex code in the case of one color only
|
|
2153
|
+
return ctx.fillStyle
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
|
|
2130
2157
|
// Get a hex value
|
|
2131
2158
|
|
|
2132
2159
|
svgMap.prototype.getHex = function (value) {
|