@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.
- package/LICENSE +21 -0
- package/dist/jsvectormap.cjs +2355 -0
- package/dist/jsvectormap.css +147 -0
- package/dist/jsvectormap.esm.js +2293 -0
- package/dist/jsvectormap.js +2301 -0
- package/dist/jsvectormap.min.css +1 -0
- package/dist/jsvectormap.min.js +1 -0
- package/dist/maps/world-merc.js +1 -0
- package/dist/maps/world.js +1 -0
- package/package.json +49 -0
- package/src/js/components/base.js +18 -0
- package/src/js/components/concerns/interactable.js +68 -0
- package/src/js/components/line.js +50 -0
- package/src/js/components/marker.js +109 -0
- package/src/js/components/region.js +53 -0
- package/src/js/components/route.js +76 -0
- package/src/js/components/tooltip.js +88 -0
- package/src/js/core/applyTransform.js +43 -0
- package/src/js/core/coordsToPoint.js +22 -0
- package/src/js/core/createLines.js +44 -0
- package/src/js/core/createMarkers.js +55 -0
- package/src/js/core/createRegions.js +23 -0
- package/src/js/core/createRoutes.js +16 -0
- package/src/js/core/createSeries.js +13 -0
- package/src/js/core/getInsetForPoint.js +13 -0
- package/src/js/core/getMarkerPosition.js +12 -0
- package/src/js/core/index.js +41 -0
- package/src/js/core/repositionLabels.js +21 -0
- package/src/js/core/repositionLines.js +30 -0
- package/src/js/core/repositionMarkers.js +11 -0
- package/src/js/core/resize.js +15 -0
- package/src/js/core/setFocus.js +46 -0
- package/src/js/core/setScale.js +65 -0
- package/src/js/core/setupContainerEvents.js +50 -0
- package/src/js/core/setupContainerTouchEvents.js +85 -0
- package/src/js/core/setupElementEvents.js +112 -0
- package/src/js/core/setupZoomButtons.js +40 -0
- package/src/js/core/updateSize.js +7 -0
- package/src/js/dataVisualization.js +87 -0
- package/src/js/defaults/events.js +11 -0
- package/src/js/defaults/options.js +90 -0
- package/src/js/eventHandler.js +47 -0
- package/src/js/index.js +25 -0
- package/src/js/legend.js +69 -0
- package/src/js/map.js +367 -0
- package/src/js/projection.js +127 -0
- package/src/js/scales/ordinalScale.js +21 -0
- package/src/js/series.js +68 -0
- package/src/js/svg/baseElement.js +53 -0
- package/src/js/svg/canvasElement.js +99 -0
- package/src/js/svg/imageElement.js +49 -0
- package/src/js/svg/shapeElement.js +48 -0
- package/src/js/svg/textElement.js +13 -0
- package/src/js/util/deepMerge.js +129 -0
- package/src/js/util/index.js +81 -0
- package/src/scss/_variables.scss +37 -0
- package/src/scss/jsvectormap.scss +153 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
class DataVisualization {
|
|
2
|
+
constructor({ scale, values }, map) {
|
|
3
|
+
this._scale = scale
|
|
4
|
+
this._values = values
|
|
5
|
+
this._fromColor = this.hexToRgb(scale[0])
|
|
6
|
+
this._toColor = this.hexToRgb(scale[1])
|
|
7
|
+
this._map = map
|
|
8
|
+
|
|
9
|
+
this.setMinMaxValues(values)
|
|
10
|
+
this.visualize()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setMinMaxValues(values) {
|
|
14
|
+
this.min = Number.MAX_VALUE
|
|
15
|
+
this.max = 0
|
|
16
|
+
|
|
17
|
+
for (let value in values) {
|
|
18
|
+
value = parseFloat(values[value])
|
|
19
|
+
|
|
20
|
+
if (value > this.max) {
|
|
21
|
+
this.max = value
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (value < this.min) {
|
|
25
|
+
this.min = value
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
visualize() {
|
|
31
|
+
let attrs = {}, value
|
|
32
|
+
|
|
33
|
+
for (let regionCode in this._values) {
|
|
34
|
+
value = parseFloat(this._values[regionCode])
|
|
35
|
+
|
|
36
|
+
if (!isNaN(value)) {
|
|
37
|
+
attrs[regionCode] = this.getValue(value)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.setAttributes(attrs)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
setAttributes(attrs) {
|
|
45
|
+
for (let code in attrs) {
|
|
46
|
+
if (this._map.regions[code]) {
|
|
47
|
+
this._map.regions[code].element.setStyle('fill', attrs[code])
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getValue(value) {
|
|
53
|
+
if (this.min === this.max) {
|
|
54
|
+
return `#${this._toColor.join('')}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let hex, color = '#'
|
|
58
|
+
|
|
59
|
+
for (var i = 0; i < 3; i++) {
|
|
60
|
+
hex = Math.round(
|
|
61
|
+
this._fromColor[i] + (this._toColor[i] - this._fromColor[i]) * ((value - this.min) / (this.max - this.min))
|
|
62
|
+
).toString(16)
|
|
63
|
+
|
|
64
|
+
color += (hex.length === 1 ? '0' : '') + hex
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return color
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
hexToRgb(h) {
|
|
71
|
+
let r = 0, g = 0, b = 0
|
|
72
|
+
|
|
73
|
+
if (h.length == 4) {
|
|
74
|
+
r = '0x' + h[1] + h[1]
|
|
75
|
+
g = '0x' + h[2] + h[2]
|
|
76
|
+
b = '0x' + h[3] + h[3]
|
|
77
|
+
} else if (h.length == 7) {
|
|
78
|
+
r = '0x' + h[1] + h[2]
|
|
79
|
+
g = '0x' + h[3] + h[4]
|
|
80
|
+
b = '0x' + h[5] + h[6]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return [parseInt(r), parseInt(g), parseInt(b)]
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default DataVisualization
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
onLoaded: 'map:loaded',
|
|
3
|
+
onViewportChange: 'viewport:changed',
|
|
4
|
+
onRegionClick: 'region:clicked',
|
|
5
|
+
onMarkerClick: 'marker:clicked',
|
|
6
|
+
onRegionSelected: 'region:selected',
|
|
7
|
+
onMarkerSelected: 'marker:selected',
|
|
8
|
+
onRegionTooltipShow: 'region.tooltip:show',
|
|
9
|
+
onMarkerTooltipShow: 'marker.tooltip:show',
|
|
10
|
+
onDestroyed: 'map:destroyed'
|
|
11
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
map: 'world',
|
|
3
|
+
backgroundColor: 'transparent',
|
|
4
|
+
draggable: true,
|
|
5
|
+
zoomButtons: true,
|
|
6
|
+
zoomOnScroll: true,
|
|
7
|
+
zoomOnScrollSpeed: 3,
|
|
8
|
+
zoomMax: 12,
|
|
9
|
+
zoomMin: 1,
|
|
10
|
+
zoomAnimate: true,
|
|
11
|
+
showTooltip: true,
|
|
12
|
+
zoomStep: 1.5,
|
|
13
|
+
bindTouchEvents: true,
|
|
14
|
+
|
|
15
|
+
// Line options
|
|
16
|
+
lineStyle: {
|
|
17
|
+
curvature: 0,
|
|
18
|
+
stroke: '#808080',
|
|
19
|
+
strokeWidth: 1,
|
|
20
|
+
strokeLinecap: 'round',
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
// Marker options
|
|
24
|
+
markersSelectable: false,
|
|
25
|
+
markersSelectableOne: false,
|
|
26
|
+
markerStyle: {
|
|
27
|
+
initial: {
|
|
28
|
+
r: 7,
|
|
29
|
+
fill: '#374151',
|
|
30
|
+
fillOpacity: 1,
|
|
31
|
+
stroke: '#FFF',
|
|
32
|
+
strokeWidth: 5,
|
|
33
|
+
strokeOpacity: .5,
|
|
34
|
+
},
|
|
35
|
+
hover: {
|
|
36
|
+
fill: '#3cc0ff',
|
|
37
|
+
cursor: 'pointer',
|
|
38
|
+
},
|
|
39
|
+
selected: {
|
|
40
|
+
fill: 'blue'
|
|
41
|
+
},
|
|
42
|
+
selectedHover: {}
|
|
43
|
+
},
|
|
44
|
+
markerLabelStyle: {
|
|
45
|
+
initial: {
|
|
46
|
+
fontFamily: 'Verdana',
|
|
47
|
+
fontSize: 12,
|
|
48
|
+
fontWeight: 500,
|
|
49
|
+
cursor: 'default',
|
|
50
|
+
fill: '#374151'
|
|
51
|
+
},
|
|
52
|
+
hover: {
|
|
53
|
+
cursor: 'pointer'
|
|
54
|
+
},
|
|
55
|
+
selected: {},
|
|
56
|
+
selectedHover: {}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Region options
|
|
60
|
+
regionsSelectable: false,
|
|
61
|
+
regionsSelectableOne: false,
|
|
62
|
+
regionStyle: {
|
|
63
|
+
initial: {
|
|
64
|
+
fill: '#dee2e8',
|
|
65
|
+
fillOpacity: 1,
|
|
66
|
+
stroke: 'none',
|
|
67
|
+
strokeWidth: 0,
|
|
68
|
+
},
|
|
69
|
+
hover: {
|
|
70
|
+
fillOpacity: .7,
|
|
71
|
+
cursor: 'pointer'
|
|
72
|
+
},
|
|
73
|
+
selected: {
|
|
74
|
+
fill: '#9ca3af'
|
|
75
|
+
},
|
|
76
|
+
selectedHover: {}
|
|
77
|
+
},
|
|
78
|
+
regionLabelStyle: {
|
|
79
|
+
initial: {
|
|
80
|
+
fontFamily: 'Verdana',
|
|
81
|
+
fontSize: '12',
|
|
82
|
+
fontWeight: 'bold',
|
|
83
|
+
cursor: 'default',
|
|
84
|
+
fill: '#35373e'
|
|
85
|
+
},
|
|
86
|
+
hover: {
|
|
87
|
+
cursor: 'pointer'
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let eventRegistry = {}
|
|
2
|
+
let eventUid = 1
|
|
3
|
+
|
|
4
|
+
const EventHandler = {
|
|
5
|
+
on(element, event, handler, options = {}) {
|
|
6
|
+
const uid = `jvm:${event}::${eventUid++}`
|
|
7
|
+
|
|
8
|
+
eventRegistry[uid] = {
|
|
9
|
+
selector: element,
|
|
10
|
+
handler,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
handler._uid = uid
|
|
14
|
+
|
|
15
|
+
element.addEventListener(event, handler, options)
|
|
16
|
+
},
|
|
17
|
+
delegate(element, event, selector, handler) {
|
|
18
|
+
event = event.split(' ')
|
|
19
|
+
|
|
20
|
+
event.forEach(eventName => {
|
|
21
|
+
EventHandler.on(element, eventName, (e) => {
|
|
22
|
+
const target = e.target
|
|
23
|
+
|
|
24
|
+
if (target.matches(selector)) {
|
|
25
|
+
handler.call(target, e)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
off(element, event, handler) {
|
|
31
|
+
const eventType = event.split(':')[1]
|
|
32
|
+
|
|
33
|
+
element.removeEventListener(eventType, handler)
|
|
34
|
+
|
|
35
|
+
delete eventRegistry[handler._uid]
|
|
36
|
+
},
|
|
37
|
+
flush() {
|
|
38
|
+
Object.keys(eventRegistry).forEach(event => {
|
|
39
|
+
EventHandler.off(eventRegistry[event].selector, event, eventRegistry[event].handler)
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
getEventRegistry() {
|
|
43
|
+
return eventRegistry
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default EventHandler
|
package/src/js/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jsVectorMap
|
|
3
|
+
* Copyrights (c) Mustafa Omar https://github.com/themustafaomar
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
import Map from './map'
|
|
7
|
+
|
|
8
|
+
import '../scss/jsvectormap.scss'
|
|
9
|
+
|
|
10
|
+
class jsVectorMap {
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
if (!options.selector) {
|
|
13
|
+
throw new Error('Selector is not given.')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return new Map(options)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Public
|
|
20
|
+
static addMap(name, map) {
|
|
21
|
+
Map.maps[name] = map
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default window.jsVectorMap = jsVectorMap
|
package/src/js/legend.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createElement, isImageUrl } from './util'
|
|
2
|
+
|
|
3
|
+
class Legend {
|
|
4
|
+
constructor(options = {}) {
|
|
5
|
+
this._options = options
|
|
6
|
+
this._map = this._options.map
|
|
7
|
+
this._series = this._options.series
|
|
8
|
+
this._body = createElement('div', 'jvm-legend')
|
|
9
|
+
|
|
10
|
+
if (this._options.cssClass) {
|
|
11
|
+
this._body.setAttribute('class', this._options.cssClass)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (options.vertical) {
|
|
15
|
+
this._map.legendVertical.appendChild(this._body)
|
|
16
|
+
} else {
|
|
17
|
+
this._map.legendHorizontal.appendChild(this._body)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this.render()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
let ticks = this._series.scale.getTicks()
|
|
25
|
+
|
|
26
|
+
this._body.innderHTML = ''
|
|
27
|
+
|
|
28
|
+
if (this._options.title) {
|
|
29
|
+
let legendTitle = createElement('div', 'jvm-legend-title', this._options.title)
|
|
30
|
+
this._body.appendChild(legendTitle)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (let i = 0; i < ticks.length; i++) {
|
|
34
|
+
let tick = createElement('div', 'jvm-legend-tick',)
|
|
35
|
+
let sample = createElement('div', 'jvm-legend-tick-sample')
|
|
36
|
+
|
|
37
|
+
switch (this._series.config.attribute) {
|
|
38
|
+
case 'fill':
|
|
39
|
+
if (isImageUrl(ticks[i].value)) {
|
|
40
|
+
sample.style.background = `url(${ticks[i].value})`
|
|
41
|
+
} else {
|
|
42
|
+
sample.style.background = ticks[i].value
|
|
43
|
+
}
|
|
44
|
+
break
|
|
45
|
+
case 'stroke':
|
|
46
|
+
sample.style.background = ticks[i].value
|
|
47
|
+
break
|
|
48
|
+
case 'image':
|
|
49
|
+
sample.style.background = `url(${typeof ticks[i].value === 'object' ? ticks[i].value.url : ticks[i].value}) no-repeat center center`
|
|
50
|
+
sample.style.backgroundSize = 'cover'
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
tick.appendChild(sample)
|
|
55
|
+
let label = ticks[i].label
|
|
56
|
+
|
|
57
|
+
if (this._options.labelRender) {
|
|
58
|
+
label = this._options.labelRender(label)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const tickText = createElement('div', 'jvm-legend-tick-text', label)
|
|
62
|
+
|
|
63
|
+
tick.appendChild(tickText)
|
|
64
|
+
this._body.appendChild(tick)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default Legend
|
package/src/js/map.js
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import {
|
|
2
|
+
merge,
|
|
3
|
+
getLineUid,
|
|
4
|
+
getElement,
|
|
5
|
+
createElement,
|
|
6
|
+
removeElement,
|
|
7
|
+
} from './util'
|
|
8
|
+
import core from './core'
|
|
9
|
+
import Defaults from './defaults/options'
|
|
10
|
+
import SVGCanvasElement from './svg/canvasElement'
|
|
11
|
+
import Events from './defaults/events'
|
|
12
|
+
import EventHandler from './eventHandler'
|
|
13
|
+
import Tooltip from './components/tooltip'
|
|
14
|
+
import DataVisualization from './dataVisualization'
|
|
15
|
+
|
|
16
|
+
const JVM_PREFIX = 'jvm-'
|
|
17
|
+
const CONTAINER_CLASS = `${JVM_PREFIX}container`
|
|
18
|
+
const MARKERS_GROUP_ID = `${JVM_PREFIX}markers-group`
|
|
19
|
+
const MARKERS_LABELS_GROUP_ID = `${JVM_PREFIX}markers-labels-group`
|
|
20
|
+
const LINES_GROUP_ID = `${JVM_PREFIX}lines-group`
|
|
21
|
+
const SERIES_CONTAINER_CLASS = `${JVM_PREFIX}series-container`
|
|
22
|
+
const SERIES_CONTAINER_H_CLASS = `${SERIES_CONTAINER_CLASS} ${JVM_PREFIX}series-h`
|
|
23
|
+
const SERIES_CONTAINER_V_CLASS = `${SERIES_CONTAINER_CLASS} ${JVM_PREFIX}series-v`
|
|
24
|
+
|
|
25
|
+
class Map {
|
|
26
|
+
static maps = {}
|
|
27
|
+
static defaults = Defaults
|
|
28
|
+
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
// Merge the given options with the default options
|
|
31
|
+
this.params = merge(Map.defaults, options, true)
|
|
32
|
+
|
|
33
|
+
// Throw an error if the given map name doesn't match
|
|
34
|
+
// the map that was set in map file
|
|
35
|
+
if (!Map.maps[this.params.map]) {
|
|
36
|
+
throw new Error(`Attempt to use map which was not loaded: ${options.map}`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.regions = {}
|
|
40
|
+
this.scale = 1
|
|
41
|
+
this.transX = 0
|
|
42
|
+
this.transY = 0
|
|
43
|
+
|
|
44
|
+
this._mapData = Map.maps[this.params.map]
|
|
45
|
+
this._markers = {}
|
|
46
|
+
this._lines = {}
|
|
47
|
+
this._defaultWidth = this._mapData.width
|
|
48
|
+
this._defaultHeight = this._mapData.height
|
|
49
|
+
this._height = 0
|
|
50
|
+
this._width = 0
|
|
51
|
+
this._baseScale = 1
|
|
52
|
+
this._baseTransX = 0
|
|
53
|
+
this._baseTransY = 0
|
|
54
|
+
|
|
55
|
+
// `document` is already ready, just initialise now
|
|
56
|
+
if (document.readyState !== 'loading') {
|
|
57
|
+
this._init()
|
|
58
|
+
} else {
|
|
59
|
+
// Wait until `document` is ready
|
|
60
|
+
window.addEventListener('DOMContentLoaded', () => this._init())
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_init() {
|
|
65
|
+
const options = this.params
|
|
66
|
+
|
|
67
|
+
this.container = getElement(options.selector)
|
|
68
|
+
this.container.classList.add(CONTAINER_CLASS)
|
|
69
|
+
|
|
70
|
+
// The map canvas element
|
|
71
|
+
this.canvas = new SVGCanvasElement(this.container)
|
|
72
|
+
|
|
73
|
+
// Set the map's background color
|
|
74
|
+
this.setBackgroundColor(options.backgroundColor)
|
|
75
|
+
|
|
76
|
+
// Create regions
|
|
77
|
+
this._createRegions()
|
|
78
|
+
|
|
79
|
+
// Update size
|
|
80
|
+
this.updateSize()
|
|
81
|
+
|
|
82
|
+
// Lines group must be created before markers
|
|
83
|
+
// Otherwise the lines will be drawn on top of the markers.
|
|
84
|
+
if (options.lines) {
|
|
85
|
+
this._linesGroup = this.canvas.createGroup(LINES_GROUP_ID)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (options.markers) {
|
|
89
|
+
this._markersGroup = this.canvas.createGroup(MARKERS_GROUP_ID)
|
|
90
|
+
this._markerLabelsGroup = this.canvas.createGroup(MARKERS_LABELS_GROUP_ID)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Create markers
|
|
94
|
+
this._createMarkers(options.markers)
|
|
95
|
+
|
|
96
|
+
// Create lines
|
|
97
|
+
this._createLines(options.lines || {})
|
|
98
|
+
|
|
99
|
+
// Position labels
|
|
100
|
+
this._repositionLabels()
|
|
101
|
+
|
|
102
|
+
// Setup the container events
|
|
103
|
+
this._setupContainerEvents()
|
|
104
|
+
|
|
105
|
+
// Setup regions/markers events
|
|
106
|
+
this._setupElementEvents()
|
|
107
|
+
|
|
108
|
+
// Create zoom buttons if `zoomButtons` is presented
|
|
109
|
+
if (options.zoomButtons) {
|
|
110
|
+
this._setupZoomButtons()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Create toolip
|
|
114
|
+
if (options.showTooltip) {
|
|
115
|
+
this._tooltip = new Tooltip(this)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Set selected regions if any
|
|
119
|
+
if (options.selectedRegions) {
|
|
120
|
+
this._setSelected('regions', options.selectedRegions)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Set selected regions if any
|
|
124
|
+
if (options.selectedMarkers) {
|
|
125
|
+
this._setSelected('_markers', options.selectedMarkers)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Set focus on a spcific region
|
|
129
|
+
if (options.focusOn) {
|
|
130
|
+
this.setFocus(options.focusOn)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Data visualization
|
|
134
|
+
if (options.visualizeData) {
|
|
135
|
+
this.dataVisualization = new DataVisualization(options.visualizeData, this)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Bind touch events if true
|
|
139
|
+
if (options.bindTouchEvents) {
|
|
140
|
+
if (
|
|
141
|
+
('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch)
|
|
142
|
+
) {
|
|
143
|
+
this._setupContainerTouchEvents()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Create series if any
|
|
148
|
+
if (options.series) {
|
|
149
|
+
this.container.appendChild(this.legendHorizontal = createElement(
|
|
150
|
+
'div', SERIES_CONTAINER_H_CLASS
|
|
151
|
+
))
|
|
152
|
+
|
|
153
|
+
this.container.appendChild(this.legendVertical = createElement(
|
|
154
|
+
'div', SERIES_CONTAINER_V_CLASS
|
|
155
|
+
))
|
|
156
|
+
|
|
157
|
+
this._createSeries()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Fire loaded event
|
|
161
|
+
this._emit(Events.onLoaded, [this])
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Public
|
|
165
|
+
|
|
166
|
+
setBackgroundColor(color) {
|
|
167
|
+
this.container.style.backgroundColor = color
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Regions
|
|
171
|
+
|
|
172
|
+
getSelectedRegions() {
|
|
173
|
+
return this._getSelected('regions')
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
clearSelectedRegions(regions = undefined) {
|
|
177
|
+
regions = this._normalizeRegions(regions) || this._getSelected('regions')
|
|
178
|
+
regions.forEach((key) => {
|
|
179
|
+
this.regions[key].element.select(false)
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
setSelectedRegions(regions) {
|
|
184
|
+
this.clearSelectedRegions()
|
|
185
|
+
this._setSelected('regions', this._normalizeRegions(regions))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Markers
|
|
189
|
+
|
|
190
|
+
getSelectedMarkers() {
|
|
191
|
+
return this._getSelected('_markers')
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
clearSelectedMarkers() {
|
|
195
|
+
this._clearSelected('_markers')
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
setSelectedMarkers(markers) {
|
|
199
|
+
this._setSelected('_markers', markers)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
addMarkers(config) {
|
|
203
|
+
config = Array.isArray(config) ? config : [config]
|
|
204
|
+
this._createMarkers(config, true)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
removeMarkers(markers) {
|
|
208
|
+
if (!markers) {
|
|
209
|
+
markers = Object.keys(this._markers)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
markers.forEach(index => {
|
|
213
|
+
// Remove the element from the DOM
|
|
214
|
+
this._markers[index].element.remove()
|
|
215
|
+
// Remove the element from markers object
|
|
216
|
+
delete this._markers[index]
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Lines
|
|
221
|
+
|
|
222
|
+
addLine(from, to, style = {}) {
|
|
223
|
+
console.warn('`addLine` method is deprecated, please use `addLines` instead.')
|
|
224
|
+
this._createLines([{ from, to, style }], this._markers, true)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
addLines(config) {
|
|
228
|
+
const uids = this._getLinesAsUids()
|
|
229
|
+
|
|
230
|
+
if (!Array.isArray(config)) {
|
|
231
|
+
config = [config]
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
this._createLines(config.filter(line => {
|
|
235
|
+
return !(uids.indexOf(getLineUid(line.from, line.to)) > -1)
|
|
236
|
+
}), true)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
removeLines(lines) {
|
|
240
|
+
if (Array.isArray(lines)) {
|
|
241
|
+
lines = lines.map(line => getLineUid(line.from, line.to))
|
|
242
|
+
} else {
|
|
243
|
+
lines = this._getLinesAsUids()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
lines.forEach(uid => {
|
|
247
|
+
this._lines[uid].dispose()
|
|
248
|
+
delete this._lines[uid]
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
removeLine(from, to) {
|
|
253
|
+
console.warn('`removeLine` method is deprecated, please use `removeLines` instead.')
|
|
254
|
+
const uid = getLineUid(from, to)
|
|
255
|
+
|
|
256
|
+
if (this._lines.hasOwnProperty(uid)) {
|
|
257
|
+
this._lines[uid].element.remove()
|
|
258
|
+
delete this._lines[uid]
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Reset map
|
|
263
|
+
reset() {
|
|
264
|
+
for (let key in this.series) {
|
|
265
|
+
for (let i = 0; i < this.series[key].length; i++) {
|
|
266
|
+
this.series[key][i].clear()
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (this.legendHorizontal) {
|
|
271
|
+
removeElement(this.legendHorizontal)
|
|
272
|
+
this.legendHorizontal = null
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (this.legendVertical) {
|
|
276
|
+
removeElement(this.legendVertical)
|
|
277
|
+
this.legendVertical = null
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.scale = this._baseScale
|
|
281
|
+
this.transX = this._baseTransX
|
|
282
|
+
this.transY = this._baseTransY
|
|
283
|
+
|
|
284
|
+
this._applyTransform()
|
|
285
|
+
this.clearSelectedMarkers()
|
|
286
|
+
this.clearSelectedRegions()
|
|
287
|
+
this.removeMarkers()
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Destroy the map
|
|
291
|
+
destroy(destroyInstance = true) {
|
|
292
|
+
// Remove event registry
|
|
293
|
+
EventHandler.flush()
|
|
294
|
+
|
|
295
|
+
// Remove tooltip from DOM and memory
|
|
296
|
+
this._tooltip.dispose()
|
|
297
|
+
|
|
298
|
+
// Fire destroyed event
|
|
299
|
+
this._emit(Events.onDestroyed)
|
|
300
|
+
|
|
301
|
+
// Remove references
|
|
302
|
+
if (destroyInstance) {
|
|
303
|
+
Object.keys(this).forEach(key => {
|
|
304
|
+
try {
|
|
305
|
+
delete this[key]
|
|
306
|
+
} catch (e) {}
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
extend(name, callback) {
|
|
312
|
+
if (typeof this[name] === 'function') {
|
|
313
|
+
throw new Error(`The method [${name}] does already exist, please use another name.`)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
Map.prototype[name] = callback
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Private
|
|
320
|
+
|
|
321
|
+
_emit(eventName, args) {
|
|
322
|
+
for (const event in Events) {
|
|
323
|
+
if (Events[event] === eventName && typeof this.params[event] === 'function') {
|
|
324
|
+
this.params[event].apply(this, args)
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Get selected markers/regions
|
|
330
|
+
_getSelected(type) {
|
|
331
|
+
const selected = []
|
|
332
|
+
|
|
333
|
+
for (const key in this[type]) {
|
|
334
|
+
if (this[type][key].element.isSelected) {
|
|
335
|
+
selected.push(key)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return selected
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
_setSelected(type, keys) {
|
|
343
|
+
keys.forEach(key => {
|
|
344
|
+
if (this[type][key]) {
|
|
345
|
+
this[type][key].element.select(true)
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
_clearSelected(type) {
|
|
351
|
+
this._getSelected(type).forEach(key => {
|
|
352
|
+
this[type][key].element.select(false)
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
_getLinesAsUids() {
|
|
357
|
+
return Object.keys(this._lines)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
_normalizeRegions(regions) {
|
|
361
|
+
return typeof regions === 'string' ? [regions] : regions
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
Object.assign(Map.prototype, core)
|
|
366
|
+
|
|
367
|
+
export default Map
|