vislite 1.0.0 → 1.1.0-alpha.1

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 (143) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +244 -239
  3. package/LICENSE +20 -20
  4. package/README.md +142 -134
  5. package/lib/Buffer/index.es.js +1 -1
  6. package/lib/Buffer/index.es.min.js +1 -1
  7. package/lib/Canvas/index.es.js +1 -1
  8. package/lib/Canvas/index.es.min.js +1 -1
  9. package/lib/Cardinal/index.es.js +1 -1
  10. package/lib/Cardinal/index.es.min.js +1 -1
  11. package/lib/Eoap/index.es.js +1 -1
  12. package/lib/Eoap/index.es.min.js +1 -1
  13. package/lib/Hermite/index.es.js +1 -1
  14. package/lib/Hermite/index.es.min.js +1 -1
  15. package/lib/Matrix4/index.es.js +1 -1
  16. package/lib/Matrix4/index.es.min.js +1 -1
  17. package/lib/Mercator/index.es.js +1 -1
  18. package/lib/Mercator/index.es.min.js +1 -1
  19. package/lib/SVG/index.es.js +1 -1
  20. package/lib/SVG/index.es.min.js +1 -1
  21. package/lib/Shader/index.es.js +1 -1
  22. package/lib/Shader/index.es.min.js +1 -1
  23. package/lib/Texture/index.es.js +1 -1
  24. package/lib/Texture/index.es.min.js +1 -1
  25. package/lib/TreeLayout/index.es.js +1 -1
  26. package/lib/TreeLayout/index.es.min.js +1 -1
  27. package/lib/animation/index.es.js +1 -1
  28. package/lib/animation/index.es.min.js +1 -1
  29. package/lib/getLoopColors/index.es.js +1 -1
  30. package/lib/getLoopColors/index.es.min.js +1 -1
  31. package/lib/getWebGLContext/index.es.js +1 -1
  32. package/lib/getWebGLContext/index.es.min.js +1 -1
  33. package/lib/index.es.js +2278 -0
  34. package/lib/index.es.min.js +5 -0
  35. package/lib/index.umd.js +1 -1
  36. package/lib/index.umd.min.js +1 -1
  37. package/lib/move/index.es.js +1 -1
  38. package/lib/move/index.es.min.js +1 -1
  39. package/lib/rotate/index.es.js +1 -1
  40. package/lib/rotate/index.es.min.js +1 -1
  41. package/lib/ruler/index.es.js +1 -1
  42. package/lib/ruler/index.es.min.js +1 -1
  43. package/lib/scale/index.es.js +1 -1
  44. package/lib/scale/index.es.min.js +1 -1
  45. package/lib/throttle/index.es.js +1 -1
  46. package/lib/throttle/index.es.min.js +1 -1
  47. package/miniprogram/ui-canvas/drawImage.js +35 -35
  48. package/miniprogram/ui-canvas/index.js +115 -115
  49. package/miniprogram/ui-canvas/index.json +4 -4
  50. package/miniprogram/ui-canvas/index.wxml +4 -4
  51. package/miniprogram/ui-canvas/index.wxss +5 -5
  52. package/package/Buffer/index.ts +2 -2
  53. package/package/Canvas/index.ts +2 -2
  54. package/package/Cardinal/index.ts +2 -2
  55. package/package/Eoap/index.ts +2 -2
  56. package/package/Hermite/index.ts +2 -2
  57. package/package/Matrix4/index.ts +2 -2
  58. package/package/Mercator/index.ts +2 -2
  59. package/package/SVG/index.ts +2 -2
  60. package/package/Shader/index.ts +2 -2
  61. package/package/Texture/index.ts +2 -2
  62. package/package/TreeLayout/index.ts +2 -2
  63. package/package/animation/index.ts +2 -2
  64. package/package/getLoopColors/index.ts +2 -2
  65. package/package/getWebGLContext/index.ts +40 -40
  66. package/package/index.ts +65 -65
  67. package/package/move/index.ts +2 -2
  68. package/package/rotate/index.ts +2 -2
  69. package/package/ruler/index.ts +2 -2
  70. package/package/scale/index.ts +2 -2
  71. package/package/throttle/index.ts +2 -2
  72. package/package.json +75 -73
  73. package/src/Canvas.ts +73 -73
  74. package/src/Eoap.ts +66 -66
  75. package/src/Matrix4/index.ts +84 -84
  76. package/src/Matrix4/move.ts +12 -12
  77. package/src/Matrix4/rotate.ts +15 -15
  78. package/src/Matrix4/scale.ts +11 -11
  79. package/src/Matrix4/transform.ts +64 -64
  80. package/src/Mercator.ts +27 -27
  81. package/src/SVG.ts +24 -24
  82. package/src/animation.ts +98 -98
  83. package/src/common/assemble.ts +22 -22
  84. package/src/common/canvas/arc.ts +51 -51
  85. package/src/common/canvas/config.ts +158 -158
  86. package/src/common/canvas/gradient.ts +24 -24
  87. package/src/common/canvas/index.ts +177 -177
  88. package/src/common/canvas/painter.ts +455 -455
  89. package/src/common/canvas/texts.ts +18 -18
  90. package/src/common/mergeOption.ts +6 -6
  91. package/src/common/setStyle.ts +5 -5
  92. package/src/common/svg/config.ts +190 -190
  93. package/src/common/svg/gradient.ts +53 -53
  94. package/src/common/svg/index.ts +347 -347
  95. package/src/common/svg/tool.ts +44 -44
  96. package/src/common/tree/index.ts +25 -25
  97. package/src/common/tree/toInnerTree.ts +59 -59
  98. package/src/common/tree/toPlainTree.ts +132 -132
  99. package/src/common/webgl/buffer.ts +79 -79
  100. package/src/common/webgl/getWebGLContext.ts +45 -45
  101. package/src/common/webgl/shader.ts +75 -75
  102. package/src/common/webgl/texture.ts +97 -97
  103. package/src/getLoopColors.ts +42 -42
  104. package/src/interpolation/Cardinal.ts +110 -110
  105. package/src/interpolation/Hermite.ts +65 -65
  106. package/src/layout/TreeLayout.ts +188 -188
  107. package/src/move.ts +7 -7
  108. package/src/rotate.ts +7 -7
  109. package/src/ruler.ts +209 -209
  110. package/src/scale.ts +6 -6
  111. package/src/throttle.ts +52 -52
  112. package/types/Buffer.d.ts +23 -23
  113. package/types/Canvas.d.ts +323 -323
  114. package/types/CanvasConfig.d.ts +106 -106
  115. package/types/CanvasOption.d.ts +8 -8
  116. package/types/CanvasOpts.d.ts +9 -9
  117. package/types/Cardinal.d.ts +13 -13
  118. package/types/Gradient.d.ts +14 -14
  119. package/types/Hermite.d.ts +18 -18
  120. package/types/Map.d.ts +9 -9
  121. package/types/Matrix4.d.ts +47 -47
  122. package/types/SVG.d.ts +238 -238
  123. package/types/SVGConfig.d.ts +79 -79
  124. package/types/Shader.d.ts +16 -16
  125. package/types/Texture.d.ts +16 -16
  126. package/types/Tree.d.ts +69 -69
  127. package/types/TreeConfig.d.ts +36 -36
  128. package/types/TreeLayout.d.ts +54 -54
  129. package/types/TreeOption.d.ts +48 -48
  130. package/types/animation.d.ts +9 -9
  131. package/types/getLoopColors.d.ts +5 -5
  132. package/types/getWebGLContext.d.ts +7 -7
  133. package/types/index.d.ts +145 -145
  134. package/types/move.d.ts +5 -5
  135. package/types/painterConfig.d.ts +2 -2
  136. package/types/rotate.d.ts +5 -5
  137. package/types/ruler.d.ts +10 -10
  138. package/types/scale.d.ts +5 -5
  139. package/types/throttle.d.ts +7 -7
  140. package/types/throttleOption.d.ts +21 -21
  141. package/types/ui-canvas.d.ts +4 -4
  142. package/uni-app/drawImage.js +19 -19
  143. package/uni-app/ui-canvas.vue +283 -283
@@ -0,0 +1,2278 @@
1
+ /*!
2
+ * VISLite JavaScript Library v1.1.0-alpha.1
3
+ * git+https://github.com/oi-contrib/VISLite.git
4
+ */
5
+ var Hermite = (function () {
6
+ function Hermite(u) {
7
+ if (u === void 0) { u = 0.5; }
8
+ this.name = 'Hermite';
9
+ this.__u = u;
10
+ }
11
+ Hermite.prototype.setP = function (x1, y1, x2, y2, s1, s2) {
12
+ if (x1 < x2) {
13
+ this.__a = x1;
14
+ this.__b = x2;
15
+ var p3 = this.__u * s1, p4 = this.__u * s2;
16
+ y1 /= (x2 - x1);
17
+ y2 /= (x2 - x1);
18
+ this.__MR = [
19
+ 2 * y1 - 2 * y2 + p3 + p4,
20
+ 3 * y2 - 3 * y1 - 2 * p3 - p4,
21
+ p3,
22
+ y1
23
+ ];
24
+ }
25
+ else
26
+ throw new Error('The point x-position should be increamented!');
27
+ return this;
28
+ };
29
+ Hermite.prototype.use = function (x) {
30
+ if (this.__MR) {
31
+ var sx = (x - this.__a) / (this.__b - this.__a), sx2 = sx * sx, sx3 = sx * sx2;
32
+ var sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3];
33
+ return sResult * (this.__b - this.__a);
34
+ }
35
+ else
36
+ throw new Error('You shoud first set the position!');
37
+ };
38
+ return Hermite;
39
+ }());
40
+
41
+ var Cardinal = (function () {
42
+ function Cardinal(t) {
43
+ if (t === void 0) { t = 0; }
44
+ this.name = 'Cardinal';
45
+ this.__t = t;
46
+ }
47
+ Cardinal.prototype.setP = function (points) {
48
+ this.__HS = {
49
+ "x": [],
50
+ "h": []
51
+ };
52
+ var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
53
+ this.__HS.x[0] = points[0][0];
54
+ for (flag = 1; flag < points.length; flag++) {
55
+ if (points[flag][0] <= points[flag - 1][0])
56
+ throw new Error('The point position should be increamented!');
57
+ this.__HS.x[flag] = points[flag][0];
58
+ if (flag < points.length - 1) {
59
+ if ((points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
60
+ (points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
61
+ points[flag + 1][1] == points[flag][1] ||
62
+ points[flag - 1][1] == points[flag][1]) {
63
+ temp = 0;
64
+ }
65
+ else {
66
+ temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]);
67
+ }
68
+ }
69
+ else {
70
+ temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
71
+ }
72
+ this.__HS.h[flag - 1] = new Hermite((1 - this.__t) * 0.5).setP(points[flag - 1][0], points[flag - 1][1], points[flag][0], points[flag][1], slope, temp);
73
+ slope = temp;
74
+ }
75
+ return this;
76
+ };
77
+ Cardinal.prototype.use = function (x) {
78
+ if (this.__HS) {
79
+ this.__i = -1;
80
+ while (this.__i + 1 < this.__HS.x.length && (x > this.__HS.x[this.__i + 1] || (this.__i == -1 && x >= this.__HS.x[this.__i + 1]))) {
81
+ this.__i += 1;
82
+ }
83
+ if (this.__i < 0) {
84
+ return this.__HS.h[0].use(this.__HS.x[0]);
85
+ }
86
+ else if (this.__i >= this.__HS.h.length) {
87
+ return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
88
+ }
89
+ return this.__HS.h[this.__i].use(x);
90
+ }
91
+ else {
92
+ throw new Error('You shoud first set the position!');
93
+ }
94
+ };
95
+ return Cardinal;
96
+ }());
97
+
98
+ function _move (d, a, b, c) {
99
+ if (c === void 0) { c = 0; }
100
+ var sqrt = Math.sqrt(a * a + b * b + c * c);
101
+ return [
102
+ 1, 0, 0, 0,
103
+ 0, 1, 0, 0,
104
+ 0, 0, 1, 0,
105
+ a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
106
+ ];
107
+ }
108
+
109
+ function _rotate (deg) {
110
+ var sin = Math.sin(deg), cos = Math.cos(deg);
111
+ return [
112
+ cos, sin, 0, 0,
113
+ -sin, cos, 0, 0,
114
+ 0, 0, 1, 0,
115
+ 0, 0, 0, 1
116
+ ];
117
+ }
118
+
119
+ function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
120
+ if (cx === void 0) { cx = 0; }
121
+ if (cy === void 0) { cy = 0; }
122
+ if (cz === void 0) { cz = 0; }
123
+ return [
124
+ xTimes, 0, 0, 0,
125
+ 0, yTimes, 0, 0,
126
+ 0, 0, zTimes, 0,
127
+ cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
128
+ ];
129
+ }
130
+
131
+ function _transform (a1, b1, c1, a2, b2, c2) {
132
+ if (typeof a1 === 'number' && typeof b1 === 'number') {
133
+ if (typeof c1 !== 'number') {
134
+ c1 = 0;
135
+ a2 = a1;
136
+ b2 = b1;
137
+ c2 = 1;
138
+ }
139
+ else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
140
+ a2 = a1;
141
+ b2 = b1;
142
+ c2 = c1;
143
+ a1 = 0;
144
+ b1 = 0;
145
+ c1 = 0;
146
+ }
147
+ if (a1 == a2 && b1 == b2 && c1 == c2)
148
+ throw new Error('It\'s not a legitimate ray!');
149
+ var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
150
+ return [
151
+ [
152
+ cos1, cos2 * sin1, sin1 * sin2, 0,
153
+ -sin1, cos1 * cos2, cos1 * sin2, 0,
154
+ 0, -sin2, cos2, 0,
155
+ b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
156
+ ],
157
+ [
158
+ cos1, -sin1, 0, 0,
159
+ cos2 * sin1, cos2 * cos1, -sin2, 0,
160
+ sin1 * sin2, cos1 * sin2, cos2, 0,
161
+ a1, b1, c1, 1
162
+ ]
163
+ ];
164
+ }
165
+ else {
166
+ throw new Error('a1 and b1 is required!');
167
+ }
168
+ }
169
+
170
+ var _multiply = function (matrix4, param) {
171
+ var newParam = [];
172
+ for (var i = 0; i < 4; i++)
173
+ for (var j = 0; j < param.length / 4; j++)
174
+ newParam[j * 4 + i] =
175
+ matrix4[i] * param[j * 4] +
176
+ matrix4[i + 4] * param[j * 4 + 1] +
177
+ matrix4[i + 8] * param[j * 4 + 2] +
178
+ matrix4[i + 12] * param[j * 4 + 3];
179
+ return newParam;
180
+ };
181
+ var __initMatrix4 = [
182
+ 1, 0, 0, 0,
183
+ 0, 1, 0, 0,
184
+ 0, 0, 1, 0,
185
+ 0, 0, 0, 1
186
+ ];
187
+ var Matrix4 = (function () {
188
+ function Matrix4(initMatrix4) {
189
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
190
+ this.name = 'Matrix4';
191
+ this.__matrix4 = initMatrix4;
192
+ }
193
+ Matrix4.prototype.setValue = function (initMatrix4) {
194
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
195
+ this.__matrix4 = initMatrix4;
196
+ return this;
197
+ };
198
+ Matrix4.prototype.move = function (dis, a, b, c) {
199
+ if (c === void 0) { c = 0; }
200
+ this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
201
+ return this;
202
+ };
203
+ Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
204
+ var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
205
+ this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
206
+ return this;
207
+ };
208
+ Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
209
+ if (cx === void 0) { cx = 0; }
210
+ if (cy === void 0) { cy = 0; }
211
+ if (cz === void 0) { cz = 0; }
212
+ this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
213
+ return this;
214
+ };
215
+ Matrix4.prototype.multiply = function (newMatrix4, flag) {
216
+ if (flag === void 0) { flag = false; }
217
+ this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
218
+ return this;
219
+ };
220
+ Matrix4.prototype.use = function (x, y, z, w) {
221
+ if (z === void 0) { z = 0; }
222
+ if (w === void 0) { w = 1; }
223
+ return _multiply(this.__matrix4, [x, y, z, w]);
224
+ };
225
+ Matrix4.prototype.value = function () {
226
+ return this.__matrix4;
227
+ };
228
+ return Matrix4;
229
+ }());
230
+
231
+ function rotate$1 (cx, cy, deg, x, y) {
232
+ var cos = Math.cos(deg), sin = Math.sin(deg);
233
+ return [
234
+ (x - cx) * cos - (y - cy) * sin + cx,
235
+ (x - cx) * sin + (y - cy) * cos + cy
236
+ ];
237
+ }
238
+
239
+ function move (ax, ay, d, x, y) {
240
+ var sqrt = Math.sqrt(ax * ax + ay * ay);
241
+ return [
242
+ ax * d / sqrt + x,
243
+ ay * d / sqrt + y
244
+ ];
245
+ }
246
+
247
+ function scale (cx, cy, times, x, y) {
248
+ return [
249
+ times * (x - cx) + cx,
250
+ times * (y - cy) + cy
251
+ ];
252
+ }
253
+
254
+ function getLoopColors (num, alpha) {
255
+ if (alpha === void 0) { alpha = 1; }
256
+ var colorList = [
257
+ 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
258
+ 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
259
+ 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
260
+ 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
261
+ 'rgba(234,124,204,' + alpha + ")"
262
+ ];
263
+ var colors = [];
264
+ if (num <= colorList.length) {
265
+ return colorList;
266
+ }
267
+ else {
268
+ if (num % colorList.length == 0) {
269
+ for (var i = 0; i < (num / colorList.length); i++) {
270
+ colors = colors.concat(colorList);
271
+ }
272
+ }
273
+ else {
274
+ for (var j = 1; j < (num / colorList.length); j++) {
275
+ colors = colors.concat(colorList);
276
+ }
277
+ if (num % colorList.length == 1) {
278
+ colors = colors.concat(colorList[4]);
279
+ }
280
+ else {
281
+ for (var k = 0; k < num % colorList.length; k++) {
282
+ colors = colors.concat(colorList[k]);
283
+ }
284
+ }
285
+ }
286
+ }
287
+ return colors;
288
+ }
289
+
290
+ var $timers = [];
291
+ var $interval = 13;
292
+ var $timerId;
293
+ function animation (doback, duration, callback) {
294
+ if (duration === void 0) { duration = 400; }
295
+ if (callback === void 0) { callback = function () { }; }
296
+ var clock = {
297
+ "timer": function (tick, duration, callback) {
298
+ if (!tick) {
299
+ throw new Error('Tick is required!');
300
+ }
301
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
302
+ $timers.push({
303
+ "id": id,
304
+ "createTime": new Date(),
305
+ "tick": tick,
306
+ "duration": duration,
307
+ "callback": callback
308
+ });
309
+ clock.start();
310
+ return id;
311
+ },
312
+ "start": function () {
313
+ if (!$timerId) {
314
+ $timerId = setInterval(clock.tick, $interval);
315
+ }
316
+ },
317
+ "tick": function () {
318
+ var createTime, flag, tick, callback, timer, duration, passTime;
319
+ var timers = $timers;
320
+ $timers = [];
321
+ $timers.length = 0;
322
+ for (flag = 0; flag < timers.length; flag++) {
323
+ timer = timers[flag];
324
+ createTime = timer.createTime;
325
+ tick = timer.tick;
326
+ duration = timer.duration;
327
+ callback = timer.callback;
328
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
329
+ passTime = passTime > 1 ? 1 : passTime;
330
+ tick(passTime);
331
+ if (passTime < 1 && timer.id) {
332
+ $timers.push(timer);
333
+ }
334
+ else {
335
+ callback(passTime);
336
+ }
337
+ }
338
+ if ($timers.length <= 0) {
339
+ clock.stop();
340
+ }
341
+ },
342
+ "stop": function () {
343
+ if ($timerId) {
344
+ clearInterval($timerId);
345
+ $timerId = null;
346
+ }
347
+ }
348
+ };
349
+ var id = clock.timer(function (deep) {
350
+ doback(deep);
351
+ }, duration, callback);
352
+ return function () {
353
+ var i;
354
+ for (i in $timers) {
355
+ if ($timers[i].id == id) {
356
+ $timers[i].id = void 0;
357
+ return;
358
+ }
359
+ }
360
+ };
361
+ }
362
+
363
+ function ruler (maxValue, minValue, num, option) {
364
+ if (maxValue < minValue) {
365
+ var temp = minValue;
366
+ minValue = maxValue;
367
+ maxValue = temp;
368
+ }
369
+ else if (maxValue == minValue) {
370
+ return [maxValue];
371
+ }
372
+ var times100 = (function (_value) {
373
+ var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
374
+ var _times100 = -1, _tiemsValue = _value;
375
+ while (_times100_base == 10 ?
376
+ (_tiemsValue >= -100 && _tiemsValue <= 100)
377
+ :
378
+ (_tiemsValue <= -100 || _tiemsValue >= 100)) {
379
+ _times100 += 1;
380
+ _tiemsValue *= _times100_base;
381
+ }
382
+ if (_times100_base == 10) {
383
+ return Math.pow(10, _times100);
384
+ }
385
+ else {
386
+ var temp = "0.";
387
+ for (var i = 1; i < _times100; i++) {
388
+ temp += "0";
389
+ }
390
+ return +(temp + "1");
391
+ }
392
+ })(maxValue - minValue);
393
+ var distance100_oral = Math.ceil((maxValue - minValue) * times100 / num);
394
+ var getResult = function (changValue) {
395
+ var distance100 = {
396
+ 3: 2,
397
+ 4: 5,
398
+ 6: 5,
399
+ 7: 5,
400
+ 8: 10,
401
+ 9: 10,
402
+ 11: 10,
403
+ 12: 10,
404
+ 13: 15,
405
+ 14: 15,
406
+ 16: 15,
407
+ 17: 15,
408
+ 18: 20,
409
+ 19: 20,
410
+ 21: 20,
411
+ 22: 20,
412
+ 23: 25,
413
+ 24: 25,
414
+ 26: 25,
415
+ 27: 25
416
+ }[distance100_oral + changValue] || (distance100_oral + changValue);
417
+ var distance = distance100 / times100;
418
+ var begin = Math.floor(minValue / distance) * distance;
419
+ var rulerArray = [];
420
+ rulerArray.push(begin);
421
+ for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
422
+ rulerArray.push(begin + distance * index);
423
+ }
424
+ return rulerArray;
425
+ };
426
+ var rulerArray = getResult(0);
427
+ var balanceMax = function () {
428
+ var rulerArray_temp = [];
429
+ var changeDist = rulerArray[rulerArray.length - 1] - (option === null || option === void 0 ? void 0 : option.max);
430
+ for (var index = 0; index < rulerArray.length; index++) {
431
+ if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) ;
432
+ else {
433
+ rulerArray_temp.push(rulerArray[index] - changeDist);
434
+ }
435
+ }
436
+ return rulerArray_temp;
437
+ };
438
+ var balanceMin = function () {
439
+ var rulerArray_temp = [];
440
+ var changeDist = rulerArray[0] - (option === null || option === void 0 ? void 0 : option.min);
441
+ for (var index = 0; index < rulerArray.length; index++) {
442
+ rulerArray_temp[index] = rulerArray[index] - changeDist;
443
+ if (maxValue <= rulerArray_temp[index])
444
+ break;
445
+ }
446
+ return rulerArray_temp;
447
+ };
448
+ if (option) {
449
+ if ('max' in option && 'min' in option && option.max >= maxValue && option.min <= minValue) {
450
+ var isAnswer = function () {
451
+ if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max)
452
+ return true;
453
+ var rulerArray_max = balanceMax();
454
+ if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
455
+ rulerArray = rulerArray_max;
456
+ return true;
457
+ }
458
+ var rulerArray_min = balanceMin();
459
+ if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
460
+ rulerArray = rulerArray_min;
461
+ return true;
462
+ }
463
+ };
464
+ if (isAnswer())
465
+ return rulerArray;
466
+ for (var changValue = 1; changValue < 100; changValue++) {
467
+ rulerArray = getResult(changValue);
468
+ if (isAnswer())
469
+ return rulerArray;
470
+ rulerArray = getResult(-changValue);
471
+ if (isAnswer())
472
+ return rulerArray;
473
+ }
474
+ }
475
+ if ('max' in option && option.max >= maxValue) {
476
+ if (option.max < rulerArray[rulerArray.length - 1]) {
477
+ rulerArray = balanceMax();
478
+ }
479
+ }
480
+ else if ('min' in option && option.min <= minValue) {
481
+ if (option.min > rulerArray[0]) {
482
+ rulerArray = balanceMin();
483
+ }
484
+ }
485
+ }
486
+ for (var index = 0; index < rulerArray.length; index++) {
487
+ var valStr = rulerArray[index] + "";
488
+ if (/\./.test(valStr)) {
489
+ if (/9{7,}$/.test(valStr)) {
490
+ valStr = valStr.replace(/9{7,}$/, '');
491
+ rulerArray[index] = +(valStr.substring(0, valStr.length - 1) + ((+valStr[valStr.length - 1]) + 1));
492
+ }
493
+ else if (/0{7,}\d$/.test(valStr)) {
494
+ rulerArray[index] = +(valStr.replace(/0{7,}\d$/, ''));
495
+ }
496
+ }
497
+ }
498
+ return rulerArray;
499
+ }
500
+
501
+ /******************************************************************************
502
+ Copyright (c) Microsoft Corporation.
503
+
504
+ Permission to use, copy, modify, and/or distribute this software for any
505
+ purpose with or without fee is hereby granted.
506
+
507
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
508
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
509
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
510
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
511
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
512
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
513
+ PERFORMANCE OF THIS SOFTWARE.
514
+ ***************************************************************************** */
515
+ /* global Reflect, Promise, SuppressedError, Symbol */
516
+
517
+ var extendStatics = function(d, b) {
518
+ extendStatics = Object.setPrototypeOf ||
519
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
520
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
521
+ return extendStatics(d, b);
522
+ };
523
+
524
+ function __extends(d, b) {
525
+ if (typeof b !== "function" && b !== null)
526
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
527
+ extendStatics(d, b);
528
+ function __() { this.constructor = d; }
529
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
530
+ }
531
+
532
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
533
+ var e = new Error(message);
534
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
535
+ };
536
+
537
+ var XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"];
538
+
539
+ function toNode(tagname) {
540
+ return document.createElementNS('http://www.w3.org/2000/svg', tagname);
541
+ }
542
+ var _setAttribute = function (el, key, value) {
543
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
544
+ el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
545
+ }
546
+ else {
547
+ el.setAttribute(key, value + "");
548
+ }
549
+ };
550
+ var setAttribute = _setAttribute;
551
+ function getAttribute(el, key) {
552
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1)
553
+ key = 'xlink:' + key;
554
+ return el.getAttribute(key);
555
+ }
556
+ function full(el, config) {
557
+ _setAttribute(el, "stroke", config.strokeStyle);
558
+ _setAttribute(el, "fill", config.fillStyle);
559
+ _setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
560
+ }
561
+ function fill(el, config) {
562
+ _setAttribute(el, "fill", config.fillStyle);
563
+ }
564
+ function stroke(el, config) {
565
+ _setAttribute(el, "stroke", config.strokeStyle);
566
+ _setAttribute(el, "fill", "none");
567
+ _setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
568
+ }
569
+
570
+ function setStyle (el, styles) {
571
+ for (var key in styles) {
572
+ el.style[key] = styles[key];
573
+ }
574
+ }
575
+
576
+ var rotate = function (cx, cy, deg, x, y) {
577
+ var cos = Math.cos(deg), sin = Math.sin(deg);
578
+ return [
579
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
580
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
581
+ ];
582
+ };
583
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
584
+ if (rotateA < 0) {
585
+ beginA += rotateA;
586
+ rotateA *= -1;
587
+ }
588
+ var temp = [];
589
+ var p;
590
+ p = rotate(0, 0, beginA, r1, 0);
591
+ temp[0] = p[0];
592
+ temp[1] = p[1];
593
+ p = rotate(0, 0, rotateA, p[0], p[1]);
594
+ temp[2] = p[0];
595
+ temp[3] = p[1];
596
+ p = rotate(0, 0, beginA, r2, 0);
597
+ temp[4] = p[0];
598
+ temp[5] = p[1];
599
+ p = rotate(0, 0, rotateA, p[0], p[1]);
600
+ temp[6] = p[0];
601
+ temp[7] = p[1];
602
+ doback(beginA, beginA + rotateA, temp[0] + cx, temp[1] + cy, temp[4] + cx, temp[5] + cy, temp[2] + cx, temp[3] + cy, temp[6] + cx, temp[7] + cy, (r2 - r1) * 0.5);
603
+ }
604
+
605
+ var initDefs = function (el) {
606
+ var defs = el.getElementsByTagName('defs');
607
+ if (defs.length <= 0) {
608
+ var newDefs = toNode("defs");
609
+ el.appendChild(newDefs);
610
+ return newDefs;
611
+ }
612
+ else {
613
+ return defs[0];
614
+ }
615
+ };
616
+ var initText$1 = function (el, config, x, y, deg) {
617
+ if (el.nodeName.toLowerCase() !== "text")
618
+ throw new Error("Need a <text> !");
619
+ setAttribute(el, "dy", {
620
+ top: config["fontSize"] * 0.5,
621
+ middle: 0,
622
+ bottom: -config["fontSize"] * 0.5,
623
+ }[config.textBaseline]);
624
+ setStyle(el, {
625
+ "text-anchor": {
626
+ left: "start",
627
+ right: "end",
628
+ center: "middle",
629
+ }[config.textAlign],
630
+ "dominant-baseline": "central",
631
+ "font-size": config["fontSize"] + "px",
632
+ "font-family": config["fontFamily"],
633
+ });
634
+ setAttribute(el, "x", x);
635
+ setAttribute(el, "y", y);
636
+ if (typeof deg == "number") {
637
+ deg = deg % 360;
638
+ setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
639
+ }
640
+ };
641
+ var initCircle$1 = function (el, cx, cy, r) {
642
+ if (el.nodeName.toLowerCase() !== "circle")
643
+ throw new Error("Need a <circle> !");
644
+ setAttribute(el, "cx", cx);
645
+ setAttribute(el, "cy", cy);
646
+ setAttribute(el, "r", r);
647
+ };
648
+ var initPath = function (el, path) {
649
+ if (el.nodeName.toLowerCase() !== "path")
650
+ throw new Error("Need a <path> !");
651
+ setAttribute(el, "d", path);
652
+ };
653
+ var initRect$1 = function (el, x, y, width, height) {
654
+ if (el.nodeName.toLowerCase() !== "rect")
655
+ throw new Error("Need a <rect> !");
656
+ if (height < 0) {
657
+ height *= -1;
658
+ y -= height;
659
+ }
660
+ if (width < 0) {
661
+ width *= -1;
662
+ x -= width;
663
+ }
664
+ setAttribute(el, "x", x);
665
+ setAttribute(el, "y", y);
666
+ setAttribute(el, "width", width);
667
+ setAttribute(el, "height", height);
668
+ };
669
+ var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
670
+ if (el.nodeName.toLowerCase() !== "path")
671
+ throw new Error("Need a <path> !");
672
+ beginDeg = (beginDeg / 180) * Math.PI;
673
+ deg = (deg / 180) * Math.PI;
674
+ beginDeg = beginDeg % (Math.PI * 2);
675
+ if (r1 > r2) {
676
+ var temp = r1;
677
+ r1 = r2;
678
+ r2 = temp;
679
+ }
680
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
681
+ deg = Math.PI * 1.999999;
682
+ }
683
+ else {
684
+ deg = deg % (Math.PI * 2);
685
+ }
686
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
687
+ var f = endA - beginA > Math.PI ? 1 : 0;
688
+ var d = "M" + begInnerX + " " + begInnerY;
689
+ if (r < 0)
690
+ r = -r;
691
+ d +=
692
+ "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
693
+ if (config.arcEndCap == "round")
694
+ d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
695
+ else if (config.arcEndCap == "-round")
696
+ d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
697
+ else
698
+ d += "L" + endOuterX + " " + endOuterY;
699
+ d +=
700
+ "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
701
+ if (config.arcStartCap == "round")
702
+ d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
703
+ else if (config.arcStartCap == "-round")
704
+ d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
705
+ else
706
+ d += "L" + begInnerX + " " + begInnerY;
707
+ if (config.arcStartCap == "butt")
708
+ d += "Z";
709
+ setAttribute(el, "d", d);
710
+ });
711
+ };
712
+
713
+ var enhanceGradient$1 = function (gradient, gradientId) {
714
+ var enhanceGradient = {
715
+ "value": function () {
716
+ return "url(#" + gradientId + ")";
717
+ },
718
+ "setColor": function (stop, color) {
719
+ var stopEl = toNode("stop");
720
+ gradient.appendChild(stopEl);
721
+ setAttribute(stopEl, "offset", (stop * 100) + "%");
722
+ setAttribute(stopEl, "style", "stop-color:" + color + ";");
723
+ return enhanceGradient;
724
+ }
725
+ };
726
+ return enhanceGradient;
727
+ };
728
+ var linearGradient$1 = function (el, x0, y0, x1, y1) {
729
+ var defs = initDefs(el);
730
+ var gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random();
731
+ var linearGradient = toNode("linearGradient");
732
+ defs.appendChild(linearGradient);
733
+ setAttribute(linearGradient, "id", gradientId);
734
+ setAttribute(linearGradient, "x1", x0 + "%");
735
+ setAttribute(linearGradient, "y1", y0 + "%");
736
+ setAttribute(linearGradient, "x2", x1 + "%");
737
+ setAttribute(linearGradient, "y2", y1 + "%");
738
+ return enhanceGradient$1(linearGradient, gradientId);
739
+ };
740
+ var radialGradient$1 = function (el, cx, cy, r) {
741
+ var defs = initDefs(el);
742
+ var gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random();
743
+ var radialGradient = toNode("radialGradient");
744
+ defs.appendChild(radialGradient);
745
+ setAttribute(radialGradient, "id", gradientId);
746
+ setAttribute(radialGradient, "cx", cx + "%");
747
+ setAttribute(radialGradient, "cy", cy + "%");
748
+ setAttribute(radialGradient, "r", r + "%");
749
+ return enhanceGradient$1(radialGradient, gradientId);
750
+ };
751
+
752
+ var SVG$1 = (function () {
753
+ function SVG(svg) {
754
+ this.name = "SVG";
755
+ this.__config = {
756
+ fillStyle: "#000",
757
+ strokeStyle: "#000",
758
+ lineWidth: 1,
759
+ textAlign: "left",
760
+ textBaseline: "middle",
761
+ "fontSize": 16,
762
+ "fontFamily": "sans-serif",
763
+ "arcStartCap": "butt",
764
+ "arcEndCap": "butt",
765
+ lineDash: [],
766
+ };
767
+ this.__path = "";
768
+ this.__currentPosition = [];
769
+ this.__svg = svg;
770
+ }
771
+ SVG.prototype.config = function (params) {
772
+ if (typeof params !== "object") {
773
+ return this.__config[params];
774
+ }
775
+ else {
776
+ for (var key in params) {
777
+ this.__config[key] = params[key];
778
+ }
779
+ }
780
+ return this;
781
+ };
782
+ SVG.prototype.useEl = function (el) {
783
+ this.__useEl = el;
784
+ return this;
785
+ };
786
+ SVG.prototype.getEl = function () {
787
+ return this.__useEl;
788
+ };
789
+ SVG.prototype.appendEl = function (el, context) {
790
+ context = context || this.__svg;
791
+ if (typeof el == "string")
792
+ el = toNode(el);
793
+ context.appendChild(el);
794
+ this.__useEl = el;
795
+ return this;
796
+ };
797
+ SVG.prototype.appendBoard = function (el, context) {
798
+ var _el = el;
799
+ if (typeof el == "string")
800
+ _el =
801
+ {
802
+ text: "text",
803
+ path: "path",
804
+ arc: "path",
805
+ circle: "circle",
806
+ rect: "rect",
807
+ }[el] || "";
808
+ if (_el == "")
809
+ throw new Error("Unsupported drawing method:" + el);
810
+ return this.appendEl(_el, context);
811
+ };
812
+ SVG.prototype.remove = function () {
813
+ if (!this.__useEl) {
814
+ throw new Error("Currently, no node can be deleted.");
815
+ }
816
+ else {
817
+ this.__useEl.parentNode.removeChild(this.__useEl);
818
+ }
819
+ return this;
820
+ };
821
+ SVG.prototype.attr = function (params) {
822
+ if (!this.__useEl)
823
+ throw new Error("Currently, no node can be modified or viewed.");
824
+ if (typeof params !== "object") {
825
+ return getAttribute(this.__useEl, params);
826
+ }
827
+ else {
828
+ for (var key in params) {
829
+ setAttribute(this.__useEl, key, params[key]);
830
+ }
831
+ return this;
832
+ }
833
+ };
834
+ SVG.prototype.fillText = function (text, x, y, deg) {
835
+ if (deg === void 0) { deg = 0; }
836
+ initText$1(this.__useEl, this.__config, x, y, deg);
837
+ this.__useEl.textContent = text;
838
+ fill(this.__useEl, this.__config);
839
+ return this;
840
+ };
841
+ SVG.prototype.strokeText = function (text, x, y, deg) {
842
+ if (deg === void 0) { deg = 0; }
843
+ initText$1(this.__useEl, this.__config, x, y, deg);
844
+ this.__useEl.textContent = text;
845
+ stroke(this.__useEl, this.__config);
846
+ return this;
847
+ };
848
+ SVG.prototype.fullText = function (text, x, y, deg) {
849
+ if (deg === void 0) { deg = 0; }
850
+ initText$1(this.__useEl, this.__config, x, y, deg);
851
+ this.__useEl.textContent = text;
852
+ full(this.__useEl, this.__config);
853
+ return this;
854
+ };
855
+ SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
856
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
857
+ fill(this.__useEl, this.__config);
858
+ return this;
859
+ };
860
+ SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
861
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
862
+ stroke(this.__useEl, this.__config);
863
+ return this;
864
+ };
865
+ SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
866
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
867
+ full(this.__useEl, this.__config);
868
+ return this;
869
+ };
870
+ SVG.prototype.fillCircle = function (cx, cy, r) {
871
+ initCircle$1(this.__useEl, cx, cy, r);
872
+ fill(this.__useEl, this.__config);
873
+ return this;
874
+ };
875
+ SVG.prototype.strokeCircle = function (cx, cy, r) {
876
+ initCircle$1(this.__useEl, cx, cy, r);
877
+ stroke(this.__useEl, this.__config);
878
+ return this;
879
+ };
880
+ SVG.prototype.fullCircle = function (cx, cy, r) {
881
+ initCircle$1(this.__useEl, cx, cy, r);
882
+ full(this.__useEl, this.__config);
883
+ return this;
884
+ };
885
+ SVG.prototype.fillRect = function (x, y, width, height) {
886
+ initRect$1(this.__useEl, x, y, width, height);
887
+ fill(this.__useEl, this.__config);
888
+ return this;
889
+ };
890
+ SVG.prototype.strokeRect = function (x, y, width, height) {
891
+ initRect$1(this.__useEl, x, y, width, height);
892
+ stroke(this.__useEl, this.__config);
893
+ return this;
894
+ };
895
+ SVG.prototype.fullRect = function (x, y, width, height) {
896
+ initRect$1(this.__useEl, x, y, width, height);
897
+ full(this.__useEl, this.__config);
898
+ return this;
899
+ };
900
+ SVG.prototype.beginPath = function () {
901
+ this.__currentPosition = [];
902
+ this.__path = "";
903
+ return this;
904
+ };
905
+ SVG.prototype.closePath = function () {
906
+ this.__path += "Z";
907
+ return this;
908
+ };
909
+ SVG.prototype.moveTo = function (x, y) {
910
+ this.__currentPosition = [x, y];
911
+ this.__path += "M" + x + " " + y;
912
+ return this;
913
+ };
914
+ SVG.prototype.lineTo = function (x, y) {
915
+ this.__currentPosition = [x, y];
916
+ this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
917
+ return this;
918
+ };
919
+ SVG.prototype.fill = function () {
920
+ initPath(this.__useEl, this.__path);
921
+ fill(this.__useEl, this.__config);
922
+ return this;
923
+ };
924
+ SVG.prototype.stroke = function () {
925
+ initPath(this.__useEl, this.__path);
926
+ stroke(this.__useEl, this.__config);
927
+ return this;
928
+ };
929
+ SVG.prototype.full = function () {
930
+ initPath(this.__useEl, this.__path);
931
+ full(this.__useEl, this.__config);
932
+ return this;
933
+ };
934
+ SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
935
+ var begPosition = rotate$1(x, y, (beginDeg / 180) * Math.PI, x + r, y);
936
+ var endPosition = rotate$1(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
937
+ if (this.__path == "") {
938
+ this.__path += "M" + begPosition[0] + "," + begPosition[1];
939
+ }
940
+ else if (begPosition[0] != this.__currentPosition[0] ||
941
+ begPosition[1] != this.__currentPosition[1]) {
942
+ this.__path += "L" + begPosition[0] + "," + begPosition[1];
943
+ }
944
+ this.__path +=
945
+ "A" +
946
+ r +
947
+ "," +
948
+ r +
949
+ " 0 " +
950
+ (deg > 180 || deg < -180 ? 1 : 0) +
951
+ "," +
952
+ (deg > 0 ? 1 : 0) +
953
+ " " +
954
+ endPosition[0] +
955
+ "," +
956
+ endPosition[1];
957
+ return this;
958
+ };
959
+ SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
960
+ this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
961
+ return this;
962
+ };
963
+ SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
964
+ this.__path +=
965
+ "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
966
+ return this;
967
+ };
968
+ SVG.prototype.bind = function (eventType, callback) {
969
+ this.__useEl.addEventListener(eventType, function (event) {
970
+ callback.call(this, event, this);
971
+ }, false);
972
+ return this;
973
+ };
974
+ SVG.prototype.createLinearGradient = function (x0, y0, x1, y1) {
975
+ return linearGradient$1(this.__svg, x0, y0, x1, y1);
976
+ };
977
+ SVG.prototype.createRadialGradient = function (cx, cy, r) {
978
+ return radialGradient$1(this.__svg, cx, cy, r);
979
+ };
980
+ return SVG;
981
+ }());
982
+
983
+ var SVG = (function (_super) {
984
+ __extends(SVG, _super);
985
+ function SVG(el) {
986
+ if (!el) {
987
+ throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
988
+ }
989
+ var width = el.clientWidth, height = el.clientHeight;
990
+ var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
991
+ el.appendChild(ViewSVG);
992
+ ViewSVG.setAttribute("width", width + "");
993
+ ViewSVG.setAttribute("height", height + "");
994
+ ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
995
+ return _super.call(this, ViewSVG) || this;
996
+ }
997
+ return SVG;
998
+ }(SVG$1));
999
+
1000
+ var initText = function (painter, config, x, y, deg) {
1001
+ painter.beginPath();
1002
+ painter.translate(x, y);
1003
+ painter.rotate(deg);
1004
+ painter.font =
1005
+ config.fontStyle +
1006
+ " " +
1007
+ config.fontWeight +
1008
+ " " +
1009
+ config.fontSize +
1010
+ "px " +
1011
+ config.fontFamily;
1012
+ return painter;
1013
+ };
1014
+ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
1015
+ if (r1 > r2) {
1016
+ var temp = r1;
1017
+ r1 = r2;
1018
+ r2 = temp;
1019
+ }
1020
+ beginDeg = beginDeg % (Math.PI * 2);
1021
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
1022
+ deg = Math.PI * 2;
1023
+ }
1024
+ else {
1025
+ deg = deg % (Math.PI * 2);
1026
+ }
1027
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
1028
+ if (r < 0)
1029
+ r = -r;
1030
+ painter.beginPath();
1031
+ painter.moveTo(begInnerX, begInnerY);
1032
+ painter.arc(cx, cy, r1, beginA, endA, false);
1033
+ if (config.arcEndCap == "round")
1034
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
1035
+ else if (config.arcEndCap == "-round")
1036
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
1037
+ else
1038
+ painter.lineTo(endOuterX, endOuterY);
1039
+ painter.arc(cx, cy, r2, endA, beginA, true);
1040
+ if (config.arcStartCap == "round")
1041
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
1042
+ else if (config.arcStartCap == "-round")
1043
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
1044
+ else
1045
+ painter.lineTo(begInnerX, begInnerY);
1046
+ });
1047
+ if (config.arcStartCap == "butt")
1048
+ painter.closePath();
1049
+ return painter;
1050
+ };
1051
+ var initCircle = function (painter, cx, cy, r) {
1052
+ painter.beginPath();
1053
+ painter.moveTo(cx + r, cy);
1054
+ painter.arc(cx, cy, r, 0, Math.PI * 2);
1055
+ return painter;
1056
+ };
1057
+ var initRect = function (painter, x, y, width, height) {
1058
+ painter.beginPath();
1059
+ painter.rect(x, y, width, height);
1060
+ return painter;
1061
+ };
1062
+
1063
+ function texts (painter, contents, width, height, doback) {
1064
+ var lineNumber = 0, content = "";
1065
+ for (var i = 0; i < contents.length; i++) {
1066
+ if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
1067
+ lineNumber += 1;
1068
+ doback(content, (lineNumber - 0.5) * height);
1069
+ content = contents[i];
1070
+ }
1071
+ else if (i == contents.length - 1) {
1072
+ lineNumber += 1;
1073
+ doback(content + contents[i], (lineNumber - 0.5) * height);
1074
+ }
1075
+ else {
1076
+ content += contents[i];
1077
+ }
1078
+ }
1079
+ return lineNumber * height;
1080
+ }
1081
+
1082
+ var Painter = (function () {
1083
+ function Painter(canvas, opts, region, isPainter, scaleSize) {
1084
+ if (opts === void 0) { opts = {}; }
1085
+ if (isPainter === void 0) { isPainter = false; }
1086
+ this.__region = null;
1087
+ this.__onlyRegion = false;
1088
+ this.__onlyView = false;
1089
+ this.__specialConfig = {
1090
+ "fontSize": 16,
1091
+ "fontFamily": "sans-serif",
1092
+ "fontWeight": 400,
1093
+ "fontStyle": "normal",
1094
+ "arcStartCap": 'butt',
1095
+ "arcEndCap": 'butt'
1096
+ };
1097
+ this.__initConfig = {
1098
+ "fillStyle": 'black',
1099
+ "strokeStyle": 'black',
1100
+ "lineWidth": 1,
1101
+ "textAlign": 'left',
1102
+ "textBaseline": 'middle',
1103
+ "lineDash": [],
1104
+ "shadowBlur": 0,
1105
+ "shadowColor": "black"
1106
+ };
1107
+ this.painter = canvas.getContext("2d", opts);
1108
+ this.__region = region;
1109
+ this.__isPainter = isPainter;
1110
+ this.painter.textBaseline = 'middle';
1111
+ this.painter.textAlign = 'left';
1112
+ }
1113
+ Painter.prototype.useConfig = function (key, value) {
1114
+ if (this.__region && !this.__onlyView) {
1115
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
1116
+ this.__region.useConfig(key, value);
1117
+ }
1118
+ }
1119
+ if (this.__isPainter && this.__onlyRegion)
1120
+ return this;
1121
+ if (key == 'lineDash') {
1122
+ if (this.painter.setLineDash)
1123
+ this.painter.setLineDash(value);
1124
+ }
1125
+ else if (key in this.__specialConfig) {
1126
+ if (key == 'fontSize') {
1127
+ value = Math.round(value);
1128
+ }
1129
+ this.__specialConfig[key] = value;
1130
+ }
1131
+ else if (key in this.__initConfig) {
1132
+ this.painter[key] = value;
1133
+ }
1134
+ else {
1135
+ throw new Error('Illegal configuration item of painter : ' + key + " !");
1136
+ }
1137
+ return this;
1138
+ };
1139
+ Painter.prototype.fillText = function (text, x, y, deg) {
1140
+ if (deg === void 0) { deg = 0; }
1141
+ if (this.__region && !this.__onlyView)
1142
+ this.__region.fillText(text, x, y, deg);
1143
+ if (this.__isPainter && this.__onlyRegion)
1144
+ return this;
1145
+ this.painter.save();
1146
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
1147
+ this.painter.restore();
1148
+ return this;
1149
+ };
1150
+ Painter.prototype.strokeText = function (text, x, y, deg) {
1151
+ if (deg === void 0) { deg = 0; }
1152
+ if (this.__region && !this.__onlyView)
1153
+ this.__region.strokeText(text, x, y, deg);
1154
+ if (this.__isPainter && this.__onlyRegion)
1155
+ return this;
1156
+ this.painter.save();
1157
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
1158
+ this.painter.restore();
1159
+ return this;
1160
+ };
1161
+ Painter.prototype.fullText = function (text, x, y, deg) {
1162
+ if (deg === void 0) { deg = 0; }
1163
+ if (this.__region && !this.__onlyView)
1164
+ this.__region.fullText(text, x, y, deg);
1165
+ if (this.__isPainter && this.__onlyRegion)
1166
+ return this;
1167
+ this.painter.save();
1168
+ initText(this.painter, this.__specialConfig, x, y, deg);
1169
+ this.painter.fillText(text, 0, 0);
1170
+ this.painter.strokeText(text, 0, 0);
1171
+ this.painter.restore();
1172
+ return this;
1173
+ };
1174
+ Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
1175
+ var _this = this;
1176
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1177
+ if (deg === void 0) { deg = 0; }
1178
+ var h = 0;
1179
+ if (this.__region && !this.__onlyView)
1180
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1181
+ if (this.__isPainter && this.__onlyRegion)
1182
+ return h;
1183
+ this.painter.save();
1184
+ initText(this.painter, this.__specialConfig, x, y, deg);
1185
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1186
+ _this.painter.fillText(content, 0, top);
1187
+ });
1188
+ this.painter.restore();
1189
+ return height;
1190
+ };
1191
+ Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
1192
+ var _this = this;
1193
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1194
+ if (deg === void 0) { deg = 0; }
1195
+ var h = 0;
1196
+ if (this.__region && !this.__onlyView)
1197
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1198
+ if (this.__isPainter && this.__onlyRegion)
1199
+ return h;
1200
+ this.painter.save();
1201
+ initText(this.painter, this.__specialConfig, x, y, deg);
1202
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1203
+ _this.painter.strokeText(content, 0, top);
1204
+ });
1205
+ this.painter.restore();
1206
+ return height;
1207
+ };
1208
+ Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
1209
+ var _this = this;
1210
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1211
+ if (deg === void 0) { deg = 0; }
1212
+ var h = 0;
1213
+ if (this.__region && !this.__onlyView)
1214
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1215
+ if (this.__isPainter && this.__onlyRegion)
1216
+ return h;
1217
+ this.painter.save();
1218
+ initText(this.painter, this.__specialConfig, x, y, deg);
1219
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1220
+ _this.painter.fillText(content, 0, top);
1221
+ _this.painter.strokeText(content, 0, top);
1222
+ });
1223
+ this.painter.restore();
1224
+ return height;
1225
+ };
1226
+ Painter.prototype.beginPath = function () {
1227
+ if (this.__region && !this.__onlyView)
1228
+ this.__region.beginPath();
1229
+ if (this.__isPainter && this.__onlyRegion)
1230
+ return this;
1231
+ this.painter.beginPath();
1232
+ return this;
1233
+ };
1234
+ Painter.prototype.closePath = function () {
1235
+ if (this.__region && !this.__onlyView)
1236
+ this.__region.closePath();
1237
+ if (this.__isPainter && this.__onlyRegion)
1238
+ return this;
1239
+ this.painter.closePath();
1240
+ return this;
1241
+ };
1242
+ Painter.prototype.moveTo = function (x, y) {
1243
+ if (this.__region && !this.__onlyView)
1244
+ this.__region.moveTo(x, y);
1245
+ if (this.__isPainter && this.__onlyRegion)
1246
+ return this;
1247
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1248
+ return this;
1249
+ };
1250
+ Painter.prototype.lineTo = function (x, y) {
1251
+ if (this.__region && !this.__onlyView)
1252
+ this.__region.lineTo(x, y);
1253
+ if (this.__isPainter && this.__onlyRegion)
1254
+ return this;
1255
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1256
+ return this;
1257
+ };
1258
+ Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
1259
+ if (this.__region && !this.__onlyView)
1260
+ this.__region.arc(x, y, r, beginDeg, deg);
1261
+ if (this.__isPainter && this.__onlyRegion)
1262
+ return this;
1263
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
1264
+ return this;
1265
+ };
1266
+ Painter.prototype.fill = function () {
1267
+ if (this.__region && !this.__onlyView)
1268
+ this.__region.fill();
1269
+ if (this.__isPainter && this.__onlyRegion)
1270
+ return this;
1271
+ this.painter.fill();
1272
+ return this;
1273
+ };
1274
+ Painter.prototype.stroke = function () {
1275
+ if (this.__region && !this.__onlyView)
1276
+ this.__region.stroke();
1277
+ if (this.__isPainter && this.__onlyRegion)
1278
+ return this;
1279
+ this.painter.stroke();
1280
+ return this;
1281
+ };
1282
+ Painter.prototype.full = function () {
1283
+ if (this.__region && !this.__onlyView)
1284
+ this.__region.full();
1285
+ if (this.__isPainter && this.__onlyRegion)
1286
+ return this;
1287
+ this.painter.fill();
1288
+ this.painter.stroke();
1289
+ return this;
1290
+ };
1291
+ Painter.prototype.save = function () {
1292
+ if (this.__region && !this.__onlyView)
1293
+ this.__region.save();
1294
+ if (this.__isPainter && this.__onlyRegion)
1295
+ return this;
1296
+ this.painter.save();
1297
+ return this;
1298
+ };
1299
+ Painter.prototype.restore = function () {
1300
+ if (this.__region && !this.__onlyView)
1301
+ this.__region.restore();
1302
+ if (this.__isPainter && this.__onlyRegion)
1303
+ return this;
1304
+ this.painter.restore();
1305
+ return this;
1306
+ };
1307
+ Painter.prototype.clip = function () {
1308
+ if (this.__region && !this.__onlyView)
1309
+ this.__region.clip();
1310
+ if (this.__isPainter && this.__onlyRegion)
1311
+ return this;
1312
+ this.painter.clip();
1313
+ return this;
1314
+ };
1315
+ Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1316
+ if (this.__region && !this.__onlyView)
1317
+ this.__region.quadraticCurveTo(cpx, cpy, x, y);
1318
+ if (this.__isPainter && this.__onlyRegion)
1319
+ return this;
1320
+ this.painter.quadraticCurveTo(cpx, cpy, x, y);
1321
+ return this;
1322
+ };
1323
+ Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1324
+ if (this.__region && !this.__onlyView)
1325
+ this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1326
+ if (this.__isPainter && this.__onlyRegion)
1327
+ return this;
1328
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1329
+ return this;
1330
+ };
1331
+ Painter.prototype.clearRect = function (x, y, w, h) {
1332
+ if (this.__region && !this.__onlyView)
1333
+ this.__region.clearRect(x, y, w, h);
1334
+ if (this.__isPainter && this.__onlyRegion)
1335
+ return this;
1336
+ this.painter.clearRect(x, y, w, h);
1337
+ return this;
1338
+ };
1339
+ Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
1340
+ if (this.__region && !this.__onlyView)
1341
+ this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
1342
+ if (this.__isPainter && this.__onlyRegion)
1343
+ return this;
1344
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
1345
+ return this;
1346
+ };
1347
+ Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
1348
+ if (this.__region && !this.__onlyView)
1349
+ this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
1350
+ if (this.__isPainter && this.__onlyRegion)
1351
+ return this;
1352
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
1353
+ return this;
1354
+ };
1355
+ Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
1356
+ if (this.__region && !this.__onlyView)
1357
+ this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
1358
+ if (this.__isPainter && this.__onlyRegion)
1359
+ return this;
1360
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
1361
+ this.painter.fill();
1362
+ this.painter.stroke();
1363
+ return this;
1364
+ };
1365
+ Painter.prototype.fillCircle = function (cx, cy, r) {
1366
+ if (this.__region && !this.__onlyView)
1367
+ this.__region.fillCircle(cx, cy, r);
1368
+ if (this.__isPainter && this.__onlyRegion)
1369
+ return this;
1370
+ initCircle(this.painter, cx, cy, r).fill();
1371
+ return this;
1372
+ };
1373
+ Painter.prototype.strokeCircle = function (cx, cy, r) {
1374
+ if (this.__region && !this.__onlyView)
1375
+ this.__region.strokeCircle(cx, cy, r);
1376
+ if (this.__isPainter && this.__onlyRegion)
1377
+ return this;
1378
+ initCircle(this.painter, cx, cy, r).stroke();
1379
+ return this;
1380
+ };
1381
+ Painter.prototype.fullCircle = function (cx, cy, r) {
1382
+ if (this.__region && !this.__onlyView)
1383
+ this.__region.fullCircle(cx, cy, r);
1384
+ if (this.__isPainter && this.__onlyRegion)
1385
+ return this;
1386
+ initCircle(this.painter, cx, cy, r);
1387
+ this.painter.fill();
1388
+ this.painter.stroke();
1389
+ return this;
1390
+ };
1391
+ Painter.prototype.fillRect = function (x, y, width, height) {
1392
+ if (this.__region && !this.__onlyView)
1393
+ this.__region.fillRect(x, y, width, height);
1394
+ if (this.__isPainter && this.__onlyRegion)
1395
+ return this;
1396
+ initRect(this.painter, x, y, width, height).fill();
1397
+ return this;
1398
+ };
1399
+ Painter.prototype.strokeRect = function (x, y, width, height) {
1400
+ if (this.__region && !this.__onlyView)
1401
+ this.__region.strokeRect(x, y, width, height);
1402
+ if (this.__isPainter && this.__onlyRegion)
1403
+ return this;
1404
+ initRect(this.painter, x, y, width, height).stroke();
1405
+ return this;
1406
+ };
1407
+ Painter.prototype.fullRect = function (x, y, width, height) {
1408
+ if (this.__region && !this.__onlyView)
1409
+ this.__region.fullRect(x, y, width, height);
1410
+ if (this.__isPainter && this.__onlyRegion)
1411
+ return this;
1412
+ initRect(this.painter, x, y, width, height);
1413
+ this.painter.fill();
1414
+ this.painter.stroke();
1415
+ return this;
1416
+ };
1417
+ Painter.prototype.draw = function () {
1418
+ return Promise.resolve();
1419
+ };
1420
+ Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
1421
+ var _this = this;
1422
+ if (isImage === void 0) { isImage = false; }
1423
+ return new Promise(function (resolve) {
1424
+ if (_this.__region && !_this.__onlyView) {
1425
+ _this.__region.fillRect(x, y, w, h);
1426
+ }
1427
+ if (_this.__isPainter && _this.__onlyRegion) {
1428
+ resolve({});
1429
+ return;
1430
+ }
1431
+ if (typeof img == 'string' && !isImage) {
1432
+ var imgInstance_1 = new Image();
1433
+ imgInstance_1.onload = function () {
1434
+ _this.painter.drawImage(imgInstance_1, 0, 0, imgInstance_1.width, imgInstance_1.height, x, y, w, h);
1435
+ resolve({});
1436
+ };
1437
+ imgInstance_1.src = img;
1438
+ }
1439
+ else {
1440
+ _this.painter.drawImage(img, 0, 0, w, h, x, y, w, h);
1441
+ resolve({});
1442
+ }
1443
+ });
1444
+ };
1445
+ return Painter;
1446
+ }());
1447
+
1448
+ function assemble (begin, end, step, count) {
1449
+ var val = [];
1450
+ for (var index = 0; index < count; index++)
1451
+ val[index] = begin;
1452
+ return function () {
1453
+ for (var i = 0; i < count; i++) {
1454
+ if (val[i] + step < end) {
1455
+ val[i] = +(val[i] + step).toFixed(7);
1456
+ break;
1457
+ }
1458
+ else if (i < count - 1) {
1459
+ val[i] = begin;
1460
+ }
1461
+ }
1462
+ return val;
1463
+ };
1464
+ }
1465
+
1466
+ var enhanceGradient = function (gradient) {
1467
+ var enhanceGradient = {
1468
+ "value": function () {
1469
+ return gradient;
1470
+ },
1471
+ "setColor": function (stop, color) {
1472
+ gradient.addColorStop(stop, color);
1473
+ return enhanceGradient;
1474
+ }
1475
+ };
1476
+ return enhanceGradient;
1477
+ };
1478
+ var linearGradient = function (painter, x0, y0, x1, y1) {
1479
+ var gradient = painter.createLinearGradient(x0, y0, x1, y1);
1480
+ return enhanceGradient(gradient);
1481
+ };
1482
+ var radialGradient = function (painter, cx, cy, r) {
1483
+ var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
1484
+ return enhanceGradient(gradient);
1485
+ };
1486
+
1487
+ var Canvas$1 = (function (_super) {
1488
+ __extends(Canvas, _super);
1489
+ function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
1490
+ if (opts === void 0) { opts = {}; }
1491
+ if (scaleSize === void 0) { scaleSize = 1; }
1492
+ var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
1493
+ willReadFrequently: true,
1494
+ }) : undefined, true, scaleSize) || this;
1495
+ _this.name = "Canvas";
1496
+ _this.__regionList = {};
1497
+ _this.__regionAssemble = assemble(0, 255, 10, 3);
1498
+ _this.__scaleSize = scaleSize;
1499
+ _this.setRegion("");
1500
+ return _this;
1501
+ }
1502
+ Canvas.prototype.config = function (configs) {
1503
+ for (var key in configs) {
1504
+ this.useConfig(key, configs[key]);
1505
+ }
1506
+ return this;
1507
+ };
1508
+ Canvas.prototype.onlyRegion = function (flag) {
1509
+ this.__onlyRegion = flag;
1510
+ return this;
1511
+ };
1512
+ Canvas.prototype.onlyView = function (flag) {
1513
+ this.__onlyView = flag;
1514
+ return this;
1515
+ };
1516
+ Canvas.prototype.setRegion = function (regionName) {
1517
+ if (this.__region) {
1518
+ if (regionName) {
1519
+ if (this.__regionList[regionName] == void 0) {
1520
+ var tempColor = this.__regionAssemble();
1521
+ this.__regionList[regionName] =
1522
+ "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
1523
+ }
1524
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
1525
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
1526
+ }
1527
+ else {
1528
+ this.__region.useConfig("fillStyle", "#000000") &&
1529
+ this.__region.useConfig("strokeStyle", "#000000");
1530
+ }
1531
+ }
1532
+ return this;
1533
+ };
1534
+ Canvas.prototype.getRegion = function (x, y) {
1535
+ var _this = this;
1536
+ return new Promise(function (resolve) {
1537
+ var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
1538
+ data: [0, 0, 0, 0]
1539
+ };
1540
+ var currentRGBA = imgData.data;
1541
+ var doit = function () {
1542
+ if (_this.__region) {
1543
+ for (var key in _this.__regionList) {
1544
+ if ("rgb(" +
1545
+ currentRGBA[0] +
1546
+ "," +
1547
+ currentRGBA[1] +
1548
+ "," +
1549
+ currentRGBA[2] +
1550
+ ")" ==
1551
+ _this.__regionList[key]) {
1552
+ resolve(key);
1553
+ break;
1554
+ }
1555
+ }
1556
+ }
1557
+ resolve("");
1558
+ };
1559
+ if (currentRGBA) {
1560
+ doit();
1561
+ }
1562
+ else {
1563
+ imgData.then(function (data) {
1564
+ currentRGBA = data;
1565
+ doit();
1566
+ });
1567
+ }
1568
+ });
1569
+ };
1570
+ Canvas.prototype.textWidth = function (text) {
1571
+ this.painter.save();
1572
+ initText(this.painter, this.__specialConfig, 0, 0, 0);
1573
+ var width = this.painter.measureText(text + "").width;
1574
+ this.painter.restore();
1575
+ return width;
1576
+ };
1577
+ Canvas.prototype.getContext = function (isRegion) {
1578
+ if (isRegion === void 0) { isRegion = false; }
1579
+ return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
1580
+ };
1581
+ Canvas.prototype.getInfo = function () {
1582
+ return {
1583
+ width: this.painter.canvas.width / this.__scaleSize,
1584
+ height: this.painter.canvas.height / this.__scaleSize
1585
+ };
1586
+ };
1587
+ Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
1588
+ return linearGradient(this.painter, x0, y0, x1, y1);
1589
+ };
1590
+ Canvas.prototype.createRadialGradient = function (cx, cy, r) {
1591
+ return radialGradient(this.painter, cx, cy, r);
1592
+ };
1593
+ Canvas.prototype.getColor = function (x, y) {
1594
+ x *= this.__scaleSize;
1595
+ y *= this.__scaleSize;
1596
+ var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
1597
+ return ("rgba(" +
1598
+ currentRGBA[0] +
1599
+ "," +
1600
+ currentRGBA[1] +
1601
+ "," +
1602
+ currentRGBA[2] +
1603
+ "," +
1604
+ currentRGBA[3] +
1605
+ ")");
1606
+ };
1607
+ return Canvas;
1608
+ }(Painter));
1609
+
1610
+ function mergeOption (option, defaultOption) {
1611
+ for (var key in option) {
1612
+ defaultOption[key] = option[key];
1613
+ }
1614
+ return defaultOption;
1615
+ }
1616
+
1617
+ var Canvas = (function (_super) {
1618
+ __extends(Canvas, _super);
1619
+ function Canvas(el, option, width, height) {
1620
+ if (option === void 0) { option = {}; }
1621
+ if (width === void 0) { width = 0; }
1622
+ if (height === void 0) { height = 0; }
1623
+ var _this = this;
1624
+ if (!el) {
1625
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
1626
+ }
1627
+ option = mergeOption(option, {
1628
+ region: true,
1629
+ willReadFrequently: false
1630
+ });
1631
+ width = width || el.clientWidth;
1632
+ height = height || el.clientHeight;
1633
+ var ViewCanvas, RegionCanvas = null;
1634
+ var _el = el;
1635
+ if (_el._vislite_canvas_) {
1636
+ ViewCanvas = _el._vislite_canvas_[0];
1637
+ RegionCanvas = _el._vislite_canvas_[1];
1638
+ }
1639
+ else {
1640
+ ViewCanvas = document.createElement('canvas');
1641
+ el.appendChild(ViewCanvas);
1642
+ if (option.region) {
1643
+ RegionCanvas = document.createElement('canvas');
1644
+ }
1645
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
1646
+ el.setAttribute('vislite', 'Canvas');
1647
+ }
1648
+ var canvasArray = [RegionCanvas, ViewCanvas];
1649
+ for (var index = 0; index < canvasArray.length; index++) {
1650
+ var canvas = canvasArray[index];
1651
+ if (canvas) {
1652
+ canvas.style.width = width + "px";
1653
+ canvas.setAttribute('width', (index * width + width) + "");
1654
+ canvas.style.height = height + "px";
1655
+ canvas.setAttribute('height', (index * height + height) + "");
1656
+ }
1657
+ }
1658
+ _this = _super.call(this, ViewCanvas, RegionCanvas, {
1659
+ willReadFrequently: option.willReadFrequently,
1660
+ }, 2) || this;
1661
+ _this.__canvas = ViewCanvas;
1662
+ _this.painter.scale(2, 2);
1663
+ return _this;
1664
+ }
1665
+ Canvas.prototype.toDataURL = function () {
1666
+ var _this = this;
1667
+ return new Promise(function (resolve) {
1668
+ resolve(_this.__canvas.toDataURL());
1669
+ });
1670
+ };
1671
+ return Canvas;
1672
+ }(Canvas$1));
1673
+
1674
+ function getWebGLContext$1 (canvas, scale, opts, mode) {
1675
+ if (opts === void 0) { opts = {}; }
1676
+ if (mode === void 0) { mode = "scaleToFill"; }
1677
+ var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
1678
+ var painter = canvas.getContext("webgl", opts);
1679
+ for (var i = 0; i < names.length; i++) {
1680
+ try {
1681
+ painter = canvas.getContext(names[i], opts);
1682
+ }
1683
+ catch (e) { }
1684
+ if (painter)
1685
+ break;
1686
+ }
1687
+ if (!painter)
1688
+ throw new Error('Non canvas or browser does not support webgl.');
1689
+ var width = painter.canvas.width, height = painter.canvas.height;
1690
+ var scaleX = scale, scaleY = scale;
1691
+ if (mode == "aspectFit") {
1692
+ if (width > height) {
1693
+ scaleX *= height / width;
1694
+ }
1695
+ else if (height > width) {
1696
+ scaleY *= width / height;
1697
+ }
1698
+ }
1699
+ else if (mode == "aspectFill") {
1700
+ if (width > height) {
1701
+ scaleY *= width / height;
1702
+ }
1703
+ else if (height > width) {
1704
+ scaleX *= height / width;
1705
+ }
1706
+ }
1707
+ var viewWidth = width * scaleX;
1708
+ var viewHeight = height * scaleY;
1709
+ painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
1710
+ painter.depthFunc(painter.LEQUAL);
1711
+ painter.enable(painter.DEPTH_TEST);
1712
+ return painter;
1713
+ }
1714
+
1715
+ var getWebGLContext = (function (el, scale, mode) {
1716
+ if (scale === void 0) { scale = 1; }
1717
+ if (!el) {
1718
+ throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
1719
+ }
1720
+ var width = el.clientWidth, height = el.clientHeight;
1721
+ var ViewCanvas;
1722
+ var _el = el;
1723
+ if (_el._vislite_canvas_) {
1724
+ ViewCanvas = _el._vislite_canvas_;
1725
+ }
1726
+ else {
1727
+ ViewCanvas = document.createElement('canvas');
1728
+ el.appendChild(ViewCanvas);
1729
+ _el._vislite_canvas_ = ViewCanvas;
1730
+ el.setAttribute('vislite', 'WebGL');
1731
+ }
1732
+ ViewCanvas.style.width = width + "px";
1733
+ ViewCanvas.setAttribute('width', width + "");
1734
+ ViewCanvas.style.height = height + "px";
1735
+ ViewCanvas.setAttribute('height', height + "");
1736
+ return getWebGLContext$1(ViewCanvas, scale, {}, mode);
1737
+ });
1738
+
1739
+ var loadShader = function (painter, type, source) {
1740
+ var shader = painter.createShader(type);
1741
+ if (shader == null)
1742
+ throw new Error('Unable to create shader!');
1743
+ painter.shaderSource(shader, source);
1744
+ painter.compileShader(shader);
1745
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1746
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1747
+ return shader;
1748
+ };
1749
+ var useShader = function (painter, vshaderSource, fshaderSource) {
1750
+ var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1751
+ var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1752
+ var glProgram = painter.createProgram();
1753
+ painter.attachShader(glProgram, vertexShader);
1754
+ painter.attachShader(glProgram, fragmentShader);
1755
+ painter.linkProgram(glProgram);
1756
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1757
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
1758
+ return glProgram;
1759
+ };
1760
+ var ShaderObject = (function () {
1761
+ function ShaderObject(painter) {
1762
+ this.__painter = painter;
1763
+ }
1764
+ ShaderObject.prototype.use = function () {
1765
+ this.__painter.useProgram(this.program);
1766
+ return this;
1767
+ };
1768
+ ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
1769
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource);
1770
+ return this;
1771
+ };
1772
+ return ShaderObject;
1773
+ }());
1774
+
1775
+ var initTexture = function (painter, type, unit) {
1776
+ var texture = painter.createTexture();
1777
+ painter.activeTexture(painter['TEXTURE' + unit]);
1778
+ painter.bindTexture(type, texture);
1779
+ return texture;
1780
+ };
1781
+ var linkImage = function (painter, type, level, format, textureType, image) {
1782
+ painter.texImage2D(type, level, format, format, textureType, image);
1783
+ };
1784
+ var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
1785
+ var types = [
1786
+ painter.TEXTURE_CUBE_MAP_POSITIVE_X,
1787
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
1788
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
1789
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
1790
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
1791
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
1792
+ ];
1793
+ var target;
1794
+ for (var i = 0; i < types.length; i++) {
1795
+ if (images[i]) {
1796
+ target = types[i];
1797
+ painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
1798
+ painter.bindTexture(type, texture);
1799
+ painter.texImage2D(target, level, format, format, textureType, images[i]);
1800
+ }
1801
+ }
1802
+ painter.generateMipmap(type);
1803
+ };
1804
+ var TextureObject = (function () {
1805
+ function TextureObject(painter, type, unit) {
1806
+ if (unit === void 0) { unit = 0; }
1807
+ this.__painter = painter;
1808
+ this.__type = {
1809
+ "2d": painter.TEXTURE_2D,
1810
+ "cube": painter.TEXTURE_CUBE_MAP
1811
+ }[type];
1812
+ this.__texture = initTexture(painter, this.__type, unit);
1813
+ painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
1814
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
1815
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
1816
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
1817
+ }
1818
+ TextureObject.prototype.useImage = function (image) {
1819
+ linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
1820
+ return this;
1821
+ };
1822
+ TextureObject.prototype.useCube = function (images, width, height) {
1823
+ linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
1824
+ return this;
1825
+ };
1826
+ return TextureObject;
1827
+ }());
1828
+
1829
+ var newBuffer = function (painter) {
1830
+ return painter.createBuffer();
1831
+ };
1832
+ var writeBuffer = function (painter, data, isElement, usage) {
1833
+ var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1834
+ painter.bufferData(TYPE, data, usage);
1835
+ };
1836
+ var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
1837
+ painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
1838
+ painter.enableVertexAttribArray(location);
1839
+ };
1840
+ var BufferObject = (function () {
1841
+ function BufferObject(painter, isElement) {
1842
+ if (isElement === void 0) { isElement = false; }
1843
+ this.__painter = painter;
1844
+ this.__isElement = isElement;
1845
+ this.__buffer = newBuffer(painter);
1846
+ this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1847
+ }
1848
+ BufferObject.prototype.use = function () {
1849
+ this.__painter.bindBuffer(this.__type, this.__buffer);
1850
+ return this;
1851
+ };
1852
+ BufferObject.prototype.write = function (data) {
1853
+ writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
1854
+ this.__fsize = data.BYTES_PER_ELEMENT;
1855
+ return this;
1856
+ };
1857
+ BufferObject.prototype.divide = function (location, size, stride, offset) {
1858
+ if (offset === void 0) { offset = 0; }
1859
+ useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
1860
+ return this;
1861
+ };
1862
+ return BufferObject;
1863
+ }());
1864
+
1865
+ var rotateX = function (deg, x, y, z) {
1866
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1867
+ return [x, y * cos - z * sin, y * sin + z * cos];
1868
+ };
1869
+ var rotateY = function (deg, x, y, z) {
1870
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1871
+ return [z * sin + x * cos, y, z * cos - x * sin];
1872
+ };
1873
+ var rotateZ = function (deg, x, y, z) {
1874
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1875
+ return [x * cos - y * sin, x * sin + y * cos, z];
1876
+ };
1877
+ var Eoap = (function () {
1878
+ function Eoap(scale, center) {
1879
+ if (scale === void 0) { scale = 7; }
1880
+ if (center === void 0) { center = [107, 36]; }
1881
+ this.name = 'Eoap';
1882
+ this.__scale = scale;
1883
+ this.__center = center;
1884
+ }
1885
+ Eoap.prototype.use = function (λ, φ) {
1886
+ var p = rotateY((360 - φ) / 180 * Math.PI, 100 * this.__scale, 0, 0);
1887
+ p = rotateZ(λ / 180 * Math.PI, p[0], p[1], p[2]);
1888
+ p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
1889
+ p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
1890
+ return [
1891
+ -p[0],
1892
+ p[1],
1893
+ p[2]
1894
+ ];
1895
+ };
1896
+ return Eoap;
1897
+ }());
1898
+
1899
+ var Mercator = (function () {
1900
+ function Mercator(scale, center) {
1901
+ if (scale === void 0) { scale = 7; }
1902
+ if (center === void 0) { center = [107, 36]; }
1903
+ this.name = 'Mercator';
1904
+ var perimeter = 100 * scale * Math.PI;
1905
+ var help = perimeter / 180;
1906
+ var cx = help * center[0];
1907
+ var cy = -1 * help * center[1];
1908
+ this.use = function (λ, φ) {
1909
+ return [
1910
+ (help * λ - cx) * 0.8,
1911
+ -1 * help * φ - cy,
1912
+ 0
1913
+ ];
1914
+ };
1915
+ }
1916
+ return Mercator;
1917
+ }());
1918
+
1919
+ function throttle (callback, option) {
1920
+ if (option === void 0) { option = {}; }
1921
+ option = mergeOption(option, {
1922
+ time: 200,
1923
+ keep: false,
1924
+ opportunity: "end"
1925
+ });
1926
+ var hadInterval = false;
1927
+ var hadClick = false;
1928
+ var oneClick = false;
1929
+ var arg;
1930
+ return function () {
1931
+ var _this = this;
1932
+ arg = arguments;
1933
+ if (!hadInterval) {
1934
+ if (option.opportunity != 'end') {
1935
+ callback.apply(_this, arg);
1936
+ }
1937
+ hadInterval = true;
1938
+ var interval_1 = setInterval(function () {
1939
+ if (hadClick) {
1940
+ if (!option.keep) {
1941
+ callback.apply(_this, arg);
1942
+ }
1943
+ }
1944
+ else {
1945
+ if (option.opportunity != 'begin') {
1946
+ if (oneClick || option.opportunity == 'end')
1947
+ callback.apply(_this, arg);
1948
+ }
1949
+ hadInterval = false;
1950
+ oneClick = false;
1951
+ clearInterval(interval_1);
1952
+ }
1953
+ hadClick = false;
1954
+ }, option.time);
1955
+ }
1956
+ else {
1957
+ hadClick = true;
1958
+ oneClick = true;
1959
+ }
1960
+ };
1961
+ }
1962
+
1963
+ var toInnerTree = (function (initTree, config) {
1964
+ var tempTree = {};
1965
+ var temp = config.root(initTree);
1966
+ var id, rid;
1967
+ id = rid = config.id(temp);
1968
+ tempTree[id] = {
1969
+ "data": temp,
1970
+ "pid": null,
1971
+ "id": id,
1972
+ "isOpen": true,
1973
+ "show": true,
1974
+ "children": []
1975
+ };
1976
+ var num = 1;
1977
+ (function createTree(pdata, pid) {
1978
+ var children = config.children(pdata, initTree);
1979
+ num += children ? children.length : 0;
1980
+ for (var flag = 0; children && flag < children.length; flag++) {
1981
+ id = config.id(children[flag]);
1982
+ tempTree[pid].children.push(id);
1983
+ tempTree[id] = {
1984
+ "data": children[flag],
1985
+ "pid": pid,
1986
+ "id": id,
1987
+ "isOpen": true,
1988
+ "show": true,
1989
+ "children": []
1990
+ };
1991
+ createTree(children[flag], id);
1992
+ }
1993
+ })(temp, id);
1994
+ return {
1995
+ rid: rid,
1996
+ value: tempTree,
1997
+ num: num
1998
+ };
1999
+ });
2000
+
2001
+ function toPlainTree (initTree, config, noOpens) {
2002
+ var treeData = toInnerTree(initTree, config);
2003
+ var alltreedata = treeData.value;
2004
+ var rootid = treeData.rid;
2005
+ if (treeData.num == 1) {
2006
+ alltreedata[rootid].left = 0.5;
2007
+ alltreedata[rootid].top = 0.5;
2008
+ alltreedata[rootid].show = true;
2009
+ return {
2010
+ deep: 1,
2011
+ node: alltreedata,
2012
+ root: rootid,
2013
+ size: 1
2014
+ };
2015
+ }
2016
+ else {
2017
+ var beforeDis_1 = [];
2018
+ var size_1 = 0, maxDeep_1 = 0;
2019
+ if (noOpens[rootid]) {
2020
+ alltreedata[rootid].left = 0.5;
2021
+ alltreedata[rootid].top = 0.5;
2022
+ alltreedata[rootid].show = true;
2023
+ size_1 = 1;
2024
+ }
2025
+ else {
2026
+ (function positionCalc(pNode, deep) {
2027
+ if (deep > maxDeep_1)
2028
+ maxDeep_1 = deep;
2029
+ var flag = 0;
2030
+ if (!noOpens[pNode.id]) {
2031
+ for (flag = 0; flag < pNode.children.length; flag++)
2032
+ positionCalc(alltreedata[pNode.children[flag]], deep + 1);
2033
+ }
2034
+ alltreedata[pNode.id].left = deep + 0.5;
2035
+ if (flag == 0) {
2036
+ if (beforeDis_1[deep] == void 0)
2037
+ beforeDis_1[deep] = -0.5;
2038
+ if (beforeDis_1[deep - 1] == void 0)
2039
+ beforeDis_1[deep - 1] = -0.5;
2040
+ alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
2041
+ var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
2042
+ if (pTop - 1 < beforeDis_1[deep - 1])
2043
+ alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
2044
+ }
2045
+ else {
2046
+ alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
2047
+ }
2048
+ if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
2049
+ var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
2050
+ alltreedata[_pid].top += needUp_1;
2051
+ if (beforeDis_1[_deep] < alltreedata[_pid].top)
2052
+ beforeDis_1[_deep] = alltreedata[_pid].top;
2053
+ for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
2054
+ doUp(alltreedata[_pid].children[_flag], _deep + 1);
2055
+ }
2056
+ })(pNode.id, deep);
2057
+ }
2058
+ beforeDis_1[deep] = alltreedata[pNode.id].top;
2059
+ if (alltreedata[pNode.id].top + 0.5 > size_1)
2060
+ size_1 = alltreedata[pNode.id].top + 0.5;
2061
+ })(alltreedata[rootid], 0);
2062
+ }
2063
+ for (var key in noOpens) {
2064
+ if (noOpens[key]) {
2065
+ alltreedata[key].isOpen = false;
2066
+ (function updateHidden(pid, left, top) {
2067
+ for (var index = 0; index < alltreedata[pid].children.length; index++) {
2068
+ alltreedata[alltreedata[pid].children[index]].left = left;
2069
+ alltreedata[alltreedata[pid].children[index]].top = top;
2070
+ alltreedata[alltreedata[pid].children[index]].show = false;
2071
+ updateHidden(alltreedata[pid].children[index], left, top);
2072
+ }
2073
+ })(key, alltreedata[key].left, alltreedata[key].top);
2074
+ }
2075
+ }
2076
+ return {
2077
+ "node": alltreedata,
2078
+ "root": rootid,
2079
+ "size": size_1,
2080
+ "deep": maxDeep_1 + 1
2081
+ };
2082
+ }
2083
+ }
2084
+
2085
+ var Tree = (function () {
2086
+ function Tree(config) {
2087
+ if (config === void 0) { config = {}; }
2088
+ this.name = 'Tree';
2089
+ this.__config = mergeOption(config, {
2090
+ root: function (initTree) { return initTree; },
2091
+ children: function (parentTree) { return parentTree.children; },
2092
+ id: function (treedata) { return treedata.name; }
2093
+ });
2094
+ }
2095
+ Tree.prototype.use = function (initTree, noOpens) {
2096
+ if (noOpens === void 0) { noOpens = {}; }
2097
+ return toPlainTree(initTree, this.__config, noOpens);
2098
+ };
2099
+ return Tree;
2100
+ }());
2101
+
2102
+ var TreeLayout = (function (_super) {
2103
+ __extends(TreeLayout, _super);
2104
+ function TreeLayout() {
2105
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2106
+ _this.name = 'TreeLayout';
2107
+ _this.__option = {
2108
+ offsetX: 0,
2109
+ offsetY: 0,
2110
+ duration: 500,
2111
+ type: "plain",
2112
+ direction: "LR",
2113
+ x: 100,
2114
+ y: 100,
2115
+ width: 100,
2116
+ height: 100,
2117
+ radius: 100
2118
+ };
2119
+ _this.__noOpens = {};
2120
+ return _this;
2121
+ }
2122
+ TreeLayout.prototype.setOption = function (option) {
2123
+ mergeOption(option, this.__option);
2124
+ return this;
2125
+ };
2126
+ TreeLayout.prototype.use = function (initTree, noOpens) {
2127
+ if (noOpens === void 0) { noOpens = {}; }
2128
+ var tree = _super.prototype.use.call(this, initTree, noOpens);
2129
+ if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
2130
+ for (var key in tree.node) {
2131
+ if (!tree.node[key].show) {
2132
+ var deep = 0, pid = key;
2133
+ do {
2134
+ pid = tree.node[pid].pid;
2135
+ deep++;
2136
+ } while (!tree.node[pid].show);
2137
+ tree.node[key].left += this.__option.offsetX * deep;
2138
+ tree.node[key].top += this.__option.offsetY * deep;
2139
+ }
2140
+ }
2141
+ }
2142
+ if (this.__option.type == 'rect') {
2143
+ if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
2144
+ var perW = this.__option.height / tree.size;
2145
+ var perD = this.__option.width / (tree.deep - 1);
2146
+ var balanceW = this.__option.y - this.__option.height * 0.5;
2147
+ var flag = this.__option.direction == 'LR' ? 1 : -1;
2148
+ for (var key in tree.node) {
2149
+ if (tree.deep == 1) {
2150
+ tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
2151
+ tree.node[key].top = this.__option.y;
2152
+ }
2153
+ else {
2154
+ tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
2155
+ tree.node[key].top = tree.node[key].top * perW + balanceW;
2156
+ }
2157
+ }
2158
+ }
2159
+ else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
2160
+ var perW = this.__option.width / tree.size;
2161
+ var perD = this.__option.height / (tree.deep - 1);
2162
+ var balanceW = this.__option.x - this.__option.width * 0.5;
2163
+ var flag = this.__option.direction == 'TB' ? 1 : -1;
2164
+ for (var key in tree.node) {
2165
+ if (tree.deep == 1) {
2166
+ tree.node[key].left = this.__option.x;
2167
+ tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
2168
+ }
2169
+ else {
2170
+ var left = tree.node[key].left;
2171
+ tree.node[key].left = tree.node[key].top * perW + balanceW;
2172
+ tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
2173
+ }
2174
+ }
2175
+ }
2176
+ }
2177
+ else if (this.__option.type == 'circle') {
2178
+ var cx = this.__option.x, cy = this.__option.y;
2179
+ var deg = Math.PI * 2 / tree.size;
2180
+ var per = this.__option.radius / (tree.deep - 1);
2181
+ for (var key in tree.node) {
2182
+ if (tree.node[key].left == 0.5) {
2183
+ tree.node[key].left = cx;
2184
+ tree.node[key].top = cy;
2185
+ }
2186
+ else {
2187
+ var position = rotate$1(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
2188
+ tree.node[key].left = position[0];
2189
+ tree.node[key].top = position[1];
2190
+ }
2191
+ }
2192
+ }
2193
+ return tree;
2194
+ };
2195
+ TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
2196
+ if (noOpens === void 0) { noOpens = {}; }
2197
+ this.__rback = renderBack;
2198
+ this.__oralTree = initTree;
2199
+ this.__noOpens = noOpens;
2200
+ this.__preTree = this.use(this.__oralTree, this.__noOpens);
2201
+ this.__rback(this.__preTree);
2202
+ return this;
2203
+ };
2204
+ TreeLayout.prototype.unbind = function () {
2205
+ this.__rback = function () { return null; };
2206
+ this.__oralTree = null;
2207
+ this.__preTree = null;
2208
+ this.__noOpens = {};
2209
+ return this;
2210
+ };
2211
+ TreeLayout.prototype.doUpdate = function () {
2212
+ var _this = this;
2213
+ var newTree = this.use(this.__oralTree, this.__noOpens);
2214
+ var cacheTree = JSON.parse(JSON.stringify(newTree));
2215
+ animation(function (deep) {
2216
+ if (_this.__preTree) {
2217
+ for (var key in cacheTree.node) {
2218
+ if (newTree.node[key].show || _this.__preTree.node[key].show) {
2219
+ cacheTree.node[key].show = true;
2220
+ cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
2221
+ cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
2222
+ }
2223
+ }
2224
+ }
2225
+ _this.__rback(cacheTree);
2226
+ }, this.__option.duration, function () {
2227
+ _this.__preTree = newTree;
2228
+ _this.__rback(_this.__preTree);
2229
+ });
2230
+ };
2231
+ TreeLayout.prototype.closeNode = function (id) {
2232
+ if (!this.__preTree)
2233
+ return this;
2234
+ this.__noOpens[id] = true;
2235
+ this.doUpdate();
2236
+ return this;
2237
+ };
2238
+ TreeLayout.prototype.openNode = function (id) {
2239
+ if (!this.__preTree)
2240
+ return this;
2241
+ this.__noOpens[id] = false;
2242
+ this.doUpdate();
2243
+ return this;
2244
+ };
2245
+ TreeLayout.prototype.toggleNode = function (id) {
2246
+ if (!this.__preTree)
2247
+ return this;
2248
+ this.__noOpens[id] = !this.__noOpens[id];
2249
+ this.doUpdate();
2250
+ return this;
2251
+ };
2252
+ return TreeLayout;
2253
+ }(Tree));
2254
+
2255
+ var index = {
2256
+ Cardinal: Cardinal,
2257
+ Hermite: Hermite,
2258
+ Matrix4: Matrix4,
2259
+ rotate: rotate$1,
2260
+ move: move,
2261
+ scale: scale,
2262
+ getLoopColors: getLoopColors,
2263
+ animation: animation,
2264
+ ruler: ruler,
2265
+ SVG: SVG,
2266
+ Canvas: Canvas,
2267
+ RawCanvas: Canvas$1,
2268
+ getWebGLContext: getWebGLContext,
2269
+ Shader: ShaderObject,
2270
+ Texture: TextureObject,
2271
+ Buffer: BufferObject,
2272
+ Eoap: Eoap,
2273
+ Mercator: Mercator,
2274
+ throttle: throttle,
2275
+ TreeLayout: TreeLayout
2276
+ };
2277
+
2278
+ export { index as default };