mapwhizz 1.1.1 → 2.0.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/dist/index.esm.js +1 -0
- package/dist/index.js +1 -0
- package/package.json +33 -8
- package/dist/main.cjs +0 -22
- package/dist/module.js +0 -0
- package/src/index.js +0 -139
- package/world-map.svg +0 -1035
package/package.json
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mapwhizz",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A reusable and customizable SVG world map React component",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
6
11
|
"scripts": {
|
|
7
|
-
"
|
|
12
|
+
"build": "rollup -c rollup.config.js",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": ">=16.8.0",
|
|
17
|
+
"react-dom": ">=16.8.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@babel/core": "^7.22.0",
|
|
21
|
+
"@babel/preset-env": "^7.22.0",
|
|
22
|
+
"@babel/preset-react": "^7.22.0",
|
|
23
|
+
"@rollup/plugin-babel": "^6.0.0",
|
|
24
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
26
|
+
"rollup": "^3.28.0",
|
|
27
|
+
"rollup-plugin-terser": "^7.0.2"
|
|
8
28
|
},
|
|
9
29
|
"keywords": [
|
|
10
|
-
"map",
|
|
11
30
|
"map",
|
|
12
31
|
"geomap",
|
|
13
32
|
"geo",
|
|
14
|
-
"
|
|
15
|
-
""
|
|
33
|
+
"world map",
|
|
34
|
+
"react",
|
|
35
|
+
"svg map",
|
|
36
|
+
"choropleth"
|
|
16
37
|
],
|
|
17
38
|
"author": "samer-goda",
|
|
18
|
-
"license": "ISC"
|
|
39
|
+
"license": "ISC",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "https://github.com/samer-goda/mapwhizz"
|
|
43
|
+
}
|
|
19
44
|
}
|
package/dist/main.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
-
import { babel } from '@rollup/plugin-babel';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
input: 'src/index.js', // Entry point of your library
|
|
7
|
-
output: [
|
|
8
|
-
{
|
|
9
|
-
file: 'dist/main.cjs', // CommonJS build
|
|
10
|
-
format: 'cjs',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
file: 'dist/module.js', // ES module build
|
|
14
|
-
format: 'es',
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
plugins: [
|
|
18
|
-
resolve(), // Resolves node_modules
|
|
19
|
-
commonjs(), // Converts CommonJS to ES modules
|
|
20
|
-
babel({ babelHelpers: 'bundled' }), // Transpiles modern JS
|
|
21
|
-
],
|
|
22
|
-
};
|
package/dist/module.js
DELETED
|
File without changes
|
package/src/index.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
// Start Class MapWhizz
|
|
3
|
-
class MapWhizz {
|
|
4
|
-
constructor(container, data) {
|
|
5
|
-
if (!(container instanceof HTMLElement)) {
|
|
6
|
-
console.error('Invalid container element');
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
this.container = container;
|
|
11
|
-
this.data = data;
|
|
12
|
-
// this.mapData = mapData;
|
|
13
|
-
|
|
14
|
-
this.svgElement = null;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
mount() {
|
|
18
|
-
try {
|
|
19
|
-
const parser = new DOMParser();
|
|
20
|
-
const svgDoc = parser.parseFromString(this.mapData, 'image/svg+xml');
|
|
21
|
-
this.svgElement = svgDoc.documentElement;
|
|
22
|
-
|
|
23
|
-
this.container.innerHTML = ''; // Clear previous content
|
|
24
|
-
this.container.appendChild(this.svgElement);
|
|
25
|
-
|
|
26
|
-
this.calculateValueRange();
|
|
27
|
-
this.addStyles();
|
|
28
|
-
this.applyColorsAndInteractions();
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error('Error loading SVG:', error);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
calculateValueRange() {
|
|
35
|
-
this.minValue = Infinity;
|
|
36
|
-
this.maxValue = -Infinity;
|
|
37
|
-
|
|
38
|
-
this.data.forEach(({ value }) => {
|
|
39
|
-
this.minValue = Math.min(this.minValue, value);
|
|
40
|
-
this.maxValue = Math.max(this.maxValue, value);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getColorForValue(value) {
|
|
45
|
-
const percentage =
|
|
46
|
-
(value - this.minValue) / (this.maxValue - this.minValue);
|
|
47
|
-
const startColor = [240, 249, 255]; // Light blue
|
|
48
|
-
const endColor = [24, 72, 176]; // Dark blue
|
|
49
|
-
|
|
50
|
-
const r = Math.round(
|
|
51
|
-
startColor[0] + percentage * (endColor[0] - startColor[0])
|
|
52
|
-
);
|
|
53
|
-
const g = Math.round(
|
|
54
|
-
startColor[1] + percentage * (endColor[1] - startColor[1])
|
|
55
|
-
);
|
|
56
|
-
const b = Math.round(
|
|
57
|
-
startColor[2] + percentage * (endColor[2] - startColor[2])
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
addStyles() {
|
|
64
|
-
const style = document.createElement('style');
|
|
65
|
-
style.textContent = `
|
|
66
|
-
path {
|
|
67
|
-
transition: all 0.3s ease;
|
|
68
|
-
stroke: #fff;
|
|
69
|
-
stroke-width: 1;
|
|
70
|
-
fill: #ccc;
|
|
71
|
-
}
|
|
72
|
-
path:hover {
|
|
73
|
-
fill: rgb(0, 0, 255) !important;
|
|
74
|
-
stroke-width: 2;
|
|
75
|
-
cursor: pointer;
|
|
76
|
-
}
|
|
77
|
-
`;
|
|
78
|
-
document.head.appendChild(style);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
applyColorsAndInteractions() {
|
|
82
|
-
const countryDataMap = new Map(
|
|
83
|
-
this.data.map((item) => [item.country, item])
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
this.svgElement.querySelectorAll('path').forEach((path) => {
|
|
87
|
-
const country = path.getAttribute('title');
|
|
88
|
-
const countryData = countryDataMap.get(country);
|
|
89
|
-
|
|
90
|
-
if (countryData) {
|
|
91
|
-
path.style.fill = this.getColorForValue(countryData.value);
|
|
92
|
-
this.addHoverInteraction(path, country, countryData);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
addHoverInteraction(path, country, countryData) {
|
|
98
|
-
path.addEventListener('mouseover', (event) => {
|
|
99
|
-
const tooltip = this.createTooltip(`${country}: ${countryData.value}`);
|
|
100
|
-
document.body.appendChild(tooltip);
|
|
101
|
-
|
|
102
|
-
const moveTooltip = (e) => {
|
|
103
|
-
tooltip.style.left = `${e.pageX + 10}px`;
|
|
104
|
-
tooltip.style.top = `${e.pageY + 10}px`;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
document.addEventListener('mousemove', moveTooltip);
|
|
108
|
-
|
|
109
|
-
path.addEventListener('mouseout', () => {
|
|
110
|
-
tooltip.remove();
|
|
111
|
-
document.removeEventListener('mousemove', moveTooltip);
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
createTooltip(text) {
|
|
117
|
-
const tooltip = document.createElement('div');
|
|
118
|
-
tooltip.style.position = 'absolute';
|
|
119
|
-
tooltip.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
|
|
120
|
-
tooltip.style.color = '#fff';
|
|
121
|
-
tooltip.style.padding = '5px 10px';
|
|
122
|
-
tooltip.style.borderRadius = '4px';
|
|
123
|
-
tooltip.style.pointerEvents = 'none';
|
|
124
|
-
tooltip.style.fontSize = '12px';
|
|
125
|
-
tooltip.style.zIndex = '1000';
|
|
126
|
-
tooltip.textContent = text;
|
|
127
|
-
|
|
128
|
-
return tooltip;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// UMD Export (Works with ES6, CommonJS, and <script> tag)
|
|
133
|
-
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
|
134
|
-
module.exports = MapWhizz;
|
|
135
|
-
} else {
|
|
136
|
-
window.MapWhizz = MapWhizz;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// export default MapWhizz;
|