@ohos-ports/jsvectormap 1.7.0-beta.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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/dist/jsvectormap.cjs +2355 -0
  3. package/dist/jsvectormap.css +147 -0
  4. package/dist/jsvectormap.esm.js +2293 -0
  5. package/dist/jsvectormap.js +2301 -0
  6. package/dist/jsvectormap.min.css +1 -0
  7. package/dist/jsvectormap.min.js +1 -0
  8. package/dist/maps/world-merc.js +1 -0
  9. package/dist/maps/world.js +1 -0
  10. package/package.json +49 -0
  11. package/src/js/components/base.js +18 -0
  12. package/src/js/components/concerns/interactable.js +68 -0
  13. package/src/js/components/line.js +50 -0
  14. package/src/js/components/marker.js +109 -0
  15. package/src/js/components/region.js +53 -0
  16. package/src/js/components/route.js +76 -0
  17. package/src/js/components/tooltip.js +88 -0
  18. package/src/js/core/applyTransform.js +43 -0
  19. package/src/js/core/coordsToPoint.js +22 -0
  20. package/src/js/core/createLines.js +44 -0
  21. package/src/js/core/createMarkers.js +55 -0
  22. package/src/js/core/createRegions.js +23 -0
  23. package/src/js/core/createRoutes.js +16 -0
  24. package/src/js/core/createSeries.js +13 -0
  25. package/src/js/core/getInsetForPoint.js +13 -0
  26. package/src/js/core/getMarkerPosition.js +12 -0
  27. package/src/js/core/index.js +41 -0
  28. package/src/js/core/repositionLabels.js +21 -0
  29. package/src/js/core/repositionLines.js +30 -0
  30. package/src/js/core/repositionMarkers.js +11 -0
  31. package/src/js/core/resize.js +15 -0
  32. package/src/js/core/setFocus.js +46 -0
  33. package/src/js/core/setScale.js +65 -0
  34. package/src/js/core/setupContainerEvents.js +50 -0
  35. package/src/js/core/setupContainerTouchEvents.js +85 -0
  36. package/src/js/core/setupElementEvents.js +112 -0
  37. package/src/js/core/setupZoomButtons.js +40 -0
  38. package/src/js/core/updateSize.js +7 -0
  39. package/src/js/dataVisualization.js +87 -0
  40. package/src/js/defaults/events.js +11 -0
  41. package/src/js/defaults/options.js +90 -0
  42. package/src/js/eventHandler.js +47 -0
  43. package/src/js/index.js +25 -0
  44. package/src/js/legend.js +69 -0
  45. package/src/js/map.js +367 -0
  46. package/src/js/projection.js +127 -0
  47. package/src/js/scales/ordinalScale.js +21 -0
  48. package/src/js/series.js +68 -0
  49. package/src/js/svg/baseElement.js +53 -0
  50. package/src/js/svg/canvasElement.js +99 -0
  51. package/src/js/svg/imageElement.js +49 -0
  52. package/src/js/svg/shapeElement.js +48 -0
  53. package/src/js/svg/textElement.js +13 -0
  54. package/src/js/util/deepMerge.js +129 -0
  55. package/src/js/util/index.js +81 -0
  56. package/src/scss/_variables.scss +37 -0
  57. package/src/scss/jsvectormap.scss +153 -0
@@ -0,0 +1,2293 @@
1
+ /**
2
+ * By https://github.com/TehShrike/deepmerge
3
+ */
4
+
5
+ var isMergeableObject = function isMergeableObject(value) {
6
+ return isNonNullObject(value) && !isSpecial(value);
7
+ };
8
+ function isNonNullObject(value) {
9
+ return !!value && typeof value === 'object';
10
+ }
11
+ function isSpecial(value) {
12
+ var stringValue = Object.prototype.toString.call(value);
13
+ return stringValue === '[object RegExp]' || stringValue === '[object Date]' || isNode(value) || isReactElement(value);
14
+ }
15
+
16
+ // see https://github.com/facebook/react/blob/b5ac963fb791d1298e7f396236383bc955f916c1/src/isomorphic/classic/element/ReactElement.js#L21-L25
17
+ var canUseSymbol = typeof Symbol === 'function' && Symbol.for;
18
+ var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for('react.element') : 0xeac7;
19
+ function isReactElement(value) {
20
+ return value.$$typeof === REACT_ELEMENT_TYPE;
21
+ }
22
+ function isNode(value) {
23
+ return value instanceof Node;
24
+ }
25
+ function emptyTarget(val) {
26
+ return Array.isArray(val) ? [] : {};
27
+ }
28
+ function cloneUnlessOtherwiseSpecified(value, options) {
29
+ return options.clone !== false && options.isMergeableObject(value) ? deepmerge(emptyTarget(value), value, options) : value;
30
+ }
31
+ function defaultArrayMerge(target, source, options) {
32
+ return target.concat(source).map(function (element) {
33
+ return cloneUnlessOtherwiseSpecified(element, options);
34
+ });
35
+ }
36
+ function getMergeFunction(key, options) {
37
+ if (!options.customMerge) {
38
+ return deepmerge;
39
+ }
40
+ var customMerge = options.customMerge(key);
41
+ return typeof customMerge === 'function' ? customMerge : deepmerge;
42
+ }
43
+ function getEnumerableOwnPropertySymbols(target) {
44
+ return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function (symbol) {
45
+ return target.propertyIsEnumerable(symbol);
46
+ }) : [];
47
+ }
48
+ function getKeys(target) {
49
+ return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target));
50
+ }
51
+ function propertyIsOnObject(object, property) {
52
+ try {
53
+ return property in object;
54
+ } catch (_) {
55
+ return false;
56
+ }
57
+ }
58
+
59
+ // Protects from prototype poisoning and unexpected merging up the prototype chain.
60
+ function propertyIsUnsafe(target, key) {
61
+ return propertyIsOnObject(target, key) // Properties are safe to merge if they don't exist in the target yet,
62
+ && !(Object.hasOwnProperty.call(target, key) // unsafe if they exist up the prototype chain,
63
+ && Object.propertyIsEnumerable.call(target, key)); // and also unsafe if they're nonenumerable.
64
+ }
65
+ function mergeObject(target, source, options) {
66
+ var destination = {};
67
+ if (options.isMergeableObject(target)) {
68
+ getKeys(target).forEach(function (key) {
69
+ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
70
+ });
71
+ }
72
+ getKeys(source).forEach(function (key) {
73
+ if (propertyIsUnsafe(target, key)) {
74
+ return;
75
+ }
76
+ if (propertyIsOnObject(target, key) && options.isMergeableObject(source[key])) {
77
+ destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
78
+ } else {
79
+ destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
80
+ }
81
+ });
82
+ return destination;
83
+ }
84
+ var deepmerge = function deepmerge(target, source, options) {
85
+ options = options || {};
86
+ options.arrayMerge = options.arrayMerge || defaultArrayMerge;
87
+ options.isMergeableObject = options.isMergeableObject || isMergeableObject;
88
+ // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge()
89
+ // implementations can use it. The caller may not replace it.
90
+ options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified;
91
+ var sourceIsArray = Array.isArray(source);
92
+ var targetIsArray = Array.isArray(target);
93
+ var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray;
94
+ if (!sourceAndTargetTypesMatch) {
95
+ return cloneUnlessOtherwiseSpecified(source, options);
96
+ } else if (sourceIsArray) {
97
+ return options.arrayMerge(target, source, options);
98
+ } else {
99
+ return mergeObject(target, source, options);
100
+ }
101
+ };
102
+
103
+ /**
104
+ * --------------------------------------------------------------------------
105
+ * Public Util Api
106
+ * --------------------------------------------------------------------------
107
+ */
108
+ var getElement = function getElement(selector) {
109
+ if (typeof selector === 'object' && typeof selector.nodeType !== 'undefined') {
110
+ return selector;
111
+ }
112
+ if (typeof selector === 'string') {
113
+ return document.querySelector(selector);
114
+ }
115
+ return null;
116
+ };
117
+ var createElement = function createElement(type, classes, content, html) {
118
+ if (html === void 0) {
119
+ html = false;
120
+ }
121
+ var el = document.createElement(type);
122
+ if (content) {
123
+ el[!html ? 'textContent' : 'innerHTML'] = content;
124
+ }
125
+ if (classes) {
126
+ el.className = classes;
127
+ }
128
+ return el;
129
+ };
130
+ var findElement = function findElement(parentElement, selector) {
131
+ return Element.prototype.querySelector.call(parentElement, selector);
132
+ };
133
+ var removeElement = function removeElement(target) {
134
+ target.parentNode.removeChild(target);
135
+ };
136
+ var isImageUrl = function isImageUrl(url) {
137
+ return /\.(jpg|gif|png)$/.test(url);
138
+ };
139
+ var hyphenate = function hyphenate(string) {
140
+ return string.replace(/[\w]([A-Z])/g, function (m) {
141
+ return m[0] + "-" + m[1];
142
+ }).toLowerCase();
143
+ };
144
+ var merge = function merge(target, source, deep) {
145
+ if (deep === void 0) {
146
+ deep = false;
147
+ }
148
+ if (deep) {
149
+ return deepmerge(target, source);
150
+ }
151
+ return Object.assign(target, source);
152
+ };
153
+ var getLineUid = function getLineUid(from, to) {
154
+ return from.toLowerCase() + ":to:" + to.toLowerCase();
155
+ };
156
+ var inherit = function inherit(target, source) {
157
+ Object.assign(target.prototype, source);
158
+ };
159
+
160
+ var eventRegistry = {};
161
+ var eventUid = 1;
162
+ var EventHandler = {
163
+ on: function on(element, event, handler, options) {
164
+ if (options === void 0) {
165
+ options = {};
166
+ }
167
+ var uid = "jvm:" + event + "::" + eventUid++;
168
+ eventRegistry[uid] = {
169
+ selector: element,
170
+ handler: handler
171
+ };
172
+ handler._uid = uid;
173
+ element.addEventListener(event, handler, options);
174
+ },
175
+ delegate: function delegate(element, event, selector, handler) {
176
+ event = event.split(' ');
177
+ event.forEach(function (eventName) {
178
+ EventHandler.on(element, eventName, function (e) {
179
+ var target = e.target;
180
+ if (target.matches(selector)) {
181
+ handler.call(target, e);
182
+ }
183
+ });
184
+ });
185
+ },
186
+ off: function off(element, event, handler) {
187
+ var eventType = event.split(':')[1];
188
+ element.removeEventListener(eventType, handler);
189
+ delete eventRegistry[handler._uid];
190
+ },
191
+ flush: function flush() {
192
+ Object.keys(eventRegistry).forEach(function (event) {
193
+ EventHandler.off(eventRegistry[event].selector, event, eventRegistry[event].handler);
194
+ });
195
+ },
196
+ getEventRegistry: function getEventRegistry() {
197
+ return eventRegistry;
198
+ }
199
+ };
200
+
201
+ function setupContainerEvents() {
202
+ var _this = this;
203
+ var map = this;
204
+ var mouseDown = false;
205
+ var oldPageX;
206
+ var oldPageY;
207
+ if (this.params.draggable) {
208
+ EventHandler.on(this.container, 'mousemove', function (e) {
209
+ if (!mouseDown) {
210
+ return false;
211
+ }
212
+ map.transX -= (oldPageX - e.pageX) / map.scale;
213
+ map.transY -= (oldPageY - e.pageY) / map.scale;
214
+ map._applyTransform();
215
+ oldPageX = e.pageX;
216
+ oldPageY = e.pageY;
217
+ });
218
+ EventHandler.on(this.container, 'mousedown', function (e) {
219
+ mouseDown = true;
220
+ oldPageX = e.pageX;
221
+ oldPageY = e.pageY;
222
+ return false;
223
+ });
224
+ EventHandler.on(document.body, 'mouseup', function () {
225
+ mouseDown = false;
226
+ });
227
+ }
228
+ if (this.params.zoomOnScroll) {
229
+ EventHandler.on(this.container, 'wheel', function (event) {
230
+ var deltaY = ((event.deltaY || -event.wheelDelta || event.detail) >> 10 || 1) * 75;
231
+ var rect = _this.container.getBoundingClientRect();
232
+ var offsetX = event.pageX - rect.left - window.scrollX;
233
+ var offsetY = event.pageY - rect.top - window.scrollY;
234
+ var zoomStep = Math.pow(1 + map.params.zoomOnScrollSpeed / 1000, -1.5 * deltaY);
235
+ if (map.tooltip) {
236
+ map._tooltip.hide();
237
+ }
238
+ map._setScale(map.scale * zoomStep, offsetX, offsetY);
239
+ event.preventDefault();
240
+ });
241
+ }
242
+ }
243
+
244
+ var Events = {
245
+ onLoaded: 'map:loaded',
246
+ onViewportChange: 'viewport:changed',
247
+ onRegionClick: 'region:clicked',
248
+ onMarkerClick: 'marker:clicked',
249
+ onRegionSelected: 'region:selected',
250
+ onMarkerSelected: 'marker:selected',
251
+ onRegionTooltipShow: 'region.tooltip:show',
252
+ onMarkerTooltipShow: 'marker.tooltip:show',
253
+ onDestroyed: 'map:destroyed'
254
+ };
255
+
256
+ var parseEvent = function parseEvent(map, selector, isTooltip) {
257
+ var element = getElement(selector);
258
+ var type = element.getAttribute('class').indexOf('jvm-region') === -1 ? 'marker' : 'region';
259
+ var isRegion = type === 'region';
260
+ var code = isRegion ? element.getAttribute('data-code') : element.getAttribute('data-index');
261
+ var event = isRegion ? Events.onRegionSelected : Events.onMarkerSelected;
262
+
263
+ // Init tooltip event
264
+ if (isTooltip) {
265
+ event = isRegion ? Events.onRegionTooltipShow : Events.onMarkerTooltipShow;
266
+ }
267
+ return {
268
+ type: type,
269
+ code: code,
270
+ event: event,
271
+ element: isRegion ? map.regions[code].element : map._markers[code].element,
272
+ tooltipText: isRegion ? map._mapData.paths[code].name || '' : map._markers[code].config.name || ''
273
+ };
274
+ };
275
+ function setupElementEvents() {
276
+ var map = this;
277
+ var container = this.container;
278
+ var pageX, pageY, mouseMoved;
279
+ EventHandler.on(container, 'mousemove', function (event) {
280
+ if (Math.abs(pageX - event.pageX) + Math.abs(pageY - event.pageY) > 2) {
281
+ mouseMoved = true;
282
+ }
283
+ });
284
+
285
+ // When the mouse is pressed
286
+ EventHandler.delegate(container, 'mousedown', '.jvm-element', function (event) {
287
+ pageX = event.pageX;
288
+ pageY = event.pageY;
289
+ mouseMoved = false;
290
+ });
291
+
292
+ // When the mouse is over the region/marker | When the mouse is out the region/marker
293
+ EventHandler.delegate(container, 'mouseover mouseout', '.jvm-element', function (event) {
294
+ var data = parseEvent(map, this, true);
295
+ var showTooltip = map.params.showTooltip;
296
+ if (event.type === 'mouseover') {
297
+ data.element.hover(true);
298
+ if (showTooltip) {
299
+ map._tooltip.text(data.tooltipText);
300
+ map._emit(data.event, [event, map._tooltip, data.code]);
301
+ if (!event.defaultPrevented) {
302
+ map._tooltip.show();
303
+ }
304
+ }
305
+ } else {
306
+ data.element.hover(false);
307
+ if (showTooltip) {
308
+ map._tooltip.hide();
309
+ }
310
+ }
311
+ });
312
+
313
+ // When the click is released
314
+ EventHandler.delegate(container, 'mouseup', '.jvm-element', function (event) {
315
+ var data = parseEvent(map, this);
316
+ if (mouseMoved) {
317
+ return;
318
+ }
319
+ if (data.type === 'region' && map.params.regionsSelectable || data.type === 'marker' && map.params.markersSelectable) {
320
+ var element = data.element;
321
+
322
+ // We're checking if regions/markers|SelectableOne option is presented
323
+ if (map.params[data.type + "sSelectableOne"]) {
324
+ data.type === 'region' ? map.clearSelectedRegions() : map.clearSelectedMarkers();
325
+ }
326
+ if (data.element.isSelected) {
327
+ element.select(false);
328
+ } else {
329
+ element.select(true);
330
+ }
331
+ map._emit(data.event, [data.code, element.isSelected, data.type === 'region' ? map.getSelectedRegions() : map.getSelectedMarkers()]);
332
+ }
333
+ });
334
+
335
+ // When region/marker is clicked
336
+ EventHandler.delegate(container, 'click', '.jvm-element', function (event) {
337
+ var _parseEvent = parseEvent(map, this),
338
+ type = _parseEvent.type,
339
+ code = _parseEvent.code;
340
+ map._emit(type === 'region' ? Events.onRegionClick : Events.onMarkerClick, [event, code]);
341
+ });
342
+ }
343
+
344
+ function setupZoomButtons() {
345
+ var _this = this;
346
+ var zoomInOption = this.params.zoomInButton;
347
+ var zoomOutOption = this.params.zoomOutButton;
348
+ var getZoomButton = function getZoomButton(zoomOption) {
349
+ return typeof zoomOption === 'string' ? document.querySelector(zoomOption) : zoomOption;
350
+ };
351
+ var zoomIn = zoomInOption ? getZoomButton(zoomInOption) : createElement('div', 'jvm-zoom-btn jvm-zoomin', '+', true);
352
+ var zoomOut = zoomOutOption ? getZoomButton(zoomOutOption) : createElement('div', 'jvm-zoom-btn jvm-zoomout', '&#x2212', true);
353
+ if (!zoomInOption) {
354
+ this.container.appendChild(zoomIn);
355
+ }
356
+ if (!zoomOutOption) {
357
+ this.container.appendChild(zoomOut);
358
+ }
359
+ var handler = function handler(zoomin) {
360
+ if (zoomin === void 0) {
361
+ zoomin = true;
362
+ }
363
+ return function () {
364
+ return _this._setScale(zoomin ? _this.scale * _this.params.zoomStep : _this.scale / _this.params.zoomStep, _this._width / 2, _this._height / 2, false, _this.params.zoomAnimate);
365
+ };
366
+ };
367
+ EventHandler.on(zoomIn, 'click', handler());
368
+ EventHandler.on(zoomOut, 'click', handler(false));
369
+ }
370
+
371
+ function setupContainerTouchEvents() {
372
+ var map = this,
373
+ touchStartScale,
374
+ touchStartDistance,
375
+ touchX,
376
+ touchY,
377
+ centerTouchX,
378
+ centerTouchY,
379
+ lastTouchesLength;
380
+ var handleTouchEvent = function handleTouchEvent(e) {
381
+ var touches = e.touches;
382
+ var offset, scale, transXOld, transYOld;
383
+ if (e.type == 'touchstart') {
384
+ lastTouchesLength = 0;
385
+ }
386
+ if (touches.length == 1) {
387
+ if (lastTouchesLength == 1) {
388
+ var _map$_tooltip;
389
+ transXOld = map.transX;
390
+ transYOld = map.transY;
391
+ map.transX -= (touchX - touches[0].pageX) / map.scale;
392
+ map.transY -= (touchY - touches[0].pageY) / map.scale;
393
+ (_map$_tooltip = map._tooltip) == null || _map$_tooltip.hide();
394
+ map._applyTransform();
395
+ if (transXOld != map.transX || transYOld != map.transY) {
396
+ e.preventDefault();
397
+ }
398
+ }
399
+ touchX = touches[0].pageX;
400
+ touchY = touches[0].pageY;
401
+ } else if (touches.length == 2) {
402
+ if (lastTouchesLength == 2) {
403
+ var _map$_tooltip2;
404
+ scale = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)) / touchStartDistance;
405
+ map._setScale(touchStartScale * scale, centerTouchX, centerTouchY);
406
+ (_map$_tooltip2 = map._tooltip) == null || _map$_tooltip2.hide();
407
+ e.preventDefault();
408
+ } else {
409
+ var rect = map.container.getBoundingClientRect();
410
+ offset = {
411
+ top: rect.top + window.scrollY,
412
+ left: rect.left + window.scrollX
413
+ };
414
+ if (touches[0].pageX > touches[1].pageX) {
415
+ centerTouchX = touches[1].pageX + (touches[0].pageX - touches[1].pageX) / 2;
416
+ } else {
417
+ centerTouchX = touches[0].pageX + (touches[1].pageX - touches[0].pageX) / 2;
418
+ }
419
+ if (touches[0].pageY > touches[1].pageY) {
420
+ centerTouchY = touches[1].pageY + (touches[0].pageY - touches[1].pageY) / 2;
421
+ } else {
422
+ centerTouchY = touches[0].pageY + (touches[1].pageY - touches[0].pageY) / 2;
423
+ }
424
+ centerTouchX -= offset.left;
425
+ centerTouchY -= offset.top;
426
+ touchStartScale = map.scale;
427
+ touchStartDistance = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2));
428
+ }
429
+ }
430
+ lastTouchesLength = touches.length;
431
+ };
432
+ EventHandler.on(map.container, 'touchstart', handleTouchEvent);
433
+ EventHandler.on(map.container, 'touchmove', handleTouchEvent);
434
+ }
435
+
436
+ function _arrayLikeToArray(r, a) {
437
+ (null == a || a > r.length) && (a = r.length);
438
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
439
+ return n;
440
+ }
441
+ function _assertThisInitialized(e) {
442
+ if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
443
+ return e;
444
+ }
445
+ function _defineProperties(e, r) {
446
+ for (var t = 0; t < r.length; t++) {
447
+ var o = r[t];
448
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
449
+ }
450
+ }
451
+ function _createClass(e, r, t) {
452
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
453
+ writable: !1
454
+ }), e;
455
+ }
456
+ function _createForOfIteratorHelperLoose(r, e) {
457
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
458
+ if (t) return (t = t.call(r)).next.bind(t);
459
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
460
+ t && (r = t);
461
+ var o = 0;
462
+ return function () {
463
+ return o >= r.length ? {
464
+ done: !0
465
+ } : {
466
+ done: !1,
467
+ value: r[o++]
468
+ };
469
+ };
470
+ }
471
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
472
+ }
473
+ function _extends() {
474
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
475
+ for (var e = 1; e < arguments.length; e++) {
476
+ var t = arguments[e];
477
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
478
+ }
479
+ return n;
480
+ }, _extends.apply(null, arguments);
481
+ }
482
+ function _inheritsLoose(t, o) {
483
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
484
+ }
485
+ function _objectWithoutPropertiesLoose(r, e) {
486
+ if (null == r) return {};
487
+ var t = {};
488
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
489
+ if (-1 !== e.indexOf(n)) continue;
490
+ t[n] = r[n];
491
+ }
492
+ return t;
493
+ }
494
+ function _setPrototypeOf(t, e) {
495
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
496
+ return t.__proto__ = e, t;
497
+ }, _setPrototypeOf(t, e);
498
+ }
499
+ function _toPrimitive(t, r) {
500
+ if ("object" != typeof t || !t) return t;
501
+ var e = t[Symbol.toPrimitive];
502
+ if (void 0 !== e) {
503
+ var i = e.call(t, r || "default");
504
+ if ("object" != typeof i) return i;
505
+ throw new TypeError("@@toPrimitive must return a primitive value.");
506
+ }
507
+ return ("string" === r ? String : Number)(t);
508
+ }
509
+ function _toPropertyKey(t) {
510
+ var i = _toPrimitive(t, "string");
511
+ return "symbol" == typeof i ? i : i + "";
512
+ }
513
+ function _unsupportedIterableToArray(r, a) {
514
+ if (r) {
515
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
516
+ var t = {}.toString.call(r).slice(8, -1);
517
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
518
+ }
519
+ }
520
+
521
+ var BaseComponent = /*#__PURE__*/function () {
522
+ function BaseComponent() {}
523
+ var _proto = BaseComponent.prototype;
524
+ _proto.dispose = function dispose() {
525
+ if (this._tooltip) {
526
+ removeElement(this._tooltip);
527
+ } else {
528
+ // @todo: move shape in base component in v2
529
+ this.shape.remove();
530
+ }
531
+ for (var _iterator = _createForOfIteratorHelperLoose(Object.getOwnPropertyNames(this)), _step; !(_step = _iterator()).done;) {
532
+ var propertyName = _step.value;
533
+ this[propertyName] = null;
534
+ }
535
+ };
536
+ return BaseComponent;
537
+ }();
538
+
539
+ var Interactable = {
540
+ getLabelText: function getLabelText(key, label) {
541
+ if (!label) {
542
+ return;
543
+ }
544
+ if (typeof label.render === 'function') {
545
+ var params = [];
546
+
547
+ // Pass additional paramater (Marker config object) in case it's a Marker.
548
+ if (this.constructor.Name === 'marker') {
549
+ params.push(this.getConfig());
550
+ }
551
+
552
+ // Becuase we need to add the key always at the end
553
+ params.push(key);
554
+ return label.render.apply(this, params);
555
+ }
556
+ return key;
557
+ },
558
+ getLabelOffsets: function getLabelOffsets(key, label) {
559
+ if (typeof label.offsets === 'function') {
560
+ return label.offsets(key);
561
+ }
562
+
563
+ // If offsets are an array of offsets e.g offsets: [ [0, 25], [10, 15] ]
564
+ if (Array.isArray(label.offsets)) {
565
+ return label.offsets[key];
566
+ }
567
+ return [0, 0];
568
+ },
569
+ setStyle: function setStyle(property, value) {
570
+ this.shape.setStyle(property, value);
571
+ },
572
+ remove: function remove() {
573
+ this.shape.remove();
574
+ if (this.label) this.label.remove();
575
+ },
576
+ hover: function hover(state) {
577
+ this._setStatus('isHovered', state);
578
+ },
579
+ select: function select(state) {
580
+ this._setStatus('isSelected', state);
581
+ },
582
+ // Private
583
+ _setStatus: function _setStatus(property, state) {
584
+ this.shape[property] = state;
585
+ this.shape.updateStyle();
586
+ this[property] = state;
587
+ if (this.label) {
588
+ this.label[property] = state;
589
+ this.label.updateStyle();
590
+ }
591
+ }
592
+ };
593
+
594
+ var Region = /*#__PURE__*/function (_BaseComponent) {
595
+ function Region(_ref) {
596
+ var _this;
597
+ var map = _ref.map,
598
+ code = _ref.code,
599
+ path = _ref.path,
600
+ style = _ref.style,
601
+ label = _ref.label,
602
+ labelStyle = _ref.labelStyle,
603
+ labelsGroup = _ref.labelsGroup;
604
+ _this = _BaseComponent.call(this) || this;
605
+ _this._map = map;
606
+ _this.shape = _this._createRegion(path, code, style);
607
+ var text = _this.getLabelText(code, label);
608
+
609
+ // If label is passed and render function returns something
610
+ if (label && text) {
611
+ var bbox = _this.shape.getBBox();
612
+ var offsets = _this.getLabelOffsets(code, label);
613
+ _this.labelX = bbox.x + bbox.width / 2 + offsets[0];
614
+ _this.labelY = bbox.y + bbox.height / 2 + offsets[1];
615
+ _this.label = _this._map.canvas.createText({
616
+ text: text,
617
+ textAnchor: 'middle',
618
+ alignmentBaseline: 'central',
619
+ dataCode: code,
620
+ x: _this.labelX,
621
+ y: _this.labelY
622
+ }, labelStyle, labelsGroup);
623
+ _this.label.addClass('jvm-region jvm-element');
624
+ }
625
+ return _this;
626
+ }
627
+ _inheritsLoose(Region, _BaseComponent);
628
+ var _proto = Region.prototype;
629
+ _proto._createRegion = function _createRegion(path, code, style) {
630
+ path = this._map.canvas.createPath({
631
+ d: path,
632
+ dataCode: code
633
+ }, style);
634
+ path.addClass('jvm-region jvm-element');
635
+ return path;
636
+ };
637
+ _proto.updateLabelPosition = function updateLabelPosition() {
638
+ if (this.label) {
639
+ this.label.set({
640
+ x: this.labelX * this._map.scale + this._map.transX * this._map.scale,
641
+ y: this.labelY * this._map.scale + this._map.transY * this._map.scale
642
+ });
643
+ }
644
+ };
645
+ return Region;
646
+ }(BaseComponent);
647
+ inherit(Region, Interactable);
648
+
649
+ function createRegions() {
650
+ this._regionLabelsGroup = this._regionLabelsGroup || this.canvas.createGroup('jvm-regions-labels-group');
651
+ for (var code in this._mapData.paths) {
652
+ var region = new Region({
653
+ map: this,
654
+ code: code,
655
+ path: this._mapData.paths[code].path,
656
+ style: merge({}, this.params.regionStyle),
657
+ labelStyle: this.params.regionLabelStyle,
658
+ labelsGroup: this._regionLabelsGroup,
659
+ label: this.params.labels && this.params.labels.regions
660
+ });
661
+ this.regions[code] = {
662
+ config: this._mapData.paths[code],
663
+ element: region
664
+ };
665
+ }
666
+ }
667
+
668
+ var LINE_CLASS = 'jvm-line';
669
+ var Line = /*#__PURE__*/function (_BaseComponent) {
670
+ function Line(options, style) {
671
+ var _this;
672
+ _this = _BaseComponent.call(this) || this;
673
+ _this._options = options;
674
+ _this._style = {
675
+ initial: style
676
+ };
677
+ _this._draw();
678
+ return _this;
679
+ }
680
+ _inheritsLoose(Line, _BaseComponent);
681
+ var _proto = Line.prototype;
682
+ _proto.setStyle = function setStyle(property, value) {
683
+ this.shape.setStyle(property, value);
684
+ };
685
+ _proto.getConfig = function getConfig() {
686
+ return this._options.config;
687
+ };
688
+ _proto._draw = function _draw() {
689
+ var _this$_options = this._options,
690
+ index = _this$_options.index,
691
+ group = _this$_options.group,
692
+ map = _this$_options.map;
693
+ var config = {
694
+ d: this._getDAttribute(),
695
+ fill: 'none',
696
+ dataIndex: index
697
+ };
698
+ this.shape = map.canvas.createPath(config, this._style, group);
699
+ this.shape.addClass(LINE_CLASS);
700
+ };
701
+ _proto._getDAttribute = function _getDAttribute() {
702
+ var _this$_options2 = this._options,
703
+ x1 = _this$_options2.x1,
704
+ y1 = _this$_options2.y1,
705
+ x2 = _this$_options2.x2,
706
+ y2 = _this$_options2.y2,
707
+ curvature = _this$_options2.curvature;
708
+ return "M" + x1 + "," + y1 + this._getQCommand(x1, y1, x2, y2, curvature) + x2 + "," + y2;
709
+ };
710
+ _proto._getQCommand = function _getQCommand(x1, y1, x2, y2, curvature) {
711
+ if (!curvature) {
712
+ return ' ';
713
+ }
714
+ var curveX = (x1 + x2) / 2 + curvature * (y2 - y1);
715
+ var curveY = (y1 + y2) / 2 - curvature * (x2 - x1);
716
+ return " Q" + curveX + "," + curveY + " ";
717
+ };
718
+ return Line;
719
+ }(BaseComponent);
720
+
721
+ var _excluded = ["curvature"],
722
+ _excluded2 = ["curvature"];
723
+ function createLines(lines) {
724
+ var point1 = false,
725
+ point2 = false;
726
+ var _this$params$lineStyl = this.params.lineStyle,
727
+ curvature = _this$params$lineStyl.curvature,
728
+ lineStyle = _objectWithoutPropertiesLoose(_this$params$lineStyl, _excluded);
729
+ for (var index in lines) {
730
+ var lineConfig = lines[index];
731
+ for (var _i = 0, _Object$values = Object.values(this._markers); _i < _Object$values.length; _i++) {
732
+ var markerConfig = _Object$values[_i].config;
733
+ if (markerConfig.name === lineConfig.from) {
734
+ point1 = this.getMarkerPosition(markerConfig);
735
+ }
736
+ if (markerConfig.name === lineConfig.to) {
737
+ point2 = this.getMarkerPosition(markerConfig);
738
+ }
739
+ }
740
+ if (point1 !== false && point2 !== false) {
741
+ var _ref = lineConfig.style || {},
742
+ curvatureOption = _ref.curvature,
743
+ style = _objectWithoutPropertiesLoose(_ref, _excluded2);
744
+
745
+ // Register lines with unique keys
746
+ this._lines[getLineUid(lineConfig.from, lineConfig.to)] = new Line({
747
+ index: index,
748
+ map: this,
749
+ group: this._linesGroup,
750
+ config: lineConfig,
751
+ x1: point1.x,
752
+ y1: point1.y,
753
+ x2: point2.x,
754
+ y2: point2.y,
755
+ curvature: curvatureOption == 0 ? 0 : curvatureOption || curvature
756
+ }, merge(lineStyle, style, true));
757
+ }
758
+ }
759
+ }
760
+
761
+ var NAME = 'marker';
762
+ var JVM_PREFIX$1 = 'jvm-';
763
+ var MARKER_CLASS = JVM_PREFIX$1 + "element " + JVM_PREFIX$1 + "marker";
764
+ var MARKER_LABEL_CLASS = JVM_PREFIX$1 + "element " + JVM_PREFIX$1 + "label";
765
+ var Marker = /*#__PURE__*/function (_BaseComponent) {
766
+ function Marker(options, style) {
767
+ var _this;
768
+ _this = _BaseComponent.call(this) || this;
769
+ _this._options = options;
770
+ _this._style = style;
771
+ _this._labelX = null;
772
+ _this._labelY = null;
773
+ _this._offsets = null;
774
+ _this._isImage = !!style.initial.image;
775
+ _this._draw();
776
+ if (_this._options.label) {
777
+ _this._drawLabel();
778
+ }
779
+ if (_this._isImage) {
780
+ _this.updateLabelPosition();
781
+ }
782
+ return _this;
783
+ }
784
+ _inheritsLoose(Marker, _BaseComponent);
785
+ var _proto = Marker.prototype;
786
+ _proto.getConfig = function getConfig() {
787
+ return this._options.config;
788
+ };
789
+ _proto.updateLabelPosition = function updateLabelPosition() {
790
+ var map = this._options.map;
791
+ if (this.label) {
792
+ this.label.set({
793
+ x: this._labelX * map.scale + this._offsets[0] + map.transX * map.scale + 5 + (this._isImage ? (this.shape.width || 0) / 2 : this.shape.node.r.baseVal.value),
794
+ y: this._labelY * map.scale + map.transY * this._options.map.scale + this._offsets[1]
795
+ });
796
+ }
797
+ };
798
+ _proto._draw = function _draw() {
799
+ var _this$_options = this._options,
800
+ index = _this$_options.index,
801
+ map = _this$_options.map,
802
+ group = _this$_options.group,
803
+ cx = _this$_options.cx,
804
+ cy = _this$_options.cy;
805
+ var shapeType = this._isImage ? 'createImage' : 'createCircle';
806
+ this.shape = map.canvas[shapeType]({
807
+ dataIndex: index,
808
+ cx: cx,
809
+ cy: cy
810
+ }, this._style, group);
811
+ this.shape.addClass(MARKER_CLASS);
812
+ };
813
+ _proto._drawLabel = function _drawLabel() {
814
+ var _this$_options2 = this._options,
815
+ index = _this$_options2.index,
816
+ map = _this$_options2.map,
817
+ label = _this$_options2.label,
818
+ labelsGroup = _this$_options2.labelsGroup,
819
+ cx = _this$_options2.cx,
820
+ cy = _this$_options2.cy,
821
+ config = _this$_options2.config,
822
+ isRecentlyCreated = _this$_options2.isRecentlyCreated;
823
+ var labelText = this.getLabelText(index, label);
824
+ this._labelX = cx / map.scale - map.transX;
825
+ this._labelY = cy / map.scale - map.transY;
826
+ this._offsets = isRecentlyCreated && config.offsets ? config.offsets : this.getLabelOffsets(index, label);
827
+ this.label = map.canvas.createText({
828
+ text: labelText,
829
+ dataIndex: index,
830
+ x: this._labelX,
831
+ y: this._labelY,
832
+ dy: '0.6ex'
833
+ }, map.params.markerLabelStyle, labelsGroup);
834
+ this.label.addClass(MARKER_LABEL_CLASS);
835
+ if (isRecentlyCreated) {
836
+ this.updateLabelPosition();
837
+ }
838
+ };
839
+ return _createClass(Marker, null, [{
840
+ key: "Name",
841
+ get: function get() {
842
+ return NAME;
843
+ }
844
+ }]);
845
+ }(BaseComponent);
846
+ inherit(Marker, Interactable);
847
+
848
+ function createMarkers(markers, isRecentlyCreated) {
849
+ var _this = this;
850
+ if (markers === void 0) {
851
+ markers = {};
852
+ }
853
+ if (isRecentlyCreated === void 0) {
854
+ isRecentlyCreated = false;
855
+ }
856
+ var _loop = function _loop() {
857
+ var config = markers[index];
858
+ var point = _this.getMarkerPosition(config);
859
+ var uid = config.coords.join(':');
860
+ if (!point) {
861
+ return 0; // continue
862
+ }
863
+
864
+ // We're checking if recently created marker does already exist
865
+ // If it does we don't need to create it again, so we'll continue
866
+ // Becuase we may have more than one marker submitted via `addMarkers` method.
867
+ if (isRecentlyCreated) {
868
+ if (Object.keys(_this._markers).filter(function (i) {
869
+ return _this._markers[i]._uid === uid;
870
+ }).length) {
871
+ return 0; // continue
872
+ }
873
+ index = Object.keys(_this._markers).length;
874
+ }
875
+ var marker = new Marker({
876
+ index: index,
877
+ map: _this,
878
+ label: _this.params.labels && _this.params.labels.markers,
879
+ labelsGroup: _this._markerLabelsGroup,
880
+ cx: point.x,
881
+ cy: point.y,
882
+ group: _this._markersGroup,
883
+ config: config,
884
+ isRecentlyCreated: isRecentlyCreated
885
+ }, merge(_this.params.markerStyle, _extends({}, config.style || {}), true));
886
+
887
+ // Check for marker duplication
888
+ // this is useful when for example: a user clicks a button for creating marker two times
889
+ // so it will remove the old one and the new one will take its place.
890
+ if (_this._markers[index]) {
891
+ _this.removeMarkers([index]);
892
+ }
893
+ _this._markers[index] = {
894
+ _uid: uid,
895
+ config: config,
896
+ element: marker
897
+ };
898
+ },
899
+ _ret;
900
+ for (var index in markers) {
901
+ _ret = _loop();
902
+ if (_ret === 0) continue;
903
+ }
904
+ }
905
+
906
+ var Legend = /*#__PURE__*/function () {
907
+ function Legend(options) {
908
+ if (options === void 0) {
909
+ options = {};
910
+ }
911
+ this._options = options;
912
+ this._map = this._options.map;
913
+ this._series = this._options.series;
914
+ this._body = createElement('div', 'jvm-legend');
915
+ if (this._options.cssClass) {
916
+ this._body.setAttribute('class', this._options.cssClass);
917
+ }
918
+ if (options.vertical) {
919
+ this._map.legendVertical.appendChild(this._body);
920
+ } else {
921
+ this._map.legendHorizontal.appendChild(this._body);
922
+ }
923
+ this.render();
924
+ }
925
+ var _proto = Legend.prototype;
926
+ _proto.render = function render() {
927
+ var ticks = this._series.scale.getTicks();
928
+ this._body.innderHTML = '';
929
+ if (this._options.title) {
930
+ var legendTitle = createElement('div', 'jvm-legend-title', this._options.title);
931
+ this._body.appendChild(legendTitle);
932
+ }
933
+ for (var i = 0; i < ticks.length; i++) {
934
+ var tick = createElement('div', 'jvm-legend-tick');
935
+ var sample = createElement('div', 'jvm-legend-tick-sample');
936
+ switch (this._series.config.attribute) {
937
+ case 'fill':
938
+ if (isImageUrl(ticks[i].value)) {
939
+ sample.style.background = "url(" + ticks[i].value + ")";
940
+ } else {
941
+ sample.style.background = ticks[i].value;
942
+ }
943
+ break;
944
+ case 'stroke':
945
+ sample.style.background = ticks[i].value;
946
+ break;
947
+ case 'image':
948
+ sample.style.background = "url(" + (typeof ticks[i].value === 'object' ? ticks[i].value.url : ticks[i].value) + ") no-repeat center center";
949
+ sample.style.backgroundSize = 'cover';
950
+ break;
951
+ }
952
+ tick.appendChild(sample);
953
+ var label = ticks[i].label;
954
+ if (this._options.labelRender) {
955
+ label = this._options.labelRender(label);
956
+ }
957
+ var tickText = createElement('div', 'jvm-legend-tick-text', label);
958
+ tick.appendChild(tickText);
959
+ this._body.appendChild(tick);
960
+ }
961
+ };
962
+ return Legend;
963
+ }();
964
+
965
+ var OrdinalScale = /*#__PURE__*/function () {
966
+ function OrdinalScale(scale) {
967
+ this._scale = scale;
968
+ }
969
+ var _proto = OrdinalScale.prototype;
970
+ _proto.getValue = function getValue(value) {
971
+ return this._scale[value];
972
+ };
973
+ _proto.getTicks = function getTicks() {
974
+ var ticks = [];
975
+ for (var key in this._scale) {
976
+ ticks.push({
977
+ label: key,
978
+ value: this._scale[key]
979
+ });
980
+ }
981
+ return ticks;
982
+ };
983
+ return OrdinalScale;
984
+ }();
985
+
986
+ var Series = /*#__PURE__*/function () {
987
+ function Series(config, elements, map) {
988
+ if (config === void 0) {
989
+ config = {};
990
+ }
991
+ // Private
992
+ this._map = map;
993
+ this._elements = elements; // Could be markers or regions
994
+ this._values = config.values || {};
995
+
996
+ // Protected
997
+ this.config = config;
998
+ this.config.attribute = config.attribute || 'fill';
999
+
1000
+ // Set initial attributes
1001
+ if (config.attributes) {
1002
+ this.setAttributes(config.attributes);
1003
+ }
1004
+ if (typeof config.scale === 'object') {
1005
+ this.scale = new OrdinalScale(config.scale);
1006
+ }
1007
+ if (this.config.legend) {
1008
+ this.legend = new Legend(merge({
1009
+ map: this._map,
1010
+ series: this
1011
+ }, this.config.legend));
1012
+ }
1013
+ this.setValues(this._values);
1014
+ }
1015
+ var _proto = Series.prototype;
1016
+ _proto.setValues = function setValues(values) {
1017
+ var attrs = {};
1018
+ for (var key in values) {
1019
+ if (values[key]) {
1020
+ attrs[key] = this.scale.getValue(values[key]);
1021
+ }
1022
+ }
1023
+ this.setAttributes(attrs);
1024
+ };
1025
+ _proto.setAttributes = function setAttributes(attrs) {
1026
+ for (var code in attrs) {
1027
+ if (this._elements[code]) {
1028
+ this._elements[code].element.setStyle(this.config.attribute, attrs[code]);
1029
+ }
1030
+ }
1031
+ };
1032
+ _proto.clear = function clear() {
1033
+ var key,
1034
+ attrs = {};
1035
+ for (key in this._values) {
1036
+ if (this._elements[key]) {
1037
+ attrs[key] = this._elements[key].element.shape.style.initial[this.config.attribute];
1038
+ }
1039
+ }
1040
+ this.setAttributes(attrs);
1041
+ this._values = {};
1042
+ };
1043
+ return Series;
1044
+ }();
1045
+
1046
+ function createSeries() {
1047
+ this.series = {
1048
+ markers: [],
1049
+ regions: []
1050
+ };
1051
+ for (var key in this.params.series) {
1052
+ for (var i = 0; i < this.params.series[key].length; i++) {
1053
+ this.series[key][i] = new Series(this.params.series[key][i], key === 'markers' ? this._markers : this.regions, this);
1054
+ }
1055
+ }
1056
+ }
1057
+
1058
+ function applyTransform() {
1059
+ var maxTransX, maxTransY, minTransX, minTransY;
1060
+ if (this._defaultWidth * this.scale <= this._width) {
1061
+ maxTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
1062
+ minTransX = (this._width - this._defaultWidth * this.scale) / (2 * this.scale);
1063
+ } else {
1064
+ maxTransX = 0;
1065
+ minTransX = (this._width - this._defaultWidth * this.scale) / this.scale;
1066
+ }
1067
+ if (this._defaultHeight * this.scale <= this._height) {
1068
+ maxTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
1069
+ minTransY = (this._height - this._defaultHeight * this.scale) / (2 * this.scale);
1070
+ } else {
1071
+ maxTransY = 0;
1072
+ minTransY = (this._height - this._defaultHeight * this.scale) / this.scale;
1073
+ }
1074
+ if (this.transY > maxTransY) {
1075
+ this.transY = maxTransY;
1076
+ } else if (this.transY < minTransY) {
1077
+ this.transY = minTransY;
1078
+ }
1079
+ if (this.transX > maxTransX) {
1080
+ this.transX = maxTransX;
1081
+ } else if (this.transX < minTransX) {
1082
+ this.transX = minTransX;
1083
+ }
1084
+ this.canvas.applyTransformParams(this.scale, this.transX, this.transY);
1085
+ if (this._markers) {
1086
+ this._repositionMarkers();
1087
+ }
1088
+ if (this._lines) {
1089
+ this._repositionLines();
1090
+ }
1091
+ this._repositionLabels();
1092
+ }
1093
+
1094
+ function resize() {
1095
+ var curBaseScale = this._baseScale;
1096
+ if (this._width / this._height > this._defaultWidth / this._defaultHeight) {
1097
+ this._baseScale = this._height / this._defaultHeight;
1098
+ this._baseTransX = Math.abs(this._width - this._defaultWidth * this._baseScale) / (2 * this._baseScale);
1099
+ } else {
1100
+ this._baseScale = this._width / this._defaultWidth;
1101
+ this._baseTransY = Math.abs(this._height - this._defaultHeight * this._baseScale) / (2 * this._baseScale);
1102
+ }
1103
+ this.scale *= this._baseScale / curBaseScale;
1104
+ this.transX *= this._baseScale / curBaseScale;
1105
+ this.transY *= this._baseScale / curBaseScale;
1106
+ }
1107
+
1108
+ function setScale(scale, anchorX, anchorY, isCentered, animate) {
1109
+ var _this = this;
1110
+ var zoomStep,
1111
+ interval,
1112
+ i = 0,
1113
+ count = Math.abs(Math.round((scale - this.scale) * 60 / Math.max(scale, this.scale))),
1114
+ scaleStart,
1115
+ scaleDiff,
1116
+ transXStart,
1117
+ transXDiff,
1118
+ transYStart,
1119
+ transYDiff,
1120
+ transX,
1121
+ transY;
1122
+ if (scale > this.params.zoomMax * this._baseScale) {
1123
+ scale = this.params.zoomMax * this._baseScale;
1124
+ } else if (scale < this.params.zoomMin * this._baseScale) {
1125
+ scale = this.params.zoomMin * this._baseScale;
1126
+ }
1127
+ if (typeof anchorX != 'undefined' && typeof anchorY != 'undefined') {
1128
+ zoomStep = scale / this.scale;
1129
+ if (isCentered) {
1130
+ transX = anchorX + this._defaultWidth * (this._width / (this._defaultWidth * scale)) / 2;
1131
+ transY = anchorY + this._defaultHeight * (this._height / (this._defaultHeight * scale)) / 2;
1132
+ } else {
1133
+ transX = this.transX - (zoomStep - 1) / scale * anchorX;
1134
+ transY = this.transY - (zoomStep - 1) / scale * anchorY;
1135
+ }
1136
+ }
1137
+ if (animate && count > 0) {
1138
+ scaleStart = this.scale;
1139
+ scaleDiff = (scale - scaleStart) / count;
1140
+ transXStart = this.transX * this.scale;
1141
+ transYStart = this.transY * this.scale;
1142
+ transXDiff = (transX * scale - transXStart) / count;
1143
+ transYDiff = (transY * scale - transYStart) / count;
1144
+ interval = setInterval(function () {
1145
+ i += 1;
1146
+ _this.scale = scaleStart + scaleDiff * i;
1147
+ _this.transX = (transXStart + transXDiff * i) / _this.scale;
1148
+ _this.transY = (transYStart + transYDiff * i) / _this.scale;
1149
+ _this._applyTransform();
1150
+ if (i == count) {
1151
+ clearInterval(interval);
1152
+ _this._emit(Events.onViewportChange, [_this.scale, _this.transX, _this.transY]);
1153
+ }
1154
+ }, 10);
1155
+ } else {
1156
+ this.transX = transX;
1157
+ this.transY = transY;
1158
+ this.scale = scale;
1159
+ this._applyTransform();
1160
+ this._emit(Events.onViewportChange, [this.scale, this.transX, this.transY]);
1161
+ }
1162
+ }
1163
+
1164
+ function setFocus(config) {
1165
+ var _this = this;
1166
+ if (config === void 0) {
1167
+ config = {};
1168
+ }
1169
+ var bbox,
1170
+ codes = [];
1171
+ if (config.region) {
1172
+ codes.push(config.region);
1173
+ } else if (config.regions) {
1174
+ codes = config.regions;
1175
+ }
1176
+ if (codes.length) {
1177
+ codes.forEach(function (code) {
1178
+ if (_this.regions[code]) {
1179
+ var itemBbox = _this.regions[code].element.shape.getBBox();
1180
+ if (itemBbox) {
1181
+ // Handle the first loop
1182
+ if (typeof bbox == 'undefined') {
1183
+ bbox = itemBbox;
1184
+ } else {
1185
+ // get the old bbox properties plus the current
1186
+ // this kinda incrementing the old values and the new values
1187
+ bbox = {
1188
+ x: Math.min(bbox.x, itemBbox.x),
1189
+ y: Math.min(bbox.y, itemBbox.y),
1190
+ width: Math.max(bbox.x + bbox.width, itemBbox.x + itemBbox.width) - Math.min(bbox.x, itemBbox.x),
1191
+ height: Math.max(bbox.y + bbox.height, itemBbox.y + itemBbox.height) - Math.min(bbox.y, itemBbox.y)
1192
+ };
1193
+ }
1194
+ }
1195
+ }
1196
+ });
1197
+ return this._setScale(Math.min(this._width / bbox.width, this._height / bbox.height), -(bbox.x + bbox.width / 2), -(bbox.y + bbox.height / 2), true, config.animate);
1198
+ } else if (config.coords) {
1199
+ var point = this.coordsToPoint(config.coords[0], config.coords[1]);
1200
+ var x = this.transX - point.x / this.scale;
1201
+ var y = this.transY - point.y / this.scale;
1202
+ return this._setScale(config.scale * this._baseScale, x, y, true, config.animate);
1203
+ }
1204
+ }
1205
+
1206
+ function updateSize() {
1207
+ this._width = this.container.offsetWidth;
1208
+ this._height = this.container.offsetHeight;
1209
+ this._resize();
1210
+ this.canvas.setSize(this._width, this._height);
1211
+ this._applyTransform();
1212
+ }
1213
+
1214
+ /**
1215
+ * ------------------------------------------------------------------------
1216
+ * Object
1217
+ * ------------------------------------------------------------------------
1218
+ */
1219
+ var Proj = {
1220
+ /* sgn(n){
1221
+ if (n > 0) {
1222
+ return 1;
1223
+ } else if (n < 0) {
1224
+ return -1;
1225
+ } else {
1226
+ return n;
1227
+ }
1228
+ }, */
1229
+ mill: function mill(lat, lng, c) {
1230
+ return {
1231
+ x: this.radius * (lng - c) * this.radDeg,
1232
+ y: -this.radius * Math.log(Math.tan((45 + 0.4 * lat) * this.radDeg)) / 0.8
1233
+ };
1234
+ },
1235
+ /* mill_inv(x, y, c) {
1236
+ return {
1237
+ lat: (2.5 * Math.atan(Math.exp(0.8 * y / this.radius)) - 5 * Math.PI / 8) * this.degRad,
1238
+ lng: (c * this.radDeg + x / this.radius) * this.degRad
1239
+ };
1240
+ }, */
1241
+ merc: function merc(lat, lng, c) {
1242
+ return {
1243
+ x: this.radius * (lng - c) * this.radDeg,
1244
+ y: -this.radius * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))
1245
+ };
1246
+ },
1247
+ /* merc_inv(x, y, c) {
1248
+ return {
1249
+ lat: (2 * Math.atan(Math.exp(y / this.radius)) - Math.PI / 2) * this.degRad,
1250
+ lng: (c * this.radDeg + x / this.radius) * this.degRad
1251
+ };
1252
+ }, */
1253
+ aea: function aea(lat, lng, c) {
1254
+ var fi0 = 0,
1255
+ lambda0 = c * this.radDeg,
1256
+ fi1 = 29.5 * this.radDeg,
1257
+ fi2 = 45.5 * this.radDeg,
1258
+ fi = lat * this.radDeg,
1259
+ lambda = lng * this.radDeg,
1260
+ n = (Math.sin(fi1) + Math.sin(fi2)) / 2,
1261
+ C = Math.cos(fi1) * Math.cos(fi1) + 2 * n * Math.sin(fi1),
1262
+ theta = n * (lambda - lambda0),
1263
+ ro = Math.sqrt(C - 2 * n * Math.sin(fi)) / n,
1264
+ ro0 = Math.sqrt(C - 2 * n * Math.sin(fi0)) / n;
1265
+ return {
1266
+ x: ro * Math.sin(theta) * this.radius,
1267
+ y: -(ro0 - ro * Math.cos(theta)) * this.radius
1268
+ };
1269
+ },
1270
+ /* aea_inv(xCoord, yCoord, c) {
1271
+ var x = xCoord / this.radius,
1272
+ y = yCoord / this.radius,
1273
+ fi0 = 0,
1274
+ lambda0 = c * this.radDeg,
1275
+ fi1 = 29.5 * this.radDeg,
1276
+ fi2 = 45.5 * this.radDeg,
1277
+ n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
1278
+ C = Math.cos(fi1)*Math.cos(fi1)+2*n*Math.sin(fi1),
1279
+ ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n,
1280
+ ro = Math.sqrt(x*x+(ro0-y)*(ro0-y)),
1281
+ theta = Math.atan( x / (ro0 - y) );
1282
+ return {
1283
+ lat: (Math.asin((C - ro * ro * n * n) / (2 * n))) * this.degRad,
1284
+ lng: (lambda0 + theta / n) * this.degRad
1285
+ };
1286
+ }, */
1287
+ lcc: function lcc(lat, lng, c) {
1288
+ var fi0 = 0,
1289
+ lambda0 = c * this.radDeg,
1290
+ lambda = lng * this.radDeg,
1291
+ fi1 = 33 * this.radDeg,
1292
+ fi2 = 45 * this.radDeg,
1293
+ fi = lat * this.radDeg,
1294
+ n = Math.log(Math.cos(fi1) * (1 / Math.cos(fi2))) / Math.log(Math.tan(Math.PI / 4 + fi2 / 2) * (1 / Math.tan(Math.PI / 4 + fi1 / 2))),
1295
+ F = Math.cos(fi1) * Math.pow(Math.tan(Math.PI / 4 + fi1 / 2), n) / n,
1296
+ ro = F * Math.pow(1 / Math.tan(Math.PI / 4 + fi / 2), n),
1297
+ ro0 = F * Math.pow(1 / Math.tan(Math.PI / 4 + fi0 / 2), n);
1298
+ return {
1299
+ x: ro * Math.sin(n * (lambda - lambda0)) * this.radius,
1300
+ y: -(ro0 - ro * Math.cos(n * (lambda - lambda0))) * this.radius
1301
+ };
1302
+ }
1303
+ /* lcc_inv(xCoord, yCoord, c) {
1304
+ var x = xCoord / this.radius,
1305
+ y = yCoord / this.radius,
1306
+ fi0 = 0,
1307
+ lambda0 = c * this.radDeg,
1308
+ fi1 = 33 * this.radDeg,
1309
+ fi2 = 45 * this.radDeg,
1310
+ n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
1311
+ F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
1312
+ ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n ),
1313
+ ro = this.sgn(n) * Math.sqrt(x*x+(ro0-y)*(ro0-y)),
1314
+ theta = Math.atan( x / (ro0 - y) );
1315
+ return {
1316
+ lat: (2 * Math.atan(Math.pow(F/ro, 1/n)) - Math.PI / 2) * this.degRad,
1317
+ lng: (lambda0 + theta / n) * this.degRad
1318
+ };
1319
+ } */
1320
+ };
1321
+ Proj.degRad = 180 / Math.PI;
1322
+ Proj.radDeg = Math.PI / 180;
1323
+ Proj.radius = 6381372;
1324
+
1325
+ function coordsToPoint(lat, lng) {
1326
+ var projection = Map.maps[this.params.map].projection;
1327
+ var _Proj$projection$type = Proj[projection.type](lat, lng, projection.centralMeridian),
1328
+ x = _Proj$projection$type.x,
1329
+ y = _Proj$projection$type.y;
1330
+ var inset = this.getInsetForPoint(x, y);
1331
+ if (!inset) {
1332
+ return false;
1333
+ }
1334
+ var bbox = inset.bbox;
1335
+ x = (x - bbox[0].x) / (bbox[1].x - bbox[0].x) * inset.width * this.scale;
1336
+ y = (y - bbox[0].y) / (bbox[1].y - bbox[0].y) * inset.height * this.scale;
1337
+ return {
1338
+ x: x + this.transX * this.scale + inset.left * this.scale,
1339
+ y: y + this.transY * this.scale + inset.top * this.scale
1340
+ };
1341
+ }
1342
+
1343
+ function getInsetForPoint(x, y) {
1344
+ var insets = Map.maps[this.params.map].insets;
1345
+ for (var index = 0; index < insets.length; index++) {
1346
+ var _insets$index$bbox = insets[index].bbox,
1347
+ start = _insets$index$bbox[0],
1348
+ end = _insets$index$bbox[1];
1349
+ if (x > start.x && x < end.x && y > start.y && y < end.y) {
1350
+ return insets[index];
1351
+ }
1352
+ }
1353
+ }
1354
+
1355
+ function getMarkerPosition(_ref) {
1356
+ var coords = _ref.coords;
1357
+ if (Map.maps[this.params.map].projection) {
1358
+ return this.coordsToPoint.apply(this, coords);
1359
+ }
1360
+ return {
1361
+ x: coords[0] * this.scale + this.transX * this.scale,
1362
+ y: coords[1] * this.scale + this.transY * this.scale
1363
+ };
1364
+ }
1365
+
1366
+ function repositionLines() {
1367
+ var _this = this;
1368
+ var curvature = this.params.lineStyle.curvature;
1369
+ Object.values(this._lines).forEach(function (line) {
1370
+ var startMarker = Object.values(_this._markers).find(function (_ref) {
1371
+ var config = _ref.config;
1372
+ return config.name === line.getConfig().from;
1373
+ });
1374
+ var endMarker = Object.values(_this._markers).find(function (_ref2) {
1375
+ var config = _ref2.config;
1376
+ return config.name === line.getConfig().to;
1377
+ });
1378
+ if (startMarker && endMarker) {
1379
+ var _this$getMarkerPositi = _this.getMarkerPosition(startMarker.config),
1380
+ x1 = _this$getMarkerPositi.x,
1381
+ y1 = _this$getMarkerPositi.y;
1382
+ var _this$getMarkerPositi2 = _this.getMarkerPosition(endMarker.config),
1383
+ x2 = _this$getMarkerPositi2.x,
1384
+ y2 = _this$getMarkerPositi2.y;
1385
+ var curvatureOption = line._options.curvature == 0 ? 0 : line._options.curvature || curvature;
1386
+ var midX = (x1 + x2) / 2;
1387
+ var midY = (y1 + y2) / 2;
1388
+ var curveX = midX + curvatureOption * (y2 - y1);
1389
+ var curveY = midY - curvatureOption * (x2 - x1);
1390
+ line.setStyle({
1391
+ d: "M" + x1 + "," + y1 + " Q" + curveX + "," + curveY + " " + x2 + "," + y2
1392
+ });
1393
+ }
1394
+ });
1395
+ }
1396
+
1397
+ function repositionMarkers() {
1398
+ for (var index in this._markers) {
1399
+ var point = this.getMarkerPosition(this._markers[index].config);
1400
+ if (point !== false) {
1401
+ this._markers[index].element.setStyle({
1402
+ cx: point.x,
1403
+ cy: point.y
1404
+ });
1405
+ }
1406
+ }
1407
+ }
1408
+
1409
+ function repositionLabels() {
1410
+ var labels = this.params.labels;
1411
+ if (!labels) {
1412
+ return;
1413
+ }
1414
+
1415
+ // Regions labels
1416
+ if (labels.regions) {
1417
+ for (var key in this.regions) {
1418
+ this.regions[key].element.updateLabelPosition();
1419
+ }
1420
+ }
1421
+
1422
+ // Markers labels
1423
+ if (labels.markers) {
1424
+ for (var _key in this._markers) {
1425
+ this._markers[_key].element.updateLabelPosition();
1426
+ }
1427
+ }
1428
+ }
1429
+
1430
+ var core = {
1431
+ _setupContainerEvents: setupContainerEvents,
1432
+ _setupElementEvents: setupElementEvents,
1433
+ _setupZoomButtons: setupZoomButtons,
1434
+ _setupContainerTouchEvents: setupContainerTouchEvents,
1435
+ _createRegions: createRegions,
1436
+ _createLines: createLines,
1437
+ _createMarkers: createMarkers,
1438
+ _createSeries: createSeries,
1439
+ _applyTransform: applyTransform,
1440
+ _resize: resize,
1441
+ _setScale: setScale,
1442
+ setFocus: setFocus,
1443
+ updateSize: updateSize,
1444
+ coordsToPoint: coordsToPoint,
1445
+ getInsetForPoint: getInsetForPoint,
1446
+ getMarkerPosition: getMarkerPosition,
1447
+ _repositionLines: repositionLines,
1448
+ _repositionMarkers: repositionMarkers,
1449
+ _repositionLabels: repositionLabels
1450
+ };
1451
+
1452
+ var Defaults = {
1453
+ map: 'world',
1454
+ backgroundColor: 'transparent',
1455
+ draggable: true,
1456
+ zoomButtons: true,
1457
+ zoomOnScroll: true,
1458
+ zoomOnScrollSpeed: 3,
1459
+ zoomMax: 12,
1460
+ zoomMin: 1,
1461
+ zoomAnimate: true,
1462
+ showTooltip: true,
1463
+ zoomStep: 1.5,
1464
+ bindTouchEvents: true,
1465
+ // Line options
1466
+ lineStyle: {
1467
+ curvature: 0,
1468
+ stroke: '#808080',
1469
+ strokeWidth: 1,
1470
+ strokeLinecap: 'round'
1471
+ },
1472
+ // Marker options
1473
+ markersSelectable: false,
1474
+ markersSelectableOne: false,
1475
+ markerStyle: {
1476
+ initial: {
1477
+ r: 7,
1478
+ fill: '#374151',
1479
+ fillOpacity: 1,
1480
+ stroke: '#FFF',
1481
+ strokeWidth: 5,
1482
+ strokeOpacity: .5
1483
+ },
1484
+ hover: {
1485
+ fill: '#3cc0ff',
1486
+ cursor: 'pointer'
1487
+ },
1488
+ selected: {
1489
+ fill: 'blue'
1490
+ },
1491
+ selectedHover: {}
1492
+ },
1493
+ markerLabelStyle: {
1494
+ initial: {
1495
+ fontFamily: 'Verdana',
1496
+ fontSize: 12,
1497
+ fontWeight: 500,
1498
+ cursor: 'default',
1499
+ fill: '#374151'
1500
+ },
1501
+ hover: {
1502
+ cursor: 'pointer'
1503
+ },
1504
+ selected: {},
1505
+ selectedHover: {}
1506
+ },
1507
+ // Region options
1508
+ regionsSelectable: false,
1509
+ regionsSelectableOne: false,
1510
+ regionStyle: {
1511
+ initial: {
1512
+ fill: '#dee2e8',
1513
+ fillOpacity: 1,
1514
+ stroke: 'none',
1515
+ strokeWidth: 0
1516
+ },
1517
+ hover: {
1518
+ fillOpacity: .7,
1519
+ cursor: 'pointer'
1520
+ },
1521
+ selected: {
1522
+ fill: '#9ca3af'
1523
+ },
1524
+ selectedHover: {}
1525
+ },
1526
+ regionLabelStyle: {
1527
+ initial: {
1528
+ fontFamily: 'Verdana',
1529
+ fontSize: '12',
1530
+ fontWeight: 'bold',
1531
+ cursor: 'default',
1532
+ fill: '#35373e'
1533
+ },
1534
+ hover: {
1535
+ cursor: 'pointer'
1536
+ }
1537
+ }
1538
+ };
1539
+
1540
+ var SVGElement = /*#__PURE__*/function () {
1541
+ function SVGElement(name, config) {
1542
+ this.node = this._createElement(name);
1543
+ if (config) {
1544
+ this.set(config);
1545
+ }
1546
+ }
1547
+
1548
+ // Create new SVG element `svg`, `g`, `path`, `line`, `circle`, `image`, etc.
1549
+ // https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS#important_namespace_uris
1550
+ var _proto = SVGElement.prototype;
1551
+ _proto._createElement = function _createElement(tagName) {
1552
+ return document.createElementNS('http://www.w3.org/2000/svg', tagName);
1553
+ };
1554
+ _proto.addClass = function addClass(className) {
1555
+ this.node.setAttribute('class', className);
1556
+ };
1557
+ _proto.getBBox = function getBBox() {
1558
+ return this.node.getBBox();
1559
+ }
1560
+
1561
+ // Apply attributes on the current node element
1562
+ ;
1563
+ _proto.set = function set(property, value) {
1564
+ if (typeof property === 'object') {
1565
+ for (var attr in property) {
1566
+ this.applyAttr(attr, property[attr]);
1567
+ }
1568
+ } else {
1569
+ this.applyAttr(property, value);
1570
+ }
1571
+ };
1572
+ _proto.get = function get(property) {
1573
+ return this.style.initial[property];
1574
+ };
1575
+ _proto.applyAttr = function applyAttr(property, value) {
1576
+ this.node.setAttribute(hyphenate(property), value);
1577
+ };
1578
+ _proto.remove = function remove() {
1579
+ removeElement(this.node);
1580
+ };
1581
+ return SVGElement;
1582
+ }();
1583
+
1584
+ var SVGShapeElement = /*#__PURE__*/function (_SVGElement) {
1585
+ function SVGShapeElement(name, config, style) {
1586
+ var _this;
1587
+ if (style === void 0) {
1588
+ style = {};
1589
+ }
1590
+ _this = _SVGElement.call(this, name, config) || this;
1591
+ _this.isHovered = false;
1592
+ _this.isSelected = false;
1593
+ _this.style = style;
1594
+ _this.style.current = {};
1595
+ _this.updateStyle();
1596
+ return _this;
1597
+ }
1598
+ _inheritsLoose(SVGShapeElement, _SVGElement);
1599
+ var _proto = SVGShapeElement.prototype;
1600
+ _proto.setStyle = function setStyle(property, value) {
1601
+ if (typeof property === 'object') {
1602
+ merge(this.style.current, property);
1603
+ } else {
1604
+ var _merge;
1605
+ merge(this.style.current, (_merge = {}, _merge[property] = value, _merge));
1606
+ }
1607
+ this.updateStyle();
1608
+ };
1609
+ _proto.updateStyle = function updateStyle() {
1610
+ var attrs = {};
1611
+ merge(attrs, this.style.initial);
1612
+ merge(attrs, this.style.current);
1613
+ if (this.isHovered) {
1614
+ merge(attrs, this.style.hover);
1615
+ }
1616
+ if (this.isSelected) {
1617
+ merge(attrs, this.style.selected);
1618
+ if (this.isHovered) {
1619
+ merge(attrs, this.style.selectedHover);
1620
+ }
1621
+ }
1622
+ this.set(attrs);
1623
+ };
1624
+ return SVGShapeElement;
1625
+ }(SVGElement);
1626
+
1627
+ var SVGTextElement = /*#__PURE__*/function (_SVGShapeElement) {
1628
+ function SVGTextElement(config, style) {
1629
+ return _SVGShapeElement.call(this, 'text', config, style) || this;
1630
+ }
1631
+ _inheritsLoose(SVGTextElement, _SVGShapeElement);
1632
+ var _proto = SVGTextElement.prototype;
1633
+ _proto.applyAttr = function applyAttr(attr, value) {
1634
+ attr === 'text' ? this.node.textContent = value : _SVGShapeElement.prototype.applyAttr.call(this, attr, value);
1635
+ };
1636
+ return SVGTextElement;
1637
+ }(SVGShapeElement);
1638
+
1639
+ var SVGImageElement = /*#__PURE__*/function (_SVGShapeElement) {
1640
+ function SVGImageElement(config, style) {
1641
+ return _SVGShapeElement.call(this, 'image', config, style) || this;
1642
+ }
1643
+ _inheritsLoose(SVGImageElement, _SVGShapeElement);
1644
+ var _proto = SVGImageElement.prototype;
1645
+ _proto.applyAttr = function applyAttr(attr, value) {
1646
+ var imageUrl;
1647
+ if (attr === 'image') {
1648
+ // This get executed when we have url in series.markers[0].scale.someScale.url
1649
+ if (typeof value === 'object') {
1650
+ imageUrl = value.url;
1651
+ this.offset = value.offset || [0, 0];
1652
+ } else {
1653
+ imageUrl = value;
1654
+ this.offset = [0, 0];
1655
+ }
1656
+ this.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageUrl);
1657
+
1658
+ // Set width and height then call this `applyAttr` again
1659
+ this.width = 23;
1660
+ this.height = 23;
1661
+ this.applyAttr('width', this.width);
1662
+ this.applyAttr('height', this.height);
1663
+ this.applyAttr('x', this.cx - this.width / 2 + this.offset[0]);
1664
+ this.applyAttr('y', this.cy - this.height / 2 + this.offset[1]);
1665
+ } else if (attr == 'cx') {
1666
+ this.cx = value;
1667
+ if (this.width) {
1668
+ this.applyAttr('x', value - this.width / 2 + this.offset[0]);
1669
+ }
1670
+ } else if (attr == 'cy') {
1671
+ this.cy = value;
1672
+ if (this.height) {
1673
+ this.applyAttr('y', value - this.height / 2 + this.offset[1]);
1674
+ }
1675
+ } else {
1676
+ // This time Call SVGElement
1677
+ _SVGShapeElement.prototype.applyAttr.apply(this, arguments);
1678
+ }
1679
+ };
1680
+ return SVGImageElement;
1681
+ }(SVGShapeElement);
1682
+
1683
+ var SVGCanvasElement = /*#__PURE__*/function (_SVGElement) {
1684
+ function SVGCanvasElement(container) {
1685
+ var _this;
1686
+ _this = _SVGElement.call(this, 'svg') || this; // Create svg element for holding the whole map
1687
+
1688
+ _this._container = container;
1689
+
1690
+ // Create the defs element
1691
+ _this._defsElement = new SVGElement('defs');
1692
+
1693
+ // Create group element which will hold the paths (regions)
1694
+ _this._rootElement = new SVGElement('g', {
1695
+ id: 'jvm-regions-group'
1696
+ });
1697
+
1698
+ // Append the defs element to the this.node (SVG tag)
1699
+ _this.node.appendChild(_this._defsElement.node);
1700
+
1701
+ // Append the group to this.node (SVG tag)
1702
+ _this.node.appendChild(_this._rootElement.node);
1703
+
1704
+ // Append this.node (SVG tag) to the container
1705
+ _this._container.appendChild(_this.node);
1706
+ return _this;
1707
+ }
1708
+ _inheritsLoose(SVGCanvasElement, _SVGElement);
1709
+ var _proto = SVGCanvasElement.prototype;
1710
+ _proto.setSize = function setSize(width, height) {
1711
+ this.node.setAttribute('width', width);
1712
+ this.node.setAttribute('height', height);
1713
+ };
1714
+ _proto.applyTransformParams = function applyTransformParams(scale, transX, transY) {
1715
+ this._rootElement.node.setAttribute('transform', "scale(" + scale + ") translate(" + transX + ", " + transY + ")");
1716
+ }
1717
+
1718
+ // Create `path` element
1719
+ ;
1720
+ _proto.createPath = function createPath(config, style, group) {
1721
+ var path = new SVGShapeElement('path', config, style);
1722
+ path.node.setAttribute('fill-rule', 'evenodd');
1723
+ return this._add(path, group);
1724
+ }
1725
+
1726
+ // Create `circle` element
1727
+ ;
1728
+ _proto.createCircle = function createCircle(config, style, group) {
1729
+ var circle = new SVGShapeElement('circle', config, style);
1730
+ return this._add(circle, group);
1731
+ }
1732
+
1733
+ // Create `line` element
1734
+ ;
1735
+ _proto.createLine = function createLine(config, style, group) {
1736
+ var line = new SVGShapeElement('line', config, style);
1737
+ return this._add(line, group);
1738
+ }
1739
+
1740
+ // Create `text` element
1741
+ ;
1742
+ _proto.createText = function createText(config, style, group) {
1743
+ var text = new SVGTextElement(config, style);
1744
+ return this._add(text, group);
1745
+ }
1746
+
1747
+ // Create `image` element
1748
+ ;
1749
+ _proto.createImage = function createImage(config, style, group) {
1750
+ var image = new SVGImageElement(config, style);
1751
+ return this._add(image, group);
1752
+ }
1753
+
1754
+ // Create `g` element
1755
+ ;
1756
+ _proto.createGroup = function createGroup(id) {
1757
+ var group = new SVGElement('g');
1758
+ this.node.appendChild(group.node);
1759
+ if (id) {
1760
+ group.node.id = id;
1761
+ }
1762
+ group.canvas = this;
1763
+ return group;
1764
+ }
1765
+
1766
+ // Add some element to a spcific group or the root element if the group isn't given
1767
+ ;
1768
+ _proto._add = function _add(element, group) {
1769
+ group = group || this._rootElement;
1770
+ group.node.appendChild(element.node);
1771
+ return element;
1772
+ };
1773
+ return SVGCanvasElement;
1774
+ }(SVGElement);
1775
+
1776
+ var Tooltip = /*#__PURE__*/function (_BaseComponent) {
1777
+ function Tooltip(map) {
1778
+ var _this;
1779
+ _this = _BaseComponent.call(this) || this;
1780
+ var tooltip = createElement('div', 'jvm-tooltip');
1781
+ _this._map = map;
1782
+ _this._tooltip = document.body.appendChild(tooltip);
1783
+ _this._bindEventListeners();
1784
+ return _this || _assertThisInitialized(_this);
1785
+ }
1786
+ _inheritsLoose(Tooltip, _BaseComponent);
1787
+ var _proto = Tooltip.prototype;
1788
+ _proto._bindEventListeners = function _bindEventListeners() {
1789
+ var _this2 = this;
1790
+ EventHandler.on(this._map.container, 'mousemove', function (event) {
1791
+ if (!_this2._tooltip.classList.contains('active')) {
1792
+ return;
1793
+ }
1794
+ var container = findElement(_this2._map.container, '#jvm-regions-group').getBoundingClientRect();
1795
+ var space = 5; // Space between the cursor and tooltip element
1796
+
1797
+ // Tooltip
1798
+ var _this2$_tooltip$getBo = _this2._tooltip.getBoundingClientRect(),
1799
+ height = _this2$_tooltip$getBo.height,
1800
+ width = _this2$_tooltip$getBo.width;
1801
+ var topIsPassed = event.clientY <= container.top + height + space;
1802
+ var top = event.pageY - height - space;
1803
+ var left = event.pageX - width - space;
1804
+
1805
+ // Ensure the tooltip will never cross outside the canvas area(map)
1806
+ if (topIsPassed) {
1807
+ // Top:
1808
+ top += height + space;
1809
+
1810
+ // The cursor is a bit larger from left side
1811
+ left -= space * 2;
1812
+ }
1813
+ if (event.clientX < container.left + width + space) {
1814
+ // Left:
1815
+ left = event.pageX + space + 2;
1816
+ if (topIsPassed) {
1817
+ left += space * 2;
1818
+ }
1819
+ }
1820
+ _this2.css({
1821
+ top: top + "px",
1822
+ left: left + "px"
1823
+ });
1824
+ });
1825
+ };
1826
+ _proto.getElement = function getElement() {
1827
+ return this._tooltip;
1828
+ };
1829
+ _proto.show = function show() {
1830
+ this._tooltip.classList.add('active');
1831
+ };
1832
+ _proto.hide = function hide() {
1833
+ this._tooltip.classList.remove('active');
1834
+ };
1835
+ _proto.text = function text(string, html) {
1836
+ if (html === void 0) {
1837
+ html = false;
1838
+ }
1839
+ var property = html ? 'innerHTML' : 'textContent';
1840
+ if (!string) {
1841
+ return this._tooltip[property];
1842
+ }
1843
+ this._tooltip[property] = string;
1844
+ };
1845
+ _proto.css = function css(_css) {
1846
+ for (var style in _css) {
1847
+ this._tooltip.style[style] = _css[style];
1848
+ }
1849
+ return this;
1850
+ };
1851
+ return Tooltip;
1852
+ }(BaseComponent);
1853
+
1854
+ var DataVisualization = /*#__PURE__*/function () {
1855
+ function DataVisualization(_ref, map) {
1856
+ var scale = _ref.scale,
1857
+ values = _ref.values;
1858
+ this._scale = scale;
1859
+ this._values = values;
1860
+ this._fromColor = this.hexToRgb(scale[0]);
1861
+ this._toColor = this.hexToRgb(scale[1]);
1862
+ this._map = map;
1863
+ this.setMinMaxValues(values);
1864
+ this.visualize();
1865
+ }
1866
+ var _proto = DataVisualization.prototype;
1867
+ _proto.setMinMaxValues = function setMinMaxValues(values) {
1868
+ this.min = Number.MAX_VALUE;
1869
+ this.max = 0;
1870
+ for (var value in values) {
1871
+ value = parseFloat(values[value]);
1872
+ if (value > this.max) {
1873
+ this.max = value;
1874
+ }
1875
+ if (value < this.min) {
1876
+ this.min = value;
1877
+ }
1878
+ }
1879
+ };
1880
+ _proto.visualize = function visualize() {
1881
+ var attrs = {},
1882
+ value;
1883
+ for (var regionCode in this._values) {
1884
+ value = parseFloat(this._values[regionCode]);
1885
+ if (!isNaN(value)) {
1886
+ attrs[regionCode] = this.getValue(value);
1887
+ }
1888
+ }
1889
+ this.setAttributes(attrs);
1890
+ };
1891
+ _proto.setAttributes = function setAttributes(attrs) {
1892
+ for (var code in attrs) {
1893
+ if (this._map.regions[code]) {
1894
+ this._map.regions[code].element.setStyle('fill', attrs[code]);
1895
+ }
1896
+ }
1897
+ };
1898
+ _proto.getValue = function getValue(value) {
1899
+ if (this.min === this.max) {
1900
+ return "#" + this._toColor.join('');
1901
+ }
1902
+ var hex,
1903
+ color = '#';
1904
+ for (var i = 0; i < 3; i++) {
1905
+ hex = Math.round(this._fromColor[i] + (this._toColor[i] - this._fromColor[i]) * ((value - this.min) / (this.max - this.min))).toString(16);
1906
+ color += (hex.length === 1 ? '0' : '') + hex;
1907
+ }
1908
+ return color;
1909
+ };
1910
+ _proto.hexToRgb = function hexToRgb(h) {
1911
+ var r = 0,
1912
+ g = 0,
1913
+ b = 0;
1914
+ if (h.length == 4) {
1915
+ r = '0x' + h[1] + h[1];
1916
+ g = '0x' + h[2] + h[2];
1917
+ b = '0x' + h[3] + h[3];
1918
+ } else if (h.length == 7) {
1919
+ r = '0x' + h[1] + h[2];
1920
+ g = '0x' + h[3] + h[4];
1921
+ b = '0x' + h[5] + h[6];
1922
+ }
1923
+ return [parseInt(r), parseInt(g), parseInt(b)];
1924
+ };
1925
+ return DataVisualization;
1926
+ }();
1927
+
1928
+ var JVM_PREFIX = 'jvm-';
1929
+ var CONTAINER_CLASS = JVM_PREFIX + "container";
1930
+ var MARKERS_GROUP_ID = JVM_PREFIX + "markers-group";
1931
+ var MARKERS_LABELS_GROUP_ID = JVM_PREFIX + "markers-labels-group";
1932
+ var LINES_GROUP_ID = JVM_PREFIX + "lines-group";
1933
+ var SERIES_CONTAINER_CLASS = JVM_PREFIX + "series-container";
1934
+ var SERIES_CONTAINER_H_CLASS = SERIES_CONTAINER_CLASS + " " + JVM_PREFIX + "series-h";
1935
+ var SERIES_CONTAINER_V_CLASS = SERIES_CONTAINER_CLASS + " " + JVM_PREFIX + "series-v";
1936
+ var Map = /*#__PURE__*/function () {
1937
+ function Map(options) {
1938
+ var _this = this;
1939
+ if (options === void 0) {
1940
+ options = {};
1941
+ }
1942
+ // Merge the given options with the default options
1943
+ this.params = merge(Map.defaults, options, true);
1944
+
1945
+ // Throw an error if the given map name doesn't match
1946
+ // the map that was set in map file
1947
+ if (!Map.maps[this.params.map]) {
1948
+ throw new Error("Attempt to use map which was not loaded: " + options.map);
1949
+ }
1950
+ this.regions = {};
1951
+ this.scale = 1;
1952
+ this.transX = 0;
1953
+ this.transY = 0;
1954
+ this._mapData = Map.maps[this.params.map];
1955
+ this._markers = {};
1956
+ this._lines = {};
1957
+ this._defaultWidth = this._mapData.width;
1958
+ this._defaultHeight = this._mapData.height;
1959
+ this._height = 0;
1960
+ this._width = 0;
1961
+ this._baseScale = 1;
1962
+ this._baseTransX = 0;
1963
+ this._baseTransY = 0;
1964
+
1965
+ // `document` is already ready, just initialise now
1966
+ if (document.readyState !== 'loading') {
1967
+ this._init();
1968
+ } else {
1969
+ // Wait until `document` is ready
1970
+ window.addEventListener('DOMContentLoaded', function () {
1971
+ return _this._init();
1972
+ });
1973
+ }
1974
+ }
1975
+ var _proto = Map.prototype;
1976
+ _proto._init = function _init() {
1977
+ var options = this.params;
1978
+ this.container = getElement(options.selector);
1979
+ this.container.classList.add(CONTAINER_CLASS);
1980
+
1981
+ // The map canvas element
1982
+ this.canvas = new SVGCanvasElement(this.container);
1983
+
1984
+ // Set the map's background color
1985
+ this.setBackgroundColor(options.backgroundColor);
1986
+
1987
+ // Create regions
1988
+ this._createRegions();
1989
+
1990
+ // Update size
1991
+ this.updateSize();
1992
+
1993
+ // Lines group must be created before markers
1994
+ // Otherwise the lines will be drawn on top of the markers.
1995
+ if (options.lines) {
1996
+ this._linesGroup = this.canvas.createGroup(LINES_GROUP_ID);
1997
+ }
1998
+ if (options.markers) {
1999
+ this._markersGroup = this.canvas.createGroup(MARKERS_GROUP_ID);
2000
+ this._markerLabelsGroup = this.canvas.createGroup(MARKERS_LABELS_GROUP_ID);
2001
+ }
2002
+
2003
+ // Create markers
2004
+ this._createMarkers(options.markers);
2005
+
2006
+ // Create lines
2007
+ this._createLines(options.lines || {});
2008
+
2009
+ // Position labels
2010
+ this._repositionLabels();
2011
+
2012
+ // Setup the container events
2013
+ this._setupContainerEvents();
2014
+
2015
+ // Setup regions/markers events
2016
+ this._setupElementEvents();
2017
+
2018
+ // Create zoom buttons if `zoomButtons` is presented
2019
+ if (options.zoomButtons) {
2020
+ this._setupZoomButtons();
2021
+ }
2022
+
2023
+ // Create toolip
2024
+ if (options.showTooltip) {
2025
+ this._tooltip = new Tooltip(this);
2026
+ }
2027
+
2028
+ // Set selected regions if any
2029
+ if (options.selectedRegions) {
2030
+ this._setSelected('regions', options.selectedRegions);
2031
+ }
2032
+
2033
+ // Set selected regions if any
2034
+ if (options.selectedMarkers) {
2035
+ this._setSelected('_markers', options.selectedMarkers);
2036
+ }
2037
+
2038
+ // Set focus on a spcific region
2039
+ if (options.focusOn) {
2040
+ this.setFocus(options.focusOn);
2041
+ }
2042
+
2043
+ // Data visualization
2044
+ if (options.visualizeData) {
2045
+ this.dataVisualization = new DataVisualization(options.visualizeData, this);
2046
+ }
2047
+
2048
+ // Bind touch events if true
2049
+ if (options.bindTouchEvents) {
2050
+ if ('ontouchstart' in window || window.DocumentTouch && document instanceof DocumentTouch) {
2051
+ this._setupContainerTouchEvents();
2052
+ }
2053
+ }
2054
+
2055
+ // Create series if any
2056
+ if (options.series) {
2057
+ this.container.appendChild(this.legendHorizontal = createElement('div', SERIES_CONTAINER_H_CLASS));
2058
+ this.container.appendChild(this.legendVertical = createElement('div', SERIES_CONTAINER_V_CLASS));
2059
+ this._createSeries();
2060
+ }
2061
+
2062
+ // Fire loaded event
2063
+ this._emit(Events.onLoaded, [this]);
2064
+ }
2065
+
2066
+ // Public
2067
+ ;
2068
+ _proto.setBackgroundColor = function setBackgroundColor(color) {
2069
+ this.container.style.backgroundColor = color;
2070
+ }
2071
+
2072
+ // Regions
2073
+ ;
2074
+ _proto.getSelectedRegions = function getSelectedRegions() {
2075
+ return this._getSelected('regions');
2076
+ };
2077
+ _proto.clearSelectedRegions = function clearSelectedRegions(regions) {
2078
+ var _this2 = this;
2079
+ if (regions === void 0) {
2080
+ regions = undefined;
2081
+ }
2082
+ regions = this._normalizeRegions(regions) || this._getSelected('regions');
2083
+ regions.forEach(function (key) {
2084
+ _this2.regions[key].element.select(false);
2085
+ });
2086
+ };
2087
+ _proto.setSelectedRegions = function setSelectedRegions(regions) {
2088
+ this.clearSelectedRegions();
2089
+ this._setSelected('regions', this._normalizeRegions(regions));
2090
+ }
2091
+
2092
+ // Markers
2093
+ ;
2094
+ _proto.getSelectedMarkers = function getSelectedMarkers() {
2095
+ return this._getSelected('_markers');
2096
+ };
2097
+ _proto.clearSelectedMarkers = function clearSelectedMarkers() {
2098
+ this._clearSelected('_markers');
2099
+ };
2100
+ _proto.setSelectedMarkers = function setSelectedMarkers(markers) {
2101
+ this._setSelected('_markers', markers);
2102
+ };
2103
+ _proto.addMarkers = function addMarkers(config) {
2104
+ config = Array.isArray(config) ? config : [config];
2105
+ this._createMarkers(config, true);
2106
+ };
2107
+ _proto.removeMarkers = function removeMarkers(markers) {
2108
+ var _this3 = this;
2109
+ if (!markers) {
2110
+ markers = Object.keys(this._markers);
2111
+ }
2112
+ markers.forEach(function (index) {
2113
+ // Remove the element from the DOM
2114
+ _this3._markers[index].element.remove();
2115
+ // Remove the element from markers object
2116
+ delete _this3._markers[index];
2117
+ });
2118
+ }
2119
+
2120
+ // Lines
2121
+ ;
2122
+ _proto.addLine = function addLine(from, to, style) {
2123
+ if (style === void 0) {
2124
+ style = {};
2125
+ }
2126
+ console.warn('`addLine` method is deprecated, please use `addLines` instead.');
2127
+ this._createLines([{
2128
+ from: from,
2129
+ to: to,
2130
+ style: style
2131
+ }], this._markers, true);
2132
+ };
2133
+ _proto.addLines = function addLines(config) {
2134
+ var uids = this._getLinesAsUids();
2135
+ if (!Array.isArray(config)) {
2136
+ config = [config];
2137
+ }
2138
+ this._createLines(config.filter(function (line) {
2139
+ return !(uids.indexOf(getLineUid(line.from, line.to)) > -1);
2140
+ }), true);
2141
+ };
2142
+ _proto.removeLines = function removeLines(lines) {
2143
+ var _this4 = this;
2144
+ if (Array.isArray(lines)) {
2145
+ lines = lines.map(function (line) {
2146
+ return getLineUid(line.from, line.to);
2147
+ });
2148
+ } else {
2149
+ lines = this._getLinesAsUids();
2150
+ }
2151
+ lines.forEach(function (uid) {
2152
+ _this4._lines[uid].dispose();
2153
+ delete _this4._lines[uid];
2154
+ });
2155
+ };
2156
+ _proto.removeLine = function removeLine(from, to) {
2157
+ console.warn('`removeLine` method is deprecated, please use `removeLines` instead.');
2158
+ var uid = getLineUid(from, to);
2159
+ if (this._lines.hasOwnProperty(uid)) {
2160
+ this._lines[uid].element.remove();
2161
+ delete this._lines[uid];
2162
+ }
2163
+ }
2164
+
2165
+ // Reset map
2166
+ ;
2167
+ _proto.reset = function reset() {
2168
+ for (var key in this.series) {
2169
+ for (var i = 0; i < this.series[key].length; i++) {
2170
+ this.series[key][i].clear();
2171
+ }
2172
+ }
2173
+ if (this.legendHorizontal) {
2174
+ removeElement(this.legendHorizontal);
2175
+ this.legendHorizontal = null;
2176
+ }
2177
+ if (this.legendVertical) {
2178
+ removeElement(this.legendVertical);
2179
+ this.legendVertical = null;
2180
+ }
2181
+ this.scale = this._baseScale;
2182
+ this.transX = this._baseTransX;
2183
+ this.transY = this._baseTransY;
2184
+ this._applyTransform();
2185
+ this.clearSelectedMarkers();
2186
+ this.clearSelectedRegions();
2187
+ this.removeMarkers();
2188
+ }
2189
+
2190
+ // Destroy the map
2191
+ ;
2192
+ _proto.destroy = function destroy(destroyInstance) {
2193
+ var _this5 = this;
2194
+ if (destroyInstance === void 0) {
2195
+ destroyInstance = true;
2196
+ }
2197
+ // Remove event registry
2198
+ EventHandler.flush();
2199
+
2200
+ // Remove tooltip from DOM and memory
2201
+ this._tooltip.dispose();
2202
+
2203
+ // Fire destroyed event
2204
+ this._emit(Events.onDestroyed);
2205
+
2206
+ // Remove references
2207
+ if (destroyInstance) {
2208
+ Object.keys(this).forEach(function (key) {
2209
+ try {
2210
+ delete _this5[key];
2211
+ } catch (e) {}
2212
+ });
2213
+ }
2214
+ };
2215
+ _proto.extend = function extend(name, callback) {
2216
+ if (typeof this[name] === 'function') {
2217
+ throw new Error("The method [" + name + "] does already exist, please use another name.");
2218
+ }
2219
+ Map.prototype[name] = callback;
2220
+ }
2221
+
2222
+ // Private
2223
+ ;
2224
+ _proto._emit = function _emit(eventName, args) {
2225
+ for (var event in Events) {
2226
+ if (Events[event] === eventName && typeof this.params[event] === 'function') {
2227
+ this.params[event].apply(this, args);
2228
+ }
2229
+ }
2230
+ }
2231
+
2232
+ // Get selected markers/regions
2233
+ ;
2234
+ _proto._getSelected = function _getSelected(type) {
2235
+ var selected = [];
2236
+ for (var key in this[type]) {
2237
+ if (this[type][key].element.isSelected) {
2238
+ selected.push(key);
2239
+ }
2240
+ }
2241
+ return selected;
2242
+ };
2243
+ _proto._setSelected = function _setSelected(type, keys) {
2244
+ var _this6 = this;
2245
+ keys.forEach(function (key) {
2246
+ if (_this6[type][key]) {
2247
+ _this6[type][key].element.select(true);
2248
+ }
2249
+ });
2250
+ };
2251
+ _proto._clearSelected = function _clearSelected(type) {
2252
+ var _this7 = this;
2253
+ this._getSelected(type).forEach(function (key) {
2254
+ _this7[type][key].element.select(false);
2255
+ });
2256
+ };
2257
+ _proto._getLinesAsUids = function _getLinesAsUids() {
2258
+ return Object.keys(this._lines);
2259
+ };
2260
+ _proto._normalizeRegions = function _normalizeRegions(regions) {
2261
+ return typeof regions === 'string' ? [regions] : regions;
2262
+ };
2263
+ return Map;
2264
+ }();
2265
+ Map.maps = {};
2266
+ Map.defaults = Defaults;
2267
+ Object.assign(Map.prototype, core);
2268
+
2269
+ /**
2270
+ * jsVectorMap
2271
+ * Copyrights (c) Mustafa Omar https://github.com/themustafaomar
2272
+ * Released under the MIT License.
2273
+ */
2274
+ var jsVectorMap = /*#__PURE__*/function () {
2275
+ function jsVectorMap(options) {
2276
+ if (options === void 0) {
2277
+ options = {};
2278
+ }
2279
+ if (!options.selector) {
2280
+ throw new Error('Selector is not given.');
2281
+ }
2282
+ return new Map(options);
2283
+ }
2284
+
2285
+ // Public
2286
+ jsVectorMap.addMap = function addMap(name, map) {
2287
+ Map.maps[name] = map;
2288
+ };
2289
+ return jsVectorMap;
2290
+ }();
2291
+ var index = (typeof window !== "undefined" ? window : globalThis).jsVectorMap = jsVectorMap;
2292
+
2293
+ export { index as default };