vislite 0.5.0 → 0.5.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +18 -18
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +5 -0
- package/LICENSE +20 -20
- package/README.md +69 -69
- package/miniprogram/ui-canvas/index.js +107 -107
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Buffer/index.ts +2 -2
- package/package/Canvas/index.ts +2 -2
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/Mercator/index.ts +2 -2
- package/package/OralCanvas/index.ts +2 -2
- package/package/OralWebGL/index.ts +2 -2
- package/package/SVG/index.ts +2 -2
- package/package/Shader/index.ts +39 -39
- package/package/Texture/index.ts +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package/WebGL/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/formatColor/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/getWebGLContext/index.ts +39 -39
- package/package/resizeObserver/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/throttle/index.ts +2 -2
- package/package/viewHandler/index.ts +2 -2
- package/package.json +1 -1
- package/src/Canvas.ts +67 -67
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/SVG.ts +24 -24
- package/src/WebGL.ts +66 -66
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +50 -50
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +29 -29
- package/src/common/canvas/index.ts +168 -168
- package/src/common/canvas/painter.ts +426 -426
- package/src/common/canvas/texts.ts +18 -18
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +174 -174
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/index.ts +25 -25
- package/src/common/tree/toInnerTree.ts +56 -56
- package/src/common/tree/toPlainTree.ts +131 -131
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- package/src/common/webgl/getColorFactory.ts +26 -26
- package/src/common/webgl/getShader.ts +48 -48
- package/src/common/webgl/getTexture.ts +11 -11
- package/src/common/webgl/getWebGLContext.ts +27 -27
- package/src/common/webgl/index.ts +223 -223
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +96 -96
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/resizeObserver.ts +36 -36
- package/src/ruler.ts +188 -188
- package/src/shader/fsColor.c +7 -7
- package/src/shader/fsColors.c +7 -7
- package/src/shader/fsCube.c +8 -8
- package/src/shader/fsImage.c +8 -8
- package/src/shader/vsColor.c +17 -17
- package/src/shader/vsColors.c +13 -13
- package/src/shader/vsCube.c +13 -13
- package/src/shader/vsImage.c +13 -13
- package/src/throttle.ts +51 -51
- package/src/viewHandler.ts +158 -158
- package/types/Buffer.d.ts +23 -23
- package/types/Canvas.d.ts +300 -300
- package/types/CanvasOption.d.ts +7 -7
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +14 -14
- package/types/Hermite.d.ts +18 -18
- package/types/Object3D.d.ts +114 -114
- package/types/SVGConfig.d.ts +76 -76
- package/types/Scene3D.d.ts +6 -6
- package/types/Shader.d.ts +21 -21
- package/types/Texture.d.ts +16 -16
- package/types/Tree.d.ts +69 -69
- package/types/TreeConfig.d.ts +24 -24
- package/types/TreeOption.d.ts +48 -48
- package/types/WebGL.d.ts +38 -38
- package/types/WebGLOption.d.ts +7 -7
- package/types/animation.d.ts +6 -6
- package/types/formatColor.d.ts +2 -2
- package/types/getLoopColors.d.ts +2 -2
- package/types/getWebGLContext.d.ts +2 -2
- package/types/painterConfig.d.ts +2 -2
- package/types/resizeObserver.d.ts +2 -2
- package/types/ruler.d.ts +7 -7
- package/types/throttle.d.ts +4 -4
- package/types/throttleOption.d.ts +21 -21
- package/types/viewHandler.d.ts +13 -13
- package/uni-app/ui-canvas.vue +226 -222
- package/lib/Buffer/index.umd.js +0 -55
- package/lib/Buffer/index.umd.min.js +0 -11
- package/lib/Canvas/index.umd.js +0 -721
- package/lib/Canvas/index.umd.min.js +0 -11
- package/lib/Cardinal/index.umd.js +0 -112
- package/lib/Cardinal/index.umd.min.js +0 -11
- package/lib/Eoap/index.umd.js +0 -53
- package/lib/Eoap/index.umd.min.js +0 -11
- package/lib/Geometry/index.umd.js +0 -205
- package/lib/Geometry/index.umd.min.js +0 -11
- package/lib/Hermite/index.umd.js +0 -55
- package/lib/Hermite/index.umd.min.js +0 -11
- package/lib/Matrix4/index.umd.js +0 -146
- package/lib/Matrix4/index.umd.min.js +0 -11
- package/lib/Mercator/index.umd.js +0 -39
- package/lib/Mercator/index.umd.min.js +0 -11
- package/lib/OralCanvas/index.es.js +0 -657
- package/lib/OralCanvas/index.es.min.js +0 -11
- package/lib/OralWebGL/index.es.js +0 -611
- package/lib/OralWebGL/index.es.min.js +0 -11
- package/lib/SVG/index.umd.js +0 -475
- package/lib/SVG/index.umd.min.js +0 -11
- package/lib/Shader/index.umd.js +0 -134
- package/lib/Shader/index.umd.min.js +0 -11
- package/lib/Texture/index.umd.js +0 -72
- package/lib/Texture/index.umd.min.js +0 -11
- package/lib/TreeLayout/index.umd.js +0 -430
- package/lib/TreeLayout/index.umd.min.js +0 -11
- package/lib/WebGL/index.umd.js +0 -684
- package/lib/WebGL/index.umd.min.js +0 -11
- package/lib/animation/index.umd.js +0 -91
- package/lib/animation/index.umd.min.js +0 -11
- package/lib/formatColor/index.umd.js +0 -59
- package/lib/formatColor/index.umd.min.js +0 -11
- package/lib/getLoopColors/index.umd.js +0 -55
- package/lib/getLoopColors/index.umd.min.js +0 -11
- package/lib/getWebGLContext/index.umd.js +0 -65
- package/lib/getWebGLContext/index.umd.min.js +0 -11
- package/lib/index.umd.js +0 -2834
- package/lib/index.umd.min.js +0 -11
- package/lib/resizeObserver/index.umd.js +0 -48
- package/lib/resizeObserver/index.umd.min.js +0 -11
- package/lib/rotate/index.umd.js +0 -27
- package/lib/rotate/index.umd.min.js +0 -11
- package/lib/ruler/index.umd.js +0 -145
- package/lib/ruler/index.umd.min.js +0 -11
- package/lib/throttle/index.umd.js +0 -70
- package/lib/throttle/index.umd.min.js +0 -11
- package/lib/viewHandler/index.umd.js +0 -139
- package/lib/viewHandler/index.umd.min.js +0 -11
package/lib/index.umd.js
DELETED
|
@@ -1,2834 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.5.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Sep 30 2023 19:14:04 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
13
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite = factory());
|
|
15
|
-
})(this, (function () { 'use strict';
|
|
16
|
-
|
|
17
|
-
var Hermite = (function () {
|
|
18
|
-
function Hermite(u) {
|
|
19
|
-
if (u === void 0) { u = 0.5; }
|
|
20
|
-
this.name = 'Hermite';
|
|
21
|
-
this.__u = u;
|
|
22
|
-
}
|
|
23
|
-
Hermite.prototype.setP = function (x1, y1, x2, y2, s1, s2) {
|
|
24
|
-
if (x1 < x2) {
|
|
25
|
-
this.__a = x1;
|
|
26
|
-
this.__b = x2;
|
|
27
|
-
var p3 = this.__u * s1, p4 = this.__u * s2;
|
|
28
|
-
y1 /= (x2 - x1);
|
|
29
|
-
y2 /= (x2 - x1);
|
|
30
|
-
this.__MR = [
|
|
31
|
-
2 * y1 - 2 * y2 + p3 + p4,
|
|
32
|
-
3 * y2 - 3 * y1 - 2 * p3 - p4,
|
|
33
|
-
p3,
|
|
34
|
-
y1
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
else
|
|
38
|
-
throw new Error('The point x-position should be increamented!');
|
|
39
|
-
return this;
|
|
40
|
-
};
|
|
41
|
-
Hermite.prototype.use = function (x) {
|
|
42
|
-
if (this.__MR) {
|
|
43
|
-
var sx = (x - this.__a) / (this.__b - this.__a), sx2 = sx * sx, sx3 = sx * sx2;
|
|
44
|
-
var sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3];
|
|
45
|
-
return sResult * (this.__b - this.__a);
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
throw new Error('You shoud first set the position!');
|
|
49
|
-
};
|
|
50
|
-
return Hermite;
|
|
51
|
-
}());
|
|
52
|
-
|
|
53
|
-
var Cardinal = (function () {
|
|
54
|
-
function Cardinal(t) {
|
|
55
|
-
if (t === void 0) { t = 0; }
|
|
56
|
-
this.name = 'Cardinal';
|
|
57
|
-
this.__t = t;
|
|
58
|
-
}
|
|
59
|
-
Cardinal.prototype.setP = function (points) {
|
|
60
|
-
this.__HS = {
|
|
61
|
-
"x": [],
|
|
62
|
-
"h": []
|
|
63
|
-
};
|
|
64
|
-
var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
|
|
65
|
-
this.__HS.x[0] = points[0][0];
|
|
66
|
-
for (flag = 1; flag < points.length; flag++) {
|
|
67
|
-
if (points[flag][0] <= points[flag - 1][0])
|
|
68
|
-
throw new Error('The point position should be increamented!');
|
|
69
|
-
this.__HS.x[flag] = points[flag][0];
|
|
70
|
-
if (flag < points.length - 1) {
|
|
71
|
-
if ((points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
|
|
72
|
-
(points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
|
|
73
|
-
points[flag + 1][1] == points[flag][1] ||
|
|
74
|
-
points[flag - 1][1] == points[flag][1]) {
|
|
75
|
-
temp = 0;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
|
|
83
|
-
}
|
|
84
|
-
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);
|
|
85
|
-
slope = temp;
|
|
86
|
-
}
|
|
87
|
-
return this;
|
|
88
|
-
};
|
|
89
|
-
Cardinal.prototype.use = function (x) {
|
|
90
|
-
if (this.__HS) {
|
|
91
|
-
this.__i = -1;
|
|
92
|
-
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]))) {
|
|
93
|
-
this.__i += 1;
|
|
94
|
-
}
|
|
95
|
-
if (this.__i < 0) {
|
|
96
|
-
return this.__HS.h[0].use(this.__HS.x[0]);
|
|
97
|
-
}
|
|
98
|
-
else if (this.__i >= this.__HS.h.length) {
|
|
99
|
-
return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
|
|
100
|
-
}
|
|
101
|
-
return this.__HS.h[this.__i].use(x);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
throw new Error('You shoud first set the position!');
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return Cardinal;
|
|
108
|
-
}());
|
|
109
|
-
|
|
110
|
-
function _move (d, a, b, c) {
|
|
111
|
-
if (c === void 0) { c = 0; }
|
|
112
|
-
var sqrt = Math.sqrt(a * a + b * b + c * c);
|
|
113
|
-
return [
|
|
114
|
-
1, 0, 0, 0,
|
|
115
|
-
0, 1, 0, 0,
|
|
116
|
-
0, 0, 1, 0,
|
|
117
|
-
a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
|
|
118
|
-
];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function _rotate (deg) {
|
|
122
|
-
var sin = Math.sin(deg), cos = Math.cos(deg);
|
|
123
|
-
return [
|
|
124
|
-
cos, sin, 0, 0,
|
|
125
|
-
-sin, cos, 0, 0,
|
|
126
|
-
0, 0, 1, 0,
|
|
127
|
-
0, 0, 0, 1
|
|
128
|
-
];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
132
|
-
if (cx === void 0) { cx = 0; }
|
|
133
|
-
if (cy === void 0) { cy = 0; }
|
|
134
|
-
if (cz === void 0) { cz = 0; }
|
|
135
|
-
return [
|
|
136
|
-
xTimes, 0, 0, 0,
|
|
137
|
-
0, yTimes, 0, 0,
|
|
138
|
-
0, 0, zTimes, 0,
|
|
139
|
-
cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function _transform (a1, b1, c1, a2, b2, c2) {
|
|
144
|
-
if (typeof a1 === 'number' && typeof b1 === 'number') {
|
|
145
|
-
if (typeof c1 !== 'number') {
|
|
146
|
-
c1 = 0;
|
|
147
|
-
a2 = a1;
|
|
148
|
-
b2 = b1;
|
|
149
|
-
c2 = 1;
|
|
150
|
-
}
|
|
151
|
-
else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
|
|
152
|
-
a2 = a1;
|
|
153
|
-
b2 = b1;
|
|
154
|
-
c2 = c1;
|
|
155
|
-
a1 = 0;
|
|
156
|
-
b1 = 0;
|
|
157
|
-
c1 = 0;
|
|
158
|
-
}
|
|
159
|
-
if (a1 == a2 && b1 == b2 && c1 == c2)
|
|
160
|
-
throw new Error('It\'s not a legitimate ray!');
|
|
161
|
-
var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
|
|
162
|
-
return [
|
|
163
|
-
[
|
|
164
|
-
cos1, cos2 * sin1, sin1 * sin2, 0,
|
|
165
|
-
-sin1, cos1 * cos2, cos1 * sin2, 0,
|
|
166
|
-
0, -sin2, cos2, 0,
|
|
167
|
-
b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
|
|
168
|
-
],
|
|
169
|
-
[
|
|
170
|
-
cos1, -sin1, 0, 0,
|
|
171
|
-
cos2 * sin1, cos2 * cos1, -sin2, 0,
|
|
172
|
-
sin1 * sin2, cos1 * sin2, cos2, 0,
|
|
173
|
-
a1, b1, c1, 1
|
|
174
|
-
]
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw new Error('a1 and b1 is required!');
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
var _multiply = function (matrix4, param) {
|
|
183
|
-
var newParam = [];
|
|
184
|
-
for (var i = 0; i < 4; i++)
|
|
185
|
-
for (var j = 0; j < param.length / 4; j++)
|
|
186
|
-
newParam[j * 4 + i] =
|
|
187
|
-
matrix4[i] * param[j * 4] +
|
|
188
|
-
matrix4[i + 4] * param[j * 4 + 1] +
|
|
189
|
-
matrix4[i + 8] * param[j * 4 + 2] +
|
|
190
|
-
matrix4[i + 12] * param[j * 4 + 3];
|
|
191
|
-
return newParam;
|
|
192
|
-
};
|
|
193
|
-
var Matrix4 = (function () {
|
|
194
|
-
function Matrix4(initMatrix4) {
|
|
195
|
-
if (initMatrix4 === void 0) { initMatrix4 = [
|
|
196
|
-
1, 0, 0, 0,
|
|
197
|
-
0, 1, 0, 0,
|
|
198
|
-
0, 0, 1, 0,
|
|
199
|
-
0, 0, 0, 1
|
|
200
|
-
]; }
|
|
201
|
-
this.name = 'Matrix4';
|
|
202
|
-
this.__matrix4 = initMatrix4;
|
|
203
|
-
}
|
|
204
|
-
Matrix4.prototype.move = function (dis, a, b, c) {
|
|
205
|
-
if (c === void 0) { c = 0; }
|
|
206
|
-
this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
|
|
207
|
-
return this;
|
|
208
|
-
};
|
|
209
|
-
Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
|
|
210
|
-
var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
|
|
211
|
-
this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
|
|
212
|
-
return this;
|
|
213
|
-
};
|
|
214
|
-
Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
|
|
215
|
-
if (cx === void 0) { cx = 0; }
|
|
216
|
-
if (cy === void 0) { cy = 0; }
|
|
217
|
-
if (cz === void 0) { cz = 0; }
|
|
218
|
-
this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
|
|
219
|
-
return this;
|
|
220
|
-
};
|
|
221
|
-
Matrix4.prototype.multiply = function (newMatrix4, flag) {
|
|
222
|
-
if (flag === void 0) { flag = false; }
|
|
223
|
-
this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
|
|
224
|
-
return this;
|
|
225
|
-
};
|
|
226
|
-
Matrix4.prototype.use = function (x, y, z, w) {
|
|
227
|
-
if (z === void 0) { z = 0; }
|
|
228
|
-
if (w === void 0) { w = 1; }
|
|
229
|
-
return _multiply(this.__matrix4, [x, y, z, w]);
|
|
230
|
-
};
|
|
231
|
-
Matrix4.prototype.value = function () {
|
|
232
|
-
return this.__matrix4;
|
|
233
|
-
};
|
|
234
|
-
return Matrix4;
|
|
235
|
-
}());
|
|
236
|
-
|
|
237
|
-
function rotate$1 (cx, cy, deg, x, y) {
|
|
238
|
-
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
239
|
-
return [
|
|
240
|
-
(x - cx) * cos - (y - cy) * sin + cx,
|
|
241
|
-
(x - cx) * sin + (y - cy) * cos + cy
|
|
242
|
-
];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function getLoopColors (num, alpha) {
|
|
246
|
-
if (alpha === void 0) { alpha = 1; }
|
|
247
|
-
var colorList = [
|
|
248
|
-
'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
|
|
249
|
-
'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
|
|
250
|
-
'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
|
|
251
|
-
'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
|
|
252
|
-
'rgba(234,124,204,' + alpha + ")"
|
|
253
|
-
];
|
|
254
|
-
var colors = [];
|
|
255
|
-
if (num <= colorList.length) {
|
|
256
|
-
return colorList;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
if (num % colorList.length == 0) {
|
|
260
|
-
for (var i = 0; i < (num / colorList.length); i++) {
|
|
261
|
-
colors = colors.concat(colorList);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
for (var j = 1; j < (num / colorList.length); j++) {
|
|
266
|
-
colors = colors.concat(colorList);
|
|
267
|
-
}
|
|
268
|
-
if (num % colorList.length == 1) {
|
|
269
|
-
colors = colors.concat(colorList[4]);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
for (var k = 0; k < num % colorList.length; k++) {
|
|
273
|
-
colors = colors.concat(colorList[k]);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return colors;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
var toHex = function (value) {
|
|
282
|
-
var hex = value.toString(16);
|
|
283
|
-
return hex.length == 1 ? ("0" + hex) : hex;
|
|
284
|
-
};
|
|
285
|
-
function formatColor (color, format) {
|
|
286
|
-
var colorNode = document.getElementsByTagName('head')[0];
|
|
287
|
-
colorNode.style['color'] = color;
|
|
288
|
-
var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
289
|
-
document.defaultView.getComputedStyle(colorNode, null) :
|
|
290
|
-
colorNode.currentStyle;
|
|
291
|
-
var oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',');
|
|
292
|
-
for (var index = 0; index < oralFormat.length; index++) {
|
|
293
|
-
oralFormat[index] = +oralFormat[index];
|
|
294
|
-
}
|
|
295
|
-
oralFormat.push(1);
|
|
296
|
-
switch (format) {
|
|
297
|
-
case "3d": {
|
|
298
|
-
return [
|
|
299
|
-
oralFormat[0] / 255,
|
|
300
|
-
oralFormat[1] / 255,
|
|
301
|
-
oralFormat[2] / 255,
|
|
302
|
-
oralFormat[3]
|
|
303
|
-
];
|
|
304
|
-
}
|
|
305
|
-
case "rgba": {
|
|
306
|
-
return "rgba(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ", ").concat(oralFormat[3], ")");
|
|
307
|
-
}
|
|
308
|
-
case "rgb": {
|
|
309
|
-
return "rgb(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ")");
|
|
310
|
-
}
|
|
311
|
-
case "hexAlpha": {
|
|
312
|
-
return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2])).concat(toHex(+(oralFormat[3] * 255).toFixed(0)));
|
|
313
|
-
}
|
|
314
|
-
case "hex": {
|
|
315
|
-
return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2]));
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
throw new Error("Unsupported color format: " + format);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
var $timers = [];
|
|
322
|
-
var $interval = 13;
|
|
323
|
-
var $timerId;
|
|
324
|
-
function animation (doback, duration, callback) {
|
|
325
|
-
if (duration === void 0) { duration = 400; }
|
|
326
|
-
if (callback === void 0) { callback = function () { }; }
|
|
327
|
-
var clock = {
|
|
328
|
-
"timer": function (tick, duration, callback) {
|
|
329
|
-
if (!tick) {
|
|
330
|
-
throw new Error('Tick is required!');
|
|
331
|
-
}
|
|
332
|
-
var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
|
|
333
|
-
$timers.push({
|
|
334
|
-
"id": id,
|
|
335
|
-
"createTime": new Date(),
|
|
336
|
-
"tick": tick,
|
|
337
|
-
"duration": duration,
|
|
338
|
-
"callback": callback
|
|
339
|
-
});
|
|
340
|
-
clock.start();
|
|
341
|
-
return id;
|
|
342
|
-
},
|
|
343
|
-
"start": function () {
|
|
344
|
-
if (!$timerId) {
|
|
345
|
-
$timerId = setInterval(clock.tick, $interval);
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
"tick": function () {
|
|
349
|
-
var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
|
|
350
|
-
$timers = [];
|
|
351
|
-
$timers.length = 0;
|
|
352
|
-
for (flag = 0; flag < timers.length; flag++) {
|
|
353
|
-
timer = timers[flag];
|
|
354
|
-
createTime = timer.createTime;
|
|
355
|
-
tick = timer.tick;
|
|
356
|
-
duration = timer.duration;
|
|
357
|
-
callback = timer.callback;
|
|
358
|
-
passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
|
|
359
|
-
passTime = passTime > 1 ? 1 : passTime;
|
|
360
|
-
tick(passTime);
|
|
361
|
-
if (passTime < 1 && timer.id) {
|
|
362
|
-
$timers.push(timer);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
callback(passTime);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if ($timers.length <= 0) {
|
|
369
|
-
clock.stop();
|
|
370
|
-
}
|
|
371
|
-
},
|
|
372
|
-
"stop": function () {
|
|
373
|
-
if ($timerId) {
|
|
374
|
-
clearInterval($timerId);
|
|
375
|
-
$timerId = null;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
var id = clock.timer(function (deep) {
|
|
380
|
-
doback(deep);
|
|
381
|
-
}, duration, callback);
|
|
382
|
-
return function () {
|
|
383
|
-
var i;
|
|
384
|
-
for (i in $timers) {
|
|
385
|
-
if ($timers[i].id == id) {
|
|
386
|
-
$timers[i].id = void 0;
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function ruler (maxValue, minValue, num, option) {
|
|
394
|
-
if (maxValue < minValue) {
|
|
395
|
-
var temp = minValue;
|
|
396
|
-
minValue = maxValue;
|
|
397
|
-
maxValue = temp;
|
|
398
|
-
}
|
|
399
|
-
else if (maxValue == minValue) {
|
|
400
|
-
return [maxValue];
|
|
401
|
-
}
|
|
402
|
-
var times100 = (function (_value) {
|
|
403
|
-
var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
|
|
404
|
-
var _times100 = -1, _tiemsValue = _value;
|
|
405
|
-
while (_times100_base == 10 ?
|
|
406
|
-
(_tiemsValue >= -100 && _tiemsValue <= 100)
|
|
407
|
-
:
|
|
408
|
-
(_tiemsValue <= -100 || _tiemsValue >= 100)) {
|
|
409
|
-
_times100 += 1;
|
|
410
|
-
_tiemsValue *= _times100_base;
|
|
411
|
-
}
|
|
412
|
-
if (_times100_base == 10) {
|
|
413
|
-
return Math.pow(10, _times100);
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
var temp = "0.";
|
|
417
|
-
for (var i = 1; i < _times100; i++) {
|
|
418
|
-
temp += "0";
|
|
419
|
-
}
|
|
420
|
-
return +(temp + "1");
|
|
421
|
-
}
|
|
422
|
-
})(maxValue - minValue);
|
|
423
|
-
var distance100_oral = Math.ceil((maxValue - minValue) * times100 / num);
|
|
424
|
-
var getResult = function (changValue) {
|
|
425
|
-
var distance100 = {
|
|
426
|
-
3: 2,
|
|
427
|
-
4: 5,
|
|
428
|
-
6: 5,
|
|
429
|
-
7: 5,
|
|
430
|
-
8: 10,
|
|
431
|
-
9: 10,
|
|
432
|
-
11: 10,
|
|
433
|
-
12: 10,
|
|
434
|
-
13: 15,
|
|
435
|
-
14: 15,
|
|
436
|
-
16: 15,
|
|
437
|
-
17: 15,
|
|
438
|
-
18: 20,
|
|
439
|
-
19: 20,
|
|
440
|
-
21: 20,
|
|
441
|
-
22: 20,
|
|
442
|
-
23: 25,
|
|
443
|
-
24: 25,
|
|
444
|
-
26: 25,
|
|
445
|
-
27: 25
|
|
446
|
-
}[distance100_oral + changValue] || (distance100_oral + changValue);
|
|
447
|
-
var distance = distance100 / times100;
|
|
448
|
-
var begin = Math.floor(minValue / distance) * distance;
|
|
449
|
-
var rulerArray = [];
|
|
450
|
-
rulerArray.push(begin);
|
|
451
|
-
for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
|
|
452
|
-
rulerArray.push(begin + distance * index);
|
|
453
|
-
}
|
|
454
|
-
return rulerArray;
|
|
455
|
-
};
|
|
456
|
-
var rulerArray = getResult(0);
|
|
457
|
-
var balanceMax = function () {
|
|
458
|
-
var rulerArray_temp = [];
|
|
459
|
-
var changeDist = rulerArray[rulerArray.length - 1] - option.max;
|
|
460
|
-
for (var index = 0; index < rulerArray.length; index++) {
|
|
461
|
-
if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) ;
|
|
462
|
-
else {
|
|
463
|
-
rulerArray_temp.push(rulerArray[index] - changeDist);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
return rulerArray_temp;
|
|
467
|
-
};
|
|
468
|
-
var balanceMin = function () {
|
|
469
|
-
var rulerArray_temp = [];
|
|
470
|
-
var changeDist = rulerArray[0] - option.min;
|
|
471
|
-
for (var index = 0; index < rulerArray.length; index++) {
|
|
472
|
-
rulerArray_temp[index] = rulerArray[index] - changeDist;
|
|
473
|
-
if (maxValue <= rulerArray_temp[index])
|
|
474
|
-
break;
|
|
475
|
-
}
|
|
476
|
-
return rulerArray_temp;
|
|
477
|
-
};
|
|
478
|
-
if (option) {
|
|
479
|
-
if ('max' in option && 'min' in option && option.max >= maxValue && option.min <= minValue) {
|
|
480
|
-
var isAnswer = function () {
|
|
481
|
-
if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max)
|
|
482
|
-
return true;
|
|
483
|
-
var rulerArray_max = balanceMax();
|
|
484
|
-
if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
|
|
485
|
-
rulerArray = rulerArray_max;
|
|
486
|
-
return true;
|
|
487
|
-
}
|
|
488
|
-
var rulerArray_min = balanceMin();
|
|
489
|
-
if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
|
|
490
|
-
rulerArray = rulerArray_min;
|
|
491
|
-
return true;
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
if (isAnswer())
|
|
495
|
-
return rulerArray;
|
|
496
|
-
for (var changValue = 1; changValue < 100; changValue++) {
|
|
497
|
-
rulerArray = getResult(changValue);
|
|
498
|
-
if (isAnswer())
|
|
499
|
-
return rulerArray;
|
|
500
|
-
rulerArray = getResult(-changValue);
|
|
501
|
-
if (isAnswer())
|
|
502
|
-
return rulerArray;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
if ('max' in option && option.max >= maxValue) {
|
|
506
|
-
if (option.max < rulerArray[rulerArray.length - 1]) {
|
|
507
|
-
rulerArray = balanceMax();
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
else if ('min' in option && option.min <= minValue) {
|
|
511
|
-
if (option.min > rulerArray[0]) {
|
|
512
|
-
rulerArray = balanceMin();
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return rulerArray;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/******************************************************************************
|
|
520
|
-
Copyright (c) Microsoft Corporation.
|
|
521
|
-
|
|
522
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
523
|
-
purpose with or without fee is hereby granted.
|
|
524
|
-
|
|
525
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
526
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
527
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
528
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
529
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
530
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
531
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
532
|
-
***************************************************************************** */
|
|
533
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
534
|
-
|
|
535
|
-
var extendStatics = function(d, b) {
|
|
536
|
-
extendStatics = Object.setPrototypeOf ||
|
|
537
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
538
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
539
|
-
return extendStatics(d, b);
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
function __extends(d, b) {
|
|
543
|
-
if (typeof b !== "function" && b !== null)
|
|
544
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
545
|
-
extendStatics(d, b);
|
|
546
|
-
function __() { this.constructor = d; }
|
|
547
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function __spreadArray(to, from, pack) {
|
|
551
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
552
|
-
if (ar || !(i in from)) {
|
|
553
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
554
|
-
ar[i] = from[i];
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
561
|
-
var e = new Error(message);
|
|
562
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
563
|
-
};
|
|
564
|
-
|
|
565
|
-
var XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"];
|
|
566
|
-
|
|
567
|
-
function toNode(tagname) {
|
|
568
|
-
return document.createElementNS('http://www.w3.org/2000/svg', tagname);
|
|
569
|
-
}
|
|
570
|
-
var _setAttribute = function (el, key, value) {
|
|
571
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
|
|
572
|
-
el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
el.setAttribute(key, value + "");
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
var setAttribute = _setAttribute;
|
|
579
|
-
function getAttribute(el, key) {
|
|
580
|
-
if (XLINK_ATTRIBUTE.indexOf(key) > -1)
|
|
581
|
-
key = 'xlink:' + key;
|
|
582
|
-
return el.getAttribute(key);
|
|
583
|
-
}
|
|
584
|
-
function full(el, config) {
|
|
585
|
-
_setAttribute(el, "stroke", config.strokeStyle);
|
|
586
|
-
_setAttribute(el, "fill", config.fillStyle);
|
|
587
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
|
|
588
|
-
}
|
|
589
|
-
function fill(el, config) {
|
|
590
|
-
_setAttribute(el, "fill", config.fillStyle);
|
|
591
|
-
}
|
|
592
|
-
function stroke(el, config) {
|
|
593
|
-
_setAttribute(el, "stroke", config.strokeStyle);
|
|
594
|
-
_setAttribute(el, "fill", "none");
|
|
595
|
-
_setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
function setStyle (el, styles) {
|
|
599
|
-
for (var key in styles) {
|
|
600
|
-
el.style[key] = styles[key];
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
var rotate = function (cx, cy, deg, x, y) {
|
|
605
|
-
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
606
|
-
return [
|
|
607
|
-
+((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
|
|
608
|
-
+((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
|
|
609
|
-
];
|
|
610
|
-
};
|
|
611
|
-
function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
|
|
612
|
-
if (rotateA < 0) {
|
|
613
|
-
beginA += rotateA;
|
|
614
|
-
rotateA *= -1;
|
|
615
|
-
}
|
|
616
|
-
var temp = [], p;
|
|
617
|
-
p = rotate(0, 0, beginA, r1, 0);
|
|
618
|
-
temp[0] = p[0];
|
|
619
|
-
temp[1] = p[1];
|
|
620
|
-
p = rotate(0, 0, rotateA, p[0], p[1]);
|
|
621
|
-
temp[2] = p[0];
|
|
622
|
-
temp[3] = p[1];
|
|
623
|
-
p = rotate(0, 0, beginA, r2, 0);
|
|
624
|
-
temp[4] = p[0];
|
|
625
|
-
temp[5] = p[1];
|
|
626
|
-
p = rotate(0, 0, rotateA, p[0], p[1]);
|
|
627
|
-
temp[6] = p[0];
|
|
628
|
-
temp[7] = p[1];
|
|
629
|
-
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);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
var initText$1 = function (el, config, x, y, deg) {
|
|
633
|
-
if (el.nodeName.toLowerCase() !== "text")
|
|
634
|
-
throw new Error("Need a <text> !");
|
|
635
|
-
setAttribute(el, "dy", {
|
|
636
|
-
top: config["fontSize"] * 0.5,
|
|
637
|
-
middle: 0,
|
|
638
|
-
bottom: -config["fontSize"] * 0.5,
|
|
639
|
-
}[config.textBaseline]);
|
|
640
|
-
setStyle(el, {
|
|
641
|
-
"text-anchor": {
|
|
642
|
-
left: "start",
|
|
643
|
-
right: "end",
|
|
644
|
-
center: "middle",
|
|
645
|
-
}[config.textAlign],
|
|
646
|
-
"dominant-baseline": "central",
|
|
647
|
-
"font-size": config["fontSize"] + "px",
|
|
648
|
-
"font-family": config["fontFamily"],
|
|
649
|
-
});
|
|
650
|
-
setAttribute(el, "x", x);
|
|
651
|
-
setAttribute(el, "y", y);
|
|
652
|
-
if (typeof deg == "number") {
|
|
653
|
-
deg = deg % 360;
|
|
654
|
-
setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
var initCircle$1 = function (el, cx, cy, r) {
|
|
658
|
-
if (el.nodeName.toLowerCase() !== "circle")
|
|
659
|
-
throw new Error("Need a <circle> !");
|
|
660
|
-
setAttribute(el, "cx", cx);
|
|
661
|
-
setAttribute(el, "cy", cy);
|
|
662
|
-
setAttribute(el, "r", r);
|
|
663
|
-
};
|
|
664
|
-
var initPath = function (el, path) {
|
|
665
|
-
if (el.nodeName.toLowerCase() !== "path")
|
|
666
|
-
throw new Error("Need a <path> !");
|
|
667
|
-
setAttribute(el, "d", path);
|
|
668
|
-
};
|
|
669
|
-
var initRect$1 = function (el, x, y, width, height) {
|
|
670
|
-
if (el.nodeName.toLowerCase() !== "rect")
|
|
671
|
-
throw new Error("Need a <rect> !");
|
|
672
|
-
if (height < 0) {
|
|
673
|
-
height *= -1;
|
|
674
|
-
y -= height;
|
|
675
|
-
}
|
|
676
|
-
if (width < 0) {
|
|
677
|
-
width *= -1;
|
|
678
|
-
x -= width;
|
|
679
|
-
}
|
|
680
|
-
setAttribute(el, "x", x);
|
|
681
|
-
setAttribute(el, "y", y);
|
|
682
|
-
setAttribute(el, "width", width);
|
|
683
|
-
setAttribute(el, "height", height);
|
|
684
|
-
};
|
|
685
|
-
var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
686
|
-
if (el.nodeName.toLowerCase() !== "path")
|
|
687
|
-
throw new Error("Need a <path> !");
|
|
688
|
-
beginDeg = (beginDeg / 180) * Math.PI;
|
|
689
|
-
deg = (deg / 180) * Math.PI;
|
|
690
|
-
beginDeg = beginDeg % (Math.PI * 2);
|
|
691
|
-
if (r1 > r2) {
|
|
692
|
-
var temp = r1;
|
|
693
|
-
r1 = r2;
|
|
694
|
-
r2 = temp;
|
|
695
|
-
}
|
|
696
|
-
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
697
|
-
deg = Math.PI * 1.999999;
|
|
698
|
-
}
|
|
699
|
-
else {
|
|
700
|
-
deg = deg % (Math.PI * 2);
|
|
701
|
-
}
|
|
702
|
-
arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
|
|
703
|
-
var f = endA - beginA > Math.PI ? 1 : 0, d = "M" + begInnerX + " " + begInnerY;
|
|
704
|
-
if (r < 0)
|
|
705
|
-
r = -r;
|
|
706
|
-
d +=
|
|
707
|
-
"A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
|
|
708
|
-
if (config.arcEndCap == "round")
|
|
709
|
-
d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
|
|
710
|
-
else if (config.arcEndCap == "-round")
|
|
711
|
-
d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
|
|
712
|
-
else
|
|
713
|
-
d += "L" + endOuterX + " " + endOuterY;
|
|
714
|
-
d +=
|
|
715
|
-
"A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
|
|
716
|
-
if (config.arcStartCap == "round")
|
|
717
|
-
d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
|
|
718
|
-
else if (config.arcStartCap == "-round")
|
|
719
|
-
d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
|
|
720
|
-
else
|
|
721
|
-
d += "L" + begInnerX + " " + begInnerY;
|
|
722
|
-
if (config.arcStartCap == "butt")
|
|
723
|
-
d += "Z";
|
|
724
|
-
setAttribute(el, "d", d);
|
|
725
|
-
});
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
var oldAttrName$1 = {
|
|
729
|
-
"font-size": "fontSize",
|
|
730
|
-
"font-family": "fontFamily",
|
|
731
|
-
"arc-start-cap": "arcStartCap",
|
|
732
|
-
"arc-end-cap": "arcEndCap",
|
|
733
|
-
};
|
|
734
|
-
var SVG$1 = (function () {
|
|
735
|
-
function SVG(svg) {
|
|
736
|
-
this.name = "SVG";
|
|
737
|
-
this.__config = {
|
|
738
|
-
fillStyle: "#000",
|
|
739
|
-
strokeStyle: "#000",
|
|
740
|
-
lineWidth: 1,
|
|
741
|
-
textAlign: "left",
|
|
742
|
-
textBaseline: "middle",
|
|
743
|
-
"fontSize": 16,
|
|
744
|
-
"fontFamily": "sans-serif",
|
|
745
|
-
"arcStartCap": "butt",
|
|
746
|
-
"arcEndCap": "butt",
|
|
747
|
-
lineDash: [],
|
|
748
|
-
};
|
|
749
|
-
this.__path = "";
|
|
750
|
-
this.__currentPosition = [];
|
|
751
|
-
this.__svg = svg;
|
|
752
|
-
}
|
|
753
|
-
SVG.prototype.config = function (params) {
|
|
754
|
-
if (typeof params !== "object") {
|
|
755
|
-
return this.__config[oldAttrName$1[params] || params];
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
for (var key in params) {
|
|
759
|
-
var _key = oldAttrName$1[key] || key;
|
|
760
|
-
this.__config[_key] = params[key];
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return this;
|
|
764
|
-
};
|
|
765
|
-
SVG.prototype.useEl = function (el) {
|
|
766
|
-
this.__useEl = el;
|
|
767
|
-
return this;
|
|
768
|
-
};
|
|
769
|
-
SVG.prototype.getEl = function () {
|
|
770
|
-
return this.__useEl;
|
|
771
|
-
};
|
|
772
|
-
SVG.prototype.appendEl = function (el, context) {
|
|
773
|
-
context = context || this.__svg;
|
|
774
|
-
if (typeof el == "string")
|
|
775
|
-
el = toNode(el);
|
|
776
|
-
context.appendChild(el);
|
|
777
|
-
this.__useEl = el;
|
|
778
|
-
return this;
|
|
779
|
-
};
|
|
780
|
-
SVG.prototype.appendBoard = function (el, context) {
|
|
781
|
-
var _el = el;
|
|
782
|
-
if (typeof el == "string")
|
|
783
|
-
_el =
|
|
784
|
-
{
|
|
785
|
-
text: "text",
|
|
786
|
-
path: "path",
|
|
787
|
-
arc: "path",
|
|
788
|
-
circle: "circle",
|
|
789
|
-
rect: "rect",
|
|
790
|
-
}[el] || "";
|
|
791
|
-
if (_el == "")
|
|
792
|
-
throw new Error("Unsupported drawing method:" + el);
|
|
793
|
-
return this.appendEl(_el, context);
|
|
794
|
-
};
|
|
795
|
-
SVG.prototype.remove = function () {
|
|
796
|
-
if (!this.__useEl) {
|
|
797
|
-
throw new Error("Currently, no node can be deleted.");
|
|
798
|
-
}
|
|
799
|
-
else {
|
|
800
|
-
this.__useEl.parentNode.removeChild(this.__useEl);
|
|
801
|
-
}
|
|
802
|
-
return this;
|
|
803
|
-
};
|
|
804
|
-
SVG.prototype.attr = function (params) {
|
|
805
|
-
if (!this.__useEl)
|
|
806
|
-
throw new Error("Currently, no node can be modified or viewed.");
|
|
807
|
-
if (typeof params !== "object") {
|
|
808
|
-
return getAttribute(this.__useEl, params);
|
|
809
|
-
}
|
|
810
|
-
else {
|
|
811
|
-
for (var key in params) {
|
|
812
|
-
setAttribute(this.__useEl, key, params[key]);
|
|
813
|
-
}
|
|
814
|
-
return this;
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
SVG.prototype.fillText = function (text, x, y, deg) {
|
|
818
|
-
if (deg === void 0) { deg = 0; }
|
|
819
|
-
initText$1(this.__useEl, this.__config, x, y, deg);
|
|
820
|
-
this.__useEl.textContent = text;
|
|
821
|
-
fill(this.__useEl, this.__config);
|
|
822
|
-
return this;
|
|
823
|
-
};
|
|
824
|
-
SVG.prototype.strokeText = function (text, x, y, deg) {
|
|
825
|
-
if (deg === void 0) { deg = 0; }
|
|
826
|
-
initText$1(this.__useEl, this.__config, x, y, deg);
|
|
827
|
-
this.__useEl.textContent = text;
|
|
828
|
-
stroke(this.__useEl, this.__config);
|
|
829
|
-
return this;
|
|
830
|
-
};
|
|
831
|
-
SVG.prototype.fullText = function (text, x, y, deg) {
|
|
832
|
-
if (deg === void 0) { deg = 0; }
|
|
833
|
-
initText$1(this.__useEl, this.__config, x, y, deg);
|
|
834
|
-
this.__useEl.textContent = text;
|
|
835
|
-
full(this.__useEl, this.__config);
|
|
836
|
-
return this;
|
|
837
|
-
};
|
|
838
|
-
SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
839
|
-
initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
|
|
840
|
-
fill(this.__useEl, this.__config);
|
|
841
|
-
return this;
|
|
842
|
-
};
|
|
843
|
-
SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
844
|
-
initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
|
|
845
|
-
stroke(this.__useEl, this.__config);
|
|
846
|
-
return this;
|
|
847
|
-
};
|
|
848
|
-
SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
849
|
-
initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
|
|
850
|
-
full(this.__useEl, this.__config);
|
|
851
|
-
return this;
|
|
852
|
-
};
|
|
853
|
-
SVG.prototype.fillCircle = function (cx, cy, r) {
|
|
854
|
-
initCircle$1(this.__useEl, cx, cy, r);
|
|
855
|
-
fill(this.__useEl, this.__config);
|
|
856
|
-
return this;
|
|
857
|
-
};
|
|
858
|
-
SVG.prototype.strokeCircle = function (cx, cy, r) {
|
|
859
|
-
initCircle$1(this.__useEl, cx, cy, r);
|
|
860
|
-
stroke(this.__useEl, this.__config);
|
|
861
|
-
return this;
|
|
862
|
-
};
|
|
863
|
-
SVG.prototype.fullCircle = function (cx, cy, r) {
|
|
864
|
-
initCircle$1(this.__useEl, cx, cy, r);
|
|
865
|
-
full(this.__useEl, this.__config);
|
|
866
|
-
return this;
|
|
867
|
-
};
|
|
868
|
-
SVG.prototype.fillRect = function (x, y, width, height) {
|
|
869
|
-
initRect$1(this.__useEl, x, y, width, height);
|
|
870
|
-
fill(this.__useEl, this.__config);
|
|
871
|
-
return this;
|
|
872
|
-
};
|
|
873
|
-
SVG.prototype.strokeRect = function (x, y, width, height) {
|
|
874
|
-
initRect$1(this.__useEl, x, y, width, height);
|
|
875
|
-
stroke(this.__useEl, this.__config);
|
|
876
|
-
return this;
|
|
877
|
-
};
|
|
878
|
-
SVG.prototype.fullRect = function (x, y, width, height) {
|
|
879
|
-
initRect$1(this.__useEl, x, y, width, height);
|
|
880
|
-
full(this.__useEl, this.__config);
|
|
881
|
-
return this;
|
|
882
|
-
};
|
|
883
|
-
SVG.prototype.beginPath = function () {
|
|
884
|
-
this.__currentPosition = [];
|
|
885
|
-
this.__path = "";
|
|
886
|
-
return this;
|
|
887
|
-
};
|
|
888
|
-
SVG.prototype.closePath = function () {
|
|
889
|
-
this.__path += "Z";
|
|
890
|
-
return this;
|
|
891
|
-
};
|
|
892
|
-
SVG.prototype.moveTo = function (x, y) {
|
|
893
|
-
this.__currentPosition = [x, y];
|
|
894
|
-
this.__path += "M" + x + " " + y;
|
|
895
|
-
return this;
|
|
896
|
-
};
|
|
897
|
-
SVG.prototype.lineTo = function (x, y) {
|
|
898
|
-
this.__currentPosition = [x, y];
|
|
899
|
-
this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
|
|
900
|
-
return this;
|
|
901
|
-
};
|
|
902
|
-
SVG.prototype.fill = function () {
|
|
903
|
-
initPath(this.__useEl, this.__path);
|
|
904
|
-
fill(this.__useEl, this.__config);
|
|
905
|
-
return this;
|
|
906
|
-
};
|
|
907
|
-
SVG.prototype.stroke = function () {
|
|
908
|
-
initPath(this.__useEl, this.__path);
|
|
909
|
-
stroke(this.__useEl, this.__config);
|
|
910
|
-
return this;
|
|
911
|
-
};
|
|
912
|
-
SVG.prototype.full = function () {
|
|
913
|
-
initPath(this.__useEl, this.__path);
|
|
914
|
-
full(this.__useEl, this.__config);
|
|
915
|
-
return this;
|
|
916
|
-
};
|
|
917
|
-
SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
|
|
918
|
-
var begPosition = rotate$1(x, y, (beginDeg / 180) * Math.PI, x + r, y);
|
|
919
|
-
var endPosition = rotate$1(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
|
|
920
|
-
if (this.__path == "") {
|
|
921
|
-
this.__path += "M" + begPosition[0] + "," + begPosition[1];
|
|
922
|
-
}
|
|
923
|
-
else if (begPosition[0] != this.__currentPosition[0] ||
|
|
924
|
-
begPosition[1] != this.__currentPosition[1]) {
|
|
925
|
-
this.__path += "L" + begPosition[0] + "," + begPosition[1];
|
|
926
|
-
}
|
|
927
|
-
this.__path +=
|
|
928
|
-
"A" +
|
|
929
|
-
r +
|
|
930
|
-
"," +
|
|
931
|
-
r +
|
|
932
|
-
" 0 " +
|
|
933
|
-
(deg > 180 || deg < -180 ? 1 : 0) +
|
|
934
|
-
"," +
|
|
935
|
-
(deg > 0 ? 1 : 0) +
|
|
936
|
-
" " +
|
|
937
|
-
endPosition[0] +
|
|
938
|
-
"," +
|
|
939
|
-
endPosition[1];
|
|
940
|
-
return this;
|
|
941
|
-
};
|
|
942
|
-
SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
943
|
-
this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
|
|
944
|
-
return this;
|
|
945
|
-
};
|
|
946
|
-
SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
947
|
-
this.__path +=
|
|
948
|
-
"C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
|
|
949
|
-
return this;
|
|
950
|
-
};
|
|
951
|
-
SVG.prototype.bind = function (eventType, callback) {
|
|
952
|
-
this.__useEl.addEventListener(eventType, function (event) {
|
|
953
|
-
callback.call(this, event, this);
|
|
954
|
-
}, false);
|
|
955
|
-
return this;
|
|
956
|
-
};
|
|
957
|
-
return SVG;
|
|
958
|
-
}());
|
|
959
|
-
|
|
960
|
-
var SVG = (function (_super) {
|
|
961
|
-
__extends(SVG, _super);
|
|
962
|
-
function SVG(el) {
|
|
963
|
-
if (!el) {
|
|
964
|
-
throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
|
|
965
|
-
}
|
|
966
|
-
var width = el.clientWidth, height = el.clientHeight;
|
|
967
|
-
var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
|
|
968
|
-
el.appendChild(ViewSVG);
|
|
969
|
-
ViewSVG.setAttribute("width", width + "");
|
|
970
|
-
ViewSVG.setAttribute("height", height + "");
|
|
971
|
-
ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
|
|
972
|
-
return _super.call(this, ViewSVG) || this;
|
|
973
|
-
}
|
|
974
|
-
return SVG;
|
|
975
|
-
}(SVG$1));
|
|
976
|
-
|
|
977
|
-
var initText = function (painter, config, x, y, deg) {
|
|
978
|
-
painter.beginPath();
|
|
979
|
-
painter.translate(x, y);
|
|
980
|
-
painter.rotate(deg);
|
|
981
|
-
painter.font =
|
|
982
|
-
config.fontStyle +
|
|
983
|
-
" " +
|
|
984
|
-
config.fontWeight +
|
|
985
|
-
" " +
|
|
986
|
-
config.fontSize +
|
|
987
|
-
"px " +
|
|
988
|
-
config.fontFamily;
|
|
989
|
-
return painter;
|
|
990
|
-
};
|
|
991
|
-
var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
|
|
992
|
-
if (r1 > r2) {
|
|
993
|
-
var temp = r1;
|
|
994
|
-
r1 = r2;
|
|
995
|
-
r2 = temp;
|
|
996
|
-
}
|
|
997
|
-
beginDeg = beginDeg % (Math.PI * 2);
|
|
998
|
-
if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
|
|
999
|
-
deg = Math.PI * 2;
|
|
1000
|
-
}
|
|
1001
|
-
else {
|
|
1002
|
-
deg = deg % (Math.PI * 2);
|
|
1003
|
-
}
|
|
1004
|
-
arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
|
|
1005
|
-
if (r < 0)
|
|
1006
|
-
r = -r;
|
|
1007
|
-
painter.beginPath();
|
|
1008
|
-
painter.moveTo(begInnerX, begInnerY);
|
|
1009
|
-
painter.arc(cx, cy, r1, beginA, endA, false);
|
|
1010
|
-
if (config.arcEndCap == "round")
|
|
1011
|
-
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
|
|
1012
|
-
else if (config.arcEndCap == "-round")
|
|
1013
|
-
painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
|
|
1014
|
-
else
|
|
1015
|
-
painter.lineTo(endOuterX, endOuterY);
|
|
1016
|
-
painter.arc(cx, cy, r2, endA, beginA, true);
|
|
1017
|
-
if (config.arcStartCap == "round")
|
|
1018
|
-
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
|
|
1019
|
-
else if (config.arcStartCap == "-round")
|
|
1020
|
-
painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
|
|
1021
|
-
else
|
|
1022
|
-
painter.lineTo(begInnerX, begInnerY);
|
|
1023
|
-
});
|
|
1024
|
-
if (config.arcStartCap == "butt")
|
|
1025
|
-
painter.closePath();
|
|
1026
|
-
return painter;
|
|
1027
|
-
};
|
|
1028
|
-
var initCircle = function (painter, cx, cy, r) {
|
|
1029
|
-
painter.beginPath();
|
|
1030
|
-
painter.moveTo(cx + r, cy);
|
|
1031
|
-
painter.arc(cx, cy, r, 0, Math.PI * 2);
|
|
1032
|
-
return painter;
|
|
1033
|
-
};
|
|
1034
|
-
var initRect = function (painter, x, y, width, height) {
|
|
1035
|
-
painter.beginPath();
|
|
1036
|
-
painter.rect(x, y, width, height);
|
|
1037
|
-
return painter;
|
|
1038
|
-
};
|
|
1039
|
-
|
|
1040
|
-
function texts (painter, contents, width, height, doback) {
|
|
1041
|
-
var lineNumber = 0, content = "";
|
|
1042
|
-
for (var i = 0; i < contents.length; i++) {
|
|
1043
|
-
if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
|
|
1044
|
-
lineNumber += 1;
|
|
1045
|
-
doback(content, (lineNumber - 0.5) * height);
|
|
1046
|
-
content = contents[i];
|
|
1047
|
-
}
|
|
1048
|
-
else if (i == contents.length - 1) {
|
|
1049
|
-
lineNumber += 1;
|
|
1050
|
-
doback(content + contents[i], (lineNumber - 0.5) * height);
|
|
1051
|
-
}
|
|
1052
|
-
else {
|
|
1053
|
-
content += contents[i];
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
return lineNumber * height;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
var Painter = (function () {
|
|
1060
|
-
function Painter(canvas, opts, region, isPainter) {
|
|
1061
|
-
if (opts === void 0) { opts = {}; }
|
|
1062
|
-
if (isPainter === void 0) { isPainter = false; }
|
|
1063
|
-
this.__region = null;
|
|
1064
|
-
this.__onlyRegion = false;
|
|
1065
|
-
this.__specialConfig = {
|
|
1066
|
-
"fontSize": 16,
|
|
1067
|
-
"fontFamily": "sans-serif",
|
|
1068
|
-
"fontWeight": 400,
|
|
1069
|
-
"fontStyle": "normal",
|
|
1070
|
-
"arcStartCap": 'butt',
|
|
1071
|
-
"arcEndCap": 'butt'
|
|
1072
|
-
};
|
|
1073
|
-
this.__initConfig = {
|
|
1074
|
-
"fillStyle": 'black',
|
|
1075
|
-
"strokeStyle": 'black',
|
|
1076
|
-
"lineWidth": 1,
|
|
1077
|
-
"textAlign": 'left',
|
|
1078
|
-
"textBaseline": 'middle',
|
|
1079
|
-
"lineDash": [],
|
|
1080
|
-
"shadowBlur": 0,
|
|
1081
|
-
"shadowColor": "black"
|
|
1082
|
-
};
|
|
1083
|
-
this.painter = canvas.getContext("2d", opts);
|
|
1084
|
-
this.__region = region;
|
|
1085
|
-
this.__isPainter = isPainter;
|
|
1086
|
-
this.painter.textBaseline = 'middle';
|
|
1087
|
-
this.painter.textAlign = 'left';
|
|
1088
|
-
}
|
|
1089
|
-
Painter.prototype.useConfig = function (key, value) {
|
|
1090
|
-
if (this.__region) {
|
|
1091
|
-
if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
|
|
1092
|
-
this.__region.useConfig(key, value);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1096
|
-
return this;
|
|
1097
|
-
if (key == 'lineDash') {
|
|
1098
|
-
if (this.painter.setLineDash)
|
|
1099
|
-
this.painter.setLineDash(value);
|
|
1100
|
-
}
|
|
1101
|
-
else if (key in this.__specialConfig) {
|
|
1102
|
-
if (key == 'fontSize') {
|
|
1103
|
-
value = Math.round(value);
|
|
1104
|
-
}
|
|
1105
|
-
this.__specialConfig[key] = value;
|
|
1106
|
-
}
|
|
1107
|
-
else if (key in this.__initConfig) {
|
|
1108
|
-
this.painter[key] = value;
|
|
1109
|
-
}
|
|
1110
|
-
else {
|
|
1111
|
-
throw new Error('Illegal configuration item of painter : ' + key + " !");
|
|
1112
|
-
}
|
|
1113
|
-
return this;
|
|
1114
|
-
};
|
|
1115
|
-
Painter.prototype.fillText = function (text, x, y, deg) {
|
|
1116
|
-
if (deg === void 0) { deg = 0; }
|
|
1117
|
-
if (this.__region)
|
|
1118
|
-
this.__region.fillText(text, x, y, deg);
|
|
1119
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1120
|
-
return this;
|
|
1121
|
-
this.painter.save();
|
|
1122
|
-
initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
|
|
1123
|
-
this.painter.restore();
|
|
1124
|
-
return this;
|
|
1125
|
-
};
|
|
1126
|
-
Painter.prototype.strokeText = function (text, x, y, deg) {
|
|
1127
|
-
if (deg === void 0) { deg = 0; }
|
|
1128
|
-
if (this.__region)
|
|
1129
|
-
this.__region.strokeText(text, x, y, deg);
|
|
1130
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1131
|
-
return this;
|
|
1132
|
-
this.painter.save();
|
|
1133
|
-
initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
|
|
1134
|
-
this.painter.restore();
|
|
1135
|
-
return this;
|
|
1136
|
-
};
|
|
1137
|
-
Painter.prototype.fullText = function (text, x, y, deg) {
|
|
1138
|
-
if (deg === void 0) { deg = 0; }
|
|
1139
|
-
if (this.__region)
|
|
1140
|
-
this.__region.fullText(text, x, y, deg);
|
|
1141
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1142
|
-
return this;
|
|
1143
|
-
this.painter.save();
|
|
1144
|
-
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
1145
|
-
this.painter.fillText(text, 0, 0);
|
|
1146
|
-
this.painter.strokeText(text, 0, 0);
|
|
1147
|
-
this.painter.restore();
|
|
1148
|
-
return this;
|
|
1149
|
-
};
|
|
1150
|
-
Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
1151
|
-
var _this = this;
|
|
1152
|
-
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
1153
|
-
if (deg === void 0) { deg = 0; }
|
|
1154
|
-
var h = 0;
|
|
1155
|
-
if (this.__region)
|
|
1156
|
-
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
1157
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1158
|
-
return h;
|
|
1159
|
-
this.painter.save();
|
|
1160
|
-
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
1161
|
-
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
1162
|
-
_this.painter.fillText(content, 0, top);
|
|
1163
|
-
});
|
|
1164
|
-
this.painter.restore();
|
|
1165
|
-
return height;
|
|
1166
|
-
};
|
|
1167
|
-
Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
1168
|
-
var _this = this;
|
|
1169
|
-
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
1170
|
-
if (deg === void 0) { deg = 0; }
|
|
1171
|
-
var h = 0;
|
|
1172
|
-
if (this.__region)
|
|
1173
|
-
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
1174
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1175
|
-
return h;
|
|
1176
|
-
this.painter.save();
|
|
1177
|
-
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
1178
|
-
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
1179
|
-
_this.painter.strokeText(content, 0, top);
|
|
1180
|
-
});
|
|
1181
|
-
this.painter.restore();
|
|
1182
|
-
return height;
|
|
1183
|
-
};
|
|
1184
|
-
Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
|
|
1185
|
-
var _this = this;
|
|
1186
|
-
if (lineHeight === void 0) { lineHeight = 1.2; }
|
|
1187
|
-
if (deg === void 0) { deg = 0; }
|
|
1188
|
-
var h = 0;
|
|
1189
|
-
if (this.__region)
|
|
1190
|
-
h = this.__region.fillTexts(contents, x, y, width, lineHeight);
|
|
1191
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1192
|
-
return h;
|
|
1193
|
-
this.painter.save();
|
|
1194
|
-
initText(this.painter, this.__specialConfig, x, y, deg);
|
|
1195
|
-
var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
|
|
1196
|
-
_this.painter.fillText(content, 0, top);
|
|
1197
|
-
_this.painter.strokeText(content, 0, top);
|
|
1198
|
-
});
|
|
1199
|
-
this.painter.restore();
|
|
1200
|
-
return height;
|
|
1201
|
-
};
|
|
1202
|
-
Painter.prototype.beginPath = function () {
|
|
1203
|
-
if (this.__region)
|
|
1204
|
-
this.__region.beginPath();
|
|
1205
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1206
|
-
return this;
|
|
1207
|
-
this.painter.beginPath();
|
|
1208
|
-
return this;
|
|
1209
|
-
};
|
|
1210
|
-
Painter.prototype.closePath = function () {
|
|
1211
|
-
if (this.__region)
|
|
1212
|
-
this.__region.closePath();
|
|
1213
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1214
|
-
return this;
|
|
1215
|
-
this.painter.closePath();
|
|
1216
|
-
return this;
|
|
1217
|
-
};
|
|
1218
|
-
Painter.prototype.moveTo = function (x, y) {
|
|
1219
|
-
if (this.__region)
|
|
1220
|
-
this.__region.moveTo(x, y);
|
|
1221
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1222
|
-
return this;
|
|
1223
|
-
this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
|
|
1224
|
-
return this;
|
|
1225
|
-
};
|
|
1226
|
-
Painter.prototype.lineTo = function (x, y) {
|
|
1227
|
-
if (this.__region)
|
|
1228
|
-
this.__region.lineTo(x, y);
|
|
1229
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1230
|
-
return this;
|
|
1231
|
-
this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
|
|
1232
|
-
return this;
|
|
1233
|
-
};
|
|
1234
|
-
Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
|
|
1235
|
-
if (this.__region)
|
|
1236
|
-
this.__region.arc(x, y, r, beginDeg, deg);
|
|
1237
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1238
|
-
return this;
|
|
1239
|
-
this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
|
|
1240
|
-
return this;
|
|
1241
|
-
};
|
|
1242
|
-
Painter.prototype.fill = function () {
|
|
1243
|
-
if (this.__region)
|
|
1244
|
-
this.__region.fill();
|
|
1245
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1246
|
-
return this;
|
|
1247
|
-
this.painter.fill();
|
|
1248
|
-
return this;
|
|
1249
|
-
};
|
|
1250
|
-
Painter.prototype.stroke = function () {
|
|
1251
|
-
if (this.__region)
|
|
1252
|
-
this.__region.stroke();
|
|
1253
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1254
|
-
return this;
|
|
1255
|
-
this.painter.stroke();
|
|
1256
|
-
return this;
|
|
1257
|
-
};
|
|
1258
|
-
Painter.prototype.full = function () {
|
|
1259
|
-
if (this.__region)
|
|
1260
|
-
this.__region.full();
|
|
1261
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1262
|
-
return this;
|
|
1263
|
-
this.painter.fill();
|
|
1264
|
-
this.painter.stroke();
|
|
1265
|
-
return this;
|
|
1266
|
-
};
|
|
1267
|
-
Painter.prototype.save = function () {
|
|
1268
|
-
if (this.__region)
|
|
1269
|
-
this.__region.save();
|
|
1270
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1271
|
-
return this;
|
|
1272
|
-
this.painter.save();
|
|
1273
|
-
return this;
|
|
1274
|
-
};
|
|
1275
|
-
Painter.prototype.restore = function () {
|
|
1276
|
-
if (this.__region)
|
|
1277
|
-
this.__region.restore();
|
|
1278
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1279
|
-
return this;
|
|
1280
|
-
this.painter.restore();
|
|
1281
|
-
return this;
|
|
1282
|
-
};
|
|
1283
|
-
Painter.prototype.clip = function () {
|
|
1284
|
-
if (this.__region)
|
|
1285
|
-
this.__region.clip();
|
|
1286
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1287
|
-
return this;
|
|
1288
|
-
this.painter.clip();
|
|
1289
|
-
return this;
|
|
1290
|
-
};
|
|
1291
|
-
Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
|
|
1292
|
-
if (this.__region)
|
|
1293
|
-
this.__region.quadraticCurveTo(cpx, cpy, x, y);
|
|
1294
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1295
|
-
return this;
|
|
1296
|
-
this.painter.quadraticCurveTo(cpx, cpy, x, y);
|
|
1297
|
-
return this;
|
|
1298
|
-
};
|
|
1299
|
-
Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
1300
|
-
if (this.__region)
|
|
1301
|
-
this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
1302
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1303
|
-
return this;
|
|
1304
|
-
this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
|
|
1305
|
-
return this;
|
|
1306
|
-
};
|
|
1307
|
-
Painter.prototype.clearRect = function (x, y, w, h) {
|
|
1308
|
-
if (this.__region)
|
|
1309
|
-
this.__region.clearRect(x, y, w, h);
|
|
1310
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1311
|
-
return this;
|
|
1312
|
-
this.painter.clearRect(x, y, w, h);
|
|
1313
|
-
return this;
|
|
1314
|
-
};
|
|
1315
|
-
Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
1316
|
-
if (this.__region)
|
|
1317
|
-
this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
|
|
1318
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1319
|
-
return this;
|
|
1320
|
-
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
|
|
1321
|
-
return this;
|
|
1322
|
-
};
|
|
1323
|
-
Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
1324
|
-
if (this.__region)
|
|
1325
|
-
this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
|
|
1326
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1327
|
-
return this;
|
|
1328
|
-
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
|
|
1329
|
-
return this;
|
|
1330
|
-
};
|
|
1331
|
-
Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
|
|
1332
|
-
if (this.__region)
|
|
1333
|
-
this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
|
|
1334
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1335
|
-
return this;
|
|
1336
|
-
initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
|
|
1337
|
-
this.painter.fill();
|
|
1338
|
-
this.painter.stroke();
|
|
1339
|
-
return this;
|
|
1340
|
-
};
|
|
1341
|
-
Painter.prototype.fillCircle = function (cx, cy, r) {
|
|
1342
|
-
if (this.__region)
|
|
1343
|
-
this.__region.fillCircle(cx, cy, r);
|
|
1344
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1345
|
-
return this;
|
|
1346
|
-
initCircle(this.painter, cx, cy, r).fill();
|
|
1347
|
-
return this;
|
|
1348
|
-
};
|
|
1349
|
-
Painter.prototype.strokeCircle = function (cx, cy, r) {
|
|
1350
|
-
if (this.__region)
|
|
1351
|
-
this.__region.strokeCircle(cx, cy, r);
|
|
1352
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1353
|
-
return this;
|
|
1354
|
-
initCircle(this.painter, cx, cy, r).stroke();
|
|
1355
|
-
return this;
|
|
1356
|
-
};
|
|
1357
|
-
Painter.prototype.fullCircle = function (cx, cy, r) {
|
|
1358
|
-
if (this.__region)
|
|
1359
|
-
this.__region.fullCircle(cx, cy, r);
|
|
1360
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1361
|
-
return this;
|
|
1362
|
-
initCircle(this.painter, cx, cy, r);
|
|
1363
|
-
this.painter.fill();
|
|
1364
|
-
this.painter.stroke();
|
|
1365
|
-
return this;
|
|
1366
|
-
};
|
|
1367
|
-
Painter.prototype.fillRect = function (x, y, width, height) {
|
|
1368
|
-
if (this.__region)
|
|
1369
|
-
this.__region.fillRect(x, y, width, height);
|
|
1370
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1371
|
-
return this;
|
|
1372
|
-
initRect(this.painter, x, y, width, height).fill();
|
|
1373
|
-
return this;
|
|
1374
|
-
};
|
|
1375
|
-
Painter.prototype.strokeRect = function (x, y, width, height) {
|
|
1376
|
-
if (this.__region)
|
|
1377
|
-
this.__region.strokeRect(x, y, width, height);
|
|
1378
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1379
|
-
return this;
|
|
1380
|
-
initRect(this.painter, x, y, width, height).stroke();
|
|
1381
|
-
return this;
|
|
1382
|
-
};
|
|
1383
|
-
Painter.prototype.fullRect = function (x, y, width, height) {
|
|
1384
|
-
if (this.__region)
|
|
1385
|
-
this.__region.fullRect(x, y, width, height);
|
|
1386
|
-
if (this.__isPainter && this.__onlyRegion)
|
|
1387
|
-
return this;
|
|
1388
|
-
initRect(this.painter, x, y, width, height);
|
|
1389
|
-
this.painter.fill();
|
|
1390
|
-
this.painter.stroke();
|
|
1391
|
-
return this;
|
|
1392
|
-
};
|
|
1393
|
-
Painter.prototype.draw = function () { };
|
|
1394
|
-
return Painter;
|
|
1395
|
-
}());
|
|
1396
|
-
|
|
1397
|
-
function assemble (begin, end, step, count) {
|
|
1398
|
-
var val = [];
|
|
1399
|
-
for (var index = 0; index < count; index++)
|
|
1400
|
-
val[index] = begin;
|
|
1401
|
-
return function () {
|
|
1402
|
-
for (var i = 0; i < count; i++) {
|
|
1403
|
-
if (val[i] + step < end) {
|
|
1404
|
-
val[i] = +(val[i] + step).toFixed(7);
|
|
1405
|
-
break;
|
|
1406
|
-
}
|
|
1407
|
-
else if (i < count - 1) {
|
|
1408
|
-
val[i] = begin;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
return val;
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
var linearGradient = function (painter, x0, y0, x1, y1) {
|
|
1416
|
-
var gradient = painter.createLinearGradient(x0, y0, x1, y1);
|
|
1417
|
-
var enhanceGradient = {
|
|
1418
|
-
"value": function () {
|
|
1419
|
-
return gradient;
|
|
1420
|
-
},
|
|
1421
|
-
"setColor": function (stop, color) {
|
|
1422
|
-
gradient.addColorStop(stop, color);
|
|
1423
|
-
return enhanceGradient;
|
|
1424
|
-
}
|
|
1425
|
-
};
|
|
1426
|
-
return enhanceGradient;
|
|
1427
|
-
};
|
|
1428
|
-
var radialGradient = function (painter, cx, cy, r) {
|
|
1429
|
-
var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
1430
|
-
var enhanceGradient = {
|
|
1431
|
-
"value": function () {
|
|
1432
|
-
return gradient;
|
|
1433
|
-
},
|
|
1434
|
-
"setColor": function (stop, color) {
|
|
1435
|
-
gradient.addColorStop(stop, color);
|
|
1436
|
-
return enhanceGradient;
|
|
1437
|
-
}
|
|
1438
|
-
};
|
|
1439
|
-
return enhanceGradient;
|
|
1440
|
-
};
|
|
1441
|
-
|
|
1442
|
-
var oldAttrName = {
|
|
1443
|
-
"font-size": "fontSize",
|
|
1444
|
-
"font-family": "fontFamily",
|
|
1445
|
-
"font-weight": "fontWeight",
|
|
1446
|
-
"font-style": "fontStyle",
|
|
1447
|
-
"arc-start-cap": "arcStartCap",
|
|
1448
|
-
"arc-end-cap": "arcEndCap",
|
|
1449
|
-
};
|
|
1450
|
-
var Canvas$1 = (function (_super) {
|
|
1451
|
-
__extends(Canvas, _super);
|
|
1452
|
-
function Canvas(ViewCanvas, RegionCanvas) {
|
|
1453
|
-
var _this = _super.call(this, ViewCanvas, {}, RegionCanvas ? new Painter(RegionCanvas, {
|
|
1454
|
-
willReadFrequently: true,
|
|
1455
|
-
}) : null, true) || this;
|
|
1456
|
-
_this.name = "Canvas";
|
|
1457
|
-
_this.__regionList = {};
|
|
1458
|
-
_this.__regionAssemble = assemble(0, 255, 10, 3);
|
|
1459
|
-
_this.setRegion("");
|
|
1460
|
-
return _this;
|
|
1461
|
-
}
|
|
1462
|
-
Canvas.prototype.config = function (configs) {
|
|
1463
|
-
for (var key in configs) {
|
|
1464
|
-
var _key = oldAttrName[key] || key;
|
|
1465
|
-
this.useConfig(_key, configs[key]);
|
|
1466
|
-
}
|
|
1467
|
-
return this;
|
|
1468
|
-
};
|
|
1469
|
-
Canvas.prototype.onlyRegion = function (flag) {
|
|
1470
|
-
this.__onlyRegion = flag;
|
|
1471
|
-
return this;
|
|
1472
|
-
};
|
|
1473
|
-
Canvas.prototype.setRegion = function (regionName) {
|
|
1474
|
-
if (this.__region) {
|
|
1475
|
-
if (regionName) {
|
|
1476
|
-
if (this.__regionList[regionName] == void 0) {
|
|
1477
|
-
var tempColor = this.__regionAssemble();
|
|
1478
|
-
this.__regionList[regionName] =
|
|
1479
|
-
"rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
|
|
1480
|
-
}
|
|
1481
|
-
this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
|
|
1482
|
-
this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
|
|
1483
|
-
}
|
|
1484
|
-
else {
|
|
1485
|
-
this.__region.useConfig("fillStyle", "#000000") &&
|
|
1486
|
-
this.__region.useConfig("strokeStyle", "#000000");
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
return this;
|
|
1490
|
-
};
|
|
1491
|
-
Canvas.prototype.getRegion = function (x, y) {
|
|
1492
|
-
var _this = this;
|
|
1493
|
-
return new Promise(function (resolve, reject) {
|
|
1494
|
-
var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
|
|
1495
|
-
data: [0, 0, 0, 0]
|
|
1496
|
-
};
|
|
1497
|
-
var currentRGBA = imgData.data;
|
|
1498
|
-
var doit = function () {
|
|
1499
|
-
if (_this.__region) {
|
|
1500
|
-
for (var key in _this.__regionList) {
|
|
1501
|
-
if ("rgb(" +
|
|
1502
|
-
currentRGBA[0] +
|
|
1503
|
-
"," +
|
|
1504
|
-
currentRGBA[1] +
|
|
1505
|
-
"," +
|
|
1506
|
-
currentRGBA[2] +
|
|
1507
|
-
")" ==
|
|
1508
|
-
_this.__regionList[key]) {
|
|
1509
|
-
resolve(key);
|
|
1510
|
-
break;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
resolve("");
|
|
1515
|
-
};
|
|
1516
|
-
if (currentRGBA) {
|
|
1517
|
-
doit();
|
|
1518
|
-
}
|
|
1519
|
-
else {
|
|
1520
|
-
imgData.then(function (data) {
|
|
1521
|
-
currentRGBA = data;
|
|
1522
|
-
doit();
|
|
1523
|
-
});
|
|
1524
|
-
}
|
|
1525
|
-
});
|
|
1526
|
-
};
|
|
1527
|
-
Canvas.prototype.textWidth = function (text) {
|
|
1528
|
-
this.painter.save();
|
|
1529
|
-
initText(this.painter, this.__specialConfig, 0, 0, 0);
|
|
1530
|
-
var width = this.painter.measureText(text + "").width;
|
|
1531
|
-
this.painter.restore();
|
|
1532
|
-
return width;
|
|
1533
|
-
};
|
|
1534
|
-
Canvas.prototype.getContext = function (isRegion) {
|
|
1535
|
-
if (isRegion === void 0) { isRegion = false; }
|
|
1536
|
-
return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
|
|
1537
|
-
};
|
|
1538
|
-
Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
|
|
1539
|
-
return linearGradient(this.painter, x0, y0, x1, y1);
|
|
1540
|
-
};
|
|
1541
|
-
Canvas.prototype.createRadialGradient = function (cx, cy, r) {
|
|
1542
|
-
return radialGradient(this.painter, cx, cy, r);
|
|
1543
|
-
};
|
|
1544
|
-
Canvas.prototype.getColor = function (x, y) {
|
|
1545
|
-
var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
|
|
1546
|
-
return ("rgba(" +
|
|
1547
|
-
currentRGBA[0] +
|
|
1548
|
-
"," +
|
|
1549
|
-
currentRGBA[1] +
|
|
1550
|
-
"," +
|
|
1551
|
-
currentRGBA[2] +
|
|
1552
|
-
"," +
|
|
1553
|
-
currentRGBA[3] +
|
|
1554
|
-
")");
|
|
1555
|
-
};
|
|
1556
|
-
return Canvas;
|
|
1557
|
-
}(Painter));
|
|
1558
|
-
|
|
1559
|
-
function mergeOption (option, defaultOption) {
|
|
1560
|
-
for (var key in option) {
|
|
1561
|
-
defaultOption[key] = option[key];
|
|
1562
|
-
}
|
|
1563
|
-
return defaultOption;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
var Canvas = (function (_super) {
|
|
1567
|
-
__extends(Canvas, _super);
|
|
1568
|
-
function Canvas(el, option) {
|
|
1569
|
-
if (option === void 0) { option = {}; }
|
|
1570
|
-
var _this = this;
|
|
1571
|
-
if (!el) {
|
|
1572
|
-
throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
|
|
1573
|
-
}
|
|
1574
|
-
option = mergeOption(option, {
|
|
1575
|
-
region: true
|
|
1576
|
-
});
|
|
1577
|
-
var width = el.clientWidth, height = el.clientHeight;
|
|
1578
|
-
var ViewCanvas, RegionCanvas;
|
|
1579
|
-
var _el = el;
|
|
1580
|
-
if (_el._vislite_canvas_) {
|
|
1581
|
-
ViewCanvas = _el._vislite_canvas_[0];
|
|
1582
|
-
RegionCanvas = _el._vislite_canvas_[1];
|
|
1583
|
-
}
|
|
1584
|
-
else {
|
|
1585
|
-
ViewCanvas = document.createElement('canvas');
|
|
1586
|
-
el.appendChild(ViewCanvas);
|
|
1587
|
-
if (option.region) {
|
|
1588
|
-
RegionCanvas = document.createElement('canvas');
|
|
1589
|
-
}
|
|
1590
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
|
|
1591
|
-
el.setAttribute('vislite', 'Canvas');
|
|
1592
|
-
}
|
|
1593
|
-
for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
|
|
1594
|
-
var canvas = _a[_i];
|
|
1595
|
-
if (canvas) {
|
|
1596
|
-
canvas.style.width = width + "px";
|
|
1597
|
-
canvas.setAttribute('width', width + "");
|
|
1598
|
-
canvas.style.height = height + "px";
|
|
1599
|
-
canvas.setAttribute('height', height + "");
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
_this = _super.call(this, ViewCanvas, RegionCanvas) || this;
|
|
1603
|
-
_this.__canvas = ViewCanvas;
|
|
1604
|
-
return _this;
|
|
1605
|
-
}
|
|
1606
|
-
Canvas.prototype.toDataURL = function () {
|
|
1607
|
-
var _this = this;
|
|
1608
|
-
return new Promise(function (resolve) {
|
|
1609
|
-
resolve(_this.__canvas.toDataURL());
|
|
1610
|
-
});
|
|
1611
|
-
};
|
|
1612
|
-
return Canvas;
|
|
1613
|
-
}(Canvas$1));
|
|
1614
|
-
|
|
1615
|
-
function getWebGLContext$1 (canvas, scale, opts) {
|
|
1616
|
-
if (opts === void 0) { opts = {}; }
|
|
1617
|
-
var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null;
|
|
1618
|
-
for (var i = 0; i < names.length; i++) {
|
|
1619
|
-
try {
|
|
1620
|
-
painter = canvas.getContext(names[i], opts);
|
|
1621
|
-
}
|
|
1622
|
-
catch (e) { }
|
|
1623
|
-
if (painter)
|
|
1624
|
-
break;
|
|
1625
|
-
}
|
|
1626
|
-
if (!painter)
|
|
1627
|
-
throw new Error('Non canvas or browser does not support webgl.');
|
|
1628
|
-
var width = painter.canvas.width, height = painter.canvas.height;
|
|
1629
|
-
var viewWidth = width * scale;
|
|
1630
|
-
var viewHeight = height * scale;
|
|
1631
|
-
painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
|
|
1632
|
-
painter.depthFunc(painter.LEQUAL);
|
|
1633
|
-
painter.enable(painter.DEPTH_TEST);
|
|
1634
|
-
return painter;
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
function getColorFactory (painter) {
|
|
1638
|
-
var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
|
|
1639
|
-
var pixels = new Uint8Array(4 * width * height);
|
|
1640
|
-
painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
|
|
1641
|
-
return function (x, y) {
|
|
1642
|
-
y = height - y;
|
|
1643
|
-
var pixelR = pixels[4 * (y * width + x)];
|
|
1644
|
-
var pixelG = pixels[4 * (y * width + x) + 1];
|
|
1645
|
-
var pixelB = pixels[4 * (y * width + x) + 2];
|
|
1646
|
-
var pixelA = pixels[4 * (y * width + x) + 3];
|
|
1647
|
-
return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
|
-
var newBuffer = function (painter) {
|
|
1652
|
-
return painter.createBuffer();
|
|
1653
|
-
};
|
|
1654
|
-
var writeBuffer = function (painter, data, isElement, usage) {
|
|
1655
|
-
var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
1656
|
-
painter.bufferData(TYPE, data, usage);
|
|
1657
|
-
};
|
|
1658
|
-
var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
|
|
1659
|
-
painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
|
|
1660
|
-
painter.enableVertexAttribArray(location);
|
|
1661
|
-
};
|
|
1662
|
-
var BufferObject = (function () {
|
|
1663
|
-
function BufferObject(painter, isElement) {
|
|
1664
|
-
if (isElement === void 0) { isElement = false; }
|
|
1665
|
-
this.__painter = painter;
|
|
1666
|
-
this.__isElement = isElement;
|
|
1667
|
-
this.__buffer = newBuffer(painter);
|
|
1668
|
-
this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
|
|
1669
|
-
}
|
|
1670
|
-
BufferObject.prototype.use = function () {
|
|
1671
|
-
this.__painter.bindBuffer(this.__type, this.__buffer);
|
|
1672
|
-
return this;
|
|
1673
|
-
};
|
|
1674
|
-
BufferObject.prototype.write = function (data) {
|
|
1675
|
-
writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
|
|
1676
|
-
this.__fsize = data.BYTES_PER_ELEMENT;
|
|
1677
|
-
return this;
|
|
1678
|
-
};
|
|
1679
|
-
BufferObject.prototype.divide = function (location, size, stride, offset) {
|
|
1680
|
-
if (offset === void 0) { offset = 0; }
|
|
1681
|
-
useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
|
|
1682
|
-
return this;
|
|
1683
|
-
};
|
|
1684
|
-
return BufferObject;
|
|
1685
|
-
}());
|
|
1686
|
-
|
|
1687
|
-
var initTexture = function (painter, type, unit) {
|
|
1688
|
-
var texture = painter.createTexture();
|
|
1689
|
-
painter.activeTexture(painter['TEXTURE' + unit]);
|
|
1690
|
-
painter.bindTexture(type, texture);
|
|
1691
|
-
return texture;
|
|
1692
|
-
};
|
|
1693
|
-
var linkImage = function (painter, type, level, format, textureType, image) {
|
|
1694
|
-
painter.texImage2D(type, level, format, format, textureType, image);
|
|
1695
|
-
};
|
|
1696
|
-
var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
|
|
1697
|
-
var types = [
|
|
1698
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_X,
|
|
1699
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
|
|
1700
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
|
|
1701
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
|
1702
|
-
painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
|
|
1703
|
-
painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
|
|
1704
|
-
], target;
|
|
1705
|
-
for (var i = 0; i < types.length; i++) {
|
|
1706
|
-
if (images[i]) {
|
|
1707
|
-
target = types[i];
|
|
1708
|
-
painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
|
|
1709
|
-
painter.bindTexture(type, texture);
|
|
1710
|
-
painter.texImage2D(target, level, format, format, textureType, images[i]);
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
painter.generateMipmap(type);
|
|
1714
|
-
};
|
|
1715
|
-
var TextureObject = (function () {
|
|
1716
|
-
function TextureObject(painter, type, unit) {
|
|
1717
|
-
if (unit === void 0) { unit = 0; }
|
|
1718
|
-
this.__painter = painter;
|
|
1719
|
-
this.__type = {
|
|
1720
|
-
"2d": painter.TEXTURE_2D,
|
|
1721
|
-
"cube": painter.TEXTURE_CUBE_MAP
|
|
1722
|
-
}[type];
|
|
1723
|
-
this.__texture = initTexture(painter, this.__type, unit);
|
|
1724
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
|
|
1725
|
-
painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
|
|
1726
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
|
|
1727
|
-
painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
|
|
1728
|
-
}
|
|
1729
|
-
TextureObject.prototype.useImage = function (image) {
|
|
1730
|
-
linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
|
|
1731
|
-
return this;
|
|
1732
|
-
};
|
|
1733
|
-
TextureObject.prototype.useCube = function (images, width, height) {
|
|
1734
|
-
linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
|
|
1735
|
-
return this;
|
|
1736
|
-
};
|
|
1737
|
-
return TextureObject;
|
|
1738
|
-
}());
|
|
1739
|
-
|
|
1740
|
-
var textures = {};
|
|
1741
|
-
function getTexture (type, painter, kind) {
|
|
1742
|
-
var uniqueName = type + "-" + kind;
|
|
1743
|
-
if (!textures[uniqueName]) {
|
|
1744
|
-
textures[uniqueName] = new TextureObject(painter, kind);
|
|
1745
|
-
}
|
|
1746
|
-
return textures[uniqueName];
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
var loadShader = function (painter, type, source) {
|
|
1750
|
-
var shader = painter.createShader(type);
|
|
1751
|
-
if (shader == null)
|
|
1752
|
-
throw new Error('Unable to create shader!');
|
|
1753
|
-
painter.shaderSource(shader, source);
|
|
1754
|
-
painter.compileShader(shader);
|
|
1755
|
-
if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
|
|
1756
|
-
throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
|
|
1757
|
-
return shader;
|
|
1758
|
-
};
|
|
1759
|
-
var useShader = function (painter, vshaderSource, fshaderSource) {
|
|
1760
|
-
var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
|
|
1761
|
-
var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
|
|
1762
|
-
var glProgram = painter.createProgram();
|
|
1763
|
-
painter.attachShader(glProgram, vertexShader);
|
|
1764
|
-
painter.attachShader(glProgram, fragmentShader);
|
|
1765
|
-
painter.linkProgram(glProgram);
|
|
1766
|
-
if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
|
|
1767
|
-
throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
|
|
1768
|
-
return glProgram;
|
|
1769
|
-
};
|
|
1770
|
-
var ShaderObject = (function () {
|
|
1771
|
-
function ShaderObject(painter) {
|
|
1772
|
-
this.__painter = painter;
|
|
1773
|
-
}
|
|
1774
|
-
ShaderObject.prototype.use = function () {
|
|
1775
|
-
this.__painter.useProgram(this.program);
|
|
1776
|
-
return this;
|
|
1777
|
-
};
|
|
1778
|
-
ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
|
|
1779
|
-
this.program = useShader(this.__painter, vshaderSource, fshaderSource);
|
|
1780
|
-
return this;
|
|
1781
|
-
};
|
|
1782
|
-
return ShaderObject;
|
|
1783
|
-
}());
|
|
1784
|
-
|
|
1785
|
-
var vsColor = "attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\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}";
|
|
1786
|
-
|
|
1787
|
-
var vsColors = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_color = a_color;\n}";
|
|
1788
|
-
|
|
1789
|
-
var vsImage = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_textcoord = a_textcoord;\n}";
|
|
1790
|
-
|
|
1791
|
-
var vsCube = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\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 v_normal = normalize(vec3(a_normal));\n}";
|
|
1792
|
-
|
|
1793
|
-
var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
|
|
1794
|
-
|
|
1795
|
-
var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
|
|
1796
|
-
|
|
1797
|
-
var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}";
|
|
1798
|
-
|
|
1799
|
-
var fsCube = "precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}";
|
|
1800
|
-
|
|
1801
|
-
var shaders = {};
|
|
1802
|
-
function getShader (type, painter, mesh) {
|
|
1803
|
-
var _a, _b;
|
|
1804
|
-
var uniqueName = type +
|
|
1805
|
-
(mesh.material.color ? "1" : "0") +
|
|
1806
|
-
(mesh.material.colors ? "1" : "0") +
|
|
1807
|
-
(mesh.material.image ? "1" : "0") +
|
|
1808
|
-
(mesh.material.cube ? "1" : "0");
|
|
1809
|
-
if (shaders[uniqueName])
|
|
1810
|
-
return shaders[uniqueName].use();
|
|
1811
|
-
var vertexShader = (_a = {},
|
|
1812
|
-
_a[type + "1000"] = vsColor,
|
|
1813
|
-
_a[type + "0100"] = vsColors,
|
|
1814
|
-
_a[type + "0010"] = vsImage,
|
|
1815
|
-
_a[type + "0001"] = vsCube,
|
|
1816
|
-
_a)[uniqueName].replace(/uniform +mat4 +u_matrix;/, "\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position");
|
|
1817
|
-
var fragmentShader = (_b = {},
|
|
1818
|
-
_b[type + "1000"] = fsColor,
|
|
1819
|
-
_b[type + "0100"] = fsColors,
|
|
1820
|
-
_b[type + "0010"] = fsImage,
|
|
1821
|
-
_b[type + "0001"] = fsCube,
|
|
1822
|
-
_b)[uniqueName];
|
|
1823
|
-
var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
|
|
1824
|
-
shaders[uniqueName] = shader;
|
|
1825
|
-
return shader;
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
function doDraw (type, painter, mesh, meshWorld, globalWorld) {
|
|
1829
|
-
var shader = getShader(type, painter, mesh);
|
|
1830
|
-
new BufferObject(painter).use()
|
|
1831
|
-
.write(mesh.geometry.attributes.position.array)
|
|
1832
|
-
.divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
|
|
1833
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
|
|
1834
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
|
|
1835
|
-
painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
|
|
1836
|
-
if (mesh.geometry.attributes.normal) {
|
|
1837
|
-
new BufferObject(painter).use()
|
|
1838
|
-
.write(mesh.geometry.attributes.normal.array)
|
|
1839
|
-
.divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
|
|
1840
|
-
}
|
|
1841
|
-
if ("color" in mesh.material) {
|
|
1842
|
-
painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
|
|
1843
|
-
}
|
|
1844
|
-
if ("colors" in mesh.material) {
|
|
1845
|
-
new BufferObject(painter).use()
|
|
1846
|
-
.write(mesh.material.colors.array)
|
|
1847
|
-
.divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0);
|
|
1848
|
-
}
|
|
1849
|
-
else if ("cube" in mesh.material) {
|
|
1850
|
-
var size = mesh.material.cube.right.image.value.width;
|
|
1851
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
|
|
1852
|
-
getTexture(type, painter, 'cube').useCube([
|
|
1853
|
-
mesh.material.cube.right.image.value,
|
|
1854
|
-
mesh.material.cube.left.image.value,
|
|
1855
|
-
mesh.material.cube.top.image.value,
|
|
1856
|
-
mesh.material.cube.bottom.image.value,
|
|
1857
|
-
mesh.material.cube.far.image.value,
|
|
1858
|
-
mesh.material.cube.near.image.value
|
|
1859
|
-
], size, size);
|
|
1860
|
-
}
|
|
1861
|
-
else if ("image" in mesh.material) {
|
|
1862
|
-
painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
|
|
1863
|
-
new BufferObject(painter).use()
|
|
1864
|
-
.write(mesh.geometry.attributes.uv.array)
|
|
1865
|
-
.divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0);
|
|
1866
|
-
getTexture(type, painter, '2d').useImage(mesh.material.image.value);
|
|
1867
|
-
}
|
|
1868
|
-
if (mesh.geometry.index) {
|
|
1869
|
-
new BufferObject(painter, true).use()
|
|
1870
|
-
.write(mesh.geometry.index.array);
|
|
1871
|
-
painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
|
|
1872
|
-
}
|
|
1873
|
-
else {
|
|
1874
|
-
painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
|
|
1878
|
-
var needUpdate = false;
|
|
1879
|
-
var scale = 10;
|
|
1880
|
-
var WebGL$1 = (function () {
|
|
1881
|
-
function WebGL(ViewCanvas, RegionCanvas) {
|
|
1882
|
-
this.name = "WebGL";
|
|
1883
|
-
this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
|
|
1884
|
-
this.__regionList = {};
|
|
1885
|
-
this.__regionAssemble = assemble(0, 1, 0.2, 3);
|
|
1886
|
-
this.__regionName = "";
|
|
1887
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
1888
|
-
this.__scene = {
|
|
1889
|
-
children: [],
|
|
1890
|
-
matrix: new Matrix4([
|
|
1891
|
-
1, 0, 0, 0,
|
|
1892
|
-
0, 1, 0, 0,
|
|
1893
|
-
0, 0, 1, 0,
|
|
1894
|
-
0, 0, 0, scale
|
|
1895
|
-
])
|
|
1896
|
-
};
|
|
1897
|
-
this.__unique = new Date().valueOf();
|
|
1898
|
-
this.painter = getWebGLContext$1(ViewCanvas, scale);
|
|
1899
|
-
if (RegionCanvas) {
|
|
1900
|
-
this.__regionPainter = getWebGLContext$1(RegionCanvas, scale, {});
|
|
1901
|
-
}
|
|
1902
|
-
var proportion = this.painter.canvas.width / this.painter.canvas.height;
|
|
1903
|
-
var xProportion = 1;
|
|
1904
|
-
var yProportion = 1;
|
|
1905
|
-
if (proportion > 1) {
|
|
1906
|
-
xProportion = 1 / proportion;
|
|
1907
|
-
}
|
|
1908
|
-
else {
|
|
1909
|
-
yProportion = proportion;
|
|
1910
|
-
}
|
|
1911
|
-
var zProportion = Math.min(xProportion, yProportion);
|
|
1912
|
-
this.__proporion = [
|
|
1913
|
-
xProportion, 0, 0, 0,
|
|
1914
|
-
0, yProportion, 0, 0,
|
|
1915
|
-
0, 0, zProportion, 0,
|
|
1916
|
-
0, 0, 0, 1
|
|
1917
|
-
];
|
|
1918
|
-
}
|
|
1919
|
-
WebGL.prototype.matrix = function (initMatrix4) {
|
|
1920
|
-
return new Matrix4(initMatrix4);
|
|
1921
|
-
};
|
|
1922
|
-
WebGL.prototype.getMatrix = function () {
|
|
1923
|
-
return this.__scene.matrix;
|
|
1924
|
-
};
|
|
1925
|
-
WebGL.prototype.getObject3D = function () {
|
|
1926
|
-
return this.__scene.children;
|
|
1927
|
-
};
|
|
1928
|
-
WebGL.prototype.review = function (isUpdateRegion) {
|
|
1929
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
1930
|
-
if (isUpdateRegion) {
|
|
1931
|
-
if (this.__regionPainter) {
|
|
1932
|
-
this.__regionPainter.clearColor(1, 1, 1, 1);
|
|
1933
|
-
this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
else {
|
|
1937
|
-
this.painter.clearColor(1, 1, 1, 1);
|
|
1938
|
-
this.painter.clear(this.painter.COLOR_BUFFER_BIT);
|
|
1939
|
-
}
|
|
1940
|
-
for (var index = 0; index < this.__scene.children.length; index++) {
|
|
1941
|
-
this.draw(this.__scene.children[index], isUpdateRegion);
|
|
1942
|
-
}
|
|
1943
|
-
return this;
|
|
1944
|
-
};
|
|
1945
|
-
WebGL.prototype.draw = function (object3D, isUpdateRegion) {
|
|
1946
|
-
if (isUpdateRegion === void 0) { isUpdateRegion = false; }
|
|
1947
|
-
if (!isUpdateRegion)
|
|
1948
|
-
needUpdate = true;
|
|
1949
|
-
var meshWorld = {
|
|
1950
|
-
matrix: object3D.matrix.value()
|
|
1951
|
-
};
|
|
1952
|
-
var globalWorld = {
|
|
1953
|
-
matrix: this.__scene.matrix.value(),
|
|
1954
|
-
proporion: this.__proporion
|
|
1955
|
-
};
|
|
1956
|
-
this.setRegion(object3D.region);
|
|
1957
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
1958
|
-
if (isUpdateRegion) {
|
|
1959
|
-
if (this.__regionPainter) {
|
|
1960
|
-
doDraw("painter" + this.__unique, this.__regionPainter, {
|
|
1961
|
-
geometry: object3D.mesh[index].geometry,
|
|
1962
|
-
material: {
|
|
1963
|
-
color: {
|
|
1964
|
-
r: this.__regionColor[0],
|
|
1965
|
-
g: this.__regionColor[1],
|
|
1966
|
-
b: this.__regionColor[2],
|
|
1967
|
-
alpha: this.__regionColor[3]
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
}, meshWorld, globalWorld);
|
|
1971
|
-
this.__getColor = getColorFactory(this.__regionPainter);
|
|
1972
|
-
}
|
|
1973
|
-
}
|
|
1974
|
-
else {
|
|
1975
|
-
doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
};
|
|
1979
|
-
WebGL.prototype.render = function (object3D) {
|
|
1980
|
-
if (!('matrix' in object3D))
|
|
1981
|
-
object3D.matrix = new Matrix4();
|
|
1982
|
-
if (!('region' in object3D))
|
|
1983
|
-
object3D.region = "";
|
|
1984
|
-
for (var index = 0; index < object3D.mesh.length; index++) {
|
|
1985
|
-
var mesh = object3D.mesh[index];
|
|
1986
|
-
if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
|
|
1987
|
-
mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
|
|
1988
|
-
}
|
|
1989
|
-
if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
|
|
1990
|
-
mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
|
|
1991
|
-
}
|
|
1992
|
-
if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
|
|
1993
|
-
mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
|
|
1994
|
-
}
|
|
1995
|
-
if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
|
|
1996
|
-
mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
|
|
1997
|
-
}
|
|
1998
|
-
if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
|
|
1999
|
-
mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
this.__scene.children.push(object3D);
|
|
2003
|
-
this.draw(object3D);
|
|
2004
|
-
};
|
|
2005
|
-
WebGL.prototype.setRegion = function (regionName) {
|
|
2006
|
-
this.__regionName = regionName + "";
|
|
2007
|
-
if (regionName) {
|
|
2008
|
-
if (this.__regionList[regionName] == void 0) {
|
|
2009
|
-
this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
|
|
2010
|
-
}
|
|
2011
|
-
this.__regionColor = this.__regionList[regionName];
|
|
2012
|
-
}
|
|
2013
|
-
else {
|
|
2014
|
-
this.__regionColor = [0, 0, 0, 1];
|
|
2015
|
-
}
|
|
2016
|
-
return this;
|
|
2017
|
-
};
|
|
2018
|
-
WebGL.prototype.getRegion = function (x, y) {
|
|
2019
|
-
var _this = this;
|
|
2020
|
-
if (needUpdate)
|
|
2021
|
-
this.review(true);
|
|
2022
|
-
needUpdate = false;
|
|
2023
|
-
return new Promise(function (resolve, reject) {
|
|
2024
|
-
var rgba = _this.__getColor(x, y);
|
|
2025
|
-
for (var key in _this.__regionList) {
|
|
2026
|
-
var currentRGBA = _this.__regionList[key];
|
|
2027
|
-
if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
|
|
2028
|
-
resolve(key);
|
|
2029
|
-
break;
|
|
2030
|
-
}
|
|
2031
|
-
}
|
|
2032
|
-
resolve("");
|
|
2033
|
-
});
|
|
2034
|
-
};
|
|
2035
|
-
return WebGL;
|
|
2036
|
-
}());
|
|
2037
|
-
|
|
2038
|
-
var WebGL = (function (_super) {
|
|
2039
|
-
__extends(WebGL, _super);
|
|
2040
|
-
function WebGL(el, option) {
|
|
2041
|
-
if (option === void 0) { option = {}; }
|
|
2042
|
-
if (!el) {
|
|
2043
|
-
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");
|
|
2044
|
-
}
|
|
2045
|
-
option = mergeOption(option, {
|
|
2046
|
-
region: true
|
|
2047
|
-
});
|
|
2048
|
-
var width = el.clientWidth, height = el.clientHeight;
|
|
2049
|
-
var ViewCanvas, RegionCanvas;
|
|
2050
|
-
var _el = el;
|
|
2051
|
-
if (_el._vislite_canvas_) {
|
|
2052
|
-
ViewCanvas = _el._vislite_canvas_[0];
|
|
2053
|
-
RegionCanvas = _el._vislite_canvas_[1];
|
|
2054
|
-
}
|
|
2055
|
-
else {
|
|
2056
|
-
if (option.region) {
|
|
2057
|
-
RegionCanvas = document.createElement('canvas');
|
|
2058
|
-
el.appendChild(RegionCanvas);
|
|
2059
|
-
RegionCanvas.style.position = 'absolute';
|
|
2060
|
-
RegionCanvas.style.zIndex = "-1";
|
|
2061
|
-
RegionCanvas.style.opacity = "0";
|
|
2062
|
-
}
|
|
2063
|
-
ViewCanvas = document.createElement('canvas');
|
|
2064
|
-
el.appendChild(ViewCanvas);
|
|
2065
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
|
|
2066
|
-
el.setAttribute('vislite', 'WebGL');
|
|
2067
|
-
}
|
|
2068
|
-
for (var _i = 0, _a = [ViewCanvas, RegionCanvas]; _i < _a.length; _i++) {
|
|
2069
|
-
var canvas = _a[_i];
|
|
2070
|
-
if (canvas) {
|
|
2071
|
-
canvas.style.width = width + "px";
|
|
2072
|
-
canvas.setAttribute('width', width + "");
|
|
2073
|
-
canvas.style.height = height + "px";
|
|
2074
|
-
canvas.setAttribute('height', height + "");
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
return _super.call(this, ViewCanvas, RegionCanvas) || this;
|
|
2078
|
-
}
|
|
2079
|
-
return WebGL;
|
|
2080
|
-
}(WebGL$1));
|
|
2081
|
-
|
|
2082
|
-
var getWebGLContext = (function (el, scale) {
|
|
2083
|
-
if (scale === void 0) { scale = 1; }
|
|
2084
|
-
if (!el) {
|
|
2085
|
-
throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
|
|
2086
|
-
}
|
|
2087
|
-
var width = el.clientWidth, height = el.clientHeight;
|
|
2088
|
-
var ViewCanvas;
|
|
2089
|
-
var _el = el;
|
|
2090
|
-
if (_el._vislite_canvas_) {
|
|
2091
|
-
ViewCanvas = _el._vislite_canvas_;
|
|
2092
|
-
}
|
|
2093
|
-
else {
|
|
2094
|
-
ViewCanvas = document.createElement('canvas');
|
|
2095
|
-
el.appendChild(ViewCanvas);
|
|
2096
|
-
_el._vislite_canvas_ = ViewCanvas;
|
|
2097
|
-
el.setAttribute('vislite', 'WebGL');
|
|
2098
|
-
}
|
|
2099
|
-
ViewCanvas.style.width = width + "px";
|
|
2100
|
-
ViewCanvas.setAttribute('width', width + "");
|
|
2101
|
-
ViewCanvas.style.height = height + "px";
|
|
2102
|
-
ViewCanvas.setAttribute('height', height + "");
|
|
2103
|
-
return getWebGLContext$1(ViewCanvas, scale);
|
|
2104
|
-
});
|
|
2105
|
-
|
|
2106
|
-
var Shader = (function (_super) {
|
|
2107
|
-
__extends(Shader, _super);
|
|
2108
|
-
function Shader() {
|
|
2109
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
2110
|
-
}
|
|
2111
|
-
Shader.prototype.compile = function (arg1, arg2) {
|
|
2112
|
-
if (arg2) {
|
|
2113
|
-
_super.prototype.compile.call(this, arg1, arg2);
|
|
2114
|
-
}
|
|
2115
|
-
else {
|
|
2116
|
-
_super.prototype.compile.call(this, {
|
|
2117
|
-
"color": vsColor,
|
|
2118
|
-
"colors": vsColors,
|
|
2119
|
-
"image": vsImage,
|
|
2120
|
-
"cube": vsCube
|
|
2121
|
-
}[arg1], {
|
|
2122
|
-
"color": fsColor,
|
|
2123
|
-
"colors": fsColors,
|
|
2124
|
-
"image": fsImage,
|
|
2125
|
-
"cube": fsCube
|
|
2126
|
-
}[arg1]);
|
|
2127
|
-
}
|
|
2128
|
-
return this;
|
|
2129
|
-
};
|
|
2130
|
-
return Shader;
|
|
2131
|
-
}(ShaderObject));
|
|
2132
|
-
|
|
2133
|
-
var rotateX = function (deg, x, y, z) {
|
|
2134
|
-
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
2135
|
-
return [x, y * cos - z * sin, y * sin + z * cos];
|
|
2136
|
-
};
|
|
2137
|
-
var rotateY = function (deg, x, y, z) {
|
|
2138
|
-
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
2139
|
-
return [z * sin + x * cos, y, z * cos - x * sin];
|
|
2140
|
-
};
|
|
2141
|
-
var rotateZ = function (deg, x, y, z) {
|
|
2142
|
-
var cos = Math.cos(deg), sin = Math.sin(deg);
|
|
2143
|
-
return [x * cos - y * sin, x * sin + y * cos, z];
|
|
2144
|
-
};
|
|
2145
|
-
var Eoap = (function () {
|
|
2146
|
-
function Eoap(scale, center) {
|
|
2147
|
-
if (scale === void 0) { scale = 7; }
|
|
2148
|
-
if (center === void 0) { center = [107, 36]; }
|
|
2149
|
-
this.name = 'Eoap';
|
|
2150
|
-
this.__scale = scale;
|
|
2151
|
-
this.__center = center;
|
|
2152
|
-
}
|
|
2153
|
-
Eoap.prototype.use = function (λ, φ) {
|
|
2154
|
-
var p = rotateY((360 - φ) / 180 * Math.PI, 100 * this.__scale, 0, 0);
|
|
2155
|
-
p = rotateZ(λ / 180 * Math.PI, p[0], p[1], p[2]);
|
|
2156
|
-
p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
|
|
2157
|
-
p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
|
|
2158
|
-
return [
|
|
2159
|
-
-p[0],
|
|
2160
|
-
p[1],
|
|
2161
|
-
p[2]
|
|
2162
|
-
];
|
|
2163
|
-
};
|
|
2164
|
-
return Eoap;
|
|
2165
|
-
}());
|
|
2166
|
-
|
|
2167
|
-
var Mercator = (function () {
|
|
2168
|
-
function Mercator(scale, center) {
|
|
2169
|
-
if (scale === void 0) { scale = 7; }
|
|
2170
|
-
if (center === void 0) { center = [107, 36]; }
|
|
2171
|
-
this.name = 'Mercator';
|
|
2172
|
-
var perimeter = 100 * scale * Math.PI;
|
|
2173
|
-
var help = perimeter / 180;
|
|
2174
|
-
var cx = help * center[0];
|
|
2175
|
-
var cy = -1 * help * center[1];
|
|
2176
|
-
this.use = function (λ, φ) {
|
|
2177
|
-
return [
|
|
2178
|
-
(help * λ - cx) * 0.8,
|
|
2179
|
-
-1 * help * φ - cy,
|
|
2180
|
-
0
|
|
2181
|
-
];
|
|
2182
|
-
};
|
|
2183
|
-
}
|
|
2184
|
-
return Mercator;
|
|
2185
|
-
}());
|
|
2186
|
-
|
|
2187
|
-
var mousePosition = function (el, event) {
|
|
2188
|
-
var bounding = el.getBoundingClientRect();
|
|
2189
|
-
return {
|
|
2190
|
-
"x": event.clientX - bounding.left,
|
|
2191
|
-
"y": event.clientY - bounding.top
|
|
2192
|
-
};
|
|
2193
|
-
};
|
|
2194
|
-
var getKeyString = function (event) {
|
|
2195
|
-
return {
|
|
2196
|
-
37: "left",
|
|
2197
|
-
38: "up",
|
|
2198
|
-
39: "right",
|
|
2199
|
-
40: "down",
|
|
2200
|
-
}[event.keyCode || event.which];
|
|
2201
|
-
};
|
|
2202
|
-
function viewHandler (callback) {
|
|
2203
|
-
var el = document.getElementsByTagName('body')[0];
|
|
2204
|
-
el.addEventListener("keydown", function (event) {
|
|
2205
|
-
var keyCode = getKeyString(event);
|
|
2206
|
-
if (keyCode == 'up') {
|
|
2207
|
-
callback({
|
|
2208
|
-
type: "lookUp",
|
|
2209
|
-
normal: [],
|
|
2210
|
-
value: 0.1,
|
|
2211
|
-
event: event
|
|
2212
|
-
});
|
|
2213
|
-
}
|
|
2214
|
-
else if (keyCode == 'down') {
|
|
2215
|
-
callback({
|
|
2216
|
-
type: "lookDown",
|
|
2217
|
-
normal: [],
|
|
2218
|
-
value: 0.1,
|
|
2219
|
-
event: event
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
else if (keyCode == 'left') {
|
|
2223
|
-
callback({
|
|
2224
|
-
type: "lookLeft",
|
|
2225
|
-
normal: [],
|
|
2226
|
-
value: 0.1,
|
|
2227
|
-
event: event
|
|
2228
|
-
});
|
|
2229
|
-
}
|
|
2230
|
-
else if (keyCode == 'right') {
|
|
2231
|
-
callback({
|
|
2232
|
-
type: "lookRight",
|
|
2233
|
-
normal: [],
|
|
2234
|
-
value: 0.1,
|
|
2235
|
-
event: event
|
|
2236
|
-
});
|
|
2237
|
-
}
|
|
2238
|
-
});
|
|
2239
|
-
var mouseP = null;
|
|
2240
|
-
var doMove = function (event) {
|
|
2241
|
-
if (mouseP == null) {
|
|
2242
|
-
callback({
|
|
2243
|
-
type: "hover",
|
|
2244
|
-
normal: [],
|
|
2245
|
-
value: 0,
|
|
2246
|
-
event: event
|
|
2247
|
-
});
|
|
2248
|
-
}
|
|
2249
|
-
else {
|
|
2250
|
-
var tempMouseP = mousePosition(el, event);
|
|
2251
|
-
var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
|
|
2252
|
-
var rotateNormal = [
|
|
2253
|
-
normal[1],
|
|
2254
|
-
normal[0],
|
|
2255
|
-
0
|
|
2256
|
-
];
|
|
2257
|
-
if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
|
|
2258
|
-
return;
|
|
2259
|
-
callback({
|
|
2260
|
-
type: "rotate",
|
|
2261
|
-
normal: rotateNormal,
|
|
2262
|
-
value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01,
|
|
2263
|
-
event: event
|
|
2264
|
-
});
|
|
2265
|
-
mouseP = tempMouseP;
|
|
2266
|
-
}
|
|
2267
|
-
};
|
|
2268
|
-
el.addEventListener("mousedown", function (event) {
|
|
2269
|
-
mouseP = mousePosition(el, event);
|
|
2270
|
-
});
|
|
2271
|
-
el.addEventListener("mouseup", function (event) {
|
|
2272
|
-
mouseP = null;
|
|
2273
|
-
});
|
|
2274
|
-
el.addEventListener("mousemove", function (event) {
|
|
2275
|
-
doMove(event);
|
|
2276
|
-
});
|
|
2277
|
-
el.addEventListener("touchend", function (event) {
|
|
2278
|
-
mouseP = null;
|
|
2279
|
-
});
|
|
2280
|
-
el.addEventListener("touchstart", function (event) {
|
|
2281
|
-
mouseP = mousePosition(el, event);
|
|
2282
|
-
});
|
|
2283
|
-
el.addEventListener("touchmove", function (event) {
|
|
2284
|
-
doMove(event.touches[0]);
|
|
2285
|
-
});
|
|
2286
|
-
var doScale = function (value, event) {
|
|
2287
|
-
if (value == 0)
|
|
2288
|
-
return;
|
|
2289
|
-
var baseTimes = 0.899;
|
|
2290
|
-
callback({
|
|
2291
|
-
type: "scale",
|
|
2292
|
-
value: value < 0 ? baseTimes : 2 - baseTimes,
|
|
2293
|
-
normal: [],
|
|
2294
|
-
event: event
|
|
2295
|
-
});
|
|
2296
|
-
};
|
|
2297
|
-
el.addEventListener("mousewheel", function (event) {
|
|
2298
|
-
doScale(event.wheelDelta, event);
|
|
2299
|
-
});
|
|
2300
|
-
if (window.addEventListener) {
|
|
2301
|
-
window.addEventListener('DOMMouseScroll', function (event) {
|
|
2302
|
-
doScale(-1 * event.detail, event);
|
|
2303
|
-
}, false);
|
|
2304
|
-
}
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
var observer;
|
|
2308
|
-
var attrValueToCallback = {}, uniqueid = 0;
|
|
2309
|
-
function resizeObserver (el, callback) {
|
|
2310
|
-
try {
|
|
2311
|
-
if (!observer) {
|
|
2312
|
-
observer = new ResizeObserver(function (entries) {
|
|
2313
|
-
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
2314
|
-
var entry = entries_1[_i];
|
|
2315
|
-
attrValueToCallback[entry.target._resize_observer_]();
|
|
2316
|
-
}
|
|
2317
|
-
});
|
|
2318
|
-
}
|
|
2319
|
-
uniqueid++;
|
|
2320
|
-
el._resize_observer_ = uniqueid;
|
|
2321
|
-
attrValueToCallback[uniqueid] = callback;
|
|
2322
|
-
observer.observe(el);
|
|
2323
|
-
return function () {
|
|
2324
|
-
if (observer) {
|
|
2325
|
-
observer.unobserve(el);
|
|
2326
|
-
delete attrValueToCallback[el._resize_observer_];
|
|
2327
|
-
}
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
catch (e) {
|
|
2331
|
-
callback();
|
|
2332
|
-
console.error('ResizeObserver undefined!');
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
function throttle (callback, option) {
|
|
2337
|
-
if (option === void 0) { option = {}; }
|
|
2338
|
-
option = mergeOption(option, {
|
|
2339
|
-
time: 200,
|
|
2340
|
-
keep: false,
|
|
2341
|
-
opportunity: "end"
|
|
2342
|
-
});
|
|
2343
|
-
var hadInterval = false;
|
|
2344
|
-
var hadClick = false;
|
|
2345
|
-
var oneClick = false;
|
|
2346
|
-
var arg;
|
|
2347
|
-
return function () {
|
|
2348
|
-
var _this = this;
|
|
2349
|
-
arg = arguments;
|
|
2350
|
-
if (!hadInterval) {
|
|
2351
|
-
if (option.opportunity != 'end') {
|
|
2352
|
-
callback.apply(_this, arg);
|
|
2353
|
-
}
|
|
2354
|
-
hadInterval = true;
|
|
2355
|
-
var interval_1 = setInterval(function () {
|
|
2356
|
-
if (hadClick) {
|
|
2357
|
-
if (!option.keep) {
|
|
2358
|
-
callback.apply(_this, arg);
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
else {
|
|
2362
|
-
if (option.opportunity != 'begin') {
|
|
2363
|
-
if (oneClick || option.opportunity == 'end')
|
|
2364
|
-
callback.apply(_this, arg);
|
|
2365
|
-
}
|
|
2366
|
-
hadInterval = false;
|
|
2367
|
-
oneClick = false;
|
|
2368
|
-
clearInterval(interval_1);
|
|
2369
|
-
}
|
|
2370
|
-
hadClick = false;
|
|
2371
|
-
}, option.time);
|
|
2372
|
-
}
|
|
2373
|
-
else {
|
|
2374
|
-
hadClick = true;
|
|
2375
|
-
oneClick = true;
|
|
2376
|
-
}
|
|
2377
|
-
};
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
var toInnerTree = (function (initTree, config) {
|
|
2381
|
-
var tempTree = {};
|
|
2382
|
-
var temp = config.root(initTree), id, rid;
|
|
2383
|
-
id = rid = config.id(temp);
|
|
2384
|
-
tempTree[id] = {
|
|
2385
|
-
"data": temp,
|
|
2386
|
-
"pid": null,
|
|
2387
|
-
"id": id,
|
|
2388
|
-
"isOpen": true,
|
|
2389
|
-
"show": true,
|
|
2390
|
-
"children": []
|
|
2391
|
-
};
|
|
2392
|
-
var num = 1;
|
|
2393
|
-
(function createTree(pdata, pid) {
|
|
2394
|
-
var children = config.children(pdata, initTree);
|
|
2395
|
-
num += children ? children.length : 0;
|
|
2396
|
-
for (var flag = 0; children && flag < children.length; flag++) {
|
|
2397
|
-
id = config.id(children[flag]);
|
|
2398
|
-
tempTree[pid].children.push(id);
|
|
2399
|
-
tempTree[id] = {
|
|
2400
|
-
"data": children[flag],
|
|
2401
|
-
"pid": pid,
|
|
2402
|
-
"id": id,
|
|
2403
|
-
"isOpen": true,
|
|
2404
|
-
"show": true,
|
|
2405
|
-
"children": []
|
|
2406
|
-
};
|
|
2407
|
-
createTree(children[flag], id);
|
|
2408
|
-
}
|
|
2409
|
-
})(temp, id);
|
|
2410
|
-
return {
|
|
2411
|
-
rid: rid,
|
|
2412
|
-
value: tempTree,
|
|
2413
|
-
num: num
|
|
2414
|
-
};
|
|
2415
|
-
});
|
|
2416
|
-
|
|
2417
|
-
function toPlainTree (initTree, config, noOpens) {
|
|
2418
|
-
var treeData = toInnerTree(initTree, config);
|
|
2419
|
-
var alltreedata = treeData.value;
|
|
2420
|
-
var rootid = treeData.rid;
|
|
2421
|
-
if (treeData.num == 1) {
|
|
2422
|
-
alltreedata[rootid].left = 0.5;
|
|
2423
|
-
alltreedata[rootid].top = 0.5;
|
|
2424
|
-
alltreedata[rootid].show = true;
|
|
2425
|
-
return {
|
|
2426
|
-
deep: 1,
|
|
2427
|
-
node: alltreedata,
|
|
2428
|
-
root: rootid,
|
|
2429
|
-
size: 1
|
|
2430
|
-
};
|
|
2431
|
-
}
|
|
2432
|
-
else {
|
|
2433
|
-
var beforeDis_1 = [], size_1 = 0, maxDeep_1 = 0;
|
|
2434
|
-
if (noOpens[rootid]) {
|
|
2435
|
-
alltreedata[rootid].left = 0.5;
|
|
2436
|
-
alltreedata[rootid].top = 0.5;
|
|
2437
|
-
alltreedata[rootid].show = true;
|
|
2438
|
-
size_1 = 1;
|
|
2439
|
-
}
|
|
2440
|
-
else {
|
|
2441
|
-
(function positionCalc(pNode, deep) {
|
|
2442
|
-
if (deep > maxDeep_1)
|
|
2443
|
-
maxDeep_1 = deep;
|
|
2444
|
-
var flag = 0;
|
|
2445
|
-
if (!noOpens[pNode.id]) {
|
|
2446
|
-
for (flag = 0; flag < pNode.children.length; flag++)
|
|
2447
|
-
positionCalc(alltreedata[pNode.children[flag]], deep + 1);
|
|
2448
|
-
}
|
|
2449
|
-
alltreedata[pNode.id].left = deep + 0.5;
|
|
2450
|
-
if (flag == 0) {
|
|
2451
|
-
if (beforeDis_1[deep] == void 0)
|
|
2452
|
-
beforeDis_1[deep] = -0.5;
|
|
2453
|
-
if (beforeDis_1[deep - 1] == void 0)
|
|
2454
|
-
beforeDis_1[deep - 1] = -0.5;
|
|
2455
|
-
alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
|
|
2456
|
-
var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
|
|
2457
|
-
if (pTop - 1 < beforeDis_1[deep - 1])
|
|
2458
|
-
alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
|
|
2459
|
-
}
|
|
2460
|
-
else {
|
|
2461
|
-
alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
|
|
2462
|
-
}
|
|
2463
|
-
if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
|
|
2464
|
-
var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
|
|
2465
|
-
alltreedata[_pid].top += needUp_1;
|
|
2466
|
-
if (beforeDis_1[_deep] < alltreedata[_pid].top)
|
|
2467
|
-
beforeDis_1[_deep] = alltreedata[_pid].top;
|
|
2468
|
-
for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
|
|
2469
|
-
doUp(alltreedata[_pid].children[_flag], _deep + 1);
|
|
2470
|
-
}
|
|
2471
|
-
})(pNode.id, deep);
|
|
2472
|
-
}
|
|
2473
|
-
beforeDis_1[deep] = alltreedata[pNode.id].top;
|
|
2474
|
-
if (alltreedata[pNode.id].top + 0.5 > size_1)
|
|
2475
|
-
size_1 = alltreedata[pNode.id].top + 0.5;
|
|
2476
|
-
})(alltreedata[rootid], 0);
|
|
2477
|
-
}
|
|
2478
|
-
for (var key in noOpens) {
|
|
2479
|
-
if (noOpens[key]) {
|
|
2480
|
-
alltreedata[key].isOpen = false;
|
|
2481
|
-
(function updateHidden(pid, left, top) {
|
|
2482
|
-
for (var index = 0; index < alltreedata[pid].children.length; index++) {
|
|
2483
|
-
alltreedata[alltreedata[pid].children[index]].left = left;
|
|
2484
|
-
alltreedata[alltreedata[pid].children[index]].top = top;
|
|
2485
|
-
alltreedata[alltreedata[pid].children[index]].show = false;
|
|
2486
|
-
updateHidden(alltreedata[pid].children[index], left, top);
|
|
2487
|
-
}
|
|
2488
|
-
})(key, alltreedata[key].left, alltreedata[key].top);
|
|
2489
|
-
}
|
|
2490
|
-
}
|
|
2491
|
-
return {
|
|
2492
|
-
"node": alltreedata,
|
|
2493
|
-
"root": rootid,
|
|
2494
|
-
"size": size_1,
|
|
2495
|
-
"deep": maxDeep_1 + 1
|
|
2496
|
-
};
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
|
-
var Tree = (function () {
|
|
2501
|
-
function Tree(config) {
|
|
2502
|
-
if (config === void 0) { config = {}; }
|
|
2503
|
-
this.name = 'Tree';
|
|
2504
|
-
this.__config = mergeOption(config, {
|
|
2505
|
-
root: function (initTree) { return initTree; },
|
|
2506
|
-
children: function (parentTree) { return parentTree.children; },
|
|
2507
|
-
id: function (treedata) { return treedata.name; }
|
|
2508
|
-
});
|
|
2509
|
-
}
|
|
2510
|
-
Tree.prototype.use = function (initTree, noOpens) {
|
|
2511
|
-
if (noOpens === void 0) { noOpens = {}; }
|
|
2512
|
-
return toPlainTree(initTree, this.__config, noOpens);
|
|
2513
|
-
};
|
|
2514
|
-
return Tree;
|
|
2515
|
-
}());
|
|
2516
|
-
|
|
2517
|
-
var TreeLayout = (function (_super) {
|
|
2518
|
-
__extends(TreeLayout, _super);
|
|
2519
|
-
function TreeLayout() {
|
|
2520
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
2521
|
-
_this.name = 'TreeLayout';
|
|
2522
|
-
_this.__option = {
|
|
2523
|
-
offsetX: 0,
|
|
2524
|
-
offsetY: 0,
|
|
2525
|
-
duration: 500,
|
|
2526
|
-
type: "plain",
|
|
2527
|
-
direction: "LR",
|
|
2528
|
-
x: 100,
|
|
2529
|
-
y: 100,
|
|
2530
|
-
width: 100,
|
|
2531
|
-
height: 100,
|
|
2532
|
-
radius: 100
|
|
2533
|
-
};
|
|
2534
|
-
_this.__noOpens = {};
|
|
2535
|
-
return _this;
|
|
2536
|
-
}
|
|
2537
|
-
TreeLayout.prototype.setOption = function (option) {
|
|
2538
|
-
mergeOption(option, this.__option);
|
|
2539
|
-
return this;
|
|
2540
|
-
};
|
|
2541
|
-
TreeLayout.prototype.use = function (initTree, noOpens) {
|
|
2542
|
-
if (noOpens === void 0) { noOpens = {}; }
|
|
2543
|
-
var tree = _super.prototype.use.call(this, initTree, noOpens);
|
|
2544
|
-
if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
|
|
2545
|
-
for (var key in tree.node) {
|
|
2546
|
-
if (!tree.node[key].show) {
|
|
2547
|
-
var deep = 0, pid = key;
|
|
2548
|
-
do {
|
|
2549
|
-
pid = tree.node[pid].pid;
|
|
2550
|
-
deep++;
|
|
2551
|
-
} while (!tree.node[pid].show);
|
|
2552
|
-
tree.node[key].left += this.__option.offsetX * deep;
|
|
2553
|
-
tree.node[key].top += this.__option.offsetY * deep;
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
if (this.__option.type == 'rect') {
|
|
2558
|
-
if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
|
|
2559
|
-
var perW = this.__option.height / tree.size;
|
|
2560
|
-
var perD = this.__option.width / (tree.deep - 1);
|
|
2561
|
-
var balanceW = this.__option.y - this.__option.height * 0.5;
|
|
2562
|
-
var flag = this.__option.direction == 'LR' ? 1 : -1;
|
|
2563
|
-
for (var key in tree.node) {
|
|
2564
|
-
if (tree.deep == 1) {
|
|
2565
|
-
tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
|
|
2566
|
-
tree.node[key].top = this.__option.y;
|
|
2567
|
-
}
|
|
2568
|
-
else {
|
|
2569
|
-
tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
|
|
2570
|
-
tree.node[key].top = tree.node[key].top * perW + balanceW;
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
}
|
|
2574
|
-
else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
|
|
2575
|
-
var perW = this.__option.width / tree.size;
|
|
2576
|
-
var perD = this.__option.height / (tree.deep - 1);
|
|
2577
|
-
var balanceW = this.__option.x - this.__option.width * 0.5;
|
|
2578
|
-
var flag = this.__option.direction == 'TB' ? 1 : -1;
|
|
2579
|
-
for (var key in tree.node) {
|
|
2580
|
-
if (tree.deep == 1) {
|
|
2581
|
-
tree.node[key].left = this.__option.x;
|
|
2582
|
-
tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
|
|
2583
|
-
}
|
|
2584
|
-
else {
|
|
2585
|
-
var left = tree.node[key].left;
|
|
2586
|
-
tree.node[key].left = tree.node[key].top * perW + balanceW;
|
|
2587
|
-
tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
else if (this.__option.type == 'circle') {
|
|
2593
|
-
var cx = this.__option.x, cy = this.__option.y;
|
|
2594
|
-
var deg = Math.PI * 2 / tree.size;
|
|
2595
|
-
var per = this.__option.radius / (tree.deep - 1);
|
|
2596
|
-
for (var key in tree.node) {
|
|
2597
|
-
if (tree.node[key].left == 0.5) {
|
|
2598
|
-
tree.node[key].left = cx;
|
|
2599
|
-
tree.node[key].top = cy;
|
|
2600
|
-
}
|
|
2601
|
-
else {
|
|
2602
|
-
var position = rotate$1(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
|
|
2603
|
-
tree.node[key].left = position[0];
|
|
2604
|
-
tree.node[key].top = position[1];
|
|
2605
|
-
}
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
return tree;
|
|
2609
|
-
};
|
|
2610
|
-
TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
|
|
2611
|
-
if (noOpens === void 0) { noOpens = {}; }
|
|
2612
|
-
this.__rback = renderBack;
|
|
2613
|
-
this.__oralTree = initTree;
|
|
2614
|
-
this.__noOpens = noOpens;
|
|
2615
|
-
this.__preTree = this.use(this.__oralTree, this.__noOpens);
|
|
2616
|
-
this.__rback(this.__preTree);
|
|
2617
|
-
return this;
|
|
2618
|
-
};
|
|
2619
|
-
TreeLayout.prototype.unbind = function () {
|
|
2620
|
-
this.__rback = null;
|
|
2621
|
-
this.__oralTree = null;
|
|
2622
|
-
this.__preTree = null;
|
|
2623
|
-
this.__noOpens = {};
|
|
2624
|
-
return this;
|
|
2625
|
-
};
|
|
2626
|
-
TreeLayout.prototype.doUpdate = function () {
|
|
2627
|
-
var _this = this;
|
|
2628
|
-
var newTree = this.use(this.__oralTree, this.__noOpens);
|
|
2629
|
-
var cacheTree = JSON.parse(JSON.stringify(newTree));
|
|
2630
|
-
animation(function (deep) {
|
|
2631
|
-
for (var key in cacheTree.node) {
|
|
2632
|
-
if (newTree.node[key].show || _this.__preTree.node[key].show) {
|
|
2633
|
-
cacheTree.node[key].show = true;
|
|
2634
|
-
cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
|
|
2635
|
-
cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
_this.__rback(cacheTree);
|
|
2639
|
-
}, this.__option.duration, function () {
|
|
2640
|
-
_this.__preTree = newTree;
|
|
2641
|
-
_this.__rback(_this.__preTree);
|
|
2642
|
-
});
|
|
2643
|
-
};
|
|
2644
|
-
TreeLayout.prototype.closeNode = function (id) {
|
|
2645
|
-
if (!this.__preTree)
|
|
2646
|
-
return;
|
|
2647
|
-
this.__noOpens[id] = true;
|
|
2648
|
-
this.doUpdate();
|
|
2649
|
-
return this;
|
|
2650
|
-
};
|
|
2651
|
-
TreeLayout.prototype.openNode = function (id) {
|
|
2652
|
-
if (!this.__preTree)
|
|
2653
|
-
return;
|
|
2654
|
-
this.__noOpens[id] = false;
|
|
2655
|
-
this.doUpdate();
|
|
2656
|
-
return this;
|
|
2657
|
-
};
|
|
2658
|
-
TreeLayout.prototype.toggleNode = function (id) {
|
|
2659
|
-
if (!this.__preTree)
|
|
2660
|
-
return;
|
|
2661
|
-
this.__noOpens[id] = !this.__noOpens[id];
|
|
2662
|
-
this.doUpdate();
|
|
2663
|
-
return this;
|
|
2664
|
-
};
|
|
2665
|
-
return TreeLayout;
|
|
2666
|
-
}(Tree));
|
|
2667
|
-
|
|
2668
|
-
var splitNum = function (precision, radius) {
|
|
2669
|
-
var num = Math.ceil(Math.PI * 2 /
|
|
2670
|
-
Math.asin(precision / radius) * 2);
|
|
2671
|
-
return (isNaN(num) || num < 12) ? 12 : num;
|
|
2672
|
-
};
|
|
2673
|
-
|
|
2674
|
-
function prismHorizontal (normal, x, y, z, radius, num, d) {
|
|
2675
|
-
var beginX, beginZ;
|
|
2676
|
-
if (num == 4) {
|
|
2677
|
-
var temp = radius / 1.414;
|
|
2678
|
-
beginX = x + temp;
|
|
2679
|
-
beginZ = z + temp;
|
|
2680
|
-
}
|
|
2681
|
-
else {
|
|
2682
|
-
beginX = x + radius;
|
|
2683
|
-
beginZ = z;
|
|
2684
|
-
}
|
|
2685
|
-
var point = [beginX, beginZ], points = [], deg = Math.PI * 2 / num;
|
|
2686
|
-
for (var i = 0; i < num; i++) {
|
|
2687
|
-
points.push(x, y, z);
|
|
2688
|
-
if (normal)
|
|
2689
|
-
points.push(0, d, 0);
|
|
2690
|
-
points.push(point[0], y, point[1]);
|
|
2691
|
-
if (normal)
|
|
2692
|
-
points.push(0, d, 0);
|
|
2693
|
-
point = rotate$1(x, z, deg * (i + 1), beginX, beginZ);
|
|
2694
|
-
points.push(point[0], y, point[1]);
|
|
2695
|
-
if (normal)
|
|
2696
|
-
points.push(0, d, 0);
|
|
2697
|
-
}
|
|
2698
|
-
return points;
|
|
2699
|
-
}
|
|
2700
|
-
|
|
2701
|
-
function prismVertical (normal, x, y, z, radius, height, num) {
|
|
2702
|
-
var points = [];
|
|
2703
|
-
var beginPosition;
|
|
2704
|
-
if (num == 4) {
|
|
2705
|
-
beginPosition = rotate$1(x, z, Math.PI * 0.25, x - radius, z);
|
|
2706
|
-
}
|
|
2707
|
-
else {
|
|
2708
|
-
beginPosition = [x + radius, z];
|
|
2709
|
-
}
|
|
2710
|
-
var deg = Math.PI * 2 / num, degHalf = Math.PI * 2 / (num * 2);
|
|
2711
|
-
var endPosition, normalPosition = [];
|
|
2712
|
-
for (var i = 0; i < num; i++) {
|
|
2713
|
-
endPosition = rotate$1.apply(void 0, __spreadArray([x, z, deg], beginPosition, false));
|
|
2714
|
-
if (normal) {
|
|
2715
|
-
var halfPosition = rotate$1.apply(void 0, __spreadArray([x, z, degHalf], beginPosition, false));
|
|
2716
|
-
normalPosition = [halfPosition[0], 0, halfPosition[1]];
|
|
2717
|
-
}
|
|
2718
|
-
points.push.apply(points, __spreadArray([beginPosition[0], y, beginPosition[1]], normalPosition, false));
|
|
2719
|
-
points.push.apply(points, __spreadArray([beginPosition[0], y + height, beginPosition[1]], normalPosition, false));
|
|
2720
|
-
points.push.apply(points, __spreadArray([endPosition[0], y + height, endPosition[1]], normalPosition, false));
|
|
2721
|
-
points.push.apply(points, __spreadArray([beginPosition[0], y, beginPosition[1]], normalPosition, false));
|
|
2722
|
-
points.push.apply(points, __spreadArray([endPosition[0], y, endPosition[1]], normalPosition, false));
|
|
2723
|
-
points.push.apply(points, __spreadArray([endPosition[0], y + height, endPosition[1]], normalPosition, false));
|
|
2724
|
-
beginPosition = endPosition;
|
|
2725
|
-
}
|
|
2726
|
-
return points;
|
|
2727
|
-
}
|
|
2728
|
-
|
|
2729
|
-
function sphereFragment (normal, cx, cy, cz, radius, num, index) {
|
|
2730
|
-
var points = [cx, cy + radius, cz], deg = Math.PI * 2 / num, point;
|
|
2731
|
-
if (normal)
|
|
2732
|
-
points.push(0, radius, 0);
|
|
2733
|
-
var copy2 = function () {
|
|
2734
|
-
points.push.apply(points, points.slice(points.length - (normal ? 12 : 6)));
|
|
2735
|
-
};
|
|
2736
|
-
for (var i = 1; i < num * 0.5; i++) {
|
|
2737
|
-
point = rotate$1(cx, cy, deg * i, cx, cy + radius);
|
|
2738
|
-
if (i > 1)
|
|
2739
|
-
copy2();
|
|
2740
|
-
var point1 = rotate$1(cx, cz, deg * index, point[0], cz);
|
|
2741
|
-
points.push(point1[0], point[1], point1[1]);
|
|
2742
|
-
if (normal)
|
|
2743
|
-
points.push(point1[0] - cx, point[1] - cy, point1[1] - cz);
|
|
2744
|
-
if (i > 1)
|
|
2745
|
-
copy2();
|
|
2746
|
-
var point2 = rotate$1(cx, cz, deg * (index + 1), point[0], cz);
|
|
2747
|
-
points.push(point2[0], point[1], point2[1]);
|
|
2748
|
-
if (normal)
|
|
2749
|
-
points.push(point2[0] - cx, point2[1] - cy, point2[1] - cz);
|
|
2750
|
-
}
|
|
2751
|
-
copy2();
|
|
2752
|
-
points.push(cx, cy - radius, cz);
|
|
2753
|
-
if (normal)
|
|
2754
|
-
points.push(0, -radius, 0);
|
|
2755
|
-
return points;
|
|
2756
|
-
}
|
|
2757
|
-
|
|
2758
|
-
var Geometry = (function () {
|
|
2759
|
-
function Geometry(option) {
|
|
2760
|
-
if (option === void 0) { option = {}; }
|
|
2761
|
-
this.name = 'Geometry';
|
|
2762
|
-
this.__option = mergeOption(option, {
|
|
2763
|
-
precision: 0.1,
|
|
2764
|
-
normal: false,
|
|
2765
|
-
});
|
|
2766
|
-
}
|
|
2767
|
-
Geometry.prototype.config = function (option) {
|
|
2768
|
-
for (var key in option) {
|
|
2769
|
-
this.__option[key] = option[key];
|
|
2770
|
-
}
|
|
2771
|
-
return this;
|
|
2772
|
-
};
|
|
2773
|
-
Geometry.prototype.cylinder = function (x, y, z, radius, height) {
|
|
2774
|
-
var num = splitNum(this.__option.precision, radius);
|
|
2775
|
-
return this.prism(x, y, z, radius, height, num);
|
|
2776
|
-
};
|
|
2777
|
-
Geometry.prototype.prism = function (x, y, z, radius, height, num) {
|
|
2778
|
-
var _a, _b, _c;
|
|
2779
|
-
var result = [{
|
|
2780
|
-
points: [],
|
|
2781
|
-
length: 0,
|
|
2782
|
-
method: "TRIANGLES"
|
|
2783
|
-
}];
|
|
2784
|
-
(_a = result[0].points).push.apply(_a, prismHorizontal(this.__option.normal, x, y, z, radius, num, height > 0 ? -1 : 1));
|
|
2785
|
-
(_b = result[0].points).push.apply(_b, prismHorizontal(this.__option.normal, x, y + height, z, radius, num, height > 0 ? 1 : -1));
|
|
2786
|
-
(_c = result[0].points).push.apply(_c, prismVertical(this.__option.normal, x, y, z, radius, height, num));
|
|
2787
|
-
result[0].length = 12 * num;
|
|
2788
|
-
return result;
|
|
2789
|
-
};
|
|
2790
|
-
Geometry.prototype.sphere = function (cx, cy, cz, radius) {
|
|
2791
|
-
var _a;
|
|
2792
|
-
var num = splitNum(this.__option.precision, radius);
|
|
2793
|
-
var result = [{
|
|
2794
|
-
points: [],
|
|
2795
|
-
length: 0,
|
|
2796
|
-
method: "TRIANGLES"
|
|
2797
|
-
}];
|
|
2798
|
-
for (var i = 0; i < num; i++) {
|
|
2799
|
-
(_a = result[0].points).push.apply(_a, sphereFragment(this.__option.normal, cx, cy, cz, radius, num, i));
|
|
2800
|
-
}
|
|
2801
|
-
result[0].length = result[0].points.length / (this.__option.normal ? 6 : 3);
|
|
2802
|
-
return result;
|
|
2803
|
-
};
|
|
2804
|
-
return Geometry;
|
|
2805
|
-
}());
|
|
2806
|
-
|
|
2807
|
-
var index = {
|
|
2808
|
-
Cardinal: Cardinal,
|
|
2809
|
-
Hermite: Hermite,
|
|
2810
|
-
Matrix4: Matrix4,
|
|
2811
|
-
rotate: rotate$1,
|
|
2812
|
-
getLoopColors: getLoopColors,
|
|
2813
|
-
formatColor: formatColor,
|
|
2814
|
-
animation: animation,
|
|
2815
|
-
ruler: ruler,
|
|
2816
|
-
SVG: SVG,
|
|
2817
|
-
Canvas: Canvas,
|
|
2818
|
-
WebGL: WebGL,
|
|
2819
|
-
getWebGLContext: getWebGLContext,
|
|
2820
|
-
Shader: Shader,
|
|
2821
|
-
Texture: TextureObject,
|
|
2822
|
-
Buffer: BufferObject,
|
|
2823
|
-
Eoap: Eoap,
|
|
2824
|
-
Mercator: Mercator,
|
|
2825
|
-
viewHandler: viewHandler,
|
|
2826
|
-
resizeObserver: resizeObserver,
|
|
2827
|
-
throttle: throttle,
|
|
2828
|
-
TreeLayout: TreeLayout,
|
|
2829
|
-
Geometry: Geometry
|
|
2830
|
-
};
|
|
2831
|
-
|
|
2832
|
-
return index;
|
|
2833
|
-
|
|
2834
|
-
}));
|