-
Notifications
You must be signed in to change notification settings - Fork 388
/
Copy pathcontrol-icons.js
235 lines (198 loc) · 17 KB
/
control-icons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
var SvgUtils = require('./svg-utilities');
module.exports = {
enable: function(instance) {
// Select (and create if necessary) defs
var defs = instance.svg.querySelector('defs')
if (!defs) {
defs = document.createElementNS(SvgUtils.svgNS, 'defs')
instance.svg.appendChild(defs)
}
// Check for style element, and create it if it doesn't exist
var styleEl = defs.querySelector('style#svg-pan-zoom-controls-styles');
if (!styleEl) {
var style = document.createElementNS(SvgUtils.svgNS, 'style')
style.setAttribute('id', 'svg-pan-zoom-controls-styles')
style.setAttribute('type', 'text/css')
style.textContent = '.svg-pan-zoom-control { cursor: pointer; fill: black; fill-opacity: 0.333; } .svg-pan-zoom-control:hover { fill-opacity: 0.8; } .svg-pan-zoom-control-background { fill: white; fill-opacity: 0.5; } .svg-pan-zoom-control-background { fill-opacity: 0.8; }'
defs.appendChild(style)
}
// Zoom Group
var zoomGroup = document.createElementNS(SvgUtils.svgNS, 'g');
zoomGroup.setAttribute('id', 'svg-pan-zoom-controls');
zoomGroup.setAttribute('transform', 'translate(' + ( instance.width - 70 ) + ' ' + ( instance.height - 76 ) + ') scale(0.75)');
zoomGroup.setAttribute('class', 'svg-pan-zoom-control');
// Control elements
// zoom elements
zoomGroup.appendChild(this._createZoomIn(instance))
zoomGroup.appendChild(this._createZoomReset(instance))
zoomGroup.appendChild(this._createZoomOut(instance))
//pan elements
zoomGroup.appendChild(this._createPanLeft(instance))
zoomGroup.appendChild(this._createPanRight(instance))
zoomGroup.appendChild(this._createPanUp(instance))
zoomGroup.appendChild(this._createPanDown(instance))
// Finally append created element
instance.svg.appendChild(zoomGroup)
// Cache control instance
instance.controlIcons = zoomGroup
}
, _createZoomIn: function(instance) {
var zoomIn = document.createElementNS(SvgUtils.svgNS, 'g');
zoomIn.setAttribute('id', 'svg-pan-zoom-zoom-in');
zoomIn.setAttribute('transform', 'translate(30.5 5) scale(0.015)');
zoomIn.setAttribute('class', 'svg-pan-zoom-control');
zoomIn.addEventListener('click', function() {instance.getPublicInstance().zoomIn()}, false)
zoomIn.addEventListener('touchstart', function() {instance.getPublicInstance().zoomIn()}, false)
var zoomInBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
zoomInBackground.setAttribute('x', '0');
zoomInBackground.setAttribute('y', '0');
zoomInBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
zoomInBackground.setAttribute('height', '1400');
zoomInBackground.setAttribute('class', 'svg-pan-zoom-control-background');
zoomIn.appendChild(zoomInBackground);
var zoomInShape = document.createElementNS(SvgUtils.svgNS, 'path');
zoomInShape.setAttribute('d', 'M1280 576v128q0 26 -19 45t-45 19h-320v320q0 26 -19 45t-45 19h-128q-26 0 -45 -19t-19 -45v-320h-320q-26 0 -45 -19t-19 -45v-128q0 -26 19 -45t45 -19h320v-320q0 -26 19 -45t45 -19h128q26 0 45 19t19 45v320h320q26 0 45 19t19 45zM1536 1120v-960 q0 -119 -84.5 -203.5t-203.5 -84.5h-960q-119 0 -203.5 84.5t-84.5 203.5v960q0 119 84.5 203.5t203.5 84.5h960q119 0 203.5 -84.5t84.5 -203.5z');
zoomInShape.setAttribute('class', 'svg-pan-zoom-control-element');
zoomIn.appendChild(zoomInShape);
return zoomIn
}
, _createZoomReset: function(instance){
// reset
var resetPanZoomControl = document.createElementNS(SvgUtils.svgNS, 'g');
resetPanZoomControl.setAttribute('id', 'svg-pan-zoom-reset-pan-zoom');
resetPanZoomControl.setAttribute('transform', 'translate(5 35) scale(0.4)');
resetPanZoomControl.setAttribute('class', 'svg-pan-zoom-control');
resetPanZoomControl.addEventListener('click', function() {instance.getPublicInstance().reset()}, false);
resetPanZoomControl.addEventListener('touchstart', function() {instance.getPublicInstance().reset()}, false);
var resetPanZoomControlBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
resetPanZoomControlBackground.setAttribute('x', '2');
resetPanZoomControlBackground.setAttribute('y', '2');
resetPanZoomControlBackground.setAttribute('width', '182'); // larger than expected because the whole group is transformed to scale down
resetPanZoomControlBackground.setAttribute('height', '58');
resetPanZoomControlBackground.setAttribute('class', 'svg-pan-zoom-control-background');
resetPanZoomControl.appendChild(resetPanZoomControlBackground);
var resetPanZoomControlShape1 = document.createElementNS(SvgUtils.svgNS, 'path');
resetPanZoomControlShape1.setAttribute('d', 'M33.051,20.632c-0.742-0.406-1.854-0.609-3.338-0.609h-7.969v9.281h7.769c1.543,0,2.701-0.188,3.473-0.562c1.365-0.656,2.048-1.953,2.048-3.891C35.032,22.757,34.372,21.351,33.051,20.632z');
resetPanZoomControlShape1.setAttribute('class', 'svg-pan-zoom-control-element');
resetPanZoomControl.appendChild(resetPanZoomControlShape1);
var resetPanZoomControlShape2 = document.createElementNS(SvgUtils.svgNS, 'path');
resetPanZoomControlShape2.setAttribute('d', 'M170.231,0.5H15.847C7.102,0.5,0.5,5.708,0.5,11.84v38.861C0.5,56.833,7.102,61.5,15.847,61.5h154.384c8.745,0,15.269-4.667,15.269-10.798V11.84C185.5,5.708,178.976,0.5,170.231,0.5z M42.837,48.569h-7.969c-0.219-0.766-0.375-1.383-0.469-1.852c-0.188-0.969-0.289-1.961-0.305-2.977l-0.047-3.211c-0.03-2.203-0.41-3.672-1.142-4.406c-0.732-0.734-2.103-1.102-4.113-1.102h-7.05v13.547h-7.055V14.022h16.524c2.361,0.047,4.178,0.344,5.45,0.891c1.272,0.547,2.351,1.352,3.234,2.414c0.731,0.875,1.31,1.844,1.737,2.906s0.64,2.273,0.64,3.633c0,1.641-0.414,3.254-1.242,4.84s-2.195,2.707-4.102,3.363c1.594,0.641,2.723,1.551,3.387,2.73s0.996,2.98,0.996,5.402v2.32c0,1.578,0.063,2.648,0.19,3.211c0.19,0.891,0.635,1.547,1.333,1.969V48.569z M75.579,48.569h-26.18V14.022h25.336v6.117H56.454v7.336h16.781v6H56.454v8.883h19.125V48.569z M104.497,46.331c-2.44,2.086-5.887,3.129-10.34,3.129c-4.548,0-8.125-1.027-10.731-3.082s-3.909-4.879-3.909-8.473h6.891c0.224,1.578,0.662,2.758,1.316,3.539c1.196,1.422,3.246,2.133,6.15,2.133c1.739,0,3.151-0.188,4.236-0.562c2.058-0.719,3.087-2.055,3.087-4.008c0-1.141-0.504-2.023-1.512-2.648c-1.008-0.609-2.607-1.148-4.796-1.617l-3.74-0.82c-3.676-0.812-6.201-1.695-7.576-2.648c-2.328-1.594-3.492-4.086-3.492-7.477c0-3.094,1.139-5.664,3.417-7.711s5.623-3.07,10.036-3.07c3.685,0,6.829,0.965,9.431,2.895c2.602,1.93,3.966,4.73,4.093,8.402h-6.938c-0.128-2.078-1.057-3.555-2.787-4.43c-1.154-0.578-2.587-0.867-4.301-0.867c-1.907,0-3.428,0.375-4.565,1.125c-1.138,0.75-1.706,1.797-1.706,3.141c0,1.234,0.561,2.156,1.682,2.766c0.721,0.406,2.25,0.883,4.589,1.43l6.063,1.43c2.657,0.625,4.648,1.461,5.975,2.508c2.059,1.625,3.089,3.977,3.089,7.055C108.157,41.624,106.937,44.245,104.497,46.331z M139.61,48.569h-26.18V14.022h25.336v6.117h-18.281v7.336h16.781v6h-16.781v8.883h19.125V48.569z M170.337,20.14h-10.336v28.43h-7.266V20.14h-10.383v-6.117h27.984V20.14z');
resetPanZoomControlShape2.setAttribute('class', 'svg-pan-zoom-control-element');
resetPanZoomControl.appendChild(resetPanZoomControlShape2);
return resetPanZoomControl
}
, _createZoomOut: function(instance){
// zoom out
var zoomOut = document.createElementNS(SvgUtils.svgNS, 'g');
zoomOut.setAttribute('id', 'svg-pan-zoom-zoom-out');
zoomOut.setAttribute('transform', 'translate(30.5 70) scale(0.015)');
zoomOut.setAttribute('class', 'svg-pan-zoom-control');
zoomOut.addEventListener('click', function() {instance.getPublicInstance().zoomOut()}, false);
zoomOut.addEventListener('touchstart', function() {instance.getPublicInstance().zoomOut()}, false);
var zoomOutBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
zoomOutBackground.setAttribute('x', '0');
zoomOutBackground.setAttribute('y', '0');
zoomOutBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
zoomOutBackground.setAttribute('height', '1400');
zoomOutBackground.setAttribute('class', 'svg-pan-zoom-control-background');
zoomOut.appendChild(zoomOutBackground);
var zoomOutShape = document.createElementNS(SvgUtils.svgNS, 'path');
zoomOutShape.setAttribute('d', 'M1280 576v128q0 26 -19 45t-45 19h-896q-26 0 -45 -19t-19 -45v-128q0 -26 19 -45t45 -19h896q26 0 45 19t19 45zM1536 1120v-960q0 -119 -84.5 -203.5t-203.5 -84.5h-960q-119 0 -203.5 84.5t-84.5 203.5v960q0 119 84.5 203.5t203.5 84.5h960q119 0 203.5 -84.5 t84.5 -203.5z');
zoomOutShape.setAttribute('class', 'svg-pan-zoom-control-element');
zoomOut.appendChild(zoomOutShape);
return zoomOut
}
, _createPanLeft: function(instance){
// zoom out
var panLeft = document.createElementNS(SvgUtils.svgNS, 'g');
panLeft.setAttribute('id', 'svg-pan-zoom-pan-left');
panLeft.setAttribute('transform', 'translate(10 -58) scale(0.015)');
panLeft.setAttribute('class', 'svg-pan-zoom-control');
panLeft.addEventListener('click', function() {instance.getPublicInstance().panBy({x: -50, y: 0})}, false);
panLeft.addEventListener('touchstart', function() {instance.getPublicInstance().panBy({x: -50, y: 0})}, false);
var panLeftBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
panLeftBackground.setAttribute('x', '0');
panLeftBackground.setAttribute('y', '0');
panLeftBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
panLeftBackground.setAttribute('height', '1400');
panLeftBackground.setAttribute('class', 'svg-pan-zoom-control-background');
panLeft.appendChild(panLeftBackground);
var panLeftShape = document.createElementNS(SvgUtils.svgNS, 'path');
panLeftShape.setAttribute('d', 'M1451.5-43.5C1395.2-99.8,1327.3-128,1248-128H288c-79.3,0-147.2,28.2-203.5,84.5C28.2,12.8,0,80.7,0,160 v960c0,79.3,28.2,147.2,84.5,203.5c56.3,56.3,124.2,84.5,203.5,84.5h960c79.3,0,147.2-28.2,203.5-84.5 c56.3-56.3,84.5-124.2,84.5-203.5V160C1536,80.7,1507.8,12.8,1451.5-43.5z M1120.2,1073.7c10.9,10.9,16.3,24.3,16.3,40.2 c0,15.9-5.4,29.3-16.3,40.2l-80.4,80.4c-10.9,10.9-24.3,16.3-40.2,16.3c-15.9,0-29.3-5.4-40.2-16.3L397,671.9 c-10.9-10.9-16.3-24.3-16.3-40.2c0-15.9,5.4-29.3,16.3-40.2L959.5,29c10.9-10.9,24.3-16.3,40.2-16.3c15.9,0,29.3,5.4,40.2,16.3 l80.4,80.4c10.9,10.9,16.3,24.3,16.3,40.2c0,15.9-5.4,29.3-16.3,40.2l-442,442L1120.2,1073.7z');
panLeftShape.setAttribute('class', 'svg-pan-zoom-control-element');
panLeft.appendChild(panLeftShape);
return panLeft
}
, _createPanRight: function(instance){
// zoom out
var panRight = document.createElementNS(SvgUtils.svgNS, 'g');
panRight.setAttribute('id', 'svg-pan-zoom-pan-right');
panRight.setAttribute('transform', 'translate(51 -58) scale(0.015)');
panRight.setAttribute('class', 'svg-pan-zoom-control');
panRight.addEventListener('click', function() {instance.getPublicInstance().panBy({x: 50, y: 0})}, false);
panRight.addEventListener('touchstart', function() {instance.getPublicInstance().panBy({x: 50, y: 0})}, false);
var panRightBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
panRightBackground.setAttribute('x', '0');
panRightBackground.setAttribute('y', '0');
panRightBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
panRightBackground.setAttribute('height', '1400');
panRightBackground.setAttribute('class', 'svg-pan-zoom-control-background');
panRight.appendChild(panRightBackground);
var panRightShape = document.createElementNS(SvgUtils.svgNS, 'path');
panRightShape.setAttribute('d', 'M1451.5-43.5C1395.2-99.8,1327.3-128,1248-128H288c-79.3,0-147.2,28.2-203.5,84.5C28.2,12.8,0,80.7,0,160 v960c0,79.3,28.2,147.2,84.5,203.5c56.3,56.3,124.2,84.5,203.5,84.5h960c79.3,0,147.2-28.2,203.5-84.5 c56.3-56.3,84.5-124.2,84.5-203.5V160C1536,80.7,1507.8,12.8,1451.5-43.5z M1120.2,1073.7c10.9,10.9,16.3,24.3,16.3,40.2 c0,15.9-5.4,29.3-16.3,40.2l-80.4,80.4c-10.9,10.9-24.3,16.3-40.2,16.3c-15.9,0-29.3-5.4-40.2-16.3L397,671.9 c-10.9-10.9-16.3-24.3-16.3-40.2c0-15.9,5.4-29.3,16.3-40.2L959.5,29c10.9-10.9,24.3-16.3,40.2-16.3c15.9,0,29.3,5.4,40.2,16.3 l80.4,80.4c10.9,10.9,16.3,24.3,16.3,40.2c0,15.9-5.4,29.3-16.3,40.2l-442,442L1120.2,1073.7z');
panRightShape.setAttribute('class', 'svg-pan-zoom-control-element');
panRightShape.setAttribute('transform', 'rotate(180 768 640)');
panRight.appendChild(panRightShape);
return panRight
}
, _createPanUp: function(instance){
// zoom out
var panUp = document.createElementNS(SvgUtils.svgNS, 'g');
panUp.setAttribute('id', 'svg-pan-zoom-pan-up');
panUp.setAttribute('transform', 'translate(30.5 -80) scale(0.015)');
panUp.setAttribute('class', 'svg-pan-zoom-control');
panUp.addEventListener('click', function() {instance.getPublicInstance().panBy({x: 0, y: -50})}, false);
panUp.addEventListener('touchstart', function() {instance.getPublicInstance().panBy({x: 0, y: -50})}, false);
var panUpBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
panUpBackground.setAttribute('x', '0');
panUpBackground.setAttribute('y', '0');
panUpBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
panUpBackground.setAttribute('height', '1400');
panUpBackground.setAttribute('class', 'svg-pan-zoom-control-background');
panUp.appendChild(panUpBackground);
var panUpShape = document.createElementNS(SvgUtils.svgNS, 'path');
panUpShape.setAttribute('d', 'M1451.5-43.5C1395.2-99.8,1327.3-128,1248-128H288c-79.3,0-147.2,28.2-203.5,84.5C28.2,12.8,0,80.7,0,160 v960c0,79.3,28.2,147.2,84.5,203.5c56.3,56.3,124.2,84.5,203.5,84.5h960c79.3,0,147.2-28.2,203.5-84.5 c56.3-56.3,84.5-124.2,84.5-203.5V160C1536,80.7,1507.8,12.8,1451.5-43.5z M1120.2,1073.7c10.9,10.9,16.3,24.3,16.3,40.2 c0,15.9-5.4,29.3-16.3,40.2l-80.4,80.4c-10.9,10.9-24.3,16.3-40.2,16.3c-15.9,0-29.3-5.4-40.2-16.3L397,671.9 c-10.9-10.9-16.3-24.3-16.3-40.2c0-15.9,5.4-29.3,16.3-40.2L959.5,29c10.9-10.9,24.3-16.3,40.2-16.3c15.9,0,29.3,5.4,40.2,16.3 l80.4,80.4c10.9,10.9,16.3,24.3,16.3,40.2c0,15.9-5.4,29.3-16.3,40.2l-442,442L1120.2,1073.7z');
panUpShape.setAttribute('class', 'svg-pan-zoom-control-element');
panUpShape.setAttribute('transform', 'rotate(90 768 640)');
panUp.appendChild(panUpShape);
return panUp
}
, _createPanDown: function(instance){
// zoom out
var panDown = document.createElementNS(SvgUtils.svgNS, 'g');
panDown.setAttribute('id', 'svg-pan-zoom-pan-down');
panDown.setAttribute('transform', 'translate(30.5 -36) scale(0.015)');
panDown.setAttribute('class', 'svg-pan-zoom-control');
panDown.addEventListener('click', function() {instance.getPublicInstance().panBy({x: 0, y: 50})}, false);
panDown.addEventListener('touchstart', function() {instance.getPublicInstance().panBy({x: 0, y: 50})}, false);
var panDownBackground = document.createElementNS(SvgUtils.svgNS, 'rect'); // TODO change these background space fillers to rounded rectangles so they look prettier
panDownBackground.setAttribute('x', '0');
panDownBackground.setAttribute('y', '0');
panDownBackground.setAttribute('width', '1500'); // larger than expected because the whole group is transformed to scale down
panDownBackground.setAttribute('height', '1400');
panDownBackground.setAttribute('class', 'svg-pan-zoom-control-background');
panDown.appendChild(panDownBackground);
var panDownShape = document.createElementNS(SvgUtils.svgNS, 'path');
panDownShape.setAttribute('d', 'M1451.5-43.5C1395.2-99.8,1327.3-128,1248-128H288c-79.3,0-147.2,28.2-203.5,84.5C28.2,12.8,0,80.7,0,160 v960c0,79.3,28.2,147.2,84.5,203.5c56.3,56.3,124.2,84.5,203.5,84.5h960c79.3,0,147.2-28.2,203.5-84.5 c56.3-56.3,84.5-124.2,84.5-203.5V160C1536,80.7,1507.8,12.8,1451.5-43.5z M1120.2,1073.7c10.9,10.9,16.3,24.3,16.3,40.2 c0,15.9-5.4,29.3-16.3,40.2l-80.4,80.4c-10.9,10.9-24.3,16.3-40.2,16.3c-15.9,0-29.3-5.4-40.2-16.3L397,671.9 c-10.9-10.9-16.3-24.3-16.3-40.2c0-15.9,5.4-29.3,16.3-40.2L959.5,29c10.9-10.9,24.3-16.3,40.2-16.3c15.9,0,29.3,5.4,40.2,16.3 l80.4,80.4c10.9,10.9,16.3,24.3,16.3,40.2c0,15.9-5.4,29.3-16.3,40.2l-442,442L1120.2,1073.7z');
panDownShape.setAttribute('class', 'svg-pan-zoom-control-element');
panDownShape.setAttribute('transform', 'rotate(270 768 640)');
panDown.appendChild(panDownShape);
return panDown
}
, disable: function(instance) {
if (instance.controlIcons) {
instance.controlIcons.parentNode.removeChild(instance.controlIcons)
instance.controlIcons = null
}
}
}