vislite 0.1.0 → 0.2.0-alpha.7

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 (112) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +24 -1
  3. package/LICENSE +20 -20
  4. package/README.md +53 -38
  5. package/lib/Canvas/index.umd.js +135 -46
  6. package/lib/Canvas/index.umd.min.js +7 -3
  7. package/lib/Cardinal/index.umd.js +6 -2
  8. package/lib/Cardinal/index.umd.min.js +6 -2
  9. package/lib/Eoap/index.umd.js +9 -5
  10. package/lib/Eoap/index.umd.min.js +6 -2
  11. package/lib/Hermite/index.umd.js +6 -2
  12. package/lib/Hermite/index.umd.min.js +6 -2
  13. package/lib/Matrix4/index.umd.js +6 -2
  14. package/lib/Matrix4/index.umd.min.js +6 -2
  15. package/lib/Mercator/index.umd.js +42 -0
  16. package/lib/Mercator/index.umd.min.js +15 -0
  17. package/lib/OralCanvas/index.es.js +124 -44
  18. package/lib/OralCanvas/index.es.min.js +7 -3
  19. package/lib/OralWebGL/index.es.js +567 -0
  20. package/lib/OralWebGL/index.es.min.js +15 -0
  21. package/lib/SVG/index.umd.js +16 -5
  22. package/lib/SVG/index.umd.min.js +7 -3
  23. package/lib/WebGL/index.umd.js +626 -0
  24. package/lib/WebGL/index.umd.min.js +15 -0
  25. package/lib/animation/index.umd.js +6 -2
  26. package/lib/animation/index.umd.min.js +6 -2
  27. package/lib/getLoopColors/index.umd.js +6 -2
  28. package/lib/getLoopColors/index.umd.min.js +6 -2
  29. package/lib/index.umd.js +1514 -863
  30. package/lib/index.umd.min.js +7 -3
  31. package/lib/rotate/index.umd.js +6 -2
  32. package/lib/rotate/index.umd.min.js +6 -2
  33. package/lib/ruler/index.umd.js +6 -2
  34. package/lib/ruler/index.umd.min.js +6 -2
  35. package/lib/viewHandler/index.umd.js +129 -0
  36. package/lib/viewHandler/index.umd.min.js +15 -0
  37. package/miniprogram/ui-canvas/index.js +18 -3
  38. package/miniprogram/ui-canvas/index.json +4 -4
  39. package/miniprogram/ui-canvas/index.wxml +4 -4
  40. package/miniprogram/ui-canvas/index.wxss +5 -5
  41. package/package/Canvas/index.ts +1 -1
  42. package/package/Cardinal/index.ts +2 -2
  43. package/package/Eoap/index.ts +2 -2
  44. package/package/Hermite/index.ts +2 -2
  45. package/package/Matrix4/index.ts +2 -2
  46. package/package/Mercator/index.ts +3 -0
  47. package/package/OralCanvas/index.ts +1 -1
  48. package/package/OralWebGL/index.ts +2 -0
  49. package/package/SVG/index.ts +2 -2
  50. package/package/WebGL/index.ts +2 -0
  51. package/package/animation/index.ts +2 -2
  52. package/package/getLoopColors/index.ts +2 -2
  53. package/package/index.ts +32 -9
  54. package/package/rotate/index.ts +2 -2
  55. package/package/ruler/index.ts +2 -2
  56. package/package/viewHandler/index.ts +3 -0
  57. package/package.json +11 -2
  58. package/src/Canvas.ts +10 -1
  59. package/src/Eoap.ts +5 -5
  60. package/src/Matrix4/index.ts +76 -76
  61. package/src/Matrix4/move.ts +12 -12
  62. package/src/Matrix4/rotate.ts +15 -15
  63. package/src/Matrix4/scale.ts +11 -11
  64. package/src/Matrix4/transform.ts +64 -64
  65. package/src/Mercator.ts +27 -0
  66. package/src/SVG.ts +1 -1
  67. package/src/WebGL.ts +53 -0
  68. package/src/animation.ts +99 -99
  69. package/src/common/assemble.ts +23 -0
  70. package/src/common/canvas/arc.ts +50 -50
  71. package/src/common/canvas/config.ts +7 -6
  72. package/src/common/canvas/index.ts +29 -28
  73. package/src/common/canvas/painter.ts +51 -8
  74. package/src/common/canvas/texts.ts +19 -0
  75. package/src/common/setStyle.ts +5 -5
  76. package/src/common/svg/config.ts +127 -126
  77. package/src/common/svg/index.ts +13 -3
  78. package/src/common/svg/tool.ts +43 -42
  79. package/src/common/webgl/buffer.ts +80 -0
  80. package/src/common/webgl/doDraw.ts +97 -0
  81. package/src/common/webgl/getColorFactory.ts +27 -0
  82. package/src/common/webgl/getShader.ts +62 -0
  83. package/src/common/webgl/getTexture.ts +12 -0
  84. package/src/common/webgl/getWebGLContext.ts +28 -0
  85. package/src/common/webgl/index.ts +212 -0
  86. package/src/common/webgl/shader.ts +76 -0
  87. package/src/common/webgl/texture.ts +99 -0
  88. package/src/getLoopColors.ts +42 -42
  89. package/src/interpolation/Cardinal.ts +91 -91
  90. package/src/interpolation/Hermite.ts +65 -65
  91. package/src/rotate.ts +7 -7
  92. package/src/ruler.ts +99 -99
  93. package/src/viewHandler.ts +140 -0
  94. package/types/Canvas.d.ts +220 -283
  95. package/types/CanvasConfig.d.ts +81 -0
  96. package/types/Cardinal.d.ts +13 -13
  97. package/types/Hermite.d.ts +18 -18
  98. package/types/Map.d.ts +10 -0
  99. package/types/Matrix4.d.ts +42 -42
  100. package/types/Object3D.d.ts +106 -0
  101. package/types/SVG.d.ts +210 -264
  102. package/types/SVGConfig.d.ts +59 -0
  103. package/types/Scene3D.d.ts +7 -0
  104. package/types/WebGL.d.ts +29 -0
  105. package/types/animation.d.ts +6 -6
  106. package/types/getLoopColors.d.ts +2 -2
  107. package/types/index.d.ts +70 -26
  108. package/types/rotate.d.ts +2 -2
  109. package/types/ruler.d.ts +2 -2
  110. package/types/viewHandler.d.ts +13 -0
  111. package/uni-app/ui-canvas.vue +94 -20
  112. package/types/Eoap.d.ts +0 -10
package/lib/index.umd.js CHANGED
@@ -1,12 +1,16 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.1.0
2
+ * VISLite JavaScript Library v0.2.0-alpha.7
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
6
6
  * Released under the MIT license
7
7
  * https://zxl20070701.github.io/notebook/home.html
8
8
  *
9
- * Publish Date: Sat Apr 29 2023 01:41:52 GMT+0800 (中国标准时间)
9
+ * 本版本系测试版本,请认真阅读下述说明再使用:
10
+ *
11
+ *【测试版本细则】
12
+ * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
+ * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
10
14
  */
11
15
  (function (global, factory) {
12
16
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -14,446 +18,6 @@
14
18
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite = factory());
15
19
  })(this, (function () { 'use strict';
16
20
 
17
- /******************************************************************************
18
- Copyright (c) Microsoft Corporation.
19
-
20
- Permission to use, copy, modify, and/or distribute this software for any
21
- purpose with or without fee is hereby granted.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
- PERFORMANCE OF THIS SOFTWARE.
30
- ***************************************************************************** */
31
- /* global Reflect, Promise */
32
-
33
- var extendStatics = function(d, b) {
34
- extendStatics = Object.setPrototypeOf ||
35
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
36
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
37
- return extendStatics(d, b);
38
- };
39
-
40
- function __extends(d, b) {
41
- if (typeof b !== "function" && b !== null)
42
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
43
- extendStatics(d, b);
44
- function __() { this.constructor = d; }
45
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
46
- }
47
-
48
- var rotate$1 = function (cx, cy, deg, x, y) {
49
- var cos = Math.cos(deg), sin = Math.sin(deg);
50
- return [
51
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
52
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
53
- ];
54
- };
55
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
56
- if (rotateA < 0) {
57
- beginA += rotateA;
58
- rotateA *= -1;
59
- }
60
- var temp = [], p;
61
- p = rotate$1(0, 0, beginA, r1, 0);
62
- temp[0] = p[0];
63
- temp[1] = p[1];
64
- p = rotate$1(0, 0, rotateA, p[0], p[1]);
65
- temp[2] = p[0];
66
- temp[3] = p[1];
67
- p = rotate$1(0, 0, beginA, r2, 0);
68
- temp[4] = p[0];
69
- temp[5] = p[1];
70
- p = rotate$1(0, 0, rotateA, p[0], p[1]);
71
- temp[6] = p[0];
72
- temp[7] = p[1];
73
- 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);
74
- }
75
-
76
- var initText$1 = function (painter, config, x, y, deg) {
77
- painter.beginPath();
78
- painter.translate(x, y);
79
- painter.rotate(deg);
80
- painter.font = config['font-style'] + " " + config["font-weight"] + " " + config['font-size'] + "px " + config['font-family'];
81
- return painter;
82
- };
83
- var initArc$1 = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
84
- if (r1 > r2) {
85
- var temp = r1;
86
- r1 = r2;
87
- r2 = temp;
88
- }
89
- beginDeg = beginDeg % (Math.PI * 2);
90
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
91
- deg = Math.PI * 2;
92
- }
93
- else {
94
- deg = deg % (Math.PI * 2);
95
- }
96
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
97
- if (r < 0)
98
- r = -r;
99
- painter.beginPath();
100
- painter.moveTo(begInnerX, begInnerY);
101
- painter.arc(cx, cy, r1, beginA, endA, false);
102
- if (config["arc-end-cap"] != 'round')
103
- painter.lineTo(endOuterX, endOuterY);
104
- else
105
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
106
- painter.arc(cx, cy, r2, endA, beginA, true);
107
- if (config["arc-start-cap"] != 'round')
108
- painter.lineTo(begInnerX, begInnerY);
109
- else
110
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
111
- });
112
- if (config["arc-start-cap"] == 'butt')
113
- painter.closePath();
114
- return painter;
115
- };
116
- var initCircle$1 = function (painter, cx, cy, r) {
117
- painter.beginPath();
118
- painter.moveTo(cx + r, cy);
119
- painter.arc(cx, cy, r, 0, Math.PI * 2);
120
- return painter;
121
- };
122
- var initRect$1 = function (painter, x, y, width, height) {
123
- painter.beginPath();
124
- painter.rect(x, y, width, height);
125
- return painter;
126
- };
127
-
128
- var Painter = (function () {
129
- function Painter(canvas, opts, region) {
130
- if (opts === void 0) { opts = {}; }
131
- this.__region = null;
132
- this.__specialConfig = {
133
- "font-size": 16,
134
- "font-family": "sans-serif",
135
- "font-weight": 400,
136
- "font-style": "normal",
137
- "arc-start-cap": 'butt',
138
- "arc-end-cap": 'butt'
139
- };
140
- this.__initConfig = {
141
- "fillStyle": 'black',
142
- "strokeStyle": 'black',
143
- "lineWidth": 1,
144
- "textAlign": 'left',
145
- "textBaseline": 'middle',
146
- "lineDash": [],
147
- "shadowBlur": 0,
148
- "shadowColor": "black"
149
- };
150
- this.painter = canvas.getContext("2d", opts);
151
- this.__region = region;
152
- this.painter.textBaseline = 'middle';
153
- this.painter.textAlign = 'left';
154
- }
155
- Painter.prototype.useConfig = function (key, value) {
156
- if (this.__region) {
157
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
158
- this.__region.useConfig(key, value);
159
- }
160
- }
161
- if (key == 'lineDash') {
162
- if (this.painter.setLineDash)
163
- this.painter.setLineDash(value);
164
- }
165
- else if (key in this.__specialConfig) {
166
- this.__specialConfig[key] = value;
167
- }
168
- else if (key in this.__initConfig) {
169
- this.painter[key] = value;
170
- }
171
- else {
172
- throw new Error('Illegal configuration item of painter : ' + key + " !");
173
- }
174
- return this;
175
- };
176
- Painter.prototype.fillText = function (text, x, y, deg) {
177
- if (deg === void 0) { deg = 0; }
178
- if (this.__region)
179
- this.__region.fillText(text, x, y, deg);
180
- this.painter.save();
181
- initText$1(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
182
- this.painter.restore();
183
- return this;
184
- };
185
- Painter.prototype.strokeText = function (text, x, y, deg) {
186
- if (deg === void 0) { deg = 0; }
187
- if (this.__region)
188
- this.__region.strokeText(text, x, y, deg);
189
- this.painter.save();
190
- initText$1(this.painter, this.__specialConfig, x, y, deg || 0).strokeText(text, 0, 0);
191
- this.painter.restore();
192
- return this;
193
- };
194
- Painter.prototype.fullText = function (text, x, y, deg) {
195
- if (deg === void 0) { deg = 0; }
196
- if (this.__region)
197
- this.__region.fullText(text, x, y, deg);
198
- this.painter.save();
199
- initText$1(this.painter, this.__specialConfig, x, y, deg || 0);
200
- this.painter.fillText(text, 0, 0);
201
- this.painter.strokeText(text, 0, 0);
202
- this.painter.restore();
203
- return this;
204
- };
205
- Painter.prototype.beginPath = function () {
206
- if (this.__region)
207
- this.__region.beginPath();
208
- this.painter.beginPath();
209
- return this;
210
- };
211
- Painter.prototype.closePath = function () {
212
- if (this.__region)
213
- this.__region.closePath();
214
- this.painter.closePath();
215
- return this;
216
- };
217
- Painter.prototype.moveTo = function (x, y) {
218
- if (this.__region)
219
- this.__region.moveTo(x, y);
220
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
221
- return this;
222
- };
223
- Painter.prototype.lineTo = function (x, y) {
224
- if (this.__region)
225
- this.__region.lineTo(x, y);
226
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
227
- return this;
228
- };
229
- Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
230
- if (this.__region)
231
- this.__region.arc(x, y, r, beginDeg, deg);
232
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
233
- return this;
234
- };
235
- Painter.prototype.fill = function () {
236
- if (this.__region)
237
- this.__region.fill();
238
- this.painter.fill();
239
- return this;
240
- };
241
- Painter.prototype.stroke = function () {
242
- if (this.__region)
243
- this.__region.stroke();
244
- this.painter.stroke();
245
- return this;
246
- };
247
- Painter.prototype.full = function () {
248
- if (this.__region)
249
- this.__region.full();
250
- this.painter.fill();
251
- this.painter.stroke();
252
- return this;
253
- };
254
- Painter.prototype.save = function () {
255
- if (this.__region)
256
- this.__region.save();
257
- this.painter.save();
258
- return this;
259
- };
260
- Painter.prototype.restore = function () {
261
- if (this.__region)
262
- this.__region.restore();
263
- this.painter.restore();
264
- return this;
265
- };
266
- Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
267
- if (this.__region)
268
- this.__region.quadraticCurveTo(cpx, cpy, x, y);
269
- this.painter.quadraticCurveTo(cpx, cpy, x, y);
270
- return this;
271
- };
272
- Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
273
- if (this.__region)
274
- this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
275
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
276
- return this;
277
- };
278
- Painter.prototype.clearRect = function (x, y, w, h) {
279
- if (this.__region)
280
- this.__region.clearRect(x, y, w, h);
281
- this.painter.clearRect(x, y, w, h);
282
- return this;
283
- };
284
- Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
285
- if (this.__region)
286
- this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
287
- initArc$1(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
288
- return this;
289
- };
290
- Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
291
- if (this.__region)
292
- this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
293
- initArc$1(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
294
- return this;
295
- };
296
- Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
297
- if (this.__region)
298
- this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
299
- initArc$1(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
300
- this.painter.fill();
301
- this.painter.stroke();
302
- return this;
303
- };
304
- Painter.prototype.fillCircle = function (cx, cy, r) {
305
- if (this.__region)
306
- this.__region.fillCircle(cx, cy, r);
307
- initCircle$1(this.painter, cx, cy, r).fill();
308
- return this;
309
- };
310
- Painter.prototype.strokeCircle = function (cx, cy, r) {
311
- if (this.__region)
312
- this.__region.strokeCircle(cx, cy, r);
313
- initCircle$1(this.painter, cx, cy, r).stroke();
314
- return this;
315
- };
316
- Painter.prototype.fullCircle = function (cx, cy, r) {
317
- if (this.__region)
318
- this.__region.fullCircle(cx, cy, r);
319
- initCircle$1(this.painter, cx, cy, r);
320
- this.painter.fill();
321
- this.painter.stroke();
322
- return this;
323
- };
324
- Painter.prototype.fillRect = function (x, y, width, height) {
325
- if (this.__region)
326
- this.__region.fillRect(x, y, width, height);
327
- initRect$1(this.painter, x, y, width, height).fill();
328
- return this;
329
- };
330
- Painter.prototype.strokeRect = function (x, y, width, height) {
331
- if (this.__region)
332
- this.__region.strokeRect(x, y, width, height);
333
- initRect$1(this.painter, x, y, width, height).stroke();
334
- return this;
335
- };
336
- Painter.prototype.fullRect = function (x, y, width, height) {
337
- if (this.__region)
338
- this.__region.fullRect(x, y, width, height);
339
- initRect$1(this.painter, x, y, width, height);
340
- this.painter.fill();
341
- this.painter.stroke();
342
- return this;
343
- };
344
- return Painter;
345
- }());
346
-
347
- var Canvas$1 = (function (_super) {
348
- __extends(Canvas, _super);
349
- function Canvas(ViewCanvas, RegionCanvas) {
350
- var _this_1 = _super.call(this, ViewCanvas, {}, new Painter(RegionCanvas, {
351
- willReadFrequently: true
352
- })) || this;
353
- _this_1.name = "Canvas";
354
- _this_1.__regionList = {};
355
- _this_1.__rgb = [0, 0, 0];
356
- _this_1.__p = 'r';
357
- _this_1.setRegion("");
358
- return _this_1;
359
- }
360
- Canvas.prototype.config = function (configs) {
361
- for (var key in configs) {
362
- this.useConfig(key, configs[key]);
363
- }
364
- return this;
365
- };
366
- Canvas.prototype.setRegion = function (regionName) {
367
- var _this = this;
368
- if (regionName) {
369
- if (this.__regionList[regionName] == undefined) {
370
- this.__regionList[regionName] = {
371
- 'r': function () {
372
- _this.__rgb[0] += 1;
373
- _this.__p = 'g';
374
- return 'rgb(' + _this.__rgb[0] + ',' + _this.__rgb[1] + ',' + _this.__rgb[2] + ')';
375
- },
376
- 'g': function () {
377
- _this.__rgb[1] += 1;
378
- _this.__p = 'b';
379
- return 'rgb(' + _this.__rgb[0] + ',' + _this.__rgb[1] + ',' + _this.__rgb[2] + ')';
380
- },
381
- 'b': function () {
382
- _this.__rgb[2] += 1;
383
- _this.__p = 'r';
384
- return 'rgb(' + _this.__rgb[0] + ',' + _this.__rgb[1] + ',' + _this.__rgb[2] + ')';
385
- }
386
- }[this.__p]();
387
- }
388
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
389
- this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
390
- }
391
- else {
392
- this.__region.useConfig("fillStyle", "#000000") &&
393
- this.__region.useConfig("strokeStyle", "#000000");
394
- }
395
- return this;
396
- };
397
- Canvas.prototype.getRegion = function (x, y) {
398
- var _this_1 = this;
399
- return new Promise(function (resolve, reject) {
400
- var imgData = _this_1.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1);
401
- var currentRGBA = imgData.data;
402
- var doit = function () {
403
- for (var key in _this_1.__regionList) {
404
- if ("rgb(" + currentRGBA[0] + "," + currentRGBA[1] + "," + currentRGBA[2] + ")" == _this_1.__regionList[key]) {
405
- resolve(key);
406
- break;
407
- }
408
- }
409
- resolve("");
410
- };
411
- if (currentRGBA) {
412
- doit();
413
- }
414
- else {
415
- imgData.then(function (data) {
416
- currentRGBA = data;
417
- doit();
418
- });
419
- }
420
- });
421
- };
422
- return Canvas;
423
- }(Painter));
424
-
425
- var Canvas = (function (_super) {
426
- __extends(Canvas, _super);
427
- function Canvas(el) {
428
- if (!el) {
429
- throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
430
- }
431
- var width = el.clientWidth, height = el.clientHeight;
432
- var ViewCanvas, RegionCanvas;
433
- var _el = el;
434
- if (_el._vislite_canvas_) {
435
- ViewCanvas = _el._vislite_canvas_[0];
436
- RegionCanvas = _el._vislite_canvas_[1];
437
- }
438
- else {
439
- ViewCanvas = document.createElement('canvas');
440
- el.appendChild(ViewCanvas);
441
- RegionCanvas = document.createElement('canvas');
442
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
443
- el.setAttribute('vislite', 'inited');
444
- }
445
- for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
446
- var canvas = _a[_i];
447
- canvas.style.width = width + "px";
448
- canvas.setAttribute('width', width + "");
449
- canvas.style.height = height + "px";
450
- canvas.setAttribute('height', height + "");
451
- }
452
- return _super.call(this, ViewCanvas, RegionCanvas) || this;
453
- }
454
- return Canvas;
455
- }(Canvas$1));
456
-
457
21
  var Hermite = (function () {
458
22
  function Hermite(u) {
459
23
  if (u === void 0) { u = 0.5; }
@@ -493,118 +57,48 @@
493
57
  var Cardinal = (function () {
494
58
  function Cardinal(t) {
495
59
  if (t === void 0) { t = 0; }
496
- this.name = 'Cardinal';
497
- this.__t = t;
498
- }
499
- Cardinal.prototype.setP = function (points) {
500
- this.__HS = {
501
- "x": [],
502
- "h": []
503
- };
504
- var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
505
- this.__HS.x[0] = points[0][0];
506
- for (flag = 1; flag < points.length; flag++) {
507
- if (points[flag][0] <= points[flag - 1][0])
508
- throw new Error('The point position should be increamented!');
509
- this.__HS.x[flag] = points[flag][0];
510
- temp = flag < points.length - 1 ?
511
- (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
512
- (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
513
- 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);
514
- slope = temp;
515
- }
516
- return this;
517
- };
518
- Cardinal.prototype.use = function (x) {
519
- if (this.__HS) {
520
- this.__i = -1;
521
- 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]))) {
522
- this.__i += 1;
523
- }
524
- if (this.__i < 0) {
525
- return this.__HS.h[0].use(this.__HS.x[0]);
526
- }
527
- else if (this.__i >= this.__HS.h.length) {
528
- return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
529
- }
530
- return this.__HS.h[this.__i].use(x);
531
- }
532
- else {
533
- throw new Error('You shoud first set the position!');
534
- }
535
- };
536
- return Cardinal;
537
- }());
538
-
539
- var rotateX = function (deg, x, y, z) {
540
- var cos = Math.cos(deg), sin = Math.sin(deg);
541
- return [x, y * cos - z * sin, y * sin + z * cos];
542
- };
543
- var rotateY = function (deg, x, y, z) {
544
- var cos = Math.cos(deg), sin = Math.sin(deg);
545
- return [z * sin + x * cos, y, z * cos - x * sin];
546
- };
547
- var rotateZ = function (deg, x, y, z) {
548
- var cos = Math.cos(deg), sin = Math.sin(deg);
549
- return [x * cos - y * sin, x * sin + y * cos, z];
550
- };
551
- var Eoap = (function () {
552
- function Eoap(scale, center) {
553
- if (scale === void 0) { scale = 7; }
554
- if (center === void 0) { center = [107, 36]; }
555
- this.name = 'Eoap';
556
- this.__scale = scale;
557
- this.__center = center;
558
- }
559
- Eoap.prototype.use = function (longitude, latitude) {
560
- var p = rotateY((360 - latitude) / 180 * Math.PI, 100 * this.__scale, 0, 0);
561
- p = rotateZ(longitude / 180 * Math.PI, p[0], p[1], p[2]);
562
- p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
563
- p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
564
- return [
565
- -p[0],
566
- p[1],
567
- p[2]
568
- ];
569
- };
570
- return Eoap;
571
- }());
572
-
573
- function getLoopColors (num, alpha) {
574
- if (alpha === void 0) { alpha = 1; }
575
- var colorList = [
576
- 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
577
- 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
578
- 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
579
- 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
580
- 'rgba(234,124,204,' + alpha + ")"
581
- ];
582
- var colors = [];
583
- if (num <= colorList.length) {
584
- return colorList;
585
- }
586
- else {
587
- if (num % colorList.length == 0) {
588
- for (var i = 0; i < (num / colorList.length); i++) {
589
- colors = colors.concat(colorList);
590
- }
60
+ this.name = 'Cardinal';
61
+ this.__t = t;
62
+ }
63
+ Cardinal.prototype.setP = function (points) {
64
+ this.__HS = {
65
+ "x": [],
66
+ "h": []
67
+ };
68
+ var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
69
+ this.__HS.x[0] = points[0][0];
70
+ for (flag = 1; flag < points.length; flag++) {
71
+ if (points[flag][0] <= points[flag - 1][0])
72
+ throw new Error('The point position should be increamented!');
73
+ this.__HS.x[flag] = points[flag][0];
74
+ temp = flag < points.length - 1 ?
75
+ (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
76
+ (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
77
+ 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);
78
+ slope = temp;
591
79
  }
592
- else {
593
- for (var j = 1; j < (num / colorList.length); j++) {
594
- colors = colors.concat(colorList);
80
+ return this;
81
+ };
82
+ Cardinal.prototype.use = function (x) {
83
+ if (this.__HS) {
84
+ this.__i = -1;
85
+ 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]))) {
86
+ this.__i += 1;
595
87
  }
596
- if (num % colorList.length == 1) {
597
- colors = colors.concat(colorList[4]);
88
+ if (this.__i < 0) {
89
+ return this.__HS.h[0].use(this.__HS.x[0]);
598
90
  }
599
- else {
600
- for (var k = 0; k < num % colorList.length; k++) {
601
- colors = colors.concat(colorList[k]);
602
- }
91
+ else if (this.__i >= this.__HS.h.length) {
92
+ return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
603
93
  }
94
+ return this.__HS.h[this.__i].use(x);
604
95
  }
605
- }
606
- return colors;
607
- }
96
+ else {
97
+ throw new Error('You shoud first set the position!');
98
+ }
99
+ };
100
+ return Cardinal;
101
+ }());
608
102
 
609
103
  function _move (d, a, b, c) {
610
104
  if (c === void 0) { c = 0; }
@@ -733,7 +227,7 @@
733
227
  return Matrix4;
734
228
  }());
735
229
 
736
- function rotate (cx, cy, deg, x, y) {
230
+ function rotate$1 (cx, cy, deg, x, y) {
737
231
  var cos = Math.cos(deg), sin = Math.sin(deg);
738
232
  return [
739
233
  (x - cx) * cos - (y - cy) * sin + cx,
@@ -741,6 +235,218 @@
741
235
  ];
742
236
  }
743
237
 
238
+ function getLoopColors (num, alpha) {
239
+ if (alpha === void 0) { alpha = 1; }
240
+ var colorList = [
241
+ 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
242
+ 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
243
+ 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
244
+ 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
245
+ 'rgba(234,124,204,' + alpha + ")"
246
+ ];
247
+ var colors = [];
248
+ if (num <= colorList.length) {
249
+ return colorList;
250
+ }
251
+ else {
252
+ if (num % colorList.length == 0) {
253
+ for (var i = 0; i < (num / colorList.length); i++) {
254
+ colors = colors.concat(colorList);
255
+ }
256
+ }
257
+ else {
258
+ for (var j = 1; j < (num / colorList.length); j++) {
259
+ colors = colors.concat(colorList);
260
+ }
261
+ if (num % colorList.length == 1) {
262
+ colors = colors.concat(colorList[4]);
263
+ }
264
+ else {
265
+ for (var k = 0; k < num % colorList.length; k++) {
266
+ colors = colors.concat(colorList[k]);
267
+ }
268
+ }
269
+ }
270
+ }
271
+ return colors;
272
+ }
273
+
274
+ var $timers = [];
275
+ var $interval = 13;
276
+ var $timerId;
277
+ function animation (doback, duration, callback) {
278
+ if (duration === void 0) { duration = 400; }
279
+ if (callback === void 0) { callback = function () { }; }
280
+ var clock = {
281
+ "timer": function (tick, duration, callback) {
282
+ if (!tick) {
283
+ throw new Error('Tick is required!');
284
+ }
285
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
286
+ $timers.push({
287
+ "id": id,
288
+ "createTime": new Date(),
289
+ "tick": tick,
290
+ "duration": duration,
291
+ "callback": callback
292
+ });
293
+ clock.start();
294
+ return id;
295
+ },
296
+ "start": function () {
297
+ if (!$timerId) {
298
+ $timerId = setInterval(clock.tick, $interval);
299
+ }
300
+ },
301
+ "tick": function () {
302
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
303
+ $timers = [];
304
+ $timers.length = 0;
305
+ for (flag = 0; flag < timers.length; flag++) {
306
+ timer = timers[flag];
307
+ createTime = timer.createTime;
308
+ tick = timer.tick;
309
+ duration = timer.duration;
310
+ callback = timer.callback;
311
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
312
+ passTime = passTime > 1 ? 1 : passTime;
313
+ tick(passTime);
314
+ if (passTime < 1 && timer.id) {
315
+ $timers.push(timer);
316
+ }
317
+ else {
318
+ callback(passTime);
319
+ }
320
+ }
321
+ if ($timers.length <= 0) {
322
+ clock.stop();
323
+ }
324
+ },
325
+ "stop": function () {
326
+ if ($timerId) {
327
+ clearInterval($timerId);
328
+ $timerId = null;
329
+ }
330
+ }
331
+ };
332
+ var id = clock.timer(function (deep) {
333
+ doback(deep);
334
+ }, duration, callback);
335
+ return function () {
336
+ var i;
337
+ for (i in $timers) {
338
+ if ($timers[i].id == id) {
339
+ $timers[i].id = undefined;
340
+ return;
341
+ }
342
+ }
343
+ };
344
+ }
345
+
346
+ function ruler (maxValue, minValue, num) {
347
+ if (maxValue < minValue) {
348
+ var temp = minValue;
349
+ minValue = maxValue;
350
+ maxValue = temp;
351
+ }
352
+ else if (maxValue == minValue) {
353
+ return [maxValue];
354
+ }
355
+ var times100 = (function (_value) {
356
+ var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
357
+ var _times100 = -1, _tiemsValue = _value;
358
+ while (_times100_base == 10 ?
359
+ (_tiemsValue >= -100 && _tiemsValue <= 100)
360
+ :
361
+ (_tiemsValue <= -100 || _tiemsValue >= 100)) {
362
+ _times100 += 1;
363
+ _tiemsValue *= _times100_base;
364
+ }
365
+ if (_times100_base == 10) {
366
+ return Math.pow(10, _times100);
367
+ }
368
+ else {
369
+ var temp = "0.";
370
+ for (var i = 1; i < _times100; i++) {
371
+ temp += "0";
372
+ }
373
+ return +(temp + "1");
374
+ }
375
+ })(maxValue - minValue);
376
+ var distance100 = Math.ceil((maxValue - minValue) * times100 / num);
377
+ distance100 = {
378
+ 3: 2,
379
+ 4: 5,
380
+ 6: 5,
381
+ 7: 5,
382
+ 8: 10,
383
+ 9: 10,
384
+ 11: 10,
385
+ 12: 10,
386
+ 13: 15,
387
+ 14: 15,
388
+ 16: 15,
389
+ 17: 15,
390
+ 18: 20,
391
+ 19: 20,
392
+ 21: 20,
393
+ 22: 20,
394
+ 23: 25,
395
+ 24: 25,
396
+ 26: 25,
397
+ 27: 25
398
+ }[distance100] || distance100;
399
+ var distance = distance100 / times100;
400
+ var begin = Math.floor(minValue / distance) * distance;
401
+ var rulerArray = [];
402
+ rulerArray.push(begin);
403
+ for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
404
+ rulerArray.push(begin + distance * index);
405
+ }
406
+ return rulerArray;
407
+ }
408
+
409
+ /******************************************************************************
410
+ Copyright (c) Microsoft Corporation.
411
+
412
+ Permission to use, copy, modify, and/or distribute this software for any
413
+ purpose with or without fee is hereby granted.
414
+
415
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
416
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
417
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
418
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
419
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
420
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
421
+ PERFORMANCE OF THIS SOFTWARE.
422
+ ***************************************************************************** */
423
+ /* global Reflect, Promise */
424
+
425
+ var extendStatics = function(d, b) {
426
+ extendStatics = Object.setPrototypeOf ||
427
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
428
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
429
+ return extendStatics(d, b);
430
+ };
431
+
432
+ function __extends(d, b) {
433
+ if (typeof b !== "function" && b !== null)
434
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
435
+ extendStatics(d, b);
436
+ function __() { this.constructor = d; }
437
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
438
+ }
439
+
440
+ function __spreadArray(to, from, pack) {
441
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
442
+ if (ar || !(i in from)) {
443
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
444
+ ar[i] = from[i];
445
+ }
446
+ }
447
+ return to.concat(ar || Array.prototype.slice.call(from));
448
+ }
449
+
744
450
  var XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"];
745
451
 
746
452
  function toNode(tagname) {
@@ -780,7 +486,35 @@
780
486
  }
781
487
  }
782
488
 
783
- var initText = function (el, config, x, y, deg) {
489
+ var rotate = function (cx, cy, deg, x, y) {
490
+ var cos = Math.cos(deg), sin = Math.sin(deg);
491
+ return [
492
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
493
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
494
+ ];
495
+ };
496
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
497
+ if (rotateA < 0) {
498
+ beginA += rotateA;
499
+ rotateA *= -1;
500
+ }
501
+ var temp = [], p;
502
+ p = rotate(0, 0, beginA, r1, 0);
503
+ temp[0] = p[0];
504
+ temp[1] = p[1];
505
+ p = rotate(0, 0, rotateA, p[0], p[1]);
506
+ temp[2] = p[0];
507
+ temp[3] = p[1];
508
+ p = rotate(0, 0, beginA, r2, 0);
509
+ temp[4] = p[0];
510
+ temp[5] = p[1];
511
+ p = rotate(0, 0, rotateA, p[0], p[1]);
512
+ temp[6] = p[0];
513
+ temp[7] = p[1];
514
+ 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);
515
+ }
516
+
517
+ var initText$1 = function (el, config, x, y, deg) {
784
518
  if (el.nodeName.toLowerCase() !== 'text')
785
519
  throw new Error('Need a <text> !');
786
520
  setAttribute(el, "dy", {
@@ -805,7 +539,7 @@
805
539
  setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
806
540
  }
807
541
  };
808
- var initCircle = function (el, cx, cy, r) {
542
+ var initCircle$1 = function (el, cx, cy, r) {
809
543
  if (el.nodeName.toLowerCase() !== 'circle')
810
544
  throw new Error('Need a <circle> !');
811
545
  setAttribute(el, 'cx', cx);
@@ -817,7 +551,7 @@
817
551
  throw new Error('Need a <path> !');
818
552
  setAttribute(el, 'd', path);
819
553
  };
820
- var initRect = function (el, x, y, width, height) {
554
+ var initRect$1 = function (el, x, y, width, height) {
821
555
  if (el.nodeName.toLowerCase() !== 'rect')
822
556
  throw new Error('Need a <rect> !');
823
557
  if (height < 0) {
@@ -828,420 +562,1337 @@
828
562
  width *= -1;
829
563
  x -= width;
830
564
  }
831
- setAttribute(el, 'x', x);
832
- setAttribute(el, 'y', y);
833
- setAttribute(el, 'width', width);
834
- setAttribute(el, 'height', height);
565
+ setAttribute(el, 'x', x);
566
+ setAttribute(el, 'y', y);
567
+ setAttribute(el, 'width', width);
568
+ setAttribute(el, 'height', height);
569
+ };
570
+ var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
571
+ if (el.nodeName.toLowerCase() !== 'path')
572
+ throw new Error('Need a <path> !');
573
+ beginDeg = beginDeg % (Math.PI * 2);
574
+ if (r1 > r2) {
575
+ var temp = r1;
576
+ r1 = r2;
577
+ r2 = temp;
578
+ }
579
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
580
+ deg = Math.PI * 1.999999;
581
+ }
582
+ else {
583
+ deg = deg % (Math.PI * 2);
584
+ }
585
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
586
+ var f = (endA - beginA) > Math.PI ? 1 : 0, d = "M" + begInnerX + " " + begInnerY;
587
+ if (r < 0)
588
+ r = -r;
589
+ d +=
590
+ "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
591
+ if (config["arc-end-cap"] == 'round')
592
+ d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
593
+ else if (config["arc-end-cap"] == '-round')
594
+ d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
595
+ else
596
+ d += "L" + endOuterX + " " + endOuterY;
597
+ d += "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
598
+ if (config["arc-start-cap"] == 'round')
599
+ d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
600
+ else if (config["arc-start-cap"] == '-round')
601
+ d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
602
+ else
603
+ d += "L" + begInnerX + " " + begInnerY;
604
+ if (config["arc-start-cap"] == 'butt')
605
+ d += "Z";
606
+ setAttribute(el, 'd', d);
607
+ });
608
+ };
609
+
610
+ var oldAttrName$1 = {
611
+ "font-size": "fontSize",
612
+ "font-family": "fontFamily",
613
+ "arc-start-cap": "arcStartCap",
614
+ "arc-end-cap": "arcEndCap"
615
+ };
616
+ var SVG$1 = (function () {
617
+ function SVG(svg) {
618
+ this.name = "SVG";
619
+ this.__config = {
620
+ "fillStyle": "#000",
621
+ "strokeStyle": "#000",
622
+ "lineWidth": 1,
623
+ "textAlign": "left",
624
+ "textBaseline": "middle",
625
+ "font-size": 16,
626
+ "font-family": "sans-serif",
627
+ "arc-start-cap": "butt",
628
+ "arc-end-cap": "butt",
629
+ "lineDash": []
630
+ };
631
+ this.__path = "";
632
+ this.__currentPosition = [];
633
+ this.__svg = svg;
634
+ }
635
+ SVG.prototype.config = function (params) {
636
+ if (typeof params !== 'object') {
637
+ return this.__config[oldAttrName$1[params] || params];
638
+ }
639
+ else {
640
+ for (var key in params) {
641
+ var _key = oldAttrName$1[key] || key;
642
+ this.__config[_key] = params[key];
643
+ }
644
+ }
645
+ return this;
646
+ };
647
+ SVG.prototype.useEl = function (el) {
648
+ this.__useEl = el;
649
+ return this;
650
+ };
651
+ SVG.prototype.getEl = function () {
652
+ return this.__useEl;
653
+ };
654
+ SVG.prototype.appendEl = function (el, context) {
655
+ context = context || this.__svg;
656
+ if (typeof el == 'string')
657
+ el = toNode(el);
658
+ context.appendChild(el);
659
+ this.__useEl = el;
660
+ return this;
661
+ };
662
+ SVG.prototype.appendBoard = function (el, context) {
663
+ var _el = el;
664
+ if (typeof el == 'string')
665
+ _el = {
666
+ text: "text",
667
+ path: "path",
668
+ arc: "path",
669
+ circle: "circle",
670
+ rect: "rect"
671
+ }[el] || "";
672
+ if (_el == "")
673
+ throw new Error("Unsupported drawing method:" + el);
674
+ return this.appendEl(_el, context);
675
+ };
676
+ SVG.prototype.remove = function () {
677
+ if (!this.__useEl) {
678
+ throw new Error("Currently, no node can be deleted.");
679
+ }
680
+ else {
681
+ this.__useEl.parentNode.removeChild(this.__useEl);
682
+ }
683
+ return this;
684
+ };
685
+ SVG.prototype.attr = function (params) {
686
+ if (!this.__useEl)
687
+ throw new Error("Currently, no node can be modified or viewed.");
688
+ if (typeof params !== 'object') {
689
+ return getAttribute(this.__useEl, params);
690
+ }
691
+ else {
692
+ for (var key in params) {
693
+ setAttribute(this.__useEl, key, params[key]);
694
+ }
695
+ return this;
696
+ }
697
+ };
698
+ SVG.prototype.fillText = function (text, x, y, deg) {
699
+ if (deg === void 0) { deg = 0; }
700
+ initText$1(this.__useEl, this.__config, x, y, deg);
701
+ this.__useEl.textContent = text;
702
+ fill(this.__useEl, this.__config);
703
+ return this;
704
+ };
705
+ SVG.prototype.strokeText = function (text, x, y, deg) {
706
+ if (deg === void 0) { deg = 0; }
707
+ initText$1(this.__useEl, this.__config, x, y, deg);
708
+ this.__useEl.textContent = text;
709
+ stroke(this.__useEl, this.__config);
710
+ return this;
711
+ };
712
+ SVG.prototype.fullText = function (text, x, y, deg) {
713
+ if (deg === void 0) { deg = 0; }
714
+ initText$1(this.__useEl, this.__config, x, y, deg);
715
+ this.__useEl.textContent = text;
716
+ full(this.__useEl, this.__config);
717
+ return this;
718
+ };
719
+ SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
720
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
721
+ fill(this.__useEl, this.__config);
722
+ return this;
723
+ };
724
+ SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
725
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
726
+ stroke(this.__useEl, this.__config);
727
+ return this;
728
+ };
729
+ SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
730
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
731
+ full(this.__useEl, this.__config);
732
+ return this;
733
+ };
734
+ SVG.prototype.fillCircle = function (cx, cy, r) {
735
+ initCircle$1(this.__useEl, cx, cy, r);
736
+ fill(this.__useEl, this.__config);
737
+ return this;
738
+ };
739
+ SVG.prototype.strokeCircle = function (cx, cy, r) {
740
+ initCircle$1(this.__useEl, cx, cy, r);
741
+ stroke(this.__useEl, this.__config);
742
+ return this;
743
+ };
744
+ SVG.prototype.fullCircle = function (cx, cy, r) {
745
+ initCircle$1(this.__useEl, cx, cy, r);
746
+ full(this.__useEl, this.__config);
747
+ return this;
748
+ };
749
+ SVG.prototype.fillRect = function (x, y, width, height) {
750
+ initRect$1(this.__useEl, x, y, width, height);
751
+ fill(this.__useEl, this.__config);
752
+ return this;
753
+ };
754
+ SVG.prototype.strokeRect = function (x, y, width, height) {
755
+ initRect$1(this.__useEl, x, y, width, height);
756
+ stroke(this.__useEl, this.__config);
757
+ return this;
758
+ };
759
+ SVG.prototype.fullRect = function (x, y, width, height) {
760
+ initRect$1(this.__useEl, x, y, width, height);
761
+ full(this.__useEl, this.__config);
762
+ return this;
763
+ };
764
+ SVG.prototype.beginPath = function () {
765
+ this.__currentPosition = [];
766
+ this.__path = "";
767
+ return this;
768
+ };
769
+ SVG.prototype.closePath = function () {
770
+ this.__path += "Z";
771
+ return this;
772
+ };
773
+ SVG.prototype.moveTo = function (x, y) {
774
+ this.__currentPosition = [x, y];
775
+ this.__path += "M" + x + " " + y;
776
+ return this;
777
+ };
778
+ SVG.prototype.lineTo = function (x, y) {
779
+ this.__currentPosition = [x, y];
780
+ this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
781
+ return this;
782
+ };
783
+ SVG.prototype.fill = function () {
784
+ initPath(this.__useEl, this.__path);
785
+ fill(this.__useEl, this.__config);
786
+ return this;
787
+ };
788
+ SVG.prototype.stroke = function () {
789
+ initPath(this.__useEl, this.__path);
790
+ stroke(this.__useEl, this.__config);
791
+ return this;
792
+ };
793
+ SVG.prototype.full = function () {
794
+ initPath(this.__useEl, this.__path);
795
+ full(this.__useEl, this.__config);
796
+ return this;
797
+ };
798
+ SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
799
+ var begPosition = rotate$1(x, y, beginDeg, x + r, y);
800
+ var endPosition = rotate$1(x, y, beginDeg + deg, x + r, y);
801
+ beginDeg = beginDeg / Math.PI * 180;
802
+ deg = deg / Math.PI * 180;
803
+ if (this.__path == '') {
804
+ this.__path += "M" + begPosition[0] + "," + begPosition[1];
805
+ }
806
+ else if (begPosition[0] != this.__currentPosition[0] || begPosition[1] != this.__currentPosition[1]) {
807
+ this.__path += "L" + begPosition[0] + "," + begPosition[1];
808
+ }
809
+ this.__path += "A" + r + "," + r + " 0 " + ((deg > 180 || deg < -180) ? 1 : 0) + "," + (deg > 0 ? 1 : 0) + " " + endPosition[0] + "," + endPosition[1];
810
+ return this;
811
+ };
812
+ SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
813
+ this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
814
+ return this;
815
+ };
816
+ SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
817
+ this.__path += "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
818
+ return this;
819
+ };
820
+ return SVG;
821
+ }());
822
+
823
+ var SVG = (function (_super) {
824
+ __extends(SVG, _super);
825
+ function SVG(el) {
826
+ if (!el) {
827
+ throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
828
+ }
829
+ var width = el.clientWidth, height = el.clientHeight;
830
+ var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
831
+ el.appendChild(ViewSVG);
832
+ ViewSVG.setAttribute("width", width + "");
833
+ ViewSVG.setAttribute("height", height + "");
834
+ ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
835
+ return _super.call(this, ViewSVG) || this;
836
+ }
837
+ return SVG;
838
+ }(SVG$1));
839
+
840
+ var initText = function (painter, config, x, y, deg) {
841
+ painter.beginPath();
842
+ painter.translate(x, y);
843
+ painter.rotate(deg);
844
+ painter.font = config.fontStyle + " " + config.fontWeight + " " + config.fontSize + "px " + config.fontFamily;
845
+ return painter;
835
846
  };
836
- var initArc = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
837
- if (el.nodeName.toLowerCase() !== 'path')
838
- throw new Error('Need a <path> !');
839
- beginDeg = beginDeg % (Math.PI * 2);
847
+ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
840
848
  if (r1 > r2) {
841
849
  var temp = r1;
842
850
  r1 = r2;
843
851
  r2 = temp;
844
852
  }
853
+ beginDeg = beginDeg % (Math.PI * 2);
845
854
  if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
846
- deg = Math.PI * 1.999999;
855
+ deg = Math.PI * 2;
847
856
  }
848
857
  else {
849
858
  deg = deg % (Math.PI * 2);
850
859
  }
851
860
  arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
852
- var f = (endA - beginA) > Math.PI ? 1 : 0, d = "M" + begInnerX + " " + begInnerY;
853
861
  if (r < 0)
854
862
  r = -r;
855
- d +=
856
- "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
857
- if (config["arc-end-cap"] == 'round')
858
- d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
859
- else if (config["arc-end-cap"] == '-round')
860
- d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
863
+ painter.beginPath();
864
+ painter.moveTo(begInnerX, begInnerY);
865
+ painter.arc(cx, cy, r1, beginA, endA, false);
866
+ if (config.arcEndCap != 'round')
867
+ painter.lineTo(endOuterX, endOuterY);
861
868
  else
862
- d += "L" + endOuterX + " " + endOuterY;
863
- d += "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
864
- if (config["arc-start-cap"] == 'round')
865
- d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
866
- else if (config["arc-start-cap"] == '-round')
867
- d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
869
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
870
+ painter.arc(cx, cy, r2, endA, beginA, true);
871
+ if (config.arcStartCap != 'round')
872
+ painter.lineTo(begInnerX, begInnerY);
868
873
  else
869
- d += "L" + begInnerX + " " + begInnerY;
870
- if (config["arc-start-cap"] == 'butt')
871
- d += "Z";
872
- setAttribute(el, 'd', d);
874
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
873
875
  });
876
+ if (config.arcStartCap == 'butt')
877
+ painter.closePath();
878
+ return painter;
879
+ };
880
+ var initCircle = function (painter, cx, cy, r) {
881
+ painter.beginPath();
882
+ painter.moveTo(cx + r, cy);
883
+ painter.arc(cx, cy, r, 0, Math.PI * 2);
884
+ return painter;
885
+ };
886
+ var initRect = function (painter, x, y, width, height) {
887
+ painter.beginPath();
888
+ painter.rect(x, y, width, height);
889
+ return painter;
874
890
  };
875
891
 
876
- var SVG$1 = (function () {
877
- function SVG(svg) {
878
- this.name = "SVG";
879
- this.__config = {
880
- "fillStyle": "#000",
881
- "strokeStyle": "#000",
892
+ function texts (painter, contents, width, height, doback) {
893
+ var lineNumber = 0, content = "";
894
+ for (var i = 0; i < contents.length; i++) {
895
+ if (painter.measureText(content + contents[i]).width > width) {
896
+ lineNumber += 1;
897
+ doback(content, (lineNumber - 0.5) * height);
898
+ content = contents[i];
899
+ }
900
+ else if (i == contents.length - 1) {
901
+ lineNumber += 1;
902
+ doback(content + contents[i], (lineNumber - 0.5) * height);
903
+ }
904
+ else {
905
+ content += contents[i];
906
+ }
907
+ }
908
+ return lineNumber * height;
909
+ }
910
+
911
+ var Painter = (function () {
912
+ function Painter(canvas, opts, region) {
913
+ if (opts === void 0) { opts = {}; }
914
+ this.__region = null;
915
+ this.__specialConfig = {
916
+ "fontSize": 16,
917
+ "fontFamily": "sans-serif",
918
+ "fontWeight": 400,
919
+ "fontStyle": "normal",
920
+ "arcStartCap": 'butt',
921
+ "arcEndCap": 'butt'
922
+ };
923
+ this.__initConfig = {
924
+ "fillStyle": 'black',
925
+ "strokeStyle": 'black',
882
926
  "lineWidth": 1,
883
- "textAlign": "left",
884
- "textBaseline": "middle",
885
- "font-size": 16,
886
- "font-family": "sans-serif",
887
- "arc-start-cap": "butt",
888
- "arc-end-cap": "butt",
889
- "lineDash": []
927
+ "textAlign": 'left',
928
+ "textBaseline": 'middle',
929
+ "lineDash": [],
930
+ "shadowBlur": 0,
931
+ "shadowColor": "black"
890
932
  };
891
- this.__path = "";
892
- this.__currentPosition = [];
893
- this.__svg = svg;
933
+ this.painter = canvas.getContext("2d", opts);
934
+ this.__region = region;
935
+ this.painter.textBaseline = 'middle';
936
+ this.painter.textAlign = 'left';
894
937
  }
895
- SVG.prototype.config = function (params) {
896
- if (typeof params !== 'object') {
897
- return this.__config[params];
938
+ Painter.prototype.useConfig = function (key, value) {
939
+ if (this.__region) {
940
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
941
+ this.__region.useConfig(key, value);
942
+ }
943
+ }
944
+ if (key == 'lineDash') {
945
+ if (this.painter.setLineDash)
946
+ this.painter.setLineDash(value);
947
+ }
948
+ else if (key in this.__specialConfig) {
949
+ this.__specialConfig[key] = value;
950
+ }
951
+ else if (key in this.__initConfig) {
952
+ this.painter[key] = value;
898
953
  }
899
954
  else {
900
- for (var key in params) {
901
- this.__config[key] = params[key];
902
- }
955
+ throw new Error('Illegal configuration item of painter : ' + key + " !");
903
956
  }
904
957
  return this;
905
958
  };
906
- SVG.prototype.useEl = function (el) {
907
- this.__useEl = el;
959
+ Painter.prototype.fillText = function (text, x, y, deg) {
960
+ if (deg === void 0) { deg = 0; }
961
+ if (this.__region)
962
+ this.__region.fillText(text, x, y, deg);
963
+ this.painter.save();
964
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
965
+ this.painter.restore();
908
966
  return this;
909
967
  };
910
- SVG.prototype.getEl = function () {
911
- return this.__useEl;
968
+ Painter.prototype.strokeText = function (text, x, y, deg) {
969
+ if (deg === void 0) { deg = 0; }
970
+ if (this.__region)
971
+ this.__region.strokeText(text, x, y, deg);
972
+ this.painter.save();
973
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
974
+ this.painter.restore();
975
+ return this;
912
976
  };
913
- SVG.prototype.appendEl = function (el, context) {
914
- context = context || this.__svg;
915
- if (typeof el == 'string')
916
- el = toNode(el);
917
- context.appendChild(el);
918
- this.__useEl = el;
977
+ Painter.prototype.fullText = function (text, x, y, deg) {
978
+ if (deg === void 0) { deg = 0; }
979
+ if (this.__region)
980
+ this.__region.fullText(text, x, y, deg);
981
+ this.painter.save();
982
+ initText(this.painter, this.__specialConfig, x, y, deg);
983
+ this.painter.fillText(text, 0, 0);
984
+ this.painter.strokeText(text, 0, 0);
985
+ this.painter.restore();
919
986
  return this;
920
987
  };
921
- SVG.prototype.appendBoard = function (el, context) {
922
- var _el = el;
923
- if (typeof el == 'string')
924
- _el = {
925
- text: "text",
926
- path: "path",
927
- arc: "path",
928
- circle: "circle",
929
- rect: "rect"
930
- }[el] || "";
931
- if (_el == "")
932
- throw new Error("Unsupported drawing method:" + el);
933
- return this.appendEl(_el, context);
988
+ Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
989
+ var _this = this;
990
+ if (lineHeight === void 0) { lineHeight = 1.2; }
991
+ if (deg === void 0) { deg = 0; }
992
+ if (this.__region)
993
+ this.__region.fillTexts(contents, x, y, width, lineHeight);
994
+ this.painter.save();
995
+ initText(this.painter, this.__specialConfig, x, y, deg);
996
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
997
+ _this.painter.fillText(content, 0, top);
998
+ });
999
+ this.painter.restore();
1000
+ return height;
934
1001
  };
935
- SVG.prototype.remove = function () {
936
- if (!this.__useEl) {
937
- throw new Error("Currently, no node can be deleted.");
938
- }
939
- else {
940
- this.__useEl.parentNode.removeChild(this.__useEl);
941
- }
1002
+ Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
1003
+ var _this = this;
1004
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1005
+ if (deg === void 0) { deg = 0; }
1006
+ if (this.__region)
1007
+ this.__region.fillTexts(contents, x, y, width, lineHeight);
1008
+ this.painter.save();
1009
+ initText(this.painter, this.__specialConfig, x, y, deg);
1010
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1011
+ _this.painter.strokeText(content, 0, top);
1012
+ });
1013
+ this.painter.restore();
1014
+ return height;
1015
+ };
1016
+ Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
1017
+ var _this = this;
1018
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1019
+ if (deg === void 0) { deg = 0; }
1020
+ if (this.__region)
1021
+ this.__region.fillTexts(contents, x, y, width, lineHeight);
1022
+ this.painter.save();
1023
+ initText(this.painter, this.__specialConfig, x, y, deg);
1024
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1025
+ _this.painter.fillText(content, 0, top);
1026
+ _this.painter.strokeText(content, 0, top);
1027
+ });
1028
+ this.painter.restore();
1029
+ return height;
1030
+ };
1031
+ Painter.prototype.beginPath = function () {
1032
+ if (this.__region)
1033
+ this.__region.beginPath();
1034
+ this.painter.beginPath();
1035
+ return this;
1036
+ };
1037
+ Painter.prototype.closePath = function () {
1038
+ if (this.__region)
1039
+ this.__region.closePath();
1040
+ this.painter.closePath();
1041
+ return this;
1042
+ };
1043
+ Painter.prototype.moveTo = function (x, y) {
1044
+ if (this.__region)
1045
+ this.__region.moveTo(x, y);
1046
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1047
+ return this;
1048
+ };
1049
+ Painter.prototype.lineTo = function (x, y) {
1050
+ if (this.__region)
1051
+ this.__region.lineTo(x, y);
1052
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1053
+ return this;
1054
+ };
1055
+ Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
1056
+ if (this.__region)
1057
+ this.__region.arc(x, y, r, beginDeg, deg);
1058
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
1059
+ return this;
1060
+ };
1061
+ Painter.prototype.fill = function () {
1062
+ if (this.__region)
1063
+ this.__region.fill();
1064
+ this.painter.fill();
1065
+ return this;
1066
+ };
1067
+ Painter.prototype.stroke = function () {
1068
+ if (this.__region)
1069
+ this.__region.stroke();
1070
+ this.painter.stroke();
1071
+ return this;
1072
+ };
1073
+ Painter.prototype.full = function () {
1074
+ if (this.__region)
1075
+ this.__region.full();
1076
+ this.painter.fill();
1077
+ this.painter.stroke();
1078
+ return this;
1079
+ };
1080
+ Painter.prototype.save = function () {
1081
+ if (this.__region)
1082
+ this.__region.save();
1083
+ this.painter.save();
1084
+ return this;
1085
+ };
1086
+ Painter.prototype.restore = function () {
1087
+ if (this.__region)
1088
+ this.__region.restore();
1089
+ this.painter.restore();
942
1090
  return this;
943
1091
  };
944
- SVG.prototype.attr = function (params) {
945
- if (!this.__useEl)
946
- throw new Error("Currently, no node can be modified or viewed.");
947
- if (typeof params !== 'object') {
948
- return getAttribute(this.__useEl, params);
949
- }
950
- else {
951
- for (var key in params) {
952
- setAttribute(this.__useEl, key, params[key]);
953
- }
954
- return this;
955
- }
1092
+ Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1093
+ if (this.__region)
1094
+ this.__region.quadraticCurveTo(cpx, cpy, x, y);
1095
+ this.painter.quadraticCurveTo(cpx, cpy, x, y);
1096
+ return this;
956
1097
  };
957
- SVG.prototype.fillText = function (text, x, y, deg) {
958
- if (deg === void 0) { deg = 0; }
959
- initText(this.__useEl, this.__config, x, y, deg);
960
- this.__useEl.textContent = text;
961
- fill(this.__useEl, this.__config);
1098
+ Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1099
+ if (this.__region)
1100
+ this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1101
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
962
1102
  return this;
963
1103
  };
964
- SVG.prototype.strokeText = function (text, x, y, deg) {
965
- if (deg === void 0) { deg = 0; }
966
- initText(this.__useEl, this.__config, x, y, deg);
967
- this.__useEl.textContent = text;
968
- stroke(this.__useEl, this.__config);
1104
+ Painter.prototype.clearRect = function (x, y, w, h) {
1105
+ if (this.__region)
1106
+ this.__region.clearRect(x, y, w, h);
1107
+ this.painter.clearRect(x, y, w, h);
969
1108
  return this;
970
1109
  };
971
- SVG.prototype.fullText = function (text, x, y, deg) {
972
- if (deg === void 0) { deg = 0; }
973
- initText(this.__useEl, this.__config, x, y, deg);
974
- this.__useEl.textContent = text;
975
- full(this.__useEl, this.__config);
1110
+ Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
1111
+ if (this.__region)
1112
+ this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
1113
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
976
1114
  return this;
977
1115
  };
978
- SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
979
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
980
- fill(this.__useEl, this.__config);
1116
+ Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
1117
+ if (this.__region)
1118
+ this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
1119
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
981
1120
  return this;
982
1121
  };
983
- SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
984
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
985
- stroke(this.__useEl, this.__config);
1122
+ Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
1123
+ if (this.__region)
1124
+ this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
1125
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
1126
+ this.painter.fill();
1127
+ this.painter.stroke();
986
1128
  return this;
987
1129
  };
988
- SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
989
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
990
- full(this.__useEl, this.__config);
1130
+ Painter.prototype.fillCircle = function (cx, cy, r) {
1131
+ if (this.__region)
1132
+ this.__region.fillCircle(cx, cy, r);
1133
+ initCircle(this.painter, cx, cy, r).fill();
991
1134
  return this;
992
1135
  };
993
- SVG.prototype.fillCircle = function (cx, cy, r) {
994
- initCircle(this.__useEl, cx, cy, r);
995
- fill(this.__useEl, this.__config);
1136
+ Painter.prototype.strokeCircle = function (cx, cy, r) {
1137
+ if (this.__region)
1138
+ this.__region.strokeCircle(cx, cy, r);
1139
+ initCircle(this.painter, cx, cy, r).stroke();
996
1140
  return this;
997
1141
  };
998
- SVG.prototype.strokeCircle = function (cx, cy, r) {
999
- initCircle(this.__useEl, cx, cy, r);
1000
- stroke(this.__useEl, this.__config);
1142
+ Painter.prototype.fullCircle = function (cx, cy, r) {
1143
+ if (this.__region)
1144
+ this.__region.fullCircle(cx, cy, r);
1145
+ initCircle(this.painter, cx, cy, r);
1146
+ this.painter.fill();
1147
+ this.painter.stroke();
1001
1148
  return this;
1002
1149
  };
1003
- SVG.prototype.fullCircle = function (cx, cy, r) {
1004
- initCircle(this.__useEl, cx, cy, r);
1005
- full(this.__useEl, this.__config);
1150
+ Painter.prototype.fillRect = function (x, y, width, height) {
1151
+ if (this.__region)
1152
+ this.__region.fillRect(x, y, width, height);
1153
+ initRect(this.painter, x, y, width, height).fill();
1006
1154
  return this;
1007
1155
  };
1008
- SVG.prototype.fillRect = function (x, y, width, height) {
1009
- initRect(this.__useEl, x, y, width, height);
1010
- fill(this.__useEl, this.__config);
1156
+ Painter.prototype.strokeRect = function (x, y, width, height) {
1157
+ if (this.__region)
1158
+ this.__region.strokeRect(x, y, width, height);
1159
+ initRect(this.painter, x, y, width, height).stroke();
1011
1160
  return this;
1012
1161
  };
1013
- SVG.prototype.strokeRect = function (x, y, width, height) {
1014
- initRect(this.__useEl, x, y, width, height);
1015
- stroke(this.__useEl, this.__config);
1162
+ Painter.prototype.fullRect = function (x, y, width, height) {
1163
+ if (this.__region)
1164
+ this.__region.fullRect(x, y, width, height);
1165
+ initRect(this.painter, x, y, width, height);
1166
+ this.painter.fill();
1167
+ this.painter.stroke();
1016
1168
  return this;
1017
1169
  };
1018
- SVG.prototype.fullRect = function (x, y, width, height) {
1019
- initRect(this.__useEl, x, y, width, height);
1020
- full(this.__useEl, this.__config);
1170
+ return Painter;
1171
+ }());
1172
+
1173
+ function assemble (begin, end, step, count) {
1174
+ var val = [];
1175
+ for (var index = 0; index < count; index++)
1176
+ val[index] = begin;
1177
+ return function () {
1178
+ for (var i = 0; i < count; i++) {
1179
+ if (val[i] < end) {
1180
+ val[i] = +(val[i] + step).toFixed(7);
1181
+ break;
1182
+ }
1183
+ else if (i < count - 1) {
1184
+ val[i] = begin;
1185
+ }
1186
+ }
1187
+ return val;
1188
+ };
1189
+ }
1190
+
1191
+ var oldAttrName = {
1192
+ "font-size": "fontSize",
1193
+ "font-family": "fontFamily",
1194
+ "font-weight": "fontWeight",
1195
+ "font-style": "fontStyle",
1196
+ "arc-start-cap": "arcStartCap",
1197
+ "arc-end-cap": "arcEndCap"
1198
+ };
1199
+ var Canvas$1 = (function (_super) {
1200
+ __extends(Canvas, _super);
1201
+ function Canvas(ViewCanvas, RegionCanvas) {
1202
+ var _this = _super.call(this, ViewCanvas, {}, new Painter(RegionCanvas, {
1203
+ willReadFrequently: true
1204
+ })) || this;
1205
+ _this.name = "Canvas";
1206
+ _this.__regionList = {};
1207
+ _this.__regionAssemble = assemble(0, 255, 1, 3);
1208
+ _this.setRegion("");
1209
+ return _this;
1210
+ }
1211
+ Canvas.prototype.config = function (configs) {
1212
+ for (var key in configs) {
1213
+ var _key = oldAttrName[key] || key;
1214
+ this.useConfig(_key, configs[key]);
1215
+ }
1021
1216
  return this;
1022
1217
  };
1023
- SVG.prototype.beginPath = function () {
1024
- this.__currentPosition = [];
1025
- this.__path = "";
1218
+ Canvas.prototype.setRegion = function (regionName) {
1219
+ if (regionName) {
1220
+ if (this.__regionList[regionName] == undefined) {
1221
+ var tempColor = this.__regionAssemble();
1222
+ this.__regionList[regionName] = "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
1223
+ }
1224
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
1225
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
1226
+ }
1227
+ else {
1228
+ this.__region.useConfig("fillStyle", "#000000") &&
1229
+ this.__region.useConfig("strokeStyle", "#000000");
1230
+ }
1026
1231
  return this;
1027
1232
  };
1028
- SVG.prototype.closePath = function () {
1029
- this.__path += "Z";
1233
+ Canvas.prototype.getRegion = function (x, y) {
1234
+ var _this = this;
1235
+ return new Promise(function (resolve, reject) {
1236
+ var imgData = _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1);
1237
+ var currentRGBA = imgData.data;
1238
+ var doit = function () {
1239
+ for (var key in _this.__regionList) {
1240
+ if ("rgb(" + currentRGBA[0] + "," + currentRGBA[1] + "," + currentRGBA[2] + ")" == _this.__regionList[key]) {
1241
+ resolve(key);
1242
+ break;
1243
+ }
1244
+ }
1245
+ resolve("");
1246
+ };
1247
+ if (currentRGBA) {
1248
+ doit();
1249
+ }
1250
+ else {
1251
+ imgData.then(function (data) {
1252
+ currentRGBA = data;
1253
+ doit();
1254
+ });
1255
+ }
1256
+ });
1257
+ };
1258
+ Canvas.prototype.getContext = function (isRegion) {
1259
+ if (isRegion === void 0) { isRegion = false; }
1260
+ return isRegion ? this.__region.painter : this.painter;
1261
+ };
1262
+ return Canvas;
1263
+ }(Painter));
1264
+
1265
+ var Canvas = (function (_super) {
1266
+ __extends(Canvas, _super);
1267
+ function Canvas(el) {
1268
+ var _this = this;
1269
+ if (!el) {
1270
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
1271
+ }
1272
+ var width = el.clientWidth, height = el.clientHeight;
1273
+ var ViewCanvas, RegionCanvas;
1274
+ var _el = el;
1275
+ if (_el._vislite_canvas_) {
1276
+ ViewCanvas = _el._vislite_canvas_[0];
1277
+ RegionCanvas = _el._vislite_canvas_[1];
1278
+ }
1279
+ else {
1280
+ ViewCanvas = document.createElement('canvas');
1281
+ el.appendChild(ViewCanvas);
1282
+ RegionCanvas = document.createElement('canvas');
1283
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
1284
+ el.setAttribute('vislite', 'Canvas');
1285
+ }
1286
+ for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
1287
+ var canvas = _a[_i];
1288
+ canvas.style.width = width + "px";
1289
+ canvas.setAttribute('width', width + "");
1290
+ canvas.style.height = height + "px";
1291
+ canvas.setAttribute('height', height + "");
1292
+ }
1293
+ _this = _super.call(this, ViewCanvas, RegionCanvas) || this;
1294
+ _this.__canvas = ViewCanvas;
1295
+ return _this;
1296
+ }
1297
+ Canvas.prototype.toDataURL = function () {
1298
+ var _this = this;
1299
+ return new Promise(function (resolve) {
1300
+ resolve(_this.__canvas.toDataURL());
1301
+ });
1302
+ };
1303
+ return Canvas;
1304
+ }(Canvas$1));
1305
+
1306
+ function getWebGLContext (canvas, scale, opts) {
1307
+ if (opts === void 0) { opts = {}; }
1308
+ var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null;
1309
+ for (var i = 0; i < names.length; i++) {
1310
+ try {
1311
+ painter = canvas.getContext(names[i], opts);
1312
+ }
1313
+ catch (e) { }
1314
+ if (painter)
1315
+ break;
1316
+ }
1317
+ if (!painter)
1318
+ throw new Error('Non canvas or browser does not support webgl.');
1319
+ var width = painter.canvas.width, height = painter.canvas.height;
1320
+ var viewWidth = width * scale;
1321
+ var viewHeight = height * scale;
1322
+ painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
1323
+ painter.depthFunc(painter.LEQUAL);
1324
+ painter.enable(painter.DEPTH_TEST);
1325
+ return painter;
1326
+ }
1327
+
1328
+ function getColorFactory (painter) {
1329
+ var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
1330
+ var pixels = new Uint8Array(4 * width * height);
1331
+ painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
1332
+ return function (x, y) {
1333
+ y = height - y;
1334
+ var pixelR = pixels[4 * (y * width + x)];
1335
+ var pixelG = pixels[4 * (y * width + x) + 1];
1336
+ var pixelB = pixels[4 * (y * width + x) + 2];
1337
+ var pixelA = pixels[4 * (y * width + x) + 3];
1338
+ return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
1339
+ };
1340
+ }
1341
+
1342
+ var newBuffer = function (painter) {
1343
+ return painter.createBuffer();
1344
+ };
1345
+ var writeBuffer = function (painter, data, isElement, usage) {
1346
+ var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1347
+ painter.bufferData(TYPE, data, usage);
1348
+ };
1349
+ var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
1350
+ painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
1351
+ painter.enableVertexAttribArray(location);
1352
+ };
1353
+ var BufferObject = (function () {
1354
+ function BufferObject(painter, isElement) {
1355
+ if (isElement === void 0) { isElement = false; }
1356
+ this.__painter = painter;
1357
+ this.__isElement = isElement;
1358
+ this.__buffer = newBuffer(painter);
1359
+ this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
1360
+ }
1361
+ BufferObject.prototype.use = function () {
1362
+ this.__painter.bindBuffer(this.__type, this.__buffer);
1030
1363
  return this;
1031
1364
  };
1032
- SVG.prototype.moveTo = function (x, y) {
1033
- this.__currentPosition = [x, y];
1034
- this.__path += "M" + x + " " + y;
1365
+ BufferObject.prototype.write = function (data) {
1366
+ writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
1367
+ this.__fsize = data.BYTES_PER_ELEMENT;
1035
1368
  return this;
1036
1369
  };
1037
- SVG.prototype.lineTo = function (x, y) {
1038
- this.__currentPosition = [x, y];
1039
- this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
1370
+ BufferObject.prototype.divide = function (location, size, stride, offset) {
1371
+ if (offset === void 0) { offset = 0; }
1372
+ useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
1040
1373
  return this;
1041
1374
  };
1042
- SVG.prototype.fill = function () {
1043
- initPath(this.__useEl, this.__path);
1044
- fill(this.__useEl, this.__config);
1375
+ return BufferObject;
1376
+ }());
1377
+
1378
+ var initTexture = function (painter, type, unit) {
1379
+ var texture = painter.createTexture();
1380
+ if (type == painter.TEXTURE_2D) {
1381
+ painter.activeTexture(painter['TEXTURE' + unit]);
1382
+ }
1383
+ painter.bindTexture(type, texture);
1384
+ return texture;
1385
+ };
1386
+ var linkImage = function (painter, type, level, format, textureType, image) {
1387
+ painter.texImage2D(type, level, format, format, textureType, image);
1388
+ };
1389
+ var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
1390
+ var types = [
1391
+ painter.TEXTURE_CUBE_MAP_POSITIVE_X,
1392
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
1393
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
1394
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
1395
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
1396
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
1397
+ ], target;
1398
+ for (var i = 0; i < types.length; i++) {
1399
+ if (images[i]) {
1400
+ target = types[i];
1401
+ painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
1402
+ painter.bindTexture(type, texture);
1403
+ painter.texImage2D(target, level, format, format, textureType, images[i]);
1404
+ }
1405
+ }
1406
+ painter.generateMipmap(type);
1407
+ };
1408
+ var TextureObject = (function () {
1409
+ function TextureObject(painter, type, unit) {
1410
+ if (unit === void 0) { unit = 0; }
1411
+ this.__painter = painter;
1412
+ this.__type = {
1413
+ "2d": painter.TEXTURE_2D,
1414
+ "cube": painter.TEXTURE_CUBE_MAP
1415
+ }[type];
1416
+ this.__texture = initTexture(painter, this.__type, unit);
1417
+ painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
1418
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
1419
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
1420
+ }
1421
+ TextureObject.prototype.useImage = function (image) {
1422
+ linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
1045
1423
  return this;
1046
1424
  };
1047
- SVG.prototype.stroke = function () {
1048
- initPath(this.__useEl, this.__path);
1049
- stroke(this.__useEl, this.__config);
1425
+ TextureObject.prototype.useCube = function (images, width, height) {
1426
+ linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
1050
1427
  return this;
1051
1428
  };
1052
- SVG.prototype.full = function () {
1053
- initPath(this.__useEl, this.__path);
1054
- full(this.__useEl, this.__config);
1429
+ return TextureObject;
1430
+ }());
1431
+
1432
+ var textures = {};
1433
+ function getTexture (type, painter, kind) {
1434
+ var uniqueName = type + "-" + kind;
1435
+ if (!textures[uniqueName]) {
1436
+ textures[uniqueName] = new TextureObject(painter, kind);
1437
+ }
1438
+ return textures[uniqueName];
1439
+ }
1440
+
1441
+ var loadShader = function (painter, type, source) {
1442
+ var shader = painter.createShader(type);
1443
+ if (shader == null)
1444
+ throw new Error('Unable to create shader!');
1445
+ painter.shaderSource(shader, source);
1446
+ painter.compileShader(shader);
1447
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1448
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1449
+ return shader;
1450
+ };
1451
+ var useShader = function (painter, vshaderSource, fshaderSource) {
1452
+ var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1453
+ var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1454
+ var glProgram = painter.createProgram();
1455
+ painter.attachShader(glProgram, vertexShader);
1456
+ painter.attachShader(glProgram, fragmentShader);
1457
+ painter.linkProgram(glProgram);
1458
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1459
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
1460
+ return glProgram;
1461
+ };
1462
+ var ShaderObject = (function () {
1463
+ function ShaderObject(painter) {
1464
+ this.__painter = painter;
1465
+ }
1466
+ ShaderObject.prototype.use = function () {
1467
+ this.__painter.useProgram(this.program);
1055
1468
  return this;
1056
1469
  };
1057
- SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
1058
- var begPosition = rotate(x, y, beginDeg, x + r, y);
1059
- var endPosition = rotate(x, y, beginDeg + deg, x + r, y);
1060
- beginDeg = beginDeg / Math.PI * 180;
1061
- deg = deg / Math.PI * 180;
1062
- if (this.__path == '') {
1063
- this.__path += "M" + begPosition[0] + "," + begPosition[1];
1470
+ ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
1471
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource);
1472
+ return this;
1473
+ };
1474
+ return ShaderObject;
1475
+ }());
1476
+
1477
+ var shaders = {};
1478
+ function getShader (type, painter, mesh) {
1479
+ var uniqueName = type +
1480
+ (mesh.geometry.attributes.normal ? "1" : "0") +
1481
+ (mesh.material.image ? "1" : "0") +
1482
+ (mesh.material.color ? "1" : "0") +
1483
+ (mesh.material.cube ? "1" : "0");
1484
+ if (shaders[uniqueName])
1485
+ return shaders[uniqueName].use();
1486
+ var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
1487
+ var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n }\n ");
1488
+ var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
1489
+ shaders[uniqueName] = shader;
1490
+ return shader;
1491
+ }
1492
+
1493
+ function doDraw (type, painter, mesh, meshWorld, globalWorld) {
1494
+ var shader = getShader(type, painter, mesh);
1495
+ new BufferObject(painter).use()
1496
+ .write(mesh.geometry.attributes.position.array)
1497
+ .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, 3, 0);
1498
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
1499
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
1500
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
1501
+ if (mesh.geometry.attributes.normal) {
1502
+ new BufferObject(painter).use()
1503
+ .write(mesh.geometry.attributes.normal.array)
1504
+ .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, 3, 0);
1505
+ }
1506
+ if ("color" in mesh.material) {
1507
+ painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
1508
+ }
1509
+ else if ("cube" in mesh.material) {
1510
+ var size = mesh.material.cube.right.image.value.width;
1511
+ getTexture(type, painter, 'cube').useCube([
1512
+ mesh.material.cube.right.image.value,
1513
+ mesh.material.cube.left.image.value,
1514
+ mesh.material.cube.top.image.value,
1515
+ mesh.material.cube.bottom.image.value,
1516
+ mesh.material.cube.far.image.value,
1517
+ mesh.material.cube.near.image.value
1518
+ ], size, size);
1519
+ }
1520
+ else if ("image" in mesh.material) {
1521
+ painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
1522
+ new BufferObject(painter).use()
1523
+ .write(mesh.geometry.attributes.uv.array)
1524
+ .divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0);
1525
+ getTexture(type, painter, '2d').useImage(mesh.material.image.value);
1526
+ }
1527
+ if (mesh.geometry.index) {
1528
+ new BufferObject(painter, true).use()
1529
+ .write(mesh.geometry.index.array);
1530
+ painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
1531
+ }
1532
+ else {
1533
+ painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
1534
+ }
1535
+ }
1536
+
1537
+ var needUpdate = false;
1538
+ var scale = 10;
1539
+ var WebGL$1 = (function () {
1540
+ function WebGL(ViewCanvas, RegionCanvas) {
1541
+ this.name = "WebGL";
1542
+ this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
1543
+ this.__regionList = {};
1544
+ this.__regionAssemble = assemble(0, 1, 0.2, 3);
1545
+ this.__regionName = "";
1546
+ this.__regionColor = [0, 0, 0, 1];
1547
+ this.__scene = {
1548
+ children: [],
1549
+ matrix: new Matrix4([
1550
+ 1, 0, 0, 0,
1551
+ 0, 1, 0, 0,
1552
+ 0, 0, -1, 0,
1553
+ 0, 0, 0, scale
1554
+ ])
1555
+ };
1556
+ this.__unique = new Date().valueOf();
1557
+ this.painter = getWebGLContext(ViewCanvas, scale);
1558
+ this.__regionPainter = getWebGLContext(RegionCanvas, scale, {});
1559
+ var proportion = this.painter.canvas.width / this.painter.canvas.height;
1560
+ var xProportion = 1;
1561
+ var yProportion = 1;
1562
+ if (proportion > 1) {
1563
+ xProportion = 1 / proportion;
1064
1564
  }
1065
- else if (begPosition[0] != this.__currentPosition[0] || begPosition[1] != this.__currentPosition[1]) {
1066
- this.__path += "L" + begPosition[0] + "," + begPosition[1];
1565
+ else {
1566
+ yProportion = proportion;
1067
1567
  }
1068
- this.__path += "A" + r + "," + r + " 0 " + ((deg > 180 || deg < -180) ? 1 : 0) + "," + (deg > 0 ? 1 : 0) + " " + endPosition[0] + "," + endPosition[1];
1069
- return this;
1568
+ var zProportion = Math.min(xProportion, yProportion);
1569
+ this.__proporion = [
1570
+ xProportion, 0, 0, 0,
1571
+ 0, yProportion, 0, 0,
1572
+ 0, 0, zProportion, 0,
1573
+ 0, 0, 0, 1
1574
+ ];
1575
+ }
1576
+ WebGL.prototype.matrix = function (initMatrix4) {
1577
+ return new Matrix4(initMatrix4);
1070
1578
  };
1071
- SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1072
- this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
1073
- return this;
1579
+ WebGL.prototype.getMatrix = function () {
1580
+ return this.__scene.matrix;
1074
1581
  };
1075
- SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1076
- this.__path += "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
1077
- return this;
1582
+ WebGL.prototype.getObject3D = function () {
1583
+ return this.__scene.children;
1078
1584
  };
1079
- return SVG;
1080
- }());
1081
-
1082
- var SVG = (function (_super) {
1083
- __extends(SVG, _super);
1084
- function SVG(el) {
1085
- if (!el) {
1086
- throw new Error("VISLite SVG :The mount point requires an HTMLElement type but encountered null.");
1585
+ WebGL.prototype.review = function (isUpdateRegion) {
1586
+ if (isUpdateRegion === void 0) { isUpdateRegion = false; }
1587
+ if (isUpdateRegion) {
1588
+ this.__regionPainter.clearColor(1, 1, 1, 1);
1589
+ this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
1087
1590
  }
1088
- var width = el.clientWidth, height = el.clientHeight;
1089
- var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
1090
- el.appendChild(ViewSVG);
1091
- ViewSVG.setAttribute("width", width + "");
1092
- ViewSVG.setAttribute("height", height + "");
1093
- ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
1094
- return _super.call(this, ViewSVG) || this;
1095
- }
1096
- return SVG;
1097
- }(SVG$1));
1098
-
1099
- var $timers = [];
1100
- var $interval = 13;
1101
- var $timerId;
1102
- function animation (doback, duration, callback) {
1103
- if (duration === void 0) { duration = 400; }
1104
- if (callback === void 0) { callback = function () { }; }
1105
- var clock = {
1106
- "timer": function (tick, duration, callback) {
1107
- if (!tick) {
1108
- throw new Error('Tick is required!');
1591
+ else {
1592
+ this.painter.clearColor(1, 1, 1, 1);
1593
+ this.painter.clear(this.painter.COLOR_BUFFER_BIT);
1594
+ }
1595
+ for (var index = 0; index < this.__scene.children.length; index++) {
1596
+ this.draw(this.__scene.children[index], isUpdateRegion);
1597
+ }
1598
+ return this;
1599
+ };
1600
+ WebGL.prototype.draw = function (object3D, isUpdateRegion) {
1601
+ if (isUpdateRegion === void 0) { isUpdateRegion = false; }
1602
+ if (!isUpdateRegion)
1603
+ needUpdate = true;
1604
+ var meshWorld = {
1605
+ matrix: object3D.matrix.value()
1606
+ };
1607
+ var globalWorld = {
1608
+ matrix: this.__scene.matrix.value(),
1609
+ proporion: this.__proporion
1610
+ };
1611
+ this.setRegion(object3D.region);
1612
+ for (var index = 0; index < object3D.mesh.length; index++) {
1613
+ if (isUpdateRegion) {
1614
+ doDraw("painter" + this.__unique, this.__regionPainter, {
1615
+ geometry: object3D.mesh[index].geometry,
1616
+ material: {
1617
+ color: {
1618
+ r: this.__regionColor[0],
1619
+ g: this.__regionColor[1],
1620
+ b: this.__regionColor[2],
1621
+ alpha: this.__regionColor[3]
1622
+ }
1623
+ }
1624
+ }, meshWorld, globalWorld);
1109
1625
  }
1110
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
1111
- $timers.push({
1112
- "id": id,
1113
- "createTime": new Date(),
1114
- "tick": tick,
1115
- "duration": duration,
1116
- "callback": callback
1117
- });
1118
- clock.start();
1119
- return id;
1120
- },
1121
- "start": function () {
1122
- if (!$timerId) {
1123
- $timerId = setInterval(clock.tick, $interval);
1626
+ else {
1627
+ doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
1124
1628
  }
1125
- },
1126
- "tick": function () {
1127
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
1128
- $timers = [];
1129
- $timers.length = 0;
1130
- for (flag = 0; flag < timers.length; flag++) {
1131
- timer = timers[flag];
1132
- createTime = timer.createTime;
1133
- tick = timer.tick;
1134
- duration = timer.duration;
1135
- callback = timer.callback;
1136
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
1137
- passTime = passTime > 1 ? 1 : passTime;
1138
- tick(passTime);
1139
- if (passTime < 1 && timer.id) {
1140
- $timers.push(timer);
1141
- }
1142
- else {
1143
- callback(passTime);
1144
- }
1629
+ }
1630
+ this.__getColor = getColorFactory(this.__regionPainter);
1631
+ };
1632
+ WebGL.prototype.render = function (object3D) {
1633
+ if (!('matrix' in object3D))
1634
+ object3D.matrix = new Matrix4();
1635
+ if (!('region' in object3D))
1636
+ object3D.region = "";
1637
+ for (var index = 0; index < object3D.mesh.length; index++) {
1638
+ var mesh = object3D.mesh[index];
1639
+ if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
1640
+ mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
1145
1641
  }
1146
- if ($timers.length <= 0) {
1147
- clock.stop();
1642
+ if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
1643
+ mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
1148
1644
  }
1149
- },
1150
- "stop": function () {
1151
- if ($timerId) {
1152
- clearInterval($timerId);
1153
- $timerId = null;
1645
+ if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
1646
+ mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
1647
+ }
1648
+ if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
1649
+ mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
1154
1650
  }
1155
1651
  }
1652
+ this.__scene.children.push(object3D);
1653
+ this.draw(object3D);
1156
1654
  };
1157
- var id = clock.timer(function (deep) {
1158
- doback(deep);
1159
- }, duration, callback);
1160
- return function () {
1161
- var i;
1162
- for (i in $timers) {
1163
- if ($timers[i].id == id) {
1164
- $timers[i].id = undefined;
1165
- return;
1655
+ WebGL.prototype.setRegion = function (regionName) {
1656
+ this.__regionName = regionName + "";
1657
+ if (regionName) {
1658
+ if (this.__regionList[regionName] == undefined) {
1659
+ this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
1166
1660
  }
1661
+ this.__regionColor = this.__regionList[regionName];
1167
1662
  }
1663
+ else {
1664
+ this.__regionColor = [0, 0, 0, 1];
1665
+ }
1666
+ return this;
1168
1667
  };
1169
- }
1668
+ WebGL.prototype.getRegion = function (x, y) {
1669
+ var _this = this;
1670
+ if (needUpdate)
1671
+ this.review(true);
1672
+ needUpdate = false;
1673
+ return new Promise(function (resolve, reject) {
1674
+ var rgba = _this.__getColor(x, y);
1675
+ for (var key in _this.__regionList) {
1676
+ var currentRGBA = _this.__regionList[key];
1677
+ if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
1678
+ resolve(key);
1679
+ break;
1680
+ }
1681
+ }
1682
+ resolve("");
1683
+ });
1684
+ };
1685
+ return WebGL;
1686
+ }());
1170
1687
 
1171
- function ruler (maxValue, minValue, num) {
1172
- if (maxValue < minValue) {
1173
- var temp = minValue;
1174
- minValue = maxValue;
1175
- maxValue = temp;
1688
+ var WebGL = (function (_super) {
1689
+ __extends(WebGL, _super);
1690
+ function WebGL(el) {
1691
+ if (!el) {
1692
+ throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
1693
+ }
1694
+ var width = el.clientWidth, height = el.clientHeight;
1695
+ var ViewCanvas, RegionCanvas;
1696
+ var _el = el;
1697
+ if (_el._vislite_canvas_) {
1698
+ ViewCanvas = _el._vislite_canvas_[0];
1699
+ RegionCanvas = _el._vislite_canvas_[1];
1700
+ }
1701
+ else {
1702
+ RegionCanvas = document.createElement('canvas');
1703
+ el.appendChild(RegionCanvas);
1704
+ RegionCanvas.style.position = 'absolute';
1705
+ RegionCanvas.style.zIndex = "-1";
1706
+ ViewCanvas = document.createElement('canvas');
1707
+ el.appendChild(ViewCanvas);
1708
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
1709
+ el.setAttribute('vislite', 'WebGL');
1710
+ }
1711
+ for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
1712
+ var canvas = _a[_i];
1713
+ canvas.style.width = width + "px";
1714
+ canvas.setAttribute('width', width + "");
1715
+ canvas.style.height = height + "px";
1716
+ canvas.setAttribute('height', height + "");
1717
+ }
1718
+ return _super.call(this, ViewCanvas, RegionCanvas) || this;
1176
1719
  }
1177
- else if (maxValue == minValue) {
1178
- return [maxValue];
1720
+ return WebGL;
1721
+ }(WebGL$1));
1722
+
1723
+ var rotateX = function (deg, x, y, z) {
1724
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1725
+ return [x, y * cos - z * sin, y * sin + z * cos];
1726
+ };
1727
+ var rotateY = function (deg, x, y, z) {
1728
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1729
+ return [z * sin + x * cos, y, z * cos - x * sin];
1730
+ };
1731
+ var rotateZ = function (deg, x, y, z) {
1732
+ var cos = Math.cos(deg), sin = Math.sin(deg);
1733
+ return [x * cos - y * sin, x * sin + y * cos, z];
1734
+ };
1735
+ var Eoap = (function () {
1736
+ function Eoap(scale, center) {
1737
+ if (scale === void 0) { scale = 7; }
1738
+ if (center === void 0) { center = [107, 36]; }
1739
+ this.name = 'Eoap';
1740
+ this.__scale = scale;
1741
+ this.__center = center;
1179
1742
  }
1180
- var times100 = (function (_value) {
1181
- var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
1182
- var _times100 = -1, _tiemsValue = _value;
1183
- while (_times100_base == 10 ?
1184
- (_tiemsValue >= -100 && _tiemsValue <= 100)
1185
- :
1186
- (_tiemsValue <= -100 || _tiemsValue >= 100)) {
1187
- _times100 += 1;
1188
- _tiemsValue *= _times100_base;
1743
+ Eoap.prototype.use = function (λ, φ) {
1744
+ var p = rotateY((360 - φ) / 180 * Math.PI, 100 * this.__scale, 0, 0);
1745
+ p = rotateZ(λ / 180 * Math.PI, p[0], p[1], p[2]);
1746
+ p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
1747
+ p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
1748
+ return [
1749
+ -p[0],
1750
+ p[1],
1751
+ p[2]
1752
+ ];
1753
+ };
1754
+ return Eoap;
1755
+ }());
1756
+
1757
+ var Mercator = (function () {
1758
+ function Mercator(scale, center) {
1759
+ if (scale === void 0) { scale = 7; }
1760
+ if (center === void 0) { center = [107, 36]; }
1761
+ this.name = 'Mercator';
1762
+ var perimeter = 100 * scale * Math.PI;
1763
+ var help = perimeter / 180;
1764
+ var cx = help * center[0];
1765
+ var cy = -1 * help * center[1];
1766
+ this.use = function (λ, φ) {
1767
+ return [
1768
+ (help * λ - cx) * 0.8,
1769
+ -1 * help * φ - cy
1770
+ ];
1771
+ };
1772
+ }
1773
+ return Mercator;
1774
+ }());
1775
+
1776
+ var mousePosition = function (el, event) {
1777
+ var bounding = el.getBoundingClientRect();
1778
+ return {
1779
+ "x": event.clientX - bounding.left,
1780
+ "y": event.clientY - bounding.top
1781
+ };
1782
+ };
1783
+ var getKeyString = function (event) {
1784
+ return {
1785
+ 37: "left",
1786
+ 38: "up",
1787
+ 39: "right",
1788
+ 40: "down",
1789
+ }[event.keyCode || event.which];
1790
+ };
1791
+ function viewHandler (callback) {
1792
+ var el = document.getElementsByTagName('body')[0];
1793
+ el.addEventListener("keydown", function (event) {
1794
+ var keyCode = getKeyString(event);
1795
+ if (keyCode == 'up') {
1796
+ callback({
1797
+ type: "lookUp",
1798
+ normal: [],
1799
+ value: 0.1
1800
+ });
1189
1801
  }
1190
- if (_times100_base == 10) {
1191
- return Math.pow(10, _times100);
1802
+ else if (keyCode == 'down') {
1803
+ callback({
1804
+ type: "lookDown",
1805
+ normal: [],
1806
+ value: 0.1
1807
+ });
1192
1808
  }
1193
- else {
1194
- var temp = "0.";
1195
- for (var i = 1; i < _times100; i++) {
1196
- temp += "0";
1197
- }
1198
- return +(temp + "1");
1809
+ else if (keyCode == 'left') {
1810
+ callback({
1811
+ type: "lookLeft",
1812
+ normal: [],
1813
+ value: 0.1
1814
+ });
1199
1815
  }
1200
- })(maxValue - minValue);
1201
- var distance100 = Math.ceil((maxValue - minValue) * times100 / num);
1202
- distance100 = {
1203
- 3: 2,
1204
- 4: 5,
1205
- 6: 5,
1206
- 7: 5,
1207
- 8: 10,
1208
- 9: 10,
1209
- 11: 10,
1210
- 12: 10,
1211
- 13: 15,
1212
- 14: 15,
1213
- 16: 15,
1214
- 17: 15,
1215
- 18: 20,
1216
- 19: 20,
1217
- 21: 20,
1218
- 22: 20,
1219
- 23: 25,
1220
- 24: 25,
1221
- 26: 25,
1222
- 27: 25
1223
- }[distance100] || distance100;
1224
- var distance = distance100 / times100;
1225
- var begin = Math.floor(minValue / distance) * distance;
1226
- var rulerArray = [];
1227
- rulerArray.push(begin);
1228
- for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
1229
- rulerArray.push(begin + distance * index);
1816
+ else if (keyCode == 'right') {
1817
+ callback({
1818
+ type: "lookRight",
1819
+ normal: [],
1820
+ value: 0.1
1821
+ });
1822
+ }
1823
+ });
1824
+ var mouseP = null;
1825
+ var doMove = function (event) {
1826
+ if (mouseP == null)
1827
+ return;
1828
+ var tempMouseP = mousePosition(el, event);
1829
+ var normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y];
1830
+ var rotateNormal = [
1831
+ normal[1],
1832
+ normal[0] * -1,
1833
+ 0
1834
+ ];
1835
+ if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
1836
+ return;
1837
+ callback({
1838
+ type: "rotate",
1839
+ normal: rotateNormal,
1840
+ value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01
1841
+ });
1842
+ mouseP = tempMouseP;
1843
+ };
1844
+ el.addEventListener("mousedown", function (event) {
1845
+ mouseP = mousePosition(el, event);
1846
+ });
1847
+ el.addEventListener("mouseup", function (event) {
1848
+ mouseP = null;
1849
+ });
1850
+ el.addEventListener("mousemove", function (event) {
1851
+ doMove(event);
1852
+ });
1853
+ el.addEventListener("touchend", function (event) {
1854
+ mouseP = null;
1855
+ });
1856
+ el.addEventListener("touchstart", function (event) {
1857
+ mouseP = mousePosition(el, event);
1858
+ });
1859
+ el.addEventListener("touchmove", function (event) {
1860
+ doMove(event.touches[0]);
1861
+ });
1862
+ var doScale = function (value) {
1863
+ if (value == 0)
1864
+ return;
1865
+ var baseTimes = 0.899;
1866
+ callback({
1867
+ type: "scale",
1868
+ value: value < 0 ? baseTimes : 2 - baseTimes,
1869
+ normal: []
1870
+ });
1871
+ };
1872
+ el.addEventListener("mousewheel", function (event) {
1873
+ doScale(event.wheelDelta);
1874
+ });
1875
+ if (window.addEventListener) {
1876
+ window.addEventListener('DOMMouseScroll', function (event) {
1877
+ doScale(-1 * event.detail);
1878
+ }, false);
1230
1879
  }
1231
- return rulerArray;
1232
1880
  }
1233
1881
 
1234
1882
  var index = {
1235
- Canvas: Canvas,
1236
1883
  Cardinal: Cardinal,
1237
- Eoap: Eoap,
1238
- getLoopColors: getLoopColors,
1239
1884
  Hermite: Hermite,
1240
1885
  Matrix4: Matrix4,
1241
- rotate: rotate,
1242
- SVG: SVG,
1886
+ rotate: rotate$1,
1887
+ getLoopColors: getLoopColors,
1243
1888
  animation: animation,
1244
- ruler: ruler
1889
+ ruler: ruler,
1890
+ SVG: SVG,
1891
+ Canvas: Canvas,
1892
+ WebGL: WebGL,
1893
+ Eoap: Eoap,
1894
+ Mercator: Mercator,
1895
+ viewHandler: viewHandler
1245
1896
  };
1246
1897
 
1247
1898
  return index;