vislite 1.3.0 → 1.4.0-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.
Files changed (191) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +307 -300
  3. package/LICENSE +20 -20
  4. package/README.md +284 -284
  5. package/lib/BarLayout/index.es.d.ts +3 -0
  6. package/lib/BarLayout/index.es.js +467 -0
  7. package/lib/BarLayout/index.es.min.d.ts +3 -0
  8. package/lib/BarLayout/index.es.min.js +10 -0
  9. package/lib/Buffer/index.es.js +35 -35
  10. package/lib/Buffer/index.es.min.js +1 -1
  11. package/lib/Canvas/index.es.js +774 -774
  12. package/lib/Canvas/index.es.min.js +1 -1
  13. package/lib/Cardinal/index.es.js +90 -90
  14. package/lib/Cardinal/index.es.min.js +1 -1
  15. package/lib/Eoap/index.es.js +33 -33
  16. package/lib/Eoap/index.es.min.js +1 -1
  17. package/lib/Hermite/index.es.js +35 -35
  18. package/lib/Hermite/index.es.min.js +1 -1
  19. package/lib/MapCoordinate/index.es.js +199 -199
  20. package/lib/MapCoordinate/index.es.min.js +1 -1
  21. package/lib/Matrix4/index.es.js +124 -124
  22. package/lib/Matrix4/index.es.min.js +1 -1
  23. package/lib/Mercator/index.es.js +19 -19
  24. package/lib/Mercator/index.es.min.js +1 -1
  25. package/lib/PieLayout/index.es.d.ts +3 -0
  26. package/lib/PieLayout/index.es.js +234 -0
  27. package/lib/PieLayout/index.es.min.d.ts +3 -0
  28. package/lib/PieLayout/index.es.min.js +9 -0
  29. package/lib/RawCanvas/index.es.js +704 -704
  30. package/lib/RawCanvas/index.es.min.js +1 -1
  31. package/lib/SVG/index.es.js +514 -491
  32. package/lib/SVG/index.es.min.js +2 -2
  33. package/lib/Shader/index.es.js +35 -35
  34. package/lib/Shader/index.es.min.js +1 -1
  35. package/lib/Texture/index.es.js +53 -53
  36. package/lib/Texture/index.es.min.js +1 -1
  37. package/lib/TreeLayout/index.es.js +316 -309
  38. package/lib/TreeLayout/index.es.min.js +6 -2
  39. package/lib/animation/index.es.js +16 -9
  40. package/lib/animation/index.es.min.js +6 -2
  41. package/lib/assemble/index.es.js +17 -17
  42. package/lib/assemble/index.es.min.js +1 -1
  43. package/lib/getLoopColors/index.es.js +35 -35
  44. package/lib/getLoopColors/index.es.min.js +1 -1
  45. package/lib/getWebGLContext/index.es.js +62 -62
  46. package/lib/getWebGLContext/index.es.min.js +1 -1
  47. package/lib/index.umd.js +2675 -2327
  48. package/lib/index.umd.min.js +12 -2
  49. package/lib/initOption/index.es.js +6 -6
  50. package/lib/initOption/index.es.min.js +1 -1
  51. package/lib/mergeOption/index.es.js +34 -34
  52. package/lib/mergeOption/index.es.min.js +1 -1
  53. package/lib/move/index.es.js +7 -7
  54. package/lib/move/index.es.min.js +1 -1
  55. package/lib/rotate/index.es.js +7 -7
  56. package/lib/rotate/index.es.min.js +1 -1
  57. package/lib/ruler/index.es.js +137 -137
  58. package/lib/ruler/index.es.min.js +1 -1
  59. package/lib/scale/index.es.js +6 -6
  60. package/lib/scale/index.es.min.js +1 -1
  61. package/lib/throttle/index.es.js +7 -2
  62. package/lib/throttle/index.es.min.js +5 -1
  63. package/minialipay/ui-canvas/drawImage.js +35 -35
  64. package/minialipay/ui-canvas/index.acss +4 -4
  65. package/minialipay/ui-canvas/index.axml +3 -3
  66. package/minialipay/ui-canvas/index.d.ts +1 -1
  67. package/minialipay/ui-canvas/index.js +100 -100
  68. package/minialipay/ui-canvas/index.json +6 -6
  69. package/miniprogram/ui-canvas/drawImage.js +35 -35
  70. package/miniprogram/ui-canvas/index.js +117 -117
  71. package/miniprogram/ui-canvas/index.json +4 -4
  72. package/miniprogram/ui-canvas/index.wxml +4 -4
  73. package/miniprogram/ui-canvas/index.wxss +5 -5
  74. package/package/BarLayout/index.ts +3 -0
  75. package/package/Buffer/index.ts +2 -2
  76. package/package/Canvas/index.ts +2 -2
  77. package/package/Cardinal/index.ts +2 -2
  78. package/package/Eoap/index.ts +2 -2
  79. package/package/Hermite/index.ts +2 -2
  80. package/package/MapCoordinate/index.ts +2 -2
  81. package/package/Matrix4/index.ts +2 -2
  82. package/package/Mercator/index.ts +2 -2
  83. package/package/PieLayout/index.ts +3 -0
  84. package/package/RawCanvas/index.ts +2 -2
  85. package/package/SVG/index.ts +2 -2
  86. package/package/Shader/index.ts +2 -2
  87. package/package/Texture/index.ts +2 -2
  88. package/package/TreeLayout/index.ts +2 -2
  89. package/package/animation/index.ts +2 -2
  90. package/package/assemble/index.ts +2 -2
  91. package/package/getLoopColors/index.ts +2 -2
  92. package/package/getWebGLContext/index.ts +40 -40
  93. package/package/index.ts +84 -80
  94. package/package/initOption/index.ts +2 -2
  95. package/package/mergeOption/index.ts +2 -2
  96. package/package/move/index.ts +2 -2
  97. package/package/rotate/index.ts +2 -2
  98. package/package/ruler/index.ts +2 -2
  99. package/package/scale/index.ts +2 -2
  100. package/package/throttle/index.ts +2 -2
  101. package/package.json +75 -75
  102. package/src/Canvas.ts +84 -84
  103. package/src/Eoap.ts +66 -66
  104. package/src/Matrix4/index.ts +84 -84
  105. package/src/Matrix4/move.ts +12 -12
  106. package/src/Matrix4/rotate.ts +15 -15
  107. package/src/Matrix4/scale.ts +11 -11
  108. package/src/Matrix4/transform.ts +64 -64
  109. package/src/Mercator.ts +27 -27
  110. package/src/SVG.ts +55 -24
  111. package/src/common/assemble.ts +22 -22
  112. package/src/common/canvas/arc.ts +51 -51
  113. package/src/common/canvas/config.ts +176 -176
  114. package/src/common/canvas/default.ts +64 -64
  115. package/src/common/canvas/gradient.ts +31 -31
  116. package/src/common/canvas/index.ts +188 -188
  117. package/src/common/canvas/painter.ts +443 -443
  118. package/src/common/canvas/texts.ts +18 -18
  119. package/src/common/map/getBoundary.ts +15 -15
  120. package/src/common/map/tool.ts +29 -29
  121. package/src/common/option.ts +29 -29
  122. package/src/common/setStyle.ts +5 -5
  123. package/src/common/svg/config.ts +213 -213
  124. package/src/common/svg/default.ts +29 -29
  125. package/src/common/svg/gradient.ts +53 -53
  126. package/src/common/svg/index.ts +332 -332
  127. package/src/common/svg/tool.ts +51 -51
  128. package/src/common/tree/index.ts +25 -25
  129. package/src/common/tree/toInnerTree.ts +61 -61
  130. package/src/common/tree/toPlainTree.ts +135 -132
  131. package/src/common/type.ts +26 -26
  132. package/src/common/webgl/buffer.ts +79 -79
  133. package/src/common/webgl/getWebGLContext.ts +45 -45
  134. package/src/common/webgl/shader.ts +75 -75
  135. package/src/common/webgl/texture.ts +98 -97
  136. package/src/coordinate/MapCoordinate.ts +80 -80
  137. package/src/getLoopColors.ts +42 -42
  138. package/src/interpolation/Cardinal.ts +110 -110
  139. package/src/interpolation/Hermite.ts +65 -65
  140. package/src/layout/BarLayout.ts +249 -0
  141. package/src/layout/PieLayout.ts +142 -0
  142. package/src/layout/TreeLayout.ts +197 -194
  143. package/src/move.ts +7 -7
  144. package/src/rotate.ts +7 -7
  145. package/src/ruler.ts +209 -209
  146. package/src/scale.ts +6 -6
  147. package/types/Bar.d.ts +92 -0
  148. package/types/BarConfig.d.ts +5 -0
  149. package/types/BarLayout.d.ts +49 -0
  150. package/types/BarOption.d.ts +32 -0
  151. package/types/Buffer.d.ts +23 -23
  152. package/types/Canvas.d.ts +352 -352
  153. package/types/CanvasConfig.d.ts +88 -88
  154. package/types/CanvasOption.d.ts +8 -8
  155. package/types/CanvasOpts.d.ts +9 -9
  156. package/types/Cardinal.d.ts +13 -13
  157. package/types/Gradient.d.ts +14 -14
  158. package/types/Hermite.d.ts +18 -18
  159. package/types/Map.d.ts +9 -9
  160. package/types/MapConfig.d.ts +27 -27
  161. package/types/MapCoordinate.d.ts +22 -22
  162. package/types/Matrix4.d.ts +47 -47
  163. package/types/Pie.d.ts +74 -0
  164. package/types/PieConfig.d.ts +27 -0
  165. package/types/PieLayout.d.ts +41 -0
  166. package/types/PieOption.d.ts +22 -0
  167. package/types/SVG.d.ts +247 -243
  168. package/types/SVGConfig.d.ts +71 -71
  169. package/types/Shader.d.ts +16 -16
  170. package/types/Texture.d.ts +16 -16
  171. package/types/Tree.d.ts +74 -74
  172. package/types/TreeConfig.d.ts +36 -36
  173. package/types/TreeLayout.d.ts +59 -59
  174. package/types/TreeOption.d.ts +48 -48
  175. package/types/animation.d.ts +5 -5
  176. package/types/assemble.d.ts +5 -5
  177. package/types/getLoopColors.d.ts +5 -5
  178. package/types/getWebGLContext.d.ts +7 -7
  179. package/types/index.d.ts +195 -179
  180. package/types/move.d.ts +5 -5
  181. package/types/option.d.ts +12 -12
  182. package/types/painterConfig.d.ts +4 -4
  183. package/types/rotate.d.ts +5 -5
  184. package/types/ruler.d.ts +10 -10
  185. package/types/scale.d.ts +5 -5
  186. package/types/throttle.d.ts +5 -5
  187. package/types/throttleOption.d.ts +1 -1
  188. package/types/ui-canvas.d.ts +4 -4
  189. package/types/uni-canvas.d.ts +3 -3
  190. package/uni-app/drawImage.js +19 -19
  191. package/uni-app/ui-canvas.vue +284 -284
package/lib/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v1.3.0
2
+ * VISLite JavaScript Library v1.4.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  (function (global, factory) {
@@ -8,291 +8,296 @@
8
8
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite = factory());
9
9
  })(this, (function () { 'use strict';
10
10
 
11
- var Hermite = (function () {
12
- function Hermite(u) {
13
- if (u === void 0) { u = 0.5; }
14
- this.name = 'Hermite';
15
- this.__u = u;
16
- }
17
- Hermite.prototype.setP = function (x1, y1, x2, y2, s1, s2) {
18
- if (x1 < x2) {
19
- this.__a = x1;
20
- this.__b = x2;
21
- var p3 = this.__u * s1, p4 = this.__u * s2;
22
- y1 /= (x2 - x1);
23
- y2 /= (x2 - x1);
24
- this.__MR = [
25
- 2 * y1 - 2 * y2 + p3 + p4,
26
- 3 * y2 - 3 * y1 - 2 * p3 - p4,
27
- p3,
28
- y1
29
- ];
30
- }
31
- else
32
- throw new Error('The point x-position should be increamented!');
33
- return this;
34
- };
35
- Hermite.prototype.use = function (x) {
36
- if (this.__MR) {
37
- var sx = (x - this.__a) / (this.__b - this.__a), sx2 = sx * sx, sx3 = sx * sx2;
38
- var sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3];
39
- return sResult * (this.__b - this.__a);
40
- }
41
- else
42
- throw new Error('You shoud first set the position!');
43
- };
44
- return Hermite;
11
+ var Hermite = (function () {
12
+ function Hermite(u) {
13
+ if (u === void 0) { u = 0.5; }
14
+ this.name = 'Hermite';
15
+ this.__u = u;
16
+ }
17
+ Hermite.prototype.setP = function (x1, y1, x2, y2, s1, s2) {
18
+ if (x1 < x2) {
19
+ this.__a = x1;
20
+ this.__b = x2;
21
+ var p3 = this.__u * s1, p4 = this.__u * s2;
22
+ y1 /= (x2 - x1);
23
+ y2 /= (x2 - x1);
24
+ this.__MR = [
25
+ 2 * y1 - 2 * y2 + p3 + p4,
26
+ 3 * y2 - 3 * y1 - 2 * p3 - p4,
27
+ p3,
28
+ y1
29
+ ];
30
+ }
31
+ else
32
+ throw new Error('The point x-position should be increamented!');
33
+ return this;
34
+ };
35
+ Hermite.prototype.use = function (x) {
36
+ if (this.__MR) {
37
+ var sx = (x - this.__a) / (this.__b - this.__a), sx2 = sx * sx, sx3 = sx * sx2;
38
+ var sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3];
39
+ return sResult * (this.__b - this.__a);
40
+ }
41
+ else
42
+ throw new Error('You shoud first set the position!');
43
+ };
44
+ return Hermite;
45
45
  }());
46
46
 
47
- var Cardinal = (function () {
48
- function Cardinal(t) {
49
- if (t === void 0) { t = 0; }
50
- this.name = 'Cardinal';
51
- this.__t = t;
52
- }
53
- Cardinal.prototype.setP = function (points) {
54
- this.__HS = {
55
- "x": [],
56
- "h": []
57
- };
58
- var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
59
- this.__HS.x[0] = points[0][0];
60
- for (flag = 1; flag < points.length; flag++) {
61
- if (points[flag][0] <= points[flag - 1][0])
62
- throw new Error('The point position should be increamented!');
63
- this.__HS.x[flag] = points[flag][0];
64
- if (flag < points.length - 1) {
65
- if ((points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
66
- (points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
67
- points[flag + 1][1] == points[flag][1] ||
68
- points[flag - 1][1] == points[flag][1]) {
69
- temp = 0;
70
- }
71
- else {
72
- temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]);
73
- }
74
- }
75
- else {
76
- temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
77
- }
78
- 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);
79
- slope = temp;
80
- }
81
- return this;
82
- };
83
- Cardinal.prototype.use = function (x) {
84
- if (this.__HS) {
85
- this.__i = -1;
86
- 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]))) {
87
- this.__i += 1;
88
- }
89
- if (this.__i < 0) {
90
- return this.__HS.h[0].use(this.__HS.x[0]);
91
- }
92
- else if (this.__i >= this.__HS.h.length) {
93
- return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
94
- }
95
- return this.__HS.h[this.__i].use(x);
96
- }
97
- else {
98
- throw new Error('You shoud first set the position!');
99
- }
100
- };
101
- return Cardinal;
47
+ var Cardinal = (function () {
48
+ function Cardinal(t) {
49
+ if (t === void 0) { t = 0; }
50
+ this.name = 'Cardinal';
51
+ this.__t = t;
52
+ }
53
+ Cardinal.prototype.setP = function (points) {
54
+ this.__HS = {
55
+ "x": [],
56
+ "h": []
57
+ };
58
+ var flag, slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]), temp;
59
+ this.__HS.x[0] = points[0][0];
60
+ for (flag = 1; flag < points.length; flag++) {
61
+ if (points[flag][0] <= points[flag - 1][0])
62
+ throw new Error('The point position should be increamented!');
63
+ this.__HS.x[flag] = points[flag][0];
64
+ if (flag < points.length - 1) {
65
+ if ((points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
66
+ (points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
67
+ points[flag + 1][1] == points[flag][1] ||
68
+ points[flag - 1][1] == points[flag][1]) {
69
+ temp = 0;
70
+ }
71
+ else {
72
+ temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]);
73
+ }
74
+ }
75
+ else {
76
+ temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0]);
77
+ }
78
+ 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);
79
+ slope = temp;
80
+ }
81
+ return this;
82
+ };
83
+ Cardinal.prototype.use = function (x) {
84
+ if (this.__HS) {
85
+ this.__i = -1;
86
+ 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]))) {
87
+ this.__i += 1;
88
+ }
89
+ if (this.__i < 0) {
90
+ return this.__HS.h[0].use(this.__HS.x[0]);
91
+ }
92
+ else if (this.__i >= this.__HS.h.length) {
93
+ return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1]);
94
+ }
95
+ return this.__HS.h[this.__i].use(x);
96
+ }
97
+ else {
98
+ throw new Error('You shoud first set the position!');
99
+ }
100
+ };
101
+ return Cardinal;
102
102
  }());
103
103
 
104
- function _move (d, a, b, c) {
105
- if (c === void 0) { c = 0; }
106
- var sqrt = Math.sqrt(a * a + b * b + c * c);
107
- return [
108
- 1, 0, 0, 0,
109
- 0, 1, 0, 0,
110
- 0, 0, 1, 0,
111
- a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
112
- ];
104
+ function _move (d, a, b, c) {
105
+ if (c === void 0) { c = 0; }
106
+ var sqrt = Math.sqrt(a * a + b * b + c * c);
107
+ return [
108
+ 1, 0, 0, 0,
109
+ 0, 1, 0, 0,
110
+ 0, 0, 1, 0,
111
+ a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
112
+ ];
113
113
  }
114
114
 
115
- function _rotate (deg) {
116
- var sin = Math.sin(deg), cos = Math.cos(deg);
117
- return [
118
- cos, sin, 0, 0,
119
- -sin, cos, 0, 0,
120
- 0, 0, 1, 0,
121
- 0, 0, 0, 1
122
- ];
115
+ function _rotate (deg) {
116
+ var sin = Math.sin(deg), cos = Math.cos(deg);
117
+ return [
118
+ cos, sin, 0, 0,
119
+ -sin, cos, 0, 0,
120
+ 0, 0, 1, 0,
121
+ 0, 0, 0, 1
122
+ ];
123
123
  }
124
124
 
125
- function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
126
- if (cx === void 0) { cx = 0; }
127
- if (cy === void 0) { cy = 0; }
128
- if (cz === void 0) { cz = 0; }
129
- return [
130
- xTimes, 0, 0, 0,
131
- 0, yTimes, 0, 0,
132
- 0, 0, zTimes, 0,
133
- cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
134
- ];
125
+ function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
126
+ if (cx === void 0) { cx = 0; }
127
+ if (cy === void 0) { cy = 0; }
128
+ if (cz === void 0) { cz = 0; }
129
+ return [
130
+ xTimes, 0, 0, 0,
131
+ 0, yTimes, 0, 0,
132
+ 0, 0, zTimes, 0,
133
+ cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
134
+ ];
135
135
  }
136
136
 
137
- function _transform (a1, b1, c1, a2, b2, c2) {
138
- if (typeof a1 === 'number' && typeof b1 === 'number') {
139
- if (typeof c1 !== 'number') {
140
- c1 = 0;
141
- a2 = a1;
142
- b2 = b1;
143
- c2 = 1;
144
- }
145
- else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
146
- a2 = a1;
147
- b2 = b1;
148
- c2 = c1;
149
- a1 = 0;
150
- b1 = 0;
151
- c1 = 0;
152
- }
153
- if (a1 == a2 && b1 == b2 && c1 == c2)
154
- throw new Error('It\'s not a legitimate ray!');
155
- 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;
156
- return [
157
- [
158
- cos1, cos2 * sin1, sin1 * sin2, 0,
159
- -sin1, cos1 * cos2, cos1 * sin2, 0,
160
- 0, -sin2, cos2, 0,
161
- b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
162
- ],
163
- [
164
- cos1, -sin1, 0, 0,
165
- cos2 * sin1, cos2 * cos1, -sin2, 0,
166
- sin1 * sin2, cos1 * sin2, cos2, 0,
167
- a1, b1, c1, 1
168
- ]
169
- ];
170
- }
171
- else {
172
- throw new Error('a1 and b1 is required!');
173
- }
137
+ function _transform (a1, b1, c1, a2, b2, c2) {
138
+ if (typeof a1 === 'number' && typeof b1 === 'number') {
139
+ if (typeof c1 !== 'number') {
140
+ c1 = 0;
141
+ a2 = a1;
142
+ b2 = b1;
143
+ c2 = 1;
144
+ }
145
+ else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
146
+ a2 = a1;
147
+ b2 = b1;
148
+ c2 = c1;
149
+ a1 = 0;
150
+ b1 = 0;
151
+ c1 = 0;
152
+ }
153
+ if (a1 == a2 && b1 == b2 && c1 == c2)
154
+ throw new Error('It\'s not a legitimate ray!');
155
+ 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;
156
+ return [
157
+ [
158
+ cos1, cos2 * sin1, sin1 * sin2, 0,
159
+ -sin1, cos1 * cos2, cos1 * sin2, 0,
160
+ 0, -sin2, cos2, 0,
161
+ b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
162
+ ],
163
+ [
164
+ cos1, -sin1, 0, 0,
165
+ cos2 * sin1, cos2 * cos1, -sin2, 0,
166
+ sin1 * sin2, cos1 * sin2, cos2, 0,
167
+ a1, b1, c1, 1
168
+ ]
169
+ ];
170
+ }
171
+ else {
172
+ throw new Error('a1 and b1 is required!');
173
+ }
174
174
  }
175
175
 
176
- var _multiply = function (matrix4, param) {
177
- var newParam = [];
178
- for (var i = 0; i < 4; i++)
179
- for (var j = 0; j < param.length / 4; j++)
180
- newParam[j * 4 + i] =
181
- matrix4[i] * param[j * 4] +
182
- matrix4[i + 4] * param[j * 4 + 1] +
183
- matrix4[i + 8] * param[j * 4 + 2] +
184
- matrix4[i + 12] * param[j * 4 + 3];
185
- return newParam;
186
- };
187
- var __initMatrix4 = [
188
- 1, 0, 0, 0,
189
- 0, 1, 0, 0,
190
- 0, 0, 1, 0,
191
- 0, 0, 0, 1
192
- ];
193
- var Matrix4 = (function () {
194
- function Matrix4(initMatrix4) {
195
- if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
196
- this.name = 'Matrix4';
197
- this.__matrix4 = initMatrix4;
198
- }
199
- Matrix4.prototype.setValue = function (initMatrix4) {
200
- if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
201
- this.__matrix4 = initMatrix4;
202
- return this;
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;
176
+ var _multiply = function (matrix4, param) {
177
+ var newParam = [];
178
+ for (var i = 0; i < 4; i++)
179
+ for (var j = 0; j < param.length / 4; j++)
180
+ newParam[j * 4 + i] =
181
+ matrix4[i] * param[j * 4] +
182
+ matrix4[i + 4] * param[j * 4 + 1] +
183
+ matrix4[i + 8] * param[j * 4 + 2] +
184
+ matrix4[i + 12] * param[j * 4 + 3];
185
+ return newParam;
186
+ };
187
+ var __initMatrix4 = [
188
+ 1, 0, 0, 0,
189
+ 0, 1, 0, 0,
190
+ 0, 0, 1, 0,
191
+ 0, 0, 0, 1
192
+ ];
193
+ var Matrix4 = (function () {
194
+ function Matrix4(initMatrix4) {
195
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
196
+ this.name = 'Matrix4';
197
+ this.__matrix4 = initMatrix4;
198
+ }
199
+ Matrix4.prototype.setValue = function (initMatrix4) {
200
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
201
+ this.__matrix4 = initMatrix4;
202
+ return this;
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
235
  }());
236
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
- ];
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
243
  }
244
244
 
245
- function move (ax, ay, d, x, y) {
246
- var sqrt = Math.sqrt(ax * ax + ay * ay);
247
- return [
248
- ax * d / sqrt + x,
249
- ay * d / sqrt + y
250
- ];
245
+ function move (ax, ay, d, x, y) {
246
+ var sqrt = Math.sqrt(ax * ax + ay * ay);
247
+ return [
248
+ ax * d / sqrt + x,
249
+ ay * d / sqrt + y
250
+ ];
251
251
  }
252
252
 
253
- function scale (cx, cy, times, x, y) {
254
- return [
255
- times * (x - cx) + cx,
256
- times * (y - cy) + cy
257
- ];
253
+ function scale (cx, cy, times, x, y) {
254
+ return [
255
+ times * (x - cx) + cx,
256
+ times * (y - cy) + cy
257
+ ];
258
258
  }
259
259
 
260
- function getLoopColors (num, alpha, colorsFactory) {
261
- if (alpha === void 0) { alpha = 1; }
262
- var colorList = colorsFactory ? colorsFactory(alpha) : [
263
- 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
264
- 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
265
- 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
266
- 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
267
- 'rgba(234,124,204,' + alpha + ")"
268
- ];
269
- var colors = [];
270
- if (num <= colorList.length) {
271
- return colorList;
272
- }
273
- else {
274
- if (num % colorList.length == 0) {
275
- for (var i = 0; i < (num / colorList.length); i++) {
276
- colors = colors.concat(colorList);
277
- }
278
- }
279
- else {
280
- for (var j = 1; j < (num / colorList.length); j++) {
281
- colors = colors.concat(colorList);
282
- }
283
- if (num % colorList.length == 1) {
284
- colors = colors.concat(colorList[4]);
285
- }
286
- else {
287
- for (var k = 0; k < num % colorList.length; k++) {
288
- colors = colors.concat(colorList[k]);
289
- }
290
- }
291
- }
292
- }
293
- return colors;
260
+ function getLoopColors (num, alpha, colorsFactory) {
261
+ if (alpha === void 0) { alpha = 1; }
262
+ var colorList = colorsFactory ? colorsFactory(alpha) : [
263
+ 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
264
+ 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
265
+ 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
266
+ 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
267
+ 'rgba(234,124,204,' + alpha + ")"
268
+ ];
269
+ var colors = [];
270
+ if (num <= colorList.length) {
271
+ return colorList;
272
+ }
273
+ else {
274
+ if (num % colorList.length == 0) {
275
+ for (var i = 0; i < (num / colorList.length); i++) {
276
+ colors = colors.concat(colorList);
277
+ }
278
+ }
279
+ else {
280
+ for (var j = 1; j < (num / colorList.length); j++) {
281
+ colors = colors.concat(colorList);
282
+ }
283
+ if (num % colorList.length == 1) {
284
+ colors = colors.concat(colorList[4]);
285
+ }
286
+ else {
287
+ for (var k = 0; k < num % colorList.length; k++) {
288
+ colors = colors.concat(colorList[k]);
289
+ }
290
+ }
291
+ }
292
+ }
293
+ return colors;
294
294
  }
295
295
 
296
+ /*!
297
+ * animation of OIPage v1.2.0
298
+ * git+https://github.com/oi-contrib/OIPage.git
299
+ */
300
+
296
301
  //当前正在运动的动画的tick函数堆栈
297
302
  var $timers = [];
298
303
  //唯一定时器的定时间隔
@@ -382,156 +387,158 @@
382
387
  doback(deep);
383
388
  }, duration, callback);
384
389
 
385
- // 返回一个函数
386
- // 用于在动画结束前结束动画
387
- return function () {
388
- var i;
389
- for (i in $timers) {
390
- if ($timers[i].id == id) {
391
- $timers[i].id = void 0;
392
- return;
390
+ return {
391
+ // 一个函数
392
+ // 用于在动画结束前结束动画
393
+ stop: function () {
394
+ var i;
395
+ for (i in $timers) {
396
+ if ($timers[i].id == id) {
397
+ $timers[i].id = void 0;
398
+ return;
399
+ }
393
400
  }
394
401
  }
395
402
  };
396
403
 
397
404
  }
398
405
 
399
- function ruler (maxValue, minValue, num, option) {
400
- if (maxValue < minValue) {
401
- var temp = minValue;
402
- minValue = maxValue;
403
- maxValue = temp;
404
- }
405
- else if (maxValue == minValue) {
406
- return [maxValue];
407
- }
408
- var times100 = (function (_value) {
409
- var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
410
- var _times100 = -1, _tiemsValue = _value;
411
- while (_times100_base == 10 ?
412
- (_tiemsValue >= -100 && _tiemsValue <= 100)
413
- :
414
- (_tiemsValue <= -100 || _tiemsValue >= 100)) {
415
- _times100 += 1;
416
- _tiemsValue *= _times100_base;
417
- }
418
- if (_times100_base == 10) {
419
- return Math.pow(10, _times100);
420
- }
421
- else {
422
- var temp = "0.";
423
- for (var i = 1; i < _times100; i++) {
424
- temp += "0";
425
- }
426
- return +(temp + "1");
427
- }
428
- })(maxValue - minValue);
429
- var distance100_oral = Math.ceil((maxValue - minValue) * times100 / num);
430
- var getResult = function (changValue) {
431
- var distance100 = {
432
- 3: 2,
433
- 4: 5,
434
- 6: 5,
435
- 7: 5,
436
- 8: 10,
437
- 9: 10,
438
- 11: 10,
439
- 12: 10,
440
- 13: 15,
441
- 14: 15,
442
- 16: 15,
443
- 17: 15,
444
- 18: 20,
445
- 19: 20,
446
- 21: 20,
447
- 22: 20,
448
- 23: 25,
449
- 24: 25,
450
- 26: 25,
451
- 27: 25
452
- }[distance100_oral + changValue] || (distance100_oral + changValue);
453
- var distance = distance100 / times100;
454
- var begin = Math.floor(minValue / distance) * distance;
455
- var rulerArray = [];
456
- rulerArray.push(begin);
457
- for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
458
- rulerArray.push(begin + distance * index);
459
- }
460
- return rulerArray;
461
- };
462
- var rulerArray = getResult(0);
463
- var balanceMax = function () {
464
- var rulerArray_temp = [];
465
- var changeDist = rulerArray[rulerArray.length - 1] - (option === null || option === void 0 ? void 0 : option.max);
466
- for (var index = 0; index < rulerArray.length; index++) {
467
- if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) ;
468
- else {
469
- rulerArray_temp.push(rulerArray[index] - changeDist);
470
- }
471
- }
472
- return rulerArray_temp;
473
- };
474
- var balanceMin = function () {
475
- var rulerArray_temp = [];
476
- var changeDist = rulerArray[0] - (option === null || option === void 0 ? void 0 : option.min);
477
- for (var index = 0; index < rulerArray.length; index++) {
478
- rulerArray_temp[index] = rulerArray[index] - changeDist;
479
- if (maxValue <= rulerArray_temp[index])
480
- break;
481
- }
482
- return rulerArray_temp;
483
- };
484
- if (option) {
485
- if ('max' in option && 'min' in option && option.max >= maxValue && option.min <= minValue) {
486
- var isAnswer = function () {
487
- if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max)
488
- return true;
489
- var rulerArray_max = balanceMax();
490
- if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
491
- rulerArray = rulerArray_max;
492
- return true;
493
- }
494
- var rulerArray_min = balanceMin();
495
- if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
496
- rulerArray = rulerArray_min;
497
- return true;
498
- }
499
- };
500
- if (isAnswer())
501
- return rulerArray;
502
- for (var changValue = 1; changValue < 100; changValue++) {
503
- rulerArray = getResult(changValue);
504
- if (isAnswer())
505
- return rulerArray;
506
- rulerArray = getResult(-changValue);
507
- if (isAnswer())
508
- return rulerArray;
509
- }
510
- }
511
- if ('max' in option && option.max >= maxValue) {
512
- if (option.max < rulerArray[rulerArray.length - 1]) {
513
- rulerArray = balanceMax();
514
- }
515
- }
516
- else if ('min' in option && option.min <= minValue) {
517
- if (option.min > rulerArray[0]) {
518
- rulerArray = balanceMin();
519
- }
520
- }
521
- }
522
- for (var index = 0; index < rulerArray.length; index++) {
523
- var valStr = rulerArray[index] + "";
524
- if (/\./.test(valStr)) {
525
- if (/9{7,}$/.test(valStr)) {
526
- valStr = valStr.replace(/9{7,}$/, '');
527
- rulerArray[index] = +(valStr.substring(0, valStr.length - 1) + ((+valStr[valStr.length - 1]) + 1));
528
- }
529
- else if (/0{7,}\d$/.test(valStr)) {
530
- rulerArray[index] = +(valStr.replace(/0{7,}\d$/, ''));
531
- }
532
- }
533
- }
534
- return rulerArray;
406
+ function ruler (maxValue, minValue, num, option) {
407
+ if (maxValue < minValue) {
408
+ var temp = minValue;
409
+ minValue = maxValue;
410
+ maxValue = temp;
411
+ }
412
+ else if (maxValue == minValue) {
413
+ return [maxValue];
414
+ }
415
+ var times100 = (function (_value) {
416
+ var _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1;
417
+ var _times100 = -1, _tiemsValue = _value;
418
+ while (_times100_base == 10 ?
419
+ (_tiemsValue >= -100 && _tiemsValue <= 100)
420
+ :
421
+ (_tiemsValue <= -100 || _tiemsValue >= 100)) {
422
+ _times100 += 1;
423
+ _tiemsValue *= _times100_base;
424
+ }
425
+ if (_times100_base == 10) {
426
+ return Math.pow(10, _times100);
427
+ }
428
+ else {
429
+ var temp = "0.";
430
+ for (var i = 1; i < _times100; i++) {
431
+ temp += "0";
432
+ }
433
+ return +(temp + "1");
434
+ }
435
+ })(maxValue - minValue);
436
+ var distance100_oral = Math.ceil((maxValue - minValue) * times100 / num);
437
+ var getResult = function (changValue) {
438
+ var distance100 = {
439
+ 3: 2,
440
+ 4: 5,
441
+ 6: 5,
442
+ 7: 5,
443
+ 8: 10,
444
+ 9: 10,
445
+ 11: 10,
446
+ 12: 10,
447
+ 13: 15,
448
+ 14: 15,
449
+ 16: 15,
450
+ 17: 15,
451
+ 18: 20,
452
+ 19: 20,
453
+ 21: 20,
454
+ 22: 20,
455
+ 23: 25,
456
+ 24: 25,
457
+ 26: 25,
458
+ 27: 25
459
+ }[distance100_oral + changValue] || (distance100_oral + changValue);
460
+ var distance = distance100 / times100;
461
+ var begin = Math.floor(minValue / distance) * distance;
462
+ var rulerArray = [];
463
+ rulerArray.push(begin);
464
+ for (var index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
465
+ rulerArray.push(begin + distance * index);
466
+ }
467
+ return rulerArray;
468
+ };
469
+ var rulerArray = getResult(0);
470
+ var balanceMax = function () {
471
+ var rulerArray_temp = [];
472
+ var changeDist = rulerArray[rulerArray.length - 1] - (option === null || option === void 0 ? void 0 : option.max);
473
+ for (var index = 0; index < rulerArray.length; index++) {
474
+ if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) ;
475
+ else {
476
+ rulerArray_temp.push(rulerArray[index] - changeDist);
477
+ }
478
+ }
479
+ return rulerArray_temp;
480
+ };
481
+ var balanceMin = function () {
482
+ var rulerArray_temp = [];
483
+ var changeDist = rulerArray[0] - (option === null || option === void 0 ? void 0 : option.min);
484
+ for (var index = 0; index < rulerArray.length; index++) {
485
+ rulerArray_temp[index] = rulerArray[index] - changeDist;
486
+ if (maxValue <= rulerArray_temp[index])
487
+ break;
488
+ }
489
+ return rulerArray_temp;
490
+ };
491
+ if (option) {
492
+ if ('max' in option && 'min' in option && option.max >= maxValue && option.min <= minValue) {
493
+ var isAnswer = function () {
494
+ if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max)
495
+ return true;
496
+ var rulerArray_max = balanceMax();
497
+ if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
498
+ rulerArray = rulerArray_max;
499
+ return true;
500
+ }
501
+ var rulerArray_min = balanceMin();
502
+ if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
503
+ rulerArray = rulerArray_min;
504
+ return true;
505
+ }
506
+ };
507
+ if (isAnswer())
508
+ return rulerArray;
509
+ for (var changValue = 1; changValue < 100; changValue++) {
510
+ rulerArray = getResult(changValue);
511
+ if (isAnswer())
512
+ return rulerArray;
513
+ rulerArray = getResult(-changValue);
514
+ if (isAnswer())
515
+ return rulerArray;
516
+ }
517
+ }
518
+ if ('max' in option && option.max >= maxValue) {
519
+ if (option.max < rulerArray[rulerArray.length - 1]) {
520
+ rulerArray = balanceMax();
521
+ }
522
+ }
523
+ else if ('min' in option && option.min <= minValue) {
524
+ if (option.min > rulerArray[0]) {
525
+ rulerArray = balanceMin();
526
+ }
527
+ }
528
+ }
529
+ for (var index = 0; index < rulerArray.length; index++) {
530
+ var valStr = rulerArray[index] + "";
531
+ if (/\./.test(valStr)) {
532
+ if (/9{7,}$/.test(valStr)) {
533
+ valStr = valStr.replace(/9{7,}$/, '');
534
+ rulerArray[index] = +(valStr.substring(0, valStr.length - 1) + ((+valStr[valStr.length - 1]) + 1));
535
+ }
536
+ else if (/0{7,}\d$/.test(valStr)) {
537
+ rulerArray[index] = +(valStr.replace(/0{7,}\d$/, ''));
538
+ }
539
+ }
540
+ }
541
+ return rulerArray;
535
542
  }
536
543
 
537
544
  /******************************************************************************
@@ -583,1551 +590,1579 @@
583
590
 
584
591
  var XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"];
585
592
 
586
- var setLineAttr = function (el, config) {
587
- setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
588
- setAttribute(el, "stroke-width", config.lineWidth + "");
589
- setAttribute(el, "stroke-linecap", config.lineCap + "");
590
- setAttribute(el, "stroke-linejoin", config.lineJoin + "");
591
- };
592
- function toNode(tagname) {
593
- return document.createElementNS('http://www.w3.org/2000/svg', tagname);
594
- }
595
- var _setAttribute = function (el, key, value) {
596
- if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
597
- el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
598
- }
599
- else {
600
- el.setAttribute(key, value + "");
601
- }
602
- };
603
- var setAttribute = _setAttribute;
604
- function getAttribute(el, key) {
605
- if (XLINK_ATTRIBUTE.indexOf(key) > -1)
606
- key = 'xlink:' + key;
607
- return el.getAttribute(key);
608
- }
609
- function full(el, config) {
610
- setLineAttr(el, config);
611
- _setAttribute(el, "stroke", config.strokeStyle);
612
- _setAttribute(el, "fill", config.fillStyle);
613
- }
614
- function fill(el, config) {
615
- _setAttribute(el, "fill", config.fillStyle);
616
- }
617
- function stroke(el, config) {
618
- setLineAttr(el, config);
619
- _setAttribute(el, "stroke", config.strokeStyle);
620
- _setAttribute(el, "fill", "none");
593
+ var setLineAttr = function (el, config) {
594
+ setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
595
+ setAttribute(el, "stroke-width", config.lineWidth + "");
596
+ setAttribute(el, "stroke-linecap", config.lineCap + "");
597
+ setAttribute(el, "stroke-linejoin", config.lineJoin + "");
598
+ };
599
+ function toNode(tagname) {
600
+ return document.createElementNS('http://www.w3.org/2000/svg', tagname);
601
+ }
602
+ var _setAttribute = function (el, key, value) {
603
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
604
+ el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
605
+ }
606
+ else {
607
+ el.setAttribute(key, value + "");
608
+ }
609
+ };
610
+ var setAttribute = _setAttribute;
611
+ function getAttribute(el, key) {
612
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1)
613
+ key = 'xlink:' + key;
614
+ return el.getAttribute(key);
615
+ }
616
+ function full(el, config) {
617
+ setLineAttr(el, config);
618
+ _setAttribute(el, "stroke", config.strokeStyle);
619
+ _setAttribute(el, "fill", config.fillStyle);
620
+ }
621
+ function fill(el, config) {
622
+ _setAttribute(el, "fill", config.fillStyle);
623
+ }
624
+ function stroke(el, config) {
625
+ setLineAttr(el, config);
626
+ _setAttribute(el, "stroke", config.strokeStyle);
627
+ _setAttribute(el, "fill", "none");
621
628
  }
622
629
 
623
- function setStyle (el, styles) {
624
- for (var key in styles) {
625
- el.style[key] = styles[key];
626
- }
630
+ function setStyle (el, styles) {
631
+ for (var key in styles) {
632
+ el.style[key] = styles[key];
633
+ }
627
634
  }
628
635
 
629
- var rotate = function (cx, cy, deg, x, y) {
630
- var cos = Math.cos(deg), sin = Math.sin(deg);
631
- return [
632
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
633
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
634
- ];
635
- };
636
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
637
- if (rotateA < 0) {
638
- beginA += rotateA;
639
- rotateA *= -1;
640
- }
641
- var temp = [];
642
- var p;
643
- p = rotate(0, 0, beginA, r1, 0);
644
- temp[0] = p[0];
645
- temp[1] = p[1];
646
- p = rotate(0, 0, rotateA, p[0], p[1]);
647
- temp[2] = p[0];
648
- temp[3] = p[1];
649
- p = rotate(0, 0, beginA, r2, 0);
650
- temp[4] = p[0];
651
- temp[5] = p[1];
652
- p = rotate(0, 0, rotateA, p[0], p[1]);
653
- temp[6] = p[0];
654
- temp[7] = p[1];
655
- 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);
636
+ var rotate = function (cx, cy, deg, x, y) {
637
+ var cos = Math.cos(deg), sin = Math.sin(deg);
638
+ return [
639
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
640
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
641
+ ];
642
+ };
643
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
644
+ if (rotateA < 0) {
645
+ beginA += rotateA;
646
+ rotateA *= -1;
647
+ }
648
+ var temp = [];
649
+ var p;
650
+ p = rotate(0, 0, beginA, r1, 0);
651
+ temp[0] = p[0];
652
+ temp[1] = p[1];
653
+ p = rotate(0, 0, rotateA, p[0], p[1]);
654
+ temp[2] = p[0];
655
+ temp[3] = p[1];
656
+ p = rotate(0, 0, beginA, r2, 0);
657
+ temp[4] = p[0];
658
+ temp[5] = p[1];
659
+ p = rotate(0, 0, rotateA, p[0], p[1]);
660
+ temp[6] = p[0];
661
+ temp[7] = p[1];
662
+ 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);
656
663
  }
657
664
 
658
- var initDefs = function (el) {
659
- var defs = el.getElementsByTagName('defs');
660
- if (defs.length <= 0) {
661
- var newDefs = toNode("defs");
662
- el.appendChild(newDefs);
663
- return newDefs;
664
- }
665
- else {
666
- return defs[0];
667
- }
668
- };
669
- var initText$1 = function (el, config, x, y, deg) {
670
- if (el.nodeName.toLowerCase() !== "text")
671
- throw new Error("Need a <text> !");
672
- setAttribute(el, "dy", {
673
- top: config["fontSize"] * 0.5,
674
- middle: 0,
675
- bottom: -config["fontSize"] * 0.5,
676
- }[config.textBaseline]);
677
- setStyle(el, {
678
- "text-anchor": {
679
- left: "start",
680
- right: "end",
681
- center: "middle",
682
- }[config.textAlign],
683
- "dominant-baseline": "central",
684
- "font-size": config["fontSize"] + "px",
685
- "font-family": config["fontFamily"],
686
- });
687
- setAttribute(el, "x", x);
688
- setAttribute(el, "y", y);
689
- if (typeof deg == "number") {
690
- deg = deg % 360;
691
- setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
692
- }
693
- };
694
- var initCircle$1 = function (el, cx, cy, r) {
695
- if (el.nodeName.toLowerCase() !== "circle")
696
- throw new Error("Need a <circle> !");
697
- setAttribute(el, "cx", cx);
698
- setAttribute(el, "cy", cy);
699
- setAttribute(el, "r", r);
700
- };
701
- var initPath = function (el, path) {
702
- if (el.nodeName.toLowerCase() !== "path")
703
- throw new Error("Need a <path> !");
704
- setAttribute(el, "d", path);
705
- };
706
- var initRect$1 = function (el, config, x, y, width, height) {
707
- if (el.nodeName.toLowerCase() !== "path")
708
- throw new Error("Need a <path> !");
709
- var rectRadius = [];
710
- if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
711
- for (var index = 0; index < 4; index++) {
712
- rectRadius.push.apply(rectRadius, config.rectRadius);
713
- }
714
- }
715
- if (height < 0) {
716
- height *= -1;
717
- y -= height;
718
- }
719
- if (width < 0) {
720
- width *= -1;
721
- x -= width;
722
- }
723
- var d = "";
724
- if (rectRadius.length >= 4) {
725
- d = "M" + (x + rectRadius[0]) + " " + y;
726
- d += "L" + (x + width - rectRadius[1]) + " " + y;
727
- d += "A" + rectRadius[1] + " " + rectRadius[1] + " 0 0 1 " + (x + width) + " " + (y + rectRadius[1]);
728
- d += "L" + (x + width) + " " + (y + height - rectRadius[2]);
729
- d += "A" + rectRadius[2] + " " + rectRadius[2] + " 0 0 1 " + (x + width - rectRadius[2]) + " " + (y + height);
730
- d += "L" + (x + rectRadius[3]) + " " + (y + height);
731
- d += "A" + rectRadius[3] + " " + rectRadius[3] + " 0 0 1 " + x + " " + (y + height - rectRadius[3]);
732
- d += "L" + x + " " + (y + rectRadius[0]);
733
- d += "A" + rectRadius[0] + " " + rectRadius[0] + " 0 0 1 " + (x + rectRadius[0]) + " " + y;
734
- }
735
- else {
736
- d = "M" + x + " " + y;
737
- d += "L" + (x + width) + " " + y;
738
- d += "L" + (x + width) + " " + (y + height);
739
- d += "L" + x + " " + (y + height);
740
- d += "Z";
741
- }
742
- setAttribute(el, "d", d);
743
- };
744
- var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
745
- if (el.nodeName.toLowerCase() !== "path")
746
- throw new Error("Need a <path> !");
747
- beginDeg = (beginDeg / 180) * Math.PI;
748
- deg = (deg / 180) * Math.PI;
749
- beginDeg = beginDeg % (Math.PI * 2);
750
- if (r1 > r2) {
751
- var temp = r1;
752
- r1 = r2;
753
- r2 = temp;
754
- }
755
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
756
- deg = Math.PI * 1.999999;
757
- }
758
- else {
759
- deg = deg % (Math.PI * 2);
760
- }
761
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
762
- var f = endA - beginA > Math.PI ? 1 : 0;
763
- var d = "M" + begInnerX + " " + begInnerY;
764
- if (r < 0)
765
- r = -r;
766
- d +=
767
- "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
768
- if (config.arcEndCap == "round")
769
- d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
770
- else if (config.arcEndCap == "-round")
771
- d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
772
- else
773
- d += "L" + endOuterX + " " + endOuterY;
774
- d +=
775
- "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
776
- if (config.arcStartCap == "round")
777
- d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
778
- else if (config.arcStartCap == "-round")
779
- d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
780
- else
781
- d += "L" + begInnerX + " " + begInnerY;
782
- if (config.arcStartCap == "butt")
783
- d += "Z";
784
- setAttribute(el, "d", d);
785
- });
665
+ var initDefs = function (el) {
666
+ var defs = el.getElementsByTagName('defs');
667
+ if (defs.length <= 0) {
668
+ var newDefs = toNode("defs");
669
+ el.appendChild(newDefs);
670
+ return newDefs;
671
+ }
672
+ else {
673
+ return defs[0];
674
+ }
675
+ };
676
+ var initText$1 = function (el, config, x, y, deg) {
677
+ if (el.nodeName.toLowerCase() !== "text")
678
+ throw new Error("Need a <text> !");
679
+ setAttribute(el, "dy", {
680
+ top: config["fontSize"] * 0.5,
681
+ middle: 0,
682
+ bottom: -config["fontSize"] * 0.5,
683
+ }[config.textBaseline]);
684
+ setStyle(el, {
685
+ "text-anchor": {
686
+ left: "start",
687
+ right: "end",
688
+ center: "middle",
689
+ }[config.textAlign],
690
+ "dominant-baseline": "central",
691
+ "font-size": config["fontSize"] + "px",
692
+ "font-family": config["fontFamily"],
693
+ });
694
+ setAttribute(el, "x", x);
695
+ setAttribute(el, "y", y);
696
+ if (typeof deg == "number") {
697
+ deg = deg % 360;
698
+ setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
699
+ }
700
+ };
701
+ var initCircle$1 = function (el, cx, cy, r) {
702
+ if (el.nodeName.toLowerCase() !== "circle")
703
+ throw new Error("Need a <circle> !");
704
+ setAttribute(el, "cx", cx);
705
+ setAttribute(el, "cy", cy);
706
+ setAttribute(el, "r", r);
707
+ };
708
+ var initPath = function (el, path) {
709
+ if (el.nodeName.toLowerCase() !== "path")
710
+ throw new Error("Need a <path> !");
711
+ setAttribute(el, "d", path);
712
+ };
713
+ var initRect$1 = function (el, config, x, y, width, height) {
714
+ if (el.nodeName.toLowerCase() !== "path")
715
+ throw new Error("Need a <path> !");
716
+ var rectRadius = [];
717
+ if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
718
+ for (var index = 0; index < 4; index++) {
719
+ rectRadius.push.apply(rectRadius, config.rectRadius);
720
+ }
721
+ }
722
+ if (height < 0) {
723
+ height *= -1;
724
+ y -= height;
725
+ }
726
+ if (width < 0) {
727
+ width *= -1;
728
+ x -= width;
729
+ }
730
+ var d = "";
731
+ if (rectRadius.length >= 4) {
732
+ d = "M" + (x + rectRadius[0]) + " " + y;
733
+ d += "L" + (x + width - rectRadius[1]) + " " + y;
734
+ d += "A" + rectRadius[1] + " " + rectRadius[1] + " 0 0 1 " + (x + width) + " " + (y + rectRadius[1]);
735
+ d += "L" + (x + width) + " " + (y + height - rectRadius[2]);
736
+ d += "A" + rectRadius[2] + " " + rectRadius[2] + " 0 0 1 " + (x + width - rectRadius[2]) + " " + (y + height);
737
+ d += "L" + (x + rectRadius[3]) + " " + (y + height);
738
+ d += "A" + rectRadius[3] + " " + rectRadius[3] + " 0 0 1 " + x + " " + (y + height - rectRadius[3]);
739
+ d += "L" + x + " " + (y + rectRadius[0]);
740
+ d += "A" + rectRadius[0] + " " + rectRadius[0] + " 0 0 1 " + (x + rectRadius[0]) + " " + y;
741
+ }
742
+ else {
743
+ d = "M" + x + " " + y;
744
+ d += "L" + (x + width) + " " + y;
745
+ d += "L" + (x + width) + " " + (y + height);
746
+ d += "L" + x + " " + (y + height);
747
+ d += "Z";
748
+ }
749
+ setAttribute(el, "d", d);
750
+ };
751
+ var initArc$1 = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
752
+ if (el.nodeName.toLowerCase() !== "path")
753
+ throw new Error("Need a <path> !");
754
+ beginDeg = (beginDeg / 180) * Math.PI;
755
+ deg = (deg / 180) * Math.PI;
756
+ beginDeg = beginDeg % (Math.PI * 2);
757
+ if (r1 > r2) {
758
+ var temp = r1;
759
+ r1 = r2;
760
+ r2 = temp;
761
+ }
762
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
763
+ deg = Math.PI * 1.999999;
764
+ }
765
+ else {
766
+ deg = deg % (Math.PI * 2);
767
+ }
768
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
769
+ var f = endA - beginA > Math.PI ? 1 : 0;
770
+ var d = "M" + begInnerX + " " + begInnerY;
771
+ if (r < 0)
772
+ r = -r;
773
+ d +=
774
+ "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
775
+ if (config.arcEndCap == "round")
776
+ d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
777
+ else if (config.arcEndCap == "-round")
778
+ d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
779
+ else
780
+ d += "L" + endOuterX + " " + endOuterY;
781
+ d +=
782
+ "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
783
+ if (config.arcStartCap == "round")
784
+ d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
785
+ else if (config.arcStartCap == "-round")
786
+ d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
787
+ else
788
+ d += "L" + begInnerX + " " + begInnerY;
789
+ if (config.arcStartCap == "butt")
790
+ d += "Z";
791
+ setAttribute(el, "d", d);
792
+ });
786
793
  };
787
794
 
788
- var enhanceGradient$1 = function (gradient, gradientId) {
789
- var enhanceGradient = {
790
- "value": function () {
791
- return "url(#" + gradientId + ")";
792
- },
793
- "setColor": function (stop, color) {
794
- var stopEl = toNode("stop");
795
- gradient.appendChild(stopEl);
796
- setAttribute(stopEl, "offset", (stop * 100) + "%");
797
- setAttribute(stopEl, "style", "stop-color:" + color + ";");
798
- return enhanceGradient;
799
- }
800
- };
801
- return enhanceGradient;
802
- };
803
- var linearGradient$1 = function (el, x0, y0, x1, y1) {
804
- var defs = initDefs(el);
805
- var gradientId = "vislite-lg-" + new Date().valueOf() + "-" + Math.random();
806
- var linearGradient = toNode("linearGradient");
807
- defs.appendChild(linearGradient);
808
- setAttribute(linearGradient, "id", gradientId);
809
- setAttribute(linearGradient, "x1", x0 + "%");
810
- setAttribute(linearGradient, "y1", y0 + "%");
811
- setAttribute(linearGradient, "x2", x1 + "%");
812
- setAttribute(linearGradient, "y2", y1 + "%");
813
- return enhanceGradient$1(linearGradient, gradientId);
814
- };
815
- var radialGradient$1 = function (el, cx, cy, r) {
816
- var defs = initDefs(el);
817
- var gradientId = "vislite-rg-" + new Date().valueOf() + "-" + Math.random();
818
- var radialGradient = toNode("radialGradient");
819
- defs.appendChild(radialGradient);
820
- setAttribute(radialGradient, "id", gradientId);
821
- setAttribute(radialGradient, "cx", cx + "%");
822
- setAttribute(radialGradient, "cy", cy + "%");
823
- setAttribute(radialGradient, "r", r + "%");
824
- return enhanceGradient$1(radialGradient, gradientId);
795
+ var enhanceGradient$1 = function (gradient, gradientId) {
796
+ var enhanceGradient = {
797
+ "value": function () {
798
+ return "url(#" + gradientId + ")";
799
+ },
800
+ "setColor": function (stop, color) {
801
+ var stopEl = toNode("stop");
802
+ gradient.appendChild(stopEl);
803
+ setAttribute(stopEl, "offset", (stop * 100) + "%");
804
+ setAttribute(stopEl, "style", "stop-color:" + color + ";");
805
+ return enhanceGradient;
806
+ }
807
+ };
808
+ return enhanceGradient;
809
+ };
810
+ var linearGradient$1 = function (el, x0, y0, x1, y1) {
811
+ var defs = initDefs(el);
812
+ var gradientId = "visliteLg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
813
+ var linearGradient = toNode("linearGradient");
814
+ defs.appendChild(linearGradient);
815
+ setAttribute(linearGradient, "id", gradientId);
816
+ setAttribute(linearGradient, "x1", x0 + "%");
817
+ setAttribute(linearGradient, "y1", y0 + "%");
818
+ setAttribute(linearGradient, "x2", x1 + "%");
819
+ setAttribute(linearGradient, "y2", y1 + "%");
820
+ return enhanceGradient$1(linearGradient, gradientId);
821
+ };
822
+ var radialGradient$1 = function (el, cx, cy, r) {
823
+ var defs = initDefs(el);
824
+ var gradientId = "visliteRg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
825
+ var radialGradient = toNode("radialGradient");
826
+ defs.appendChild(radialGradient);
827
+ setAttribute(radialGradient, "id", gradientId);
828
+ setAttribute(radialGradient, "cx", cx + "%");
829
+ setAttribute(radialGradient, "cy", cy + "%");
830
+ setAttribute(radialGradient, "r", r + "%");
831
+ return enhanceGradient$1(radialGradient, gradientId);
825
832
  };
826
833
 
827
- function defaultFactory$1 () {
828
- return {
829
- fillStyle: "#000",
830
- strokeStyle: "#000",
831
- textAlign: "left",
832
- textBaseline: "middle",
833
- "fontSize": 16,
834
- "fontFamily": "sans-serif",
835
- "arcStartCap": "butt",
836
- "arcEndCap": "butt",
837
- lineDash: [],
838
- lineWidth: 1,
839
- lineCap: "butt",
840
- lineJoin: "miter",
841
- "rectRadius": []
842
- };
834
+ function defaultFactory$1 () {
835
+ return {
836
+ fillStyle: "rgb(0,0,0)",
837
+ strokeStyle: "rgb(0,0,0)",
838
+ textAlign: "left",
839
+ textBaseline: "middle",
840
+ "fontSize": 16,
841
+ "fontFamily": "sans-serif",
842
+ "arcStartCap": "butt",
843
+ "arcEndCap": "butt",
844
+ lineDash: [],
845
+ lineWidth: 1,
846
+ lineCap: "butt",
847
+ lineJoin: "miter",
848
+ "rectRadius": []
849
+ };
843
850
  }
844
851
 
845
- var SVG$1 = (function () {
846
- function SVG(svg) {
847
- this.name = "SVG";
848
- this.__config = defaultFactory$1();
849
- this.__path = "";
850
- this.__currentPosition = [];
851
- this.__svg = svg;
852
- }
853
- SVG.prototype.config = function (params) {
854
- if (typeof params !== "object") {
855
- return this.__config[params];
856
- }
857
- else {
858
- for (var key in params) {
859
- this.__config[key] = params[key];
860
- }
861
- }
862
- return this;
863
- };
864
- SVG.prototype.reset = function () {
865
- this.config(defaultFactory$1());
866
- return this;
867
- };
868
- SVG.prototype.useEl = function (el) {
869
- this.__useEl = el;
870
- return this;
871
- };
872
- SVG.prototype.getEl = function () {
873
- return this.__useEl;
874
- };
875
- SVG.prototype.appendEl = function (el, context) {
876
- context = context || this.__svg;
877
- if (typeof el == "string")
878
- el = toNode(el);
879
- context.appendChild(el);
880
- this.__useEl = el;
881
- return this;
882
- };
883
- SVG.prototype.appendBoard = function (el, context) {
884
- var _el = el;
885
- if (typeof el == "string")
886
- _el =
887
- {
888
- text: "text",
889
- path: "path",
890
- arc: "path",
891
- circle: "circle",
892
- rect: "rect",
893
- }[el] || "";
894
- if (_el == "")
895
- throw new Error("Unsupported drawing method:" + el);
896
- return this.appendEl(_el, context);
897
- };
898
- SVG.prototype.remove = function () {
899
- if (!this.__useEl) {
900
- throw new Error("Currently, no node can be deleted.");
901
- }
902
- else {
903
- this.__useEl.parentNode.removeChild(this.__useEl);
904
- }
905
- return this;
906
- };
907
- SVG.prototype.attr = function (params) {
908
- if (!this.__useEl)
909
- throw new Error("Currently, no node can be modified or viewed.");
910
- if (typeof params !== "object") {
911
- return getAttribute(this.__useEl, params);
912
- }
913
- else {
914
- for (var key in params) {
915
- setAttribute(this.__useEl, key, params[key]);
916
- }
917
- return this;
918
- }
919
- };
920
- SVG.prototype.fillText = function (text, x, y, deg) {
921
- if (deg === void 0) { deg = 0; }
922
- initText$1(this.__useEl, this.__config, x, y, deg);
923
- this.__useEl.textContent = text;
924
- fill(this.__useEl, this.__config);
925
- return this;
926
- };
927
- SVG.prototype.strokeText = function (text, x, y, deg) {
928
- if (deg === void 0) { deg = 0; }
929
- initText$1(this.__useEl, this.__config, x, y, deg);
930
- this.__useEl.textContent = text;
931
- stroke(this.__useEl, this.__config);
932
- return this;
933
- };
934
- SVG.prototype.fullText = function (text, x, y, deg) {
935
- if (deg === void 0) { deg = 0; }
936
- initText$1(this.__useEl, this.__config, x, y, deg);
937
- this.__useEl.textContent = text;
938
- full(this.__useEl, this.__config);
939
- return this;
940
- };
941
- SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
942
- initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
943
- fill(this.__useEl, this.__config);
944
- return this;
945
- };
946
- SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
947
- initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
948
- stroke(this.__useEl, this.__config);
949
- return this;
950
- };
951
- SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
952
- initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
953
- full(this.__useEl, this.__config);
954
- return this;
955
- };
956
- SVG.prototype.fillCircle = function (cx, cy, r) {
957
- initCircle$1(this.__useEl, cx, cy, r);
958
- fill(this.__useEl, this.__config);
959
- return this;
960
- };
961
- SVG.prototype.strokeCircle = function (cx, cy, r) {
962
- initCircle$1(this.__useEl, cx, cy, r);
963
- stroke(this.__useEl, this.__config);
964
- return this;
965
- };
966
- SVG.prototype.fullCircle = function (cx, cy, r) {
967
- initCircle$1(this.__useEl, cx, cy, r);
968
- full(this.__useEl, this.__config);
969
- return this;
970
- };
971
- SVG.prototype.fillRect = function (x, y, width, height) {
972
- initRect$1(this.__useEl, this.__config, x, y, width, height);
973
- fill(this.__useEl, this.__config);
974
- return this;
975
- };
976
- SVG.prototype.strokeRect = function (x, y, width, height) {
977
- initRect$1(this.__useEl, this.__config, x, y, width, height);
978
- stroke(this.__useEl, this.__config);
979
- return this;
980
- };
981
- SVG.prototype.fullRect = function (x, y, width, height) {
982
- initRect$1(this.__useEl, this.__config, x, y, width, height);
983
- full(this.__useEl, this.__config);
984
- return this;
985
- };
986
- SVG.prototype.beginPath = function () {
987
- this.__currentPosition = [];
988
- this.__path = "";
989
- return this;
990
- };
991
- SVG.prototype.closePath = function () {
992
- this.__path += "Z";
993
- return this;
994
- };
995
- SVG.prototype.moveTo = function (x, y) {
996
- this.__currentPosition = [x, y];
997
- this.__path += "M" + x + " " + y;
998
- return this;
999
- };
1000
- SVG.prototype.lineTo = function (x, y) {
1001
- this.__currentPosition = [x, y];
1002
- this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
1003
- return this;
1004
- };
1005
- SVG.prototype.fill = function () {
1006
- initPath(this.__useEl, this.__path);
1007
- fill(this.__useEl, this.__config);
1008
- return this;
1009
- };
1010
- SVG.prototype.stroke = function () {
1011
- initPath(this.__useEl, this.__path);
1012
- stroke(this.__useEl, this.__config);
1013
- return this;
1014
- };
1015
- SVG.prototype.full = function () {
1016
- initPath(this.__useEl, this.__path);
1017
- full(this.__useEl, this.__config);
1018
- return this;
1019
- };
1020
- SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
1021
- var begPosition = rotate$1(x, y, (beginDeg / 180) * Math.PI, x + r, y);
1022
- var endPosition = rotate$1(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
1023
- if (this.__path == "") {
1024
- this.__path += "M" + begPosition[0] + "," + begPosition[1];
1025
- }
1026
- else if (begPosition[0] != this.__currentPosition[0] ||
1027
- begPosition[1] != this.__currentPosition[1]) {
1028
- this.__path += "L" + begPosition[0] + "," + begPosition[1];
1029
- }
1030
- this.__path +=
1031
- "A" +
1032
- r +
1033
- "," +
1034
- r +
1035
- " 0 " +
1036
- (deg > 180 || deg < -180 ? 1 : 0) +
1037
- "," +
1038
- (deg > 0 ? 1 : 0) +
1039
- " " +
1040
- endPosition[0] +
1041
- "," +
1042
- endPosition[1];
1043
- return this;
1044
- };
1045
- SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1046
- this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
1047
- return this;
1048
- };
1049
- SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1050
- this.__path +=
1051
- "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
1052
- return this;
1053
- };
1054
- SVG.prototype.bind = function (eventType, callback) {
1055
- this.__useEl.addEventListener(eventType, function (event) {
1056
- callback.call(this, event, this);
1057
- }, false);
1058
- return this;
1059
- };
1060
- SVG.prototype.createLinearGradient = function (x0, y0, x1, y1) {
1061
- return linearGradient$1(this.__svg, x0, y0, x1, y1);
1062
- };
1063
- SVG.prototype.createRadialGradient = function (cx, cy, r) {
1064
- return radialGradient$1(this.__svg, cx, cy, r);
1065
- };
1066
- return SVG;
852
+ var SVG$1 = (function () {
853
+ function SVG(svg) {
854
+ this.name = "SVG";
855
+ this.__config = defaultFactory$1();
856
+ this.__path = "";
857
+ this.__currentPosition = [];
858
+ this.__svg = svg;
859
+ }
860
+ SVG.prototype.config = function (params) {
861
+ if (typeof params !== "object") {
862
+ return this.__config[params];
863
+ }
864
+ else {
865
+ for (var key in params) {
866
+ this.__config[key] = params[key];
867
+ }
868
+ }
869
+ return this;
870
+ };
871
+ SVG.prototype.reset = function () {
872
+ this.config(defaultFactory$1());
873
+ return this;
874
+ };
875
+ SVG.prototype.useEl = function (el) {
876
+ this.__useEl = el;
877
+ return this;
878
+ };
879
+ SVG.prototype.getEl = function () {
880
+ return this.__useEl;
881
+ };
882
+ SVG.prototype.appendEl = function (el, context) {
883
+ context = context || this.__svg;
884
+ if (typeof el == "string")
885
+ el = toNode(el);
886
+ context.appendChild(el);
887
+ this.__useEl = el;
888
+ return this;
889
+ };
890
+ SVG.prototype.appendBoard = function (el, context) {
891
+ var _el = el;
892
+ if (typeof el == "string")
893
+ _el =
894
+ {
895
+ text: "text",
896
+ path: "path",
897
+ arc: "path",
898
+ circle: "circle",
899
+ rect: "rect",
900
+ }[el] || "";
901
+ if (_el == "")
902
+ throw new Error("Unsupported drawing method:" + el);
903
+ return this.appendEl(_el, context);
904
+ };
905
+ SVG.prototype.remove = function () {
906
+ if (!this.__useEl) {
907
+ throw new Error("Currently, no node can be deleted.");
908
+ }
909
+ else {
910
+ this.__useEl.parentNode.removeChild(this.__useEl);
911
+ }
912
+ return this;
913
+ };
914
+ SVG.prototype.attr = function (params) {
915
+ if (!this.__useEl)
916
+ throw new Error("Currently, no node can be modified or viewed.");
917
+ if (typeof params !== "object") {
918
+ return getAttribute(this.__useEl, params);
919
+ }
920
+ else {
921
+ for (var key in params) {
922
+ setAttribute(this.__useEl, key, params[key]);
923
+ }
924
+ return this;
925
+ }
926
+ };
927
+ SVG.prototype.fillText = function (text, x, y, deg) {
928
+ if (deg === void 0) { deg = 0; }
929
+ initText$1(this.__useEl, this.__config, x, y, deg);
930
+ this.__useEl.textContent = text;
931
+ fill(this.__useEl, this.__config);
932
+ return this;
933
+ };
934
+ SVG.prototype.strokeText = function (text, x, y, deg) {
935
+ if (deg === void 0) { deg = 0; }
936
+ initText$1(this.__useEl, this.__config, x, y, deg);
937
+ this.__useEl.textContent = text;
938
+ stroke(this.__useEl, this.__config);
939
+ return this;
940
+ };
941
+ SVG.prototype.fullText = function (text, x, y, deg) {
942
+ if (deg === void 0) { deg = 0; }
943
+ initText$1(this.__useEl, this.__config, x, y, deg);
944
+ this.__useEl.textContent = text;
945
+ full(this.__useEl, this.__config);
946
+ return this;
947
+ };
948
+ SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
949
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
950
+ fill(this.__useEl, this.__config);
951
+ return this;
952
+ };
953
+ SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
954
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
955
+ stroke(this.__useEl, this.__config);
956
+ return this;
957
+ };
958
+ SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
959
+ initArc$1(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
960
+ full(this.__useEl, this.__config);
961
+ return this;
962
+ };
963
+ SVG.prototype.fillCircle = function (cx, cy, r) {
964
+ initCircle$1(this.__useEl, cx, cy, r);
965
+ fill(this.__useEl, this.__config);
966
+ return this;
967
+ };
968
+ SVG.prototype.strokeCircle = function (cx, cy, r) {
969
+ initCircle$1(this.__useEl, cx, cy, r);
970
+ stroke(this.__useEl, this.__config);
971
+ return this;
972
+ };
973
+ SVG.prototype.fullCircle = function (cx, cy, r) {
974
+ initCircle$1(this.__useEl, cx, cy, r);
975
+ full(this.__useEl, this.__config);
976
+ return this;
977
+ };
978
+ SVG.prototype.fillRect = function (x, y, width, height) {
979
+ initRect$1(this.__useEl, this.__config, x, y, width, height);
980
+ fill(this.__useEl, this.__config);
981
+ return this;
982
+ };
983
+ SVG.prototype.strokeRect = function (x, y, width, height) {
984
+ initRect$1(this.__useEl, this.__config, x, y, width, height);
985
+ stroke(this.__useEl, this.__config);
986
+ return this;
987
+ };
988
+ SVG.prototype.fullRect = function (x, y, width, height) {
989
+ initRect$1(this.__useEl, this.__config, x, y, width, height);
990
+ full(this.__useEl, this.__config);
991
+ return this;
992
+ };
993
+ SVG.prototype.beginPath = function () {
994
+ this.__currentPosition = [];
995
+ this.__path = "";
996
+ return this;
997
+ };
998
+ SVG.prototype.closePath = function () {
999
+ this.__path += "Z";
1000
+ return this;
1001
+ };
1002
+ SVG.prototype.moveTo = function (x, y) {
1003
+ this.__currentPosition = [x, y];
1004
+ this.__path += "M" + x + " " + y;
1005
+ return this;
1006
+ };
1007
+ SVG.prototype.lineTo = function (x, y) {
1008
+ this.__currentPosition = [x, y];
1009
+ this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
1010
+ return this;
1011
+ };
1012
+ SVG.prototype.fill = function () {
1013
+ initPath(this.__useEl, this.__path);
1014
+ fill(this.__useEl, this.__config);
1015
+ return this;
1016
+ };
1017
+ SVG.prototype.stroke = function () {
1018
+ initPath(this.__useEl, this.__path);
1019
+ stroke(this.__useEl, this.__config);
1020
+ return this;
1021
+ };
1022
+ SVG.prototype.full = function () {
1023
+ initPath(this.__useEl, this.__path);
1024
+ full(this.__useEl, this.__config);
1025
+ return this;
1026
+ };
1027
+ SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
1028
+ var begPosition = rotate$1(x, y, (beginDeg / 180) * Math.PI, x + r, y);
1029
+ var endPosition = rotate$1(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
1030
+ if (this.__path == "") {
1031
+ this.__path += "M" + begPosition[0] + "," + begPosition[1];
1032
+ }
1033
+ else if (begPosition[0] != this.__currentPosition[0] ||
1034
+ begPosition[1] != this.__currentPosition[1]) {
1035
+ this.__path += "L" + begPosition[0] + "," + begPosition[1];
1036
+ }
1037
+ this.__path +=
1038
+ "A" +
1039
+ r +
1040
+ "," +
1041
+ r +
1042
+ " 0 " +
1043
+ (deg > 180 || deg < -180 ? 1 : 0) +
1044
+ "," +
1045
+ (deg > 0 ? 1 : 0) +
1046
+ " " +
1047
+ endPosition[0] +
1048
+ "," +
1049
+ endPosition[1];
1050
+ return this;
1051
+ };
1052
+ SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1053
+ this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
1054
+ return this;
1055
+ };
1056
+ SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1057
+ this.__path +=
1058
+ "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
1059
+ return this;
1060
+ };
1061
+ SVG.prototype.bind = function (eventType, callback) {
1062
+ this.__useEl.addEventListener(eventType, function (event) {
1063
+ callback.call(this, event, this);
1064
+ }, false);
1065
+ return this;
1066
+ };
1067
+ SVG.prototype.createLinearGradient = function (x0, y0, x1, y1) {
1068
+ return linearGradient$1(this.__svg, x0, y0, x1, y1);
1069
+ };
1070
+ SVG.prototype.createRadialGradient = function (cx, cy, r) {
1071
+ return radialGradient$1(this.__svg, cx, cy, r);
1072
+ };
1073
+ return SVG;
1067
1074
  }());
1068
1075
 
1069
- var SVG = (function (_super) {
1070
- __extends(SVG, _super);
1071
- function SVG(el) {
1072
- if (!el) {
1073
- throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
1074
- }
1075
- var width = el.clientWidth, height = el.clientHeight;
1076
- var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
1077
- el.appendChild(ViewSVG);
1078
- ViewSVG.setAttribute("width", width + "");
1079
- ViewSVG.setAttribute("height", height + "");
1080
- ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
1081
- return _super.call(this, ViewSVG) || this;
1082
- }
1083
- return SVG;
1076
+ var SVG = (function (_super) {
1077
+ __extends(SVG, _super);
1078
+ function SVG(el) {
1079
+ var _this = this;
1080
+ if (!el) {
1081
+ throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
1082
+ }
1083
+ var width = el.clientWidth, height = el.clientHeight;
1084
+ var ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
1085
+ el.appendChild(ViewSVG);
1086
+ ViewSVG.setAttribute("width", width + "");
1087
+ ViewSVG.setAttribute("height", height + "");
1088
+ ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
1089
+ _this = _super.call(this, ViewSVG) || this;
1090
+ _this.__el = el;
1091
+ return _this;
1092
+ }
1093
+ SVG.prototype.toDataURL = function () {
1094
+ var _this = this;
1095
+ return new Promise(function (resolve) {
1096
+ var width = _this.__el.clientWidth, height = _this.__el.clientHeight;
1097
+ var img = document.createElement('img');
1098
+ img.setAttribute('width', width + "");
1099
+ img.setAttribute('height', height + "");
1100
+ var base64_svg = "data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' width='" + width + "' height='" + height + "'>" + _this.__svg.innerHTML.replace(/"/g, "'") + "</svg>";
1101
+ img.setAttribute('src', base64_svg);
1102
+ setTimeout(function () {
1103
+ var canvas = document.createElement('canvas');
1104
+ canvas.setAttribute('width', width + "");
1105
+ canvas.setAttribute('height', height + "");
1106
+ var painter = canvas.getContext('2d');
1107
+ if (painter)
1108
+ painter.drawImage(img, 0, 0, width, height);
1109
+ resolve(canvas.toDataURL());
1110
+ }, 100);
1111
+ });
1112
+ };
1113
+ return SVG;
1084
1114
  }(SVG$1));
1085
1115
 
1086
- var initText = function (painter, config, x, y, deg) {
1087
- painter.beginPath();
1088
- painter.translate(x, y);
1089
- painter.rotate(deg);
1090
- painter.font =
1091
- config.fontStyle +
1092
- " " +
1093
- config.fontWeight +
1094
- " " +
1095
- config.fontSize +
1096
- "px " +
1097
- config.fontFamily;
1098
- return painter;
1099
- };
1100
- var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
1101
- if (r1 > r2) {
1102
- var temp = r1;
1103
- r1 = r2;
1104
- r2 = temp;
1105
- }
1106
- beginDeg = beginDeg % (Math.PI * 2);
1107
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
1108
- deg = Math.PI * 2;
1109
- }
1110
- else {
1111
- deg = deg % (Math.PI * 2);
1112
- }
1113
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
1114
- if (r < 0)
1115
- r = -r;
1116
- painter.beginPath();
1117
- painter.moveTo(begInnerX, begInnerY);
1118
- painter.arc(cx, cy, r1, beginA, endA, false);
1119
- if (config.arcEndCap == "round")
1120
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
1121
- else if (config.arcEndCap == "-round")
1122
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
1123
- else
1124
- painter.lineTo(endOuterX, endOuterY);
1125
- painter.arc(cx, cy, r2, endA, beginA, true);
1126
- if (config.arcStartCap == "round")
1127
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
1128
- else if (config.arcStartCap == "-round")
1129
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
1130
- else
1131
- painter.lineTo(begInnerX, begInnerY);
1132
- });
1133
- if (config.arcStartCap == "butt")
1134
- painter.closePath();
1135
- return painter;
1136
- };
1137
- var initCircle = function (painter, cx, cy, r) {
1138
- painter.beginPath();
1139
- painter.moveTo(cx + r, cy);
1140
- painter.arc(cx, cy, r, 0, Math.PI * 2);
1141
- return painter;
1142
- };
1143
- var initRect = function (painter, config, x, y, width, height) {
1144
- painter.beginPath();
1145
- var rectRadius = [];
1146
- if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
1147
- for (var index = 0; index < 4; index++) {
1148
- rectRadius.push.apply(rectRadius, config.rectRadius);
1149
- }
1150
- }
1151
- if (rectRadius.length >= 4) {
1152
- painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
1153
- painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
1154
- painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
1155
- painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
1156
- painter.closePath();
1157
- }
1158
- else {
1159
- painter.rect(x, y, width, height);
1160
- }
1161
- return painter;
1116
+ var initText = function (painter, config, x, y, deg) {
1117
+ painter.beginPath();
1118
+ painter.translate(x, y);
1119
+ painter.rotate(deg);
1120
+ painter.font =
1121
+ config.fontStyle +
1122
+ " " +
1123
+ config.fontWeight +
1124
+ " " +
1125
+ config.fontSize +
1126
+ "px " +
1127
+ config.fontFamily;
1128
+ return painter;
1129
+ };
1130
+ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
1131
+ if (r1 > r2) {
1132
+ var temp = r1;
1133
+ r1 = r2;
1134
+ r2 = temp;
1135
+ }
1136
+ beginDeg = beginDeg % (Math.PI * 2);
1137
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
1138
+ deg = Math.PI * 2;
1139
+ }
1140
+ else {
1141
+ deg = deg % (Math.PI * 2);
1142
+ }
1143
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
1144
+ if (r < 0)
1145
+ r = -r;
1146
+ painter.beginPath();
1147
+ painter.moveTo(begInnerX, begInnerY);
1148
+ painter.arc(cx, cy, r1, beginA, endA, false);
1149
+ if (config.arcEndCap == "round")
1150
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
1151
+ else if (config.arcEndCap == "-round")
1152
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
1153
+ else
1154
+ painter.lineTo(endOuterX, endOuterY);
1155
+ painter.arc(cx, cy, r2, endA, beginA, true);
1156
+ if (config.arcStartCap == "round")
1157
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
1158
+ else if (config.arcStartCap == "-round")
1159
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
1160
+ else
1161
+ painter.lineTo(begInnerX, begInnerY);
1162
+ });
1163
+ if (config.arcStartCap == "butt")
1164
+ painter.closePath();
1165
+ return painter;
1166
+ };
1167
+ var initCircle = function (painter, cx, cy, r) {
1168
+ painter.beginPath();
1169
+ painter.moveTo(cx + r, cy);
1170
+ painter.arc(cx, cy, r, 0, Math.PI * 2);
1171
+ return painter;
1172
+ };
1173
+ var initRect = function (painter, config, x, y, width, height) {
1174
+ painter.beginPath();
1175
+ var rectRadius = [];
1176
+ if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
1177
+ for (var index = 0; index < 4; index++) {
1178
+ rectRadius.push.apply(rectRadius, config.rectRadius);
1179
+ }
1180
+ }
1181
+ if (rectRadius.length >= 4) {
1182
+ painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
1183
+ painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
1184
+ painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
1185
+ painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
1186
+ painter.closePath();
1187
+ }
1188
+ else {
1189
+ painter.rect(x, y, width, height);
1190
+ }
1191
+ return painter;
1162
1192
  };
1163
1193
 
1164
- function texts (painter, contents, width, height, doback) {
1165
- var lineNumber = 0, content = "";
1166
- for (var i = 0; i < contents.length; i++) {
1167
- if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
1168
- lineNumber += 1;
1169
- doback(content, (lineNumber - 0.5) * height);
1170
- content = contents[i];
1171
- }
1172
- else if (i == contents.length - 1) {
1173
- lineNumber += 1;
1174
- doback(content + contents[i], (lineNumber - 0.5) * height);
1175
- }
1176
- else {
1177
- content += contents[i];
1178
- }
1179
- }
1180
- return lineNumber * height;
1194
+ function texts (painter, contents, width, height, doback) {
1195
+ var lineNumber = 0, content = "";
1196
+ for (var i = 0; i < contents.length; i++) {
1197
+ if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
1198
+ lineNumber += 1;
1199
+ doback(content, (lineNumber - 0.5) * height);
1200
+ content = contents[i];
1201
+ }
1202
+ else if (i == contents.length - 1) {
1203
+ lineNumber += 1;
1204
+ doback(content + contents[i], (lineNumber - 0.5) * height);
1205
+ }
1206
+ else {
1207
+ content += contents[i];
1208
+ }
1209
+ }
1210
+ return lineNumber * height;
1181
1211
  }
1182
1212
 
1183
- function defaultFactory (type) {
1184
- var special = {
1185
- "fontSize": 16,
1186
- "fontFamily": "sans-serif",
1187
- "fontWeight": 400,
1188
- "fontStyle": "normal",
1189
- "arcStartCap": 'butt',
1190
- "arcEndCap": 'butt',
1191
- "rectRadius": []
1192
- };
1193
- var init = {
1194
- "fillStyle": 'black',
1195
- "strokeStyle": 'black',
1196
- "lineWidth": 1,
1197
- "lineCap": "butt",
1198
- "lineJoin": "miter",
1199
- "lineDash": [],
1200
- "textAlign": 'left',
1201
- "textBaseline": 'middle',
1202
- "shadowBlur": 0,
1203
- "shadowColor": "black"
1204
- };
1205
- if (type == 'special')
1206
- return special;
1207
- else if (type == 'init')
1208
- return init;
1209
- else
1210
- return __assign(__assign({}, special), init);
1213
+ function defaultFactory (type) {
1214
+ var special = {
1215
+ "fontSize": 16,
1216
+ "fontFamily": "sans-serif",
1217
+ "fontWeight": 400,
1218
+ "fontStyle": "normal",
1219
+ "arcStartCap": 'butt',
1220
+ "arcEndCap": 'butt',
1221
+ "rectRadius": []
1222
+ };
1223
+ var init = {
1224
+ "fillStyle": 'black',
1225
+ "strokeStyle": 'black',
1226
+ "lineWidth": 1,
1227
+ "lineCap": "butt",
1228
+ "lineJoin": "miter",
1229
+ "lineDash": [],
1230
+ "textAlign": 'left',
1231
+ "textBaseline": 'middle',
1232
+ "shadowBlur": 0,
1233
+ "shadowColor": "black"
1234
+ };
1235
+ if (type == 'special')
1236
+ return special;
1237
+ else if (type == 'init')
1238
+ return init;
1239
+ else
1240
+ return __assign(__assign({}, special), init);
1211
1241
  }
1212
1242
 
1213
- var Painter = (function () {
1214
- function Painter(canvas, opts, region, isPainter, scaleSize) {
1215
- if (opts === void 0) { opts = {}; }
1216
- if (isPainter === void 0) { isPainter = false; }
1217
- this.__region = null;
1218
- this.__onlyRegion = false;
1219
- this.__onlyView = false;
1220
- this.__specialConfig = defaultFactory("special");
1221
- this.__initConfig = defaultFactory("init");
1222
- this.painter = canvas.getContext("2d", opts);
1223
- this.__region = region;
1224
- this.__isPainter = isPainter;
1225
- this.painter.textBaseline = 'middle';
1226
- this.painter.textAlign = 'left';
1227
- }
1228
- Painter.prototype.useConfig = function (key, value) {
1229
- if (this.__region && !this.__onlyView) {
1230
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
1231
- this.__region.useConfig(key, value);
1232
- }
1233
- }
1234
- if (this.__isPainter && this.__onlyRegion)
1235
- return this;
1236
- if (key == 'lineDash') {
1237
- if (this.painter.setLineDash)
1238
- this.painter.setLineDash(value);
1239
- }
1240
- else if (key in this.__specialConfig) {
1241
- if (key == 'fontSize') {
1242
- value = Math.round(value);
1243
- }
1244
- this.__specialConfig[key] = value;
1245
- }
1246
- else if (key in this.__initConfig) {
1247
- this.painter[key] = value;
1248
- }
1249
- else {
1250
- throw new Error('Illegal configuration item of painter : ' + key + " !");
1251
- }
1252
- return this;
1253
- };
1254
- Painter.prototype.fillText = function (text, x, y, deg) {
1255
- if (deg === void 0) { deg = 0; }
1256
- if (this.__region && !this.__onlyView)
1257
- this.__region.fillText(text, x, y, deg);
1258
- if (this.__isPainter && this.__onlyRegion)
1259
- return this;
1260
- this.painter.save();
1261
- initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
1262
- this.painter.restore();
1263
- return this;
1264
- };
1265
- Painter.prototype.strokeText = function (text, x, y, deg) {
1266
- if (deg === void 0) { deg = 0; }
1267
- if (this.__region && !this.__onlyView)
1268
- this.__region.strokeText(text, x, y, deg);
1269
- if (this.__isPainter && this.__onlyRegion)
1270
- return this;
1271
- this.painter.save();
1272
- initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
1273
- this.painter.restore();
1274
- return this;
1275
- };
1276
- Painter.prototype.fullText = function (text, x, y, deg) {
1277
- if (deg === void 0) { deg = 0; }
1278
- if (this.__region && !this.__onlyView)
1279
- this.__region.fullText(text, x, y, deg);
1280
- if (this.__isPainter && this.__onlyRegion)
1281
- return this;
1282
- this.painter.save();
1283
- initText(this.painter, this.__specialConfig, x, y, deg);
1284
- this.painter.fillText(text, 0, 0);
1285
- this.painter.strokeText(text, 0, 0);
1286
- this.painter.restore();
1287
- return this;
1288
- };
1289
- Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
1290
- var _this = this;
1291
- if (lineHeight === void 0) { lineHeight = 1.2; }
1292
- if (deg === void 0) { deg = 0; }
1293
- var h = 0;
1294
- if (this.__region && !this.__onlyView)
1295
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1296
- if (this.__isPainter && this.__onlyRegion)
1297
- return h;
1298
- this.painter.save();
1299
- initText(this.painter, this.__specialConfig, x, y, deg);
1300
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1301
- _this.painter.fillText(content, 0, top);
1302
- });
1303
- this.painter.restore();
1304
- return height;
1305
- };
1306
- Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
1307
- var _this = this;
1308
- if (lineHeight === void 0) { lineHeight = 1.2; }
1309
- if (deg === void 0) { deg = 0; }
1310
- var h = 0;
1311
- if (this.__region && !this.__onlyView)
1312
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1313
- if (this.__isPainter && this.__onlyRegion)
1314
- return h;
1315
- this.painter.save();
1316
- initText(this.painter, this.__specialConfig, x, y, deg);
1317
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1318
- _this.painter.strokeText(content, 0, top);
1319
- });
1320
- this.painter.restore();
1321
- return height;
1322
- };
1323
- Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
1324
- var _this = this;
1325
- if (lineHeight === void 0) { lineHeight = 1.2; }
1326
- if (deg === void 0) { deg = 0; }
1327
- var h = 0;
1328
- if (this.__region && !this.__onlyView)
1329
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1330
- if (this.__isPainter && this.__onlyRegion)
1331
- return h;
1332
- this.painter.save();
1333
- initText(this.painter, this.__specialConfig, x, y, deg);
1334
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1335
- _this.painter.fillText(content, 0, top);
1336
- _this.painter.strokeText(content, 0, top);
1337
- });
1338
- this.painter.restore();
1339
- return height;
1340
- };
1341
- Painter.prototype.beginPath = function () {
1342
- if (this.__region && !this.__onlyView)
1343
- this.__region.beginPath();
1344
- if (this.__isPainter && this.__onlyRegion)
1345
- return this;
1346
- this.painter.beginPath();
1347
- return this;
1348
- };
1349
- Painter.prototype.closePath = function () {
1350
- if (this.__region && !this.__onlyView)
1351
- this.__region.closePath();
1352
- if (this.__isPainter && this.__onlyRegion)
1353
- return this;
1354
- this.painter.closePath();
1355
- return this;
1356
- };
1357
- Painter.prototype.moveTo = function (x, y) {
1358
- if (this.__region && !this.__onlyView)
1359
- this.__region.moveTo(x, y);
1360
- if (this.__isPainter && this.__onlyRegion)
1361
- return this;
1362
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1363
- return this;
1364
- };
1365
- Painter.prototype.lineTo = function (x, y) {
1366
- if (this.__region && !this.__onlyView)
1367
- this.__region.lineTo(x, y);
1368
- if (this.__isPainter && this.__onlyRegion)
1369
- return this;
1370
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1371
- return this;
1372
- };
1373
- Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
1374
- if (this.__region && !this.__onlyView)
1375
- this.__region.arc(x, y, r, beginDeg, deg);
1376
- if (this.__isPainter && this.__onlyRegion)
1377
- return this;
1378
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
1379
- return this;
1380
- };
1381
- Painter.prototype.fill = function () {
1382
- if (this.__region && !this.__onlyView)
1383
- this.__region.fill();
1384
- if (this.__isPainter && this.__onlyRegion)
1385
- return this;
1386
- this.painter.fill();
1387
- return this;
1388
- };
1389
- Painter.prototype.stroke = function () {
1390
- if (this.__region && !this.__onlyView)
1391
- this.__region.stroke();
1392
- if (this.__isPainter && this.__onlyRegion)
1393
- return this;
1394
- this.painter.stroke();
1395
- return this;
1396
- };
1397
- Painter.prototype.full = function () {
1398
- if (this.__region && !this.__onlyView)
1399
- this.__region.full();
1400
- if (this.__isPainter && this.__onlyRegion)
1401
- return this;
1402
- this.painter.fill();
1403
- this.painter.stroke();
1404
- return this;
1405
- };
1406
- Painter.prototype.save = function () {
1407
- if (this.__region && !this.__onlyView)
1408
- this.__region.save();
1409
- if (this.__isPainter && this.__onlyRegion)
1410
- return this;
1411
- this.painter.save();
1412
- return this;
1413
- };
1414
- Painter.prototype.restore = function () {
1415
- if (this.__region && !this.__onlyView)
1416
- this.__region.restore();
1417
- if (this.__isPainter && this.__onlyRegion)
1418
- return this;
1419
- this.painter.restore();
1420
- return this;
1421
- };
1422
- Painter.prototype.clip = function () {
1423
- if (this.__region && !this.__onlyView)
1424
- this.__region.clip();
1425
- if (this.__isPainter && this.__onlyRegion)
1426
- return this;
1427
- this.painter.clip();
1428
- return this;
1429
- };
1430
- Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1431
- if (this.__region && !this.__onlyView)
1432
- this.__region.quadraticCurveTo(cpx, cpy, x, y);
1433
- if (this.__isPainter && this.__onlyRegion)
1434
- return this;
1435
- this.painter.quadraticCurveTo(cpx, cpy, x, y);
1436
- return this;
1437
- };
1438
- Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1439
- if (this.__region && !this.__onlyView)
1440
- this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1441
- if (this.__isPainter && this.__onlyRegion)
1442
- return this;
1443
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1444
- return this;
1445
- };
1446
- Painter.prototype.clearRect = function (x, y, w, h) {
1447
- if (this.__region && !this.__onlyView)
1448
- this.__region.clearRect(x, y, w, h);
1449
- if (this.__isPainter && this.__onlyRegion)
1450
- return this;
1451
- this.painter.clearRect(x, y, w, h);
1452
- return this;
1453
- };
1454
- Painter.prototype.clearCircle = function (cx, cy, r) {
1455
- if (this.__region && !this.__onlyView)
1456
- this.__region.clearCircle(cx, cy, r);
1457
- if (this.__isPainter && this.__onlyRegion)
1458
- return this;
1459
- this.painter.beginPath();
1460
- this.painter.globalCompositeOperation = "destination-out";
1461
- this.painter.arc(cx, cy, r, 0, Math.PI * 2);
1462
- this.painter.fill();
1463
- this.painter.globalCompositeOperation = "source-over";
1464
- this.painter.closePath();
1465
- return this;
1466
- };
1467
- Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
1468
- if (this.__region && !this.__onlyView)
1469
- this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
1470
- if (this.__isPainter && this.__onlyRegion)
1471
- return this;
1472
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
1473
- return this;
1474
- };
1475
- Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
1476
- if (this.__region && !this.__onlyView)
1477
- this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
1478
- if (this.__isPainter && this.__onlyRegion)
1479
- return this;
1480
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
1481
- return this;
1482
- };
1483
- Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
1484
- if (this.__region && !this.__onlyView)
1485
- this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
1486
- if (this.__isPainter && this.__onlyRegion)
1487
- return this;
1488
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
1489
- this.painter.fill();
1490
- this.painter.stroke();
1491
- return this;
1492
- };
1493
- Painter.prototype.fillCircle = function (cx, cy, r) {
1494
- if (this.__region && !this.__onlyView)
1495
- this.__region.fillCircle(cx, cy, r);
1496
- if (this.__isPainter && this.__onlyRegion)
1497
- return this;
1498
- initCircle(this.painter, cx, cy, r).fill();
1499
- return this;
1500
- };
1501
- Painter.prototype.strokeCircle = function (cx, cy, r) {
1502
- if (this.__region && !this.__onlyView)
1503
- this.__region.strokeCircle(cx, cy, r);
1504
- if (this.__isPainter && this.__onlyRegion)
1505
- return this;
1506
- initCircle(this.painter, cx, cy, r).stroke();
1507
- return this;
1508
- };
1509
- Painter.prototype.fullCircle = function (cx, cy, r) {
1510
- if (this.__region && !this.__onlyView)
1511
- this.__region.fullCircle(cx, cy, r);
1512
- if (this.__isPainter && this.__onlyRegion)
1513
- return this;
1514
- initCircle(this.painter, cx, cy, r);
1515
- this.painter.fill();
1516
- this.painter.stroke();
1517
- return this;
1518
- };
1519
- Painter.prototype.fillRect = function (x, y, width, height) {
1520
- if (this.__region && !this.__onlyView)
1521
- this.__region.fillRect(x, y, width, height);
1522
- if (this.__isPainter && this.__onlyRegion)
1523
- return this;
1524
- initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
1525
- return this;
1526
- };
1527
- Painter.prototype.strokeRect = function (x, y, width, height) {
1528
- if (this.__region && !this.__onlyView)
1529
- this.__region.strokeRect(x, y, width, height);
1530
- if (this.__isPainter && this.__onlyRegion)
1531
- return this;
1532
- initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
1533
- return this;
1534
- };
1535
- Painter.prototype.fullRect = function (x, y, width, height) {
1536
- if (this.__region && !this.__onlyView)
1537
- this.__region.fullRect(x, y, width, height);
1538
- if (this.__isPainter && this.__onlyRegion)
1539
- return this;
1540
- initRect(this.painter, this.__specialConfig, x, y, width, height);
1541
- this.painter.fill();
1542
- this.painter.stroke();
1543
- return this;
1544
- };
1545
- Painter.prototype.draw = function () {
1546
- return Promise.resolve();
1547
- };
1548
- Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
1549
- var _this = this;
1550
- if (isImage === void 0) { isImage = false; }
1551
- return new Promise(function (resolve) {
1552
- if (_this.__region && !_this.__onlyView) {
1553
- _this.__region.fillRect(x, y, w, h);
1554
- }
1555
- if (_this.__isPainter && _this.__onlyRegion) {
1556
- resolve({});
1557
- return;
1558
- }
1559
- if (typeof img == 'string' && !isImage) {
1560
- var imgInstance_1 = new Image();
1561
- imgInstance_1.onload = function () {
1562
- _this.painter.drawImage(imgInstance_1, x, y, w, h);
1563
- resolve({});
1564
- };
1565
- imgInstance_1.src = img;
1566
- }
1567
- else {
1568
- _this.painter.drawImage(img, x, y, w, h);
1569
- resolve({});
1570
- }
1571
- });
1572
- };
1573
- Painter.prototype.install = function (methods) {
1574
- var _this = this;
1575
- var _loop_1 = function (key) {
1576
- if (key in this_1) {
1577
- throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
1578
- }
1579
- else {
1580
- this_1[key] = function () {
1581
- var args = [];
1582
- for (var _i = 0; _i < arguments.length; _i++) {
1583
- args[_i] = arguments[_i];
1584
- }
1585
- var value = methods[key].apply(_this, args);
1586
- if (value != void 0)
1587
- return value;
1588
- return _this;
1589
- };
1590
- }
1591
- };
1592
- var this_1 = this;
1593
- for (var key in methods) {
1594
- _loop_1(key);
1595
- }
1596
- return this;
1597
- };
1598
- return Painter;
1243
+ var Painter = (function () {
1244
+ function Painter(canvas, opts, region, isPainter, scaleSize) {
1245
+ if (opts === void 0) { opts = {}; }
1246
+ if (isPainter === void 0) { isPainter = false; }
1247
+ this.__region = null;
1248
+ this.__onlyRegion = false;
1249
+ this.__onlyView = false;
1250
+ this.__specialConfig = defaultFactory("special");
1251
+ this.__initConfig = defaultFactory("init");
1252
+ this.painter = canvas.getContext("2d", opts);
1253
+ this.__region = region;
1254
+ this.__isPainter = isPainter;
1255
+ this.painter.textBaseline = 'middle';
1256
+ this.painter.textAlign = 'left';
1257
+ }
1258
+ Painter.prototype.useConfig = function (key, value) {
1259
+ if (this.__region && !this.__onlyView) {
1260
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
1261
+ this.__region.useConfig(key, value);
1262
+ }
1263
+ }
1264
+ if (this.__isPainter && this.__onlyRegion)
1265
+ return this;
1266
+ if (key == 'lineDash') {
1267
+ if (this.painter.setLineDash)
1268
+ this.painter.setLineDash(value);
1269
+ }
1270
+ else if (key in this.__specialConfig) {
1271
+ if (key == 'fontSize') {
1272
+ value = Math.round(value);
1273
+ }
1274
+ this.__specialConfig[key] = value;
1275
+ }
1276
+ else if (key in this.__initConfig) {
1277
+ this.painter[key] = value;
1278
+ }
1279
+ else {
1280
+ throw new Error('Illegal configuration item of painter : ' + key + " !");
1281
+ }
1282
+ return this;
1283
+ };
1284
+ Painter.prototype.fillText = function (text, x, y, deg) {
1285
+ if (deg === void 0) { deg = 0; }
1286
+ if (this.__region && !this.__onlyView)
1287
+ this.__region.fillText(text, x, y, deg);
1288
+ if (this.__isPainter && this.__onlyRegion)
1289
+ return this;
1290
+ this.painter.save();
1291
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
1292
+ this.painter.restore();
1293
+ return this;
1294
+ };
1295
+ Painter.prototype.strokeText = function (text, x, y, deg) {
1296
+ if (deg === void 0) { deg = 0; }
1297
+ if (this.__region && !this.__onlyView)
1298
+ this.__region.strokeText(text, x, y, deg);
1299
+ if (this.__isPainter && this.__onlyRegion)
1300
+ return this;
1301
+ this.painter.save();
1302
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
1303
+ this.painter.restore();
1304
+ return this;
1305
+ };
1306
+ Painter.prototype.fullText = function (text, x, y, deg) {
1307
+ if (deg === void 0) { deg = 0; }
1308
+ if (this.__region && !this.__onlyView)
1309
+ this.__region.fullText(text, x, y, deg);
1310
+ if (this.__isPainter && this.__onlyRegion)
1311
+ return this;
1312
+ this.painter.save();
1313
+ initText(this.painter, this.__specialConfig, x, y, deg);
1314
+ this.painter.fillText(text, 0, 0);
1315
+ this.painter.strokeText(text, 0, 0);
1316
+ this.painter.restore();
1317
+ return this;
1318
+ };
1319
+ Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
1320
+ var _this = this;
1321
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1322
+ if (deg === void 0) { deg = 0; }
1323
+ var h = 0;
1324
+ if (this.__region && !this.__onlyView)
1325
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1326
+ if (this.__isPainter && this.__onlyRegion)
1327
+ return h;
1328
+ this.painter.save();
1329
+ initText(this.painter, this.__specialConfig, x, y, deg);
1330
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1331
+ _this.painter.fillText(content, 0, top);
1332
+ });
1333
+ this.painter.restore();
1334
+ return height;
1335
+ };
1336
+ Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
1337
+ var _this = this;
1338
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1339
+ if (deg === void 0) { deg = 0; }
1340
+ var h = 0;
1341
+ if (this.__region && !this.__onlyView)
1342
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1343
+ if (this.__isPainter && this.__onlyRegion)
1344
+ return h;
1345
+ this.painter.save();
1346
+ initText(this.painter, this.__specialConfig, x, y, deg);
1347
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1348
+ _this.painter.strokeText(content, 0, top);
1349
+ });
1350
+ this.painter.restore();
1351
+ return height;
1352
+ };
1353
+ Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
1354
+ var _this = this;
1355
+ if (lineHeight === void 0) { lineHeight = 1.2; }
1356
+ if (deg === void 0) { deg = 0; }
1357
+ var h = 0;
1358
+ if (this.__region && !this.__onlyView)
1359
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
1360
+ if (this.__isPainter && this.__onlyRegion)
1361
+ return h;
1362
+ this.painter.save();
1363
+ initText(this.painter, this.__specialConfig, x, y, deg);
1364
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
1365
+ _this.painter.fillText(content, 0, top);
1366
+ _this.painter.strokeText(content, 0, top);
1367
+ });
1368
+ this.painter.restore();
1369
+ return height;
1370
+ };
1371
+ Painter.prototype.beginPath = function () {
1372
+ if (this.__region && !this.__onlyView)
1373
+ this.__region.beginPath();
1374
+ if (this.__isPainter && this.__onlyRegion)
1375
+ return this;
1376
+ this.painter.beginPath();
1377
+ return this;
1378
+ };
1379
+ Painter.prototype.closePath = function () {
1380
+ if (this.__region && !this.__onlyView)
1381
+ this.__region.closePath();
1382
+ if (this.__isPainter && this.__onlyRegion)
1383
+ return this;
1384
+ this.painter.closePath();
1385
+ return this;
1386
+ };
1387
+ Painter.prototype.moveTo = function (x, y) {
1388
+ if (this.__region && !this.__onlyView)
1389
+ this.__region.moveTo(x, y);
1390
+ if (this.__isPainter && this.__onlyRegion)
1391
+ return this;
1392
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1393
+ return this;
1394
+ };
1395
+ Painter.prototype.lineTo = function (x, y) {
1396
+ if (this.__region && !this.__onlyView)
1397
+ this.__region.lineTo(x, y);
1398
+ if (this.__isPainter && this.__onlyRegion)
1399
+ return this;
1400
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
1401
+ return this;
1402
+ };
1403
+ Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
1404
+ if (this.__region && !this.__onlyView)
1405
+ this.__region.arc(x, y, r, beginDeg, deg);
1406
+ if (this.__isPainter && this.__onlyRegion)
1407
+ return this;
1408
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
1409
+ return this;
1410
+ };
1411
+ Painter.prototype.fill = function () {
1412
+ if (this.__region && !this.__onlyView)
1413
+ this.__region.fill();
1414
+ if (this.__isPainter && this.__onlyRegion)
1415
+ return this;
1416
+ this.painter.fill();
1417
+ return this;
1418
+ };
1419
+ Painter.prototype.stroke = function () {
1420
+ if (this.__region && !this.__onlyView)
1421
+ this.__region.stroke();
1422
+ if (this.__isPainter && this.__onlyRegion)
1423
+ return this;
1424
+ this.painter.stroke();
1425
+ return this;
1426
+ };
1427
+ Painter.prototype.full = function () {
1428
+ if (this.__region && !this.__onlyView)
1429
+ this.__region.full();
1430
+ if (this.__isPainter && this.__onlyRegion)
1431
+ return this;
1432
+ this.painter.fill();
1433
+ this.painter.stroke();
1434
+ return this;
1435
+ };
1436
+ Painter.prototype.save = function () {
1437
+ if (this.__region && !this.__onlyView)
1438
+ this.__region.save();
1439
+ if (this.__isPainter && this.__onlyRegion)
1440
+ return this;
1441
+ this.painter.save();
1442
+ return this;
1443
+ };
1444
+ Painter.prototype.restore = function () {
1445
+ if (this.__region && !this.__onlyView)
1446
+ this.__region.restore();
1447
+ if (this.__isPainter && this.__onlyRegion)
1448
+ return this;
1449
+ this.painter.restore();
1450
+ return this;
1451
+ };
1452
+ Painter.prototype.clip = function () {
1453
+ if (this.__region && !this.__onlyView)
1454
+ this.__region.clip();
1455
+ if (this.__isPainter && this.__onlyRegion)
1456
+ return this;
1457
+ this.painter.clip();
1458
+ return this;
1459
+ };
1460
+ Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
1461
+ if (this.__region && !this.__onlyView)
1462
+ this.__region.quadraticCurveTo(cpx, cpy, x, y);
1463
+ if (this.__isPainter && this.__onlyRegion)
1464
+ return this;
1465
+ this.painter.quadraticCurveTo(cpx, cpy, x, y);
1466
+ return this;
1467
+ };
1468
+ Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
1469
+ if (this.__region && !this.__onlyView)
1470
+ this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1471
+ if (this.__isPainter && this.__onlyRegion)
1472
+ return this;
1473
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
1474
+ return this;
1475
+ };
1476
+ Painter.prototype.clearRect = function (x, y, w, h) {
1477
+ if (this.__region && !this.__onlyView)
1478
+ this.__region.clearRect(x, y, w, h);
1479
+ if (this.__isPainter && this.__onlyRegion)
1480
+ return this;
1481
+ this.painter.clearRect(x, y, w, h);
1482
+ return this;
1483
+ };
1484
+ Painter.prototype.clearCircle = function (cx, cy, r) {
1485
+ if (this.__region && !this.__onlyView)
1486
+ this.__region.clearCircle(cx, cy, r);
1487
+ if (this.__isPainter && this.__onlyRegion)
1488
+ return this;
1489
+ this.painter.beginPath();
1490
+ this.painter.globalCompositeOperation = "destination-out";
1491
+ this.painter.arc(cx, cy, r, 0, Math.PI * 2);
1492
+ this.painter.fill();
1493
+ this.painter.globalCompositeOperation = "source-over";
1494
+ this.painter.closePath();
1495
+ return this;
1496
+ };
1497
+ Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
1498
+ if (this.__region && !this.__onlyView)
1499
+ this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
1500
+ if (this.__isPainter && this.__onlyRegion)
1501
+ return this;
1502
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
1503
+ return this;
1504
+ };
1505
+ Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
1506
+ if (this.__region && !this.__onlyView)
1507
+ this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
1508
+ if (this.__isPainter && this.__onlyRegion)
1509
+ return this;
1510
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
1511
+ return this;
1512
+ };
1513
+ Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
1514
+ if (this.__region && !this.__onlyView)
1515
+ this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
1516
+ if (this.__isPainter && this.__onlyRegion)
1517
+ return this;
1518
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
1519
+ this.painter.fill();
1520
+ this.painter.stroke();
1521
+ return this;
1522
+ };
1523
+ Painter.prototype.fillCircle = function (cx, cy, r) {
1524
+ if (this.__region && !this.__onlyView)
1525
+ this.__region.fillCircle(cx, cy, r);
1526
+ if (this.__isPainter && this.__onlyRegion)
1527
+ return this;
1528
+ initCircle(this.painter, cx, cy, r).fill();
1529
+ return this;
1530
+ };
1531
+ Painter.prototype.strokeCircle = function (cx, cy, r) {
1532
+ if (this.__region && !this.__onlyView)
1533
+ this.__region.strokeCircle(cx, cy, r);
1534
+ if (this.__isPainter && this.__onlyRegion)
1535
+ return this;
1536
+ initCircle(this.painter, cx, cy, r).stroke();
1537
+ return this;
1538
+ };
1539
+ Painter.prototype.fullCircle = function (cx, cy, r) {
1540
+ if (this.__region && !this.__onlyView)
1541
+ this.__region.fullCircle(cx, cy, r);
1542
+ if (this.__isPainter && this.__onlyRegion)
1543
+ return this;
1544
+ initCircle(this.painter, cx, cy, r);
1545
+ this.painter.fill();
1546
+ this.painter.stroke();
1547
+ return this;
1548
+ };
1549
+ Painter.prototype.fillRect = function (x, y, width, height) {
1550
+ if (this.__region && !this.__onlyView)
1551
+ this.__region.fillRect(x, y, width, height);
1552
+ if (this.__isPainter && this.__onlyRegion)
1553
+ return this;
1554
+ initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
1555
+ return this;
1556
+ };
1557
+ Painter.prototype.strokeRect = function (x, y, width, height) {
1558
+ if (this.__region && !this.__onlyView)
1559
+ this.__region.strokeRect(x, y, width, height);
1560
+ if (this.__isPainter && this.__onlyRegion)
1561
+ return this;
1562
+ initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
1563
+ return this;
1564
+ };
1565
+ Painter.prototype.fullRect = function (x, y, width, height) {
1566
+ if (this.__region && !this.__onlyView)
1567
+ this.__region.fullRect(x, y, width, height);
1568
+ if (this.__isPainter && this.__onlyRegion)
1569
+ return this;
1570
+ initRect(this.painter, this.__specialConfig, x, y, width, height);
1571
+ this.painter.fill();
1572
+ this.painter.stroke();
1573
+ return this;
1574
+ };
1575
+ Painter.prototype.draw = function () {
1576
+ return Promise.resolve();
1577
+ };
1578
+ Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
1579
+ var _this = this;
1580
+ if (isImage === void 0) { isImage = false; }
1581
+ return new Promise(function (resolve) {
1582
+ if (_this.__region && !_this.__onlyView) {
1583
+ _this.__region.fillRect(x, y, w, h);
1584
+ }
1585
+ if (_this.__isPainter && _this.__onlyRegion) {
1586
+ resolve({});
1587
+ return;
1588
+ }
1589
+ if (typeof img == 'string' && !isImage) {
1590
+ var imgInstance_1 = new Image();
1591
+ imgInstance_1.onload = function () {
1592
+ _this.painter.drawImage(imgInstance_1, x, y, w, h);
1593
+ resolve({});
1594
+ };
1595
+ imgInstance_1.src = img;
1596
+ }
1597
+ else {
1598
+ _this.painter.drawImage(img, x, y, w, h);
1599
+ resolve({});
1600
+ }
1601
+ });
1602
+ };
1603
+ Painter.prototype.install = function (methods) {
1604
+ var _this = this;
1605
+ var _loop_1 = function (key) {
1606
+ if (key in this_1) {
1607
+ throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
1608
+ }
1609
+ else {
1610
+ this_1[key] = function () {
1611
+ var args = [];
1612
+ for (var _i = 0; _i < arguments.length; _i++) {
1613
+ args[_i] = arguments[_i];
1614
+ }
1615
+ var value = methods[key].apply(_this, args);
1616
+ if (value != void 0)
1617
+ return value;
1618
+ return _this;
1619
+ };
1620
+ }
1621
+ };
1622
+ var this_1 = this;
1623
+ for (var key in methods) {
1624
+ _loop_1(key);
1625
+ }
1626
+ return this;
1627
+ };
1628
+ return Painter;
1599
1629
  }());
1600
1630
 
1601
- function assemble (begin, end, step, count) {
1602
- var val = [];
1603
- for (var index = 0; index < count; index++)
1604
- val[index] = begin;
1605
- return function () {
1606
- for (var i = 0; i < count; i++) {
1607
- if (val[i] + step < end) {
1608
- val[i] = +(val[i] + step).toFixed(7);
1609
- break;
1610
- }
1611
- else if (i < count - 1) {
1612
- val[i] = begin;
1613
- }
1614
- }
1615
- return val;
1616
- };
1631
+ function assemble (begin, end, step, count) {
1632
+ var val = [];
1633
+ for (var index = 0; index < count; index++)
1634
+ val[index] = begin;
1635
+ return function () {
1636
+ for (var i = 0; i < count; i++) {
1637
+ if (val[i] + step < end) {
1638
+ val[i] = +(val[i] + step).toFixed(7);
1639
+ break;
1640
+ }
1641
+ else if (i < count - 1) {
1642
+ val[i] = begin;
1643
+ }
1644
+ }
1645
+ return val;
1646
+ };
1617
1647
  }
1618
1648
 
1619
- var enhanceGradient = function (gradient, calcStop) {
1620
- var enhanceGradient = {
1621
- "value": function () {
1622
- return gradient;
1623
- },
1624
- "setColor": function (stop, color) {
1625
- gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
1626
- return enhanceGradient;
1627
- }
1628
- };
1629
- return enhanceGradient;
1630
- };
1631
- var linearGradient = function (painter, x0, y0, x1, y1) {
1632
- var gradient = painter.createLinearGradient(x0, y0, x1, y1);
1633
- return enhanceGradient(gradient);
1634
- };
1635
- var radialGradient = function (painter, cx, cy, r) {
1636
- var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
1637
- return enhanceGradient(gradient);
1638
- };
1639
- var conicGradient = function (painter, cx, cy, startDeg, deg) {
1640
- var gradient = painter.createConicGradient(startDeg, cx, cy);
1641
- return enhanceGradient(gradient, deg ? function (stop) {
1642
- return deg / (Math.PI * 2) * stop;
1643
- } : undefined);
1649
+ var enhanceGradient = function (gradient, calcStop) {
1650
+ var enhanceGradient = {
1651
+ "value": function () {
1652
+ return gradient;
1653
+ },
1654
+ "setColor": function (stop, color) {
1655
+ gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
1656
+ return enhanceGradient;
1657
+ }
1658
+ };
1659
+ return enhanceGradient;
1660
+ };
1661
+ var linearGradient = function (painter, x0, y0, x1, y1) {
1662
+ var gradient = painter.createLinearGradient(x0, y0, x1, y1);
1663
+ return enhanceGradient(gradient);
1664
+ };
1665
+ var radialGradient = function (painter, cx, cy, r) {
1666
+ var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
1667
+ return enhanceGradient(gradient);
1668
+ };
1669
+ var conicGradient = function (painter, cx, cy, startDeg, deg) {
1670
+ var gradient = painter.createConicGradient(startDeg, cx, cy);
1671
+ return enhanceGradient(gradient, deg ? function (stop) {
1672
+ return deg / (Math.PI * 2) * stop;
1673
+ } : void 0);
1644
1674
  };
1645
1675
 
1646
- var Canvas$1 = (function (_super) {
1647
- __extends(Canvas, _super);
1648
- function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
1649
- if (opts === void 0) { opts = {}; }
1650
- if (scaleSize === void 0) { scaleSize = 1; }
1651
- var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
1652
- willReadFrequently: true,
1653
- }) : undefined, true, scaleSize) || this;
1654
- _this.name = "Canvas";
1655
- _this.__regionList = {};
1656
- _this.__regionAssemble = assemble(0, 255, 10, 3);
1657
- _this.__scaleSize = scaleSize;
1658
- _this.setRegion("");
1659
- return _this;
1660
- }
1661
- Canvas.prototype.config = function (configs) {
1662
- for (var key in configs) {
1663
- this.useConfig(key, configs[key]);
1664
- }
1665
- return this;
1666
- };
1667
- Canvas.prototype.reset = function () {
1668
- this.config(defaultFactory());
1669
- return this;
1670
- };
1671
- Canvas.prototype.onlyRegion = function (flag) {
1672
- this.__onlyRegion = flag;
1673
- return this;
1674
- };
1675
- Canvas.prototype.onlyView = function (flag) {
1676
- this.__onlyView = flag;
1677
- return this;
1678
- };
1679
- Canvas.prototype.setRegion = function (regionName) {
1680
- if (this.__region) {
1681
- if (regionName) {
1682
- if (this.__regionList[regionName] == void 0) {
1683
- var tempColor = this.__regionAssemble();
1684
- this.__regionList[regionName] =
1685
- "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
1686
- }
1687
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
1688
- this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
1689
- }
1690
- else {
1691
- this.__region.useConfig("fillStyle", "#000000") &&
1692
- this.__region.useConfig("strokeStyle", "#000000");
1693
- }
1694
- }
1695
- return this;
1696
- };
1697
- Canvas.prototype.getRegion = function (x, y) {
1698
- var _this = this;
1699
- return new Promise(function (resolve) {
1700
- var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
1701
- data: [0, 0, 0, 0]
1702
- };
1703
- var currentRGBA = imgData.data;
1704
- var doit = function () {
1705
- if (_this.__region) {
1706
- for (var key in _this.__regionList) {
1707
- if ("rgb(" +
1708
- currentRGBA[0] +
1709
- "," +
1710
- currentRGBA[1] +
1711
- "," +
1712
- currentRGBA[2] +
1713
- ")" ==
1714
- _this.__regionList[key]) {
1715
- resolve(key);
1716
- break;
1717
- }
1718
- }
1719
- }
1720
- resolve("");
1721
- };
1722
- if (currentRGBA) {
1723
- doit();
1724
- }
1725
- else {
1726
- imgData.then(function (data) {
1727
- currentRGBA = data;
1728
- doit();
1729
- });
1730
- }
1731
- });
1732
- };
1733
- Canvas.prototype.textWidth = function (text) {
1734
- this.painter.save();
1735
- initText(this.painter, this.__specialConfig, 0, 0, 0);
1736
- var width = this.painter.measureText(text + "").width;
1737
- this.painter.restore();
1738
- return width;
1739
- };
1740
- Canvas.prototype.getContext = function (isRegion) {
1741
- if (isRegion === void 0) { isRegion = false; }
1742
- return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
1743
- };
1744
- Canvas.prototype.getInfo = function () {
1745
- return {
1746
- width: this.painter.canvas.width / this.__scaleSize,
1747
- height: this.painter.canvas.height / this.__scaleSize
1748
- };
1749
- };
1750
- Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
1751
- return linearGradient(this.painter, x0, y0, x1, y1);
1752
- };
1753
- Canvas.prototype.createRadialGradient = function (cx, cy, r) {
1754
- return radialGradient(this.painter, cx, cy, r);
1755
- };
1756
- Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
1757
- return conicGradient(this.painter, cx, cy, beginDeg, deg);
1758
- };
1759
- Canvas.prototype.getColor = function (x, y) {
1760
- x *= this.__scaleSize;
1761
- y *= this.__scaleSize;
1762
- var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
1763
- return ("rgba(" +
1764
- currentRGBA[0] +
1765
- "," +
1766
- currentRGBA[1] +
1767
- "," +
1768
- currentRGBA[2] +
1769
- "," +
1770
- currentRGBA[3] +
1771
- ")");
1772
- };
1773
- return Canvas;
1676
+ var Canvas$1 = (function (_super) {
1677
+ __extends(Canvas, _super);
1678
+ function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
1679
+ if (opts === void 0) { opts = {}; }
1680
+ if (scaleSize === void 0) { scaleSize = 1; }
1681
+ var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
1682
+ willReadFrequently: true,
1683
+ }) : undefined, true, scaleSize) || this;
1684
+ _this.name = "Canvas";
1685
+ _this.__regionList = {};
1686
+ _this.__regionAssemble = assemble(0, 255, 10, 3);
1687
+ _this.__scaleSize = scaleSize;
1688
+ _this.setRegion("");
1689
+ return _this;
1690
+ }
1691
+ Canvas.prototype.config = function (configs) {
1692
+ for (var key in configs) {
1693
+ this.useConfig(key, configs[key]);
1694
+ }
1695
+ return this;
1696
+ };
1697
+ Canvas.prototype.reset = function () {
1698
+ this.config(defaultFactory());
1699
+ return this;
1700
+ };
1701
+ Canvas.prototype.onlyRegion = function (flag) {
1702
+ this.__onlyRegion = flag;
1703
+ return this;
1704
+ };
1705
+ Canvas.prototype.onlyView = function (flag) {
1706
+ this.__onlyView = flag;
1707
+ return this;
1708
+ };
1709
+ Canvas.prototype.setRegion = function (regionName) {
1710
+ if (this.__region) {
1711
+ if (regionName) {
1712
+ if (this.__regionList[regionName] == void 0) {
1713
+ var tempColor = this.__regionAssemble();
1714
+ this.__regionList[regionName] =
1715
+ "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
1716
+ }
1717
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
1718
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
1719
+ }
1720
+ else {
1721
+ this.__region.useConfig("fillStyle", "#000000") &&
1722
+ this.__region.useConfig("strokeStyle", "#000000");
1723
+ }
1724
+ }
1725
+ return this;
1726
+ };
1727
+ Canvas.prototype.getRegion = function (x, y) {
1728
+ var _this = this;
1729
+ return new Promise(function (resolve) {
1730
+ var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
1731
+ data: [0, 0, 0, 0]
1732
+ };
1733
+ var currentRGBA = imgData.data;
1734
+ var doit = function () {
1735
+ if (_this.__region) {
1736
+ for (var key in _this.__regionList) {
1737
+ if ("rgb(" +
1738
+ currentRGBA[0] +
1739
+ "," +
1740
+ currentRGBA[1] +
1741
+ "," +
1742
+ currentRGBA[2] +
1743
+ ")" ==
1744
+ _this.__regionList[key]) {
1745
+ resolve(key);
1746
+ break;
1747
+ }
1748
+ }
1749
+ }
1750
+ resolve("");
1751
+ };
1752
+ if (currentRGBA) {
1753
+ doit();
1754
+ }
1755
+ else {
1756
+ imgData.then(function (data) {
1757
+ currentRGBA = data;
1758
+ doit();
1759
+ });
1760
+ }
1761
+ });
1762
+ };
1763
+ Canvas.prototype.textWidth = function (text) {
1764
+ this.painter.save();
1765
+ initText(this.painter, this.__specialConfig, 0, 0, 0);
1766
+ var width = this.painter.measureText(text + "").width;
1767
+ this.painter.restore();
1768
+ return width;
1769
+ };
1770
+ Canvas.prototype.getContext = function (isRegion) {
1771
+ if (isRegion === void 0) { isRegion = false; }
1772
+ return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
1773
+ };
1774
+ Canvas.prototype.getInfo = function () {
1775
+ return {
1776
+ width: this.painter.canvas.width / this.__scaleSize,
1777
+ height: this.painter.canvas.height / this.__scaleSize
1778
+ };
1779
+ };
1780
+ Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
1781
+ return linearGradient(this.painter, x0, y0, x1, y1);
1782
+ };
1783
+ Canvas.prototype.createRadialGradient = function (cx, cy, r) {
1784
+ return radialGradient(this.painter, cx, cy, r);
1785
+ };
1786
+ Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
1787
+ return conicGradient(this.painter, cx, cy, beginDeg, deg);
1788
+ };
1789
+ Canvas.prototype.getColor = function (x, y) {
1790
+ x *= this.__scaleSize;
1791
+ y *= this.__scaleSize;
1792
+ var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
1793
+ return ("rgba(" +
1794
+ currentRGBA[0] +
1795
+ "," +
1796
+ currentRGBA[1] +
1797
+ "," +
1798
+ currentRGBA[2] +
1799
+ "," +
1800
+ currentRGBA[3] +
1801
+ ")");
1802
+ };
1803
+ return Canvas;
1774
1804
  }(Painter));
1775
1805
 
1776
- var toString = Object.prototype.toString;
1777
- function getType(value) {
1778
- if (value == null) {
1779
- return value === undefined ? '[object Undefined]' : '[object Null]';
1780
- }
1781
- return toString.call(value);
1782
- }
1783
- function isPlainObject(value) {
1784
- if (value === null || typeof value !== 'object' || getType(value) != '[object Object]') {
1785
- return false;
1786
- }
1787
- if (Object.getPrototypeOf(value) === null) {
1788
- return true;
1789
- }
1790
- var proto = value;
1791
- while (Object.getPrototypeOf(proto) !== null) {
1792
- proto = Object.getPrototypeOf(proto);
1793
- }
1794
- return Object.getPrototypeOf(value) === proto;
1806
+ var toString = Object.prototype.toString;
1807
+ function getType(value) {
1808
+ if (value == null) {
1809
+ return value === undefined ? '[object Undefined]' : '[object Null]';
1810
+ }
1811
+ return toString.call(value);
1812
+ }
1813
+ function isPlainObject(value) {
1814
+ if (value === null || typeof value !== 'object' || getType(value) != '[object Object]') {
1815
+ return false;
1816
+ }
1817
+ if (Object.getPrototypeOf(value) === null) {
1818
+ return true;
1819
+ }
1820
+ var proto = value;
1821
+ while (Object.getPrototypeOf(proto) !== null) {
1822
+ proto = Object.getPrototypeOf(proto);
1823
+ }
1824
+ return Object.getPrototypeOf(value) === proto;
1795
1825
  }
1796
1826
 
1797
- function initOption(setOption, defaultOption) {
1798
- for (var key in setOption) {
1799
- defaultOption[key] = setOption[key];
1800
- }
1801
- return defaultOption;
1802
- }
1803
- function mergeOption(oldOption, newOption) {
1804
- (function doit(oldOption, newOption) {
1805
- for (var key in newOption) {
1806
- var value = newOption[key];
1807
- if (isPlainObject(value)) {
1808
- if (!oldOption[key])
1809
- oldOption[key] = {};
1810
- doit(oldOption[key], newOption[key]);
1811
- }
1812
- else {
1813
- oldOption[key] = value;
1814
- }
1815
- }
1816
- })(oldOption, newOption);
1827
+ function initOption(setOption, defaultOption) {
1828
+ for (var key in setOption) {
1829
+ defaultOption[key] = setOption[key];
1830
+ }
1831
+ return defaultOption;
1832
+ }
1833
+ function mergeOption(oldOption, newOption) {
1834
+ (function doit(oldOption, newOption) {
1835
+ for (var key in newOption) {
1836
+ var value = newOption[key];
1837
+ if (isPlainObject(value)) {
1838
+ if (!oldOption[key])
1839
+ oldOption[key] = {};
1840
+ doit(oldOption[key], newOption[key]);
1841
+ }
1842
+ else {
1843
+ oldOption[key] = value;
1844
+ }
1845
+ }
1846
+ })(oldOption, newOption);
1817
1847
  }
1818
1848
 
1819
- var Canvas = (function (_super) {
1820
- __extends(Canvas, _super);
1821
- function Canvas(el, option, width, height) {
1822
- if (option === void 0) { option = {}; }
1823
- if (width === void 0) { width = 0; }
1824
- if (height === void 0) { height = 0; }
1825
- var _this = this;
1826
- if (!el) {
1827
- throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
1828
- }
1829
- option = initOption(option, {
1830
- region: true,
1831
- willReadFrequently: false
1832
- });
1833
- width = width || el.clientWidth;
1834
- height = height || el.clientHeight;
1835
- var ViewCanvas, RegionCanvas = null;
1836
- var _el = el;
1837
- if (_el._vislite_canvas_) {
1838
- ViewCanvas = _el._vislite_canvas_[0];
1839
- RegionCanvas = _el._vislite_canvas_[1];
1840
- }
1841
- else {
1842
- ViewCanvas = document.createElement('canvas');
1843
- el.appendChild(ViewCanvas);
1844
- if (option.region) {
1845
- RegionCanvas = document.createElement('canvas');
1846
- }
1847
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
1848
- el.setAttribute('vislite', 'Canvas');
1849
- }
1850
- var canvasArray = [RegionCanvas, ViewCanvas];
1851
- for (var index = 0; index < canvasArray.length; index++) {
1852
- var canvas = canvasArray[index];
1853
- if (canvas) {
1854
- canvas.style.width = width + "px";
1855
- canvas.setAttribute('width', (index * width + width) + "");
1856
- canvas.style.height = height + "px";
1857
- canvas.setAttribute('height', (index * height + height) + "");
1858
- }
1859
- }
1860
- _this = _super.call(this, ViewCanvas, RegionCanvas, {
1861
- willReadFrequently: option.willReadFrequently,
1862
- }, 2) || this;
1863
- _this.__canvas = ViewCanvas;
1864
- _this.__el = el;
1865
- _this.painter.scale(2, 2);
1866
- return _this;
1867
- }
1868
- Canvas.prototype.toDataURL = function () {
1869
- var _this = this;
1870
- return new Promise(function (resolve) {
1871
- resolve(_this.__canvas.toDataURL());
1872
- });
1873
- };
1874
- Canvas.prototype.bind = function (eventName, callback) {
1875
- var _this = this;
1876
- this.__el.addEventListener(eventName, function (event) {
1877
- _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
1878
- callback(regionName, event.offsetX, event.offsetY);
1879
- });
1880
- });
1881
- return this;
1882
- };
1883
- return Canvas;
1849
+ var Canvas = (function (_super) {
1850
+ __extends(Canvas, _super);
1851
+ function Canvas(el, option, width, height) {
1852
+ if (option === void 0) { option = {}; }
1853
+ if (width === void 0) { width = 0; }
1854
+ if (height === void 0) { height = 0; }
1855
+ var _this = this;
1856
+ if (!el) {
1857
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
1858
+ }
1859
+ option = initOption(option, {
1860
+ region: true,
1861
+ willReadFrequently: false
1862
+ });
1863
+ width = width || el.clientWidth;
1864
+ height = height || el.clientHeight;
1865
+ var ViewCanvas, RegionCanvas = null;
1866
+ var _el = el;
1867
+ if (_el._vislite_canvas_) {
1868
+ ViewCanvas = _el._vislite_canvas_[0];
1869
+ RegionCanvas = _el._vislite_canvas_[1];
1870
+ }
1871
+ else {
1872
+ ViewCanvas = document.createElement('canvas');
1873
+ el.appendChild(ViewCanvas);
1874
+ if (option.region) {
1875
+ RegionCanvas = document.createElement('canvas');
1876
+ }
1877
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
1878
+ el.setAttribute('vislite', 'Canvas');
1879
+ }
1880
+ var canvasArray = [RegionCanvas, ViewCanvas];
1881
+ for (var index = 0; index < canvasArray.length; index++) {
1882
+ var canvas = canvasArray[index];
1883
+ if (canvas) {
1884
+ canvas.style.width = width + "px";
1885
+ canvas.setAttribute('width', (index * width + width) + "");
1886
+ canvas.style.height = height + "px";
1887
+ canvas.setAttribute('height', (index * height + height) + "");
1888
+ }
1889
+ }
1890
+ _this = _super.call(this, ViewCanvas, RegionCanvas, {
1891
+ willReadFrequently: option.willReadFrequently,
1892
+ }, 2) || this;
1893
+ _this.__canvas = ViewCanvas;
1894
+ _this.__el = el;
1895
+ _this.painter.scale(2, 2);
1896
+ return _this;
1897
+ }
1898
+ Canvas.prototype.toDataURL = function () {
1899
+ var _this = this;
1900
+ return new Promise(function (resolve) {
1901
+ resolve(_this.__canvas.toDataURL());
1902
+ });
1903
+ };
1904
+ Canvas.prototype.bind = function (eventName, callback) {
1905
+ var _this = this;
1906
+ this.__el.addEventListener(eventName, function (event) {
1907
+ _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
1908
+ callback(regionName, event.offsetX, event.offsetY);
1909
+ });
1910
+ });
1911
+ return this;
1912
+ };
1913
+ return Canvas;
1884
1914
  }(Canvas$1));
1885
1915
 
1886
- function getWebGLContext$1 (canvas, scale, opts, mode) {
1887
- if (opts === void 0) { opts = {}; }
1888
- if (mode === void 0) { mode = "scaleToFill"; }
1889
- var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
1890
- var painter = canvas.getContext("webgl", opts);
1891
- for (var i = 0; i < names.length; i++) {
1892
- try {
1893
- painter = canvas.getContext(names[i], opts);
1894
- }
1895
- catch (e) { }
1896
- if (painter)
1897
- break;
1898
- }
1899
- if (!painter)
1900
- throw new Error('Non canvas or browser does not support webgl.');
1901
- var width = painter.canvas.width, height = painter.canvas.height;
1902
- var scaleX = scale, scaleY = scale;
1903
- if (mode == "aspectFit") {
1904
- if (width > height) {
1905
- scaleX *= height / width;
1906
- }
1907
- else if (height > width) {
1908
- scaleY *= width / height;
1909
- }
1910
- }
1911
- else if (mode == "aspectFill") {
1912
- if (width > height) {
1913
- scaleY *= width / height;
1914
- }
1915
- else if (height > width) {
1916
- scaleX *= height / width;
1917
- }
1918
- }
1919
- var viewWidth = width * scaleX;
1920
- var viewHeight = height * scaleY;
1921
- painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
1922
- painter.depthFunc(painter.LEQUAL);
1923
- painter.enable(painter.DEPTH_TEST);
1924
- return painter;
1916
+ function getWebGLContext$1 (canvas, scale, opts, mode) {
1917
+ if (opts === void 0) { opts = {}; }
1918
+ if (mode === void 0) { mode = "scaleToFill"; }
1919
+ var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
1920
+ var painter = canvas.getContext("webgl", opts);
1921
+ for (var i = 0; i < names.length; i++) {
1922
+ try {
1923
+ painter = canvas.getContext(names[i], opts);
1924
+ }
1925
+ catch (e) { }
1926
+ if (painter)
1927
+ break;
1928
+ }
1929
+ if (!painter)
1930
+ throw new Error('Non canvas or browser does not support webgl.');
1931
+ var width = painter.canvas.width, height = painter.canvas.height;
1932
+ var scaleX = scale, scaleY = scale;
1933
+ if (mode == "aspectFit") {
1934
+ if (width > height) {
1935
+ scaleX *= height / width;
1936
+ }
1937
+ else if (height > width) {
1938
+ scaleY *= width / height;
1939
+ }
1940
+ }
1941
+ else if (mode == "aspectFill") {
1942
+ if (width > height) {
1943
+ scaleY *= width / height;
1944
+ }
1945
+ else if (height > width) {
1946
+ scaleX *= height / width;
1947
+ }
1948
+ }
1949
+ var viewWidth = width * scaleX;
1950
+ var viewHeight = height * scaleY;
1951
+ painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
1952
+ painter.depthFunc(painter.LEQUAL);
1953
+ painter.enable(painter.DEPTH_TEST);
1954
+ return painter;
1925
1955
  }
1926
1956
 
1927
- var getWebGLContext = (function (el, scale, mode) {
1928
- if (scale === void 0) { scale = 1; }
1929
- if (!el) {
1930
- throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
1931
- }
1932
- var width = el.clientWidth, height = el.clientHeight;
1933
- var ViewCanvas;
1934
- var _el = el;
1935
- if (_el._vislite_canvas_) {
1936
- ViewCanvas = _el._vislite_canvas_;
1937
- }
1938
- else {
1939
- ViewCanvas = document.createElement('canvas');
1940
- el.appendChild(ViewCanvas);
1941
- _el._vislite_canvas_ = ViewCanvas;
1942
- el.setAttribute('vislite', 'WebGL');
1943
- }
1944
- ViewCanvas.style.width = width + "px";
1945
- ViewCanvas.setAttribute('width', width + "");
1946
- ViewCanvas.style.height = height + "px";
1947
- ViewCanvas.setAttribute('height', height + "");
1948
- return getWebGLContext$1(ViewCanvas, scale, {}, mode);
1957
+ var getWebGLContext = (function (el, scale, mode) {
1958
+ if (scale === void 0) { scale = 1; }
1959
+ if (!el) {
1960
+ throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");
1961
+ }
1962
+ var width = el.clientWidth, height = el.clientHeight;
1963
+ var ViewCanvas;
1964
+ var _el = el;
1965
+ if (_el._vislite_canvas_) {
1966
+ ViewCanvas = _el._vislite_canvas_;
1967
+ }
1968
+ else {
1969
+ ViewCanvas = document.createElement('canvas');
1970
+ el.appendChild(ViewCanvas);
1971
+ _el._vislite_canvas_ = ViewCanvas;
1972
+ el.setAttribute('vislite', 'WebGL');
1973
+ }
1974
+ ViewCanvas.style.width = width + "px";
1975
+ ViewCanvas.setAttribute('width', width + "");
1976
+ ViewCanvas.style.height = height + "px";
1977
+ ViewCanvas.setAttribute('height', height + "");
1978
+ return getWebGLContext$1(ViewCanvas, scale, {}, mode);
1949
1979
  });
1950
1980
 
1951
- var loadShader = function (painter, type, source) {
1952
- var shader = painter.createShader(type);
1953
- if (shader == null)
1954
- throw new Error('Unable to create shader!');
1955
- painter.shaderSource(shader, source);
1956
- painter.compileShader(shader);
1957
- if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1958
- throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1959
- return shader;
1960
- };
1961
- var useShader = function (painter, vshaderSource, fshaderSource) {
1962
- var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1963
- var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1964
- var glProgram = painter.createProgram();
1965
- painter.attachShader(glProgram, vertexShader);
1966
- painter.attachShader(glProgram, fragmentShader);
1967
- painter.linkProgram(glProgram);
1968
- if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1969
- throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
1970
- return glProgram;
1971
- };
1972
- var ShaderObject = (function () {
1973
- function ShaderObject(painter) {
1974
- this.__painter = painter;
1975
- }
1976
- ShaderObject.prototype.use = function () {
1977
- this.__painter.useProgram(this.program);
1978
- return this;
1979
- };
1980
- ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
1981
- this.program = useShader(this.__painter, vshaderSource, fshaderSource);
1982
- return this;
1983
- };
1984
- return ShaderObject;
1981
+ var loadShader = function (painter, type, source) {
1982
+ var shader = painter.createShader(type);
1983
+ if (shader == null)
1984
+ throw new Error('Unable to create shader!');
1985
+ painter.shaderSource(shader, source);
1986
+ painter.compileShader(shader);
1987
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
1988
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
1989
+ return shader;
1990
+ };
1991
+ var useShader = function (painter, vshaderSource, fshaderSource) {
1992
+ var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
1993
+ var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
1994
+ var glProgram = painter.createProgram();
1995
+ painter.attachShader(glProgram, vertexShader);
1996
+ painter.attachShader(glProgram, fragmentShader);
1997
+ painter.linkProgram(glProgram);
1998
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
1999
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
2000
+ return glProgram;
2001
+ };
2002
+ var ShaderObject = (function () {
2003
+ function ShaderObject(painter) {
2004
+ this.__painter = painter;
2005
+ }
2006
+ ShaderObject.prototype.use = function () {
2007
+ this.__painter.useProgram(this.program);
2008
+ return this;
2009
+ };
2010
+ ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
2011
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource);
2012
+ return this;
2013
+ };
2014
+ return ShaderObject;
1985
2015
  }());
1986
2016
 
1987
- var initTexture = function (painter, type, unit) {
1988
- var texture = painter.createTexture();
1989
- painter.activeTexture(painter['TEXTURE' + unit]);
1990
- painter.bindTexture(type, texture);
1991
- return texture;
1992
- };
1993
- var linkImage = function (painter, type, level, format, textureType, image) {
1994
- painter.texImage2D(type, level, format, format, textureType, image);
1995
- };
1996
- var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
1997
- var types = [
1998
- painter.TEXTURE_CUBE_MAP_POSITIVE_X,
1999
- painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
2000
- painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
2001
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
2002
- painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
2003
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
2004
- ];
2005
- var target;
2006
- for (var i = 0; i < types.length; i++) {
2007
- if (images[i]) {
2008
- target = types[i];
2009
- painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
2010
- painter.bindTexture(type, texture);
2011
- painter.texImage2D(target, level, format, format, textureType, images[i]);
2012
- }
2013
- }
2014
- painter.generateMipmap(type);
2015
- };
2016
- var TextureObject = (function () {
2017
- function TextureObject(painter, type, unit) {
2018
- if (unit === void 0) { unit = 0; }
2019
- this.__painter = painter;
2020
- this.__type = {
2021
- "2d": painter.TEXTURE_2D,
2022
- "cube": painter.TEXTURE_CUBE_MAP
2023
- }[type];
2024
- this.__texture = initTexture(painter, this.__type, unit);
2025
- painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
2026
- painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
2027
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
2028
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
2029
- }
2030
- TextureObject.prototype.useImage = function (image) {
2031
- linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
2032
- return this;
2033
- };
2034
- TextureObject.prototype.useCube = function (images, width, height) {
2035
- linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
2036
- return this;
2037
- };
2038
- return TextureObject;
2017
+ var initTexture = function (painter, type, unit) {
2018
+ var texture = painter.createTexture();
2019
+ painter.activeTexture(painter['TEXTURE' + unit]);
2020
+ painter.bindTexture(type, texture);
2021
+ return texture;
2022
+ };
2023
+ var linkImage = function (painter, type, level, format, textureType, image) {
2024
+ painter.texImage2D(type, level, format, format, textureType, image);
2025
+ };
2026
+ var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
2027
+ var types = [
2028
+ painter.TEXTURE_CUBE_MAP_POSITIVE_X,
2029
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
2030
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
2031
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
2032
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
2033
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
2034
+ ];
2035
+ var target;
2036
+ for (var i = 0; i < types.length; i++) {
2037
+ if (images[i]) {
2038
+ target = types[i];
2039
+ painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
2040
+ painter.bindTexture(type, texture);
2041
+ painter.texImage2D(target, level, format, format, textureType, images[i]);
2042
+ }
2043
+ }
2044
+ painter.generateMipmap(type);
2045
+ };
2046
+ var TextureObject = (function () {
2047
+ function TextureObject(painter, type, unit) {
2048
+ if (unit === void 0) { unit = 0; }
2049
+ this.__painter = painter;
2050
+ this.__type = {
2051
+ "2d": painter.TEXTURE_2D,
2052
+ "cube": painter.TEXTURE_CUBE_MAP
2053
+ }[type];
2054
+ this.__texture = initTexture(painter, this.__type, unit);
2055
+ painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
2056
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
2057
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
2058
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
2059
+ }
2060
+ TextureObject.prototype.useImage = function (image) {
2061
+ linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
2062
+ return this;
2063
+ };
2064
+ TextureObject.prototype.useCube = function (images, width, height) {
2065
+ linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
2066
+ return this;
2067
+ };
2068
+ return TextureObject;
2039
2069
  }());
2040
2070
 
2041
- var newBuffer = function (painter) {
2042
- return painter.createBuffer();
2043
- };
2044
- var writeBuffer = function (painter, data, isElement, usage) {
2045
- var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
2046
- painter.bufferData(TYPE, data, usage);
2047
- };
2048
- var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
2049
- painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
2050
- painter.enableVertexAttribArray(location);
2051
- };
2052
- var BufferObject = (function () {
2053
- function BufferObject(painter, isElement) {
2054
- if (isElement === void 0) { isElement = false; }
2055
- this.__painter = painter;
2056
- this.__isElement = isElement;
2057
- this.__buffer = newBuffer(painter);
2058
- this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
2059
- }
2060
- BufferObject.prototype.use = function () {
2061
- this.__painter.bindBuffer(this.__type, this.__buffer);
2062
- return this;
2063
- };
2064
- BufferObject.prototype.write = function (data) {
2065
- writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
2066
- this.__fsize = data.BYTES_PER_ELEMENT;
2067
- return this;
2068
- };
2069
- BufferObject.prototype.divide = function (location, size, stride, offset) {
2070
- if (offset === void 0) { offset = 0; }
2071
- useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
2072
- return this;
2073
- };
2074
- return BufferObject;
2071
+ var newBuffer = function (painter) {
2072
+ return painter.createBuffer();
2073
+ };
2074
+ var writeBuffer = function (painter, data, isElement, usage) {
2075
+ var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
2076
+ painter.bufferData(TYPE, data, usage);
2077
+ };
2078
+ var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
2079
+ painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
2080
+ painter.enableVertexAttribArray(location);
2081
+ };
2082
+ var BufferObject = (function () {
2083
+ function BufferObject(painter, isElement) {
2084
+ if (isElement === void 0) { isElement = false; }
2085
+ this.__painter = painter;
2086
+ this.__isElement = isElement;
2087
+ this.__buffer = newBuffer(painter);
2088
+ this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
2089
+ }
2090
+ BufferObject.prototype.use = function () {
2091
+ this.__painter.bindBuffer(this.__type, this.__buffer);
2092
+ return this;
2093
+ };
2094
+ BufferObject.prototype.write = function (data) {
2095
+ writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
2096
+ this.__fsize = data.BYTES_PER_ELEMENT;
2097
+ return this;
2098
+ };
2099
+ BufferObject.prototype.divide = function (location, size, stride, offset) {
2100
+ if (offset === void 0) { offset = 0; }
2101
+ useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
2102
+ return this;
2103
+ };
2104
+ return BufferObject;
2075
2105
  }());
2076
2106
 
2077
- var rotateX = function (deg, x, y, z) {
2078
- var cos = Math.cos(deg), sin = Math.sin(deg);
2079
- return [x, y * cos - z * sin, y * sin + z * cos];
2080
- };
2081
- var rotateY = function (deg, x, y, z) {
2082
- var cos = Math.cos(deg), sin = Math.sin(deg);
2083
- return [z * sin + x * cos, y, z * cos - x * sin];
2084
- };
2085
- var rotateZ = function (deg, x, y, z) {
2086
- var cos = Math.cos(deg), sin = Math.sin(deg);
2087
- return [x * cos - y * sin, x * sin + y * cos, z];
2088
- };
2089
- var Eoap = (function () {
2090
- function Eoap(scale, center) {
2091
- if (scale === void 0) { scale = 7; }
2092
- if (center === void 0) { center = [107, 36]; }
2093
- this.name = 'Eoap';
2094
- this.__scale = scale;
2095
- this.__center = center;
2096
- }
2097
- Eoap.prototype.use = function (λ, φ) {
2098
- var p = rotateY((360 - φ) / 180 * Math.PI, 100 * this.__scale, 0, 0);
2099
- p = rotateZ(λ / 180 * Math.PI, p[0], p[1], p[2]);
2100
- p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
2101
- p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
2102
- return [
2103
- -p[0],
2104
- p[1],
2105
- p[2]
2106
- ];
2107
- };
2108
- return Eoap;
2107
+ var rotateX = function (deg, x, y, z) {
2108
+ var cos = Math.cos(deg), sin = Math.sin(deg);
2109
+ return [x, y * cos - z * sin, y * sin + z * cos];
2110
+ };
2111
+ var rotateY = function (deg, x, y, z) {
2112
+ var cos = Math.cos(deg), sin = Math.sin(deg);
2113
+ return [z * sin + x * cos, y, z * cos - x * sin];
2114
+ };
2115
+ var rotateZ = function (deg, x, y, z) {
2116
+ var cos = Math.cos(deg), sin = Math.sin(deg);
2117
+ return [x * cos - y * sin, x * sin + y * cos, z];
2118
+ };
2119
+ var Eoap = (function () {
2120
+ function Eoap(scale, center) {
2121
+ if (scale === void 0) { scale = 7; }
2122
+ if (center === void 0) { center = [107, 36]; }
2123
+ this.name = 'Eoap';
2124
+ this.__scale = scale;
2125
+ this.__center = center;
2126
+ }
2127
+ Eoap.prototype.use = function (λ, φ) {
2128
+ var p = rotateY((360 - φ) / 180 * Math.PI, 100 * this.__scale, 0, 0);
2129
+ p = rotateZ(λ / 180 * Math.PI, p[0], p[1], p[2]);
2130
+ p = rotateZ((90 - this.__center[0]) / 180 * Math.PI, p[0], p[1], p[2]);
2131
+ p = rotateX((90 - this.__center[1]) / 180 * Math.PI, p[0], p[1], p[2]);
2132
+ return [
2133
+ -p[0],
2134
+ p[1],
2135
+ p[2]
2136
+ ];
2137
+ };
2138
+ return Eoap;
2109
2139
  }());
2110
2140
 
2111
- var Mercator = (function () {
2112
- function Mercator(scale, center) {
2113
- if (scale === void 0) { scale = 7; }
2114
- if (center === void 0) { center = [107, 36]; }
2115
- this.name = 'Mercator';
2116
- var perimeter = 100 * scale * Math.PI;
2117
- var help = perimeter / 180;
2118
- var cx = help * center[0];
2119
- var cy = -1 * help * center[1];
2120
- this.use = function (λ, φ) {
2121
- return [
2122
- (help * λ - cx) * 0.8,
2123
- -1 * help * φ - cy,
2124
- 0
2125
- ];
2126
- };
2127
- }
2128
- return Mercator;
2141
+ var Mercator = (function () {
2142
+ function Mercator(scale, center) {
2143
+ if (scale === void 0) { scale = 7; }
2144
+ if (center === void 0) { center = [107, 36]; }
2145
+ this.name = 'Mercator';
2146
+ var perimeter = 100 * scale * Math.PI;
2147
+ var help = perimeter / 180;
2148
+ var cx = help * center[0];
2149
+ var cy = -1 * help * center[1];
2150
+ this.use = function (λ, φ) {
2151
+ return [
2152
+ (help * λ - cx) * 0.8,
2153
+ -1 * help * φ - cy,
2154
+ 0
2155
+ ];
2156
+ };
2157
+ }
2158
+ return Mercator;
2129
2159
  }());
2130
2160
 
2161
+ /*!
2162
+ * throttle of OIPage v1.2.0
2163
+ * git+https://github.com/oi-contrib/OIPage.git
2164
+ */
2165
+
2131
2166
  function throttle(callback, _option) {
2132
2167
 
2133
2168
  // 缺省值
@@ -2136,7 +2171,7 @@
2136
2171
  keep: false,
2137
2172
  opportunity: "end"
2138
2173
  };
2139
-
2174
+
2140
2175
  // 校对
2141
2176
  if (_option) {
2142
2177
  for (var key in _option) {
@@ -2179,443 +2214,756 @@
2179
2214
  };
2180
2215
  }
2181
2216
 
2182
- function mllData(geoJson) {
2183
- var minLongitude = null, maxLongitude = null, minLatitude = null, maxLatitude = null;
2184
- var forPolygon = function (coordinates) {
2185
- for (var j = 0; j < coordinates.length; j++) {
2186
- for (var k = 0; k < coordinates[j].length; k++) {
2187
- var longitude = coordinates[j][k][0], latitude = coordinates[j][k][1];
2188
- if (minLongitude == void 0 || minLongitude > longitude)
2189
- minLongitude = longitude;
2190
- if (maxLongitude == void 0 || maxLongitude < longitude)
2191
- maxLongitude = longitude;
2192
- if (minLatitude == void 0 || minLatitude > latitude)
2193
- minLatitude = latitude;
2194
- if (maxLatitude == void 0 || maxLatitude < latitude)
2195
- maxLatitude = latitude;
2196
- }
2197
- }
2198
- };
2199
- var features = geoJson.features;
2200
- for (var i = 0; i < features.length; i++) {
2201
- if (features[i].geometry.type == "Polygon") {
2202
- forPolygon(features[i].geometry.coordinates);
2203
- }
2204
- else if (features[i].geometry.type == "MultiPolygon") {
2205
- for (var j = 0; j < features[i].geometry.coordinates.length; j++) {
2206
- forPolygon(features[i].geometry.coordinates[j]);
2207
- }
2208
- }
2209
- }
2210
- return [minLongitude, maxLongitude, minLatitude, maxLatitude];
2217
+ function mllData(geoJson) {
2218
+ var minLongitude = null, maxLongitude = null, minLatitude = null, maxLatitude = null;
2219
+ var forPolygon = function (coordinates) {
2220
+ for (var j = 0; j < coordinates.length; j++) {
2221
+ for (var k = 0; k < coordinates[j].length; k++) {
2222
+ var longitude = coordinates[j][k][0], latitude = coordinates[j][k][1];
2223
+ if (minLongitude == void 0 || minLongitude > longitude)
2224
+ minLongitude = longitude;
2225
+ if (maxLongitude == void 0 || maxLongitude < longitude)
2226
+ maxLongitude = longitude;
2227
+ if (minLatitude == void 0 || minLatitude > latitude)
2228
+ minLatitude = latitude;
2229
+ if (maxLatitude == void 0 || maxLatitude < latitude)
2230
+ maxLatitude = latitude;
2231
+ }
2232
+ }
2233
+ };
2234
+ var features = geoJson.features;
2235
+ for (var i = 0; i < features.length; i++) {
2236
+ if (features[i].geometry.type == "Polygon") {
2237
+ forPolygon(features[i].geometry.coordinates);
2238
+ }
2239
+ else if (features[i].geometry.type == "MultiPolygon") {
2240
+ for (var j = 0; j < features[i].geometry.coordinates.length; j++) {
2241
+ forPolygon(features[i].geometry.coordinates[j]);
2242
+ }
2243
+ }
2244
+ }
2245
+ return [minLongitude, maxLongitude, minLatitude, maxLatitude];
2211
2246
  }
2212
2247
 
2213
- function getBoundary () {
2214
- var geos = [];
2215
- for (var _i = 0; _i < arguments.length; _i++) {
2216
- geos[_i] = arguments[_i];
2217
- }
2218
- var minLongitude = null, maxLongitude = null, minLatitude = null, maxLatitude = null;
2219
- for (var _a = 0, geos_1 = geos; _a < geos_1.length; _a++) {
2220
- var geoJson = geos_1[_a];
2221
- var _b = mllData(geoJson), _minLongitude = _b[0], _maxLongitude = _b[1], _minLatitude = _b[2], _maxLatitude = _b[3];
2222
- if (minLongitude == void 0 || _minLongitude < minLongitude)
2223
- minLongitude = _minLongitude;
2224
- if (maxLongitude == void 0 || _maxLongitude > maxLongitude)
2225
- maxLongitude = _maxLongitude;
2226
- if (minLatitude == void 0 || _minLatitude < minLatitude)
2227
- minLatitude = _minLatitude;
2228
- if (maxLatitude == void 0 || _maxLatitude > maxLatitude)
2229
- maxLatitude = _maxLatitude;
2230
- }
2231
- return [minLongitude, maxLongitude, minLatitude, maxLatitude];
2248
+ function getBoundary () {
2249
+ var geos = [];
2250
+ for (var _i = 0; _i < arguments.length; _i++) {
2251
+ geos[_i] = arguments[_i];
2252
+ }
2253
+ var minLongitude = null, maxLongitude = null, minLatitude = null, maxLatitude = null;
2254
+ for (var _a = 0, geos_1 = geos; _a < geos_1.length; _a++) {
2255
+ var geoJson = geos_1[_a];
2256
+ var _b = mllData(geoJson), _minLongitude = _b[0], _maxLongitude = _b[1], _minLatitude = _b[2], _maxLatitude = _b[3];
2257
+ if (minLongitude == void 0 || _minLongitude < minLongitude)
2258
+ minLongitude = _minLongitude;
2259
+ if (maxLongitude == void 0 || _maxLongitude > maxLongitude)
2260
+ maxLongitude = _maxLongitude;
2261
+ if (minLatitude == void 0 || _minLatitude < minLatitude)
2262
+ minLatitude = _minLatitude;
2263
+ if (maxLatitude == void 0 || _maxLatitude > maxLatitude)
2264
+ maxLatitude = _maxLatitude;
2265
+ }
2266
+ return [minLongitude, maxLongitude, minLatitude, maxLatitude];
2232
2267
  }
2233
2268
 
2234
- var MapCoordinate = (function () {
2235
- function MapCoordinate(config) {
2236
- if (config === void 0) { config = {}; }
2237
- this.name = 'MapCoordinate';
2238
- this.__config = initOption(config, {
2239
- api: "Mercator",
2240
- width: 400,
2241
- height: 300,
2242
- left: 0,
2243
- top: 0
2244
- });
2245
- }
2246
- MapCoordinate.prototype.$$updateMap = function () {
2247
- var _a = this.__boundary, minLongitude = _a[0], maxLongitude = _a[1], minLatitude = _a[2], maxLatitude = _a[3];
2248
- if (this.__config.api == "Eoap") {
2249
- var xScale = this.__config.width * 0.836 / (maxLongitude - minLongitude);
2250
- var yScale = this.__config.height * 0.557 / (maxLatitude - minLatitude);
2251
- this.__map = new Eoap(xScale < yScale ? xScale : yScale, [
2252
- (minLongitude + maxLongitude) * 0.5 * 0.9778,
2253
- (minLatitude + maxLatitude) * 0.5 * 1.025
2254
- ]);
2255
- }
2256
- else if (this.__config.api == "Mercator") {
2257
- var xScale = this.__config.width * 0.72 / (maxLongitude - minLongitude);
2258
- var yScale = this.__config.height * 0.575 / (maxLatitude - minLatitude);
2259
- this.__map = new Mercator(xScale < yScale ? xScale : yScale, [
2260
- (minLongitude + maxLongitude) * 0.5,
2261
- (minLatitude + maxLatitude) * 0.5
2262
- ]);
2263
- }
2264
- else {
2265
- throw new Error("Unexpected API types:" + this.__config.api);
2266
- }
2267
- };
2268
- MapCoordinate.prototype.setConfig = function (config) {
2269
- mergeOption(this.__config, config);
2270
- this.$$updateMap();
2271
- return this;
2272
- };
2273
- MapCoordinate.prototype.setGeos = function () {
2274
- var geos = [];
2275
- for (var _i = 0; _i < arguments.length; _i++) {
2276
- geos[_i] = arguments[_i];
2277
- }
2278
- this.__boundary = getBoundary.apply(void 0, geos);
2279
- this.$$updateMap();
2280
- return this;
2281
- };
2282
- MapCoordinate.prototype.use = function (λ, φ) {
2283
- if (this.__map) {
2284
- var dxyz = this.__map.use(λ, φ);
2285
- return [
2286
- this.__config.left + this.__config.width * 0.5 + dxyz[0],
2287
- this.__config.top + this.__config.height * 0.5 + dxyz[1],
2288
- ];
2289
- }
2290
- else {
2291
- throw new Error("Geographic data not set");
2292
- }
2293
- };
2294
- return MapCoordinate;
2269
+ var MapCoordinate = (function () {
2270
+ function MapCoordinate(config) {
2271
+ if (config === void 0) { config = {}; }
2272
+ this.name = 'MapCoordinate';
2273
+ this.__config = initOption(config, {
2274
+ api: "Mercator",
2275
+ width: 400,
2276
+ height: 300,
2277
+ left: 0,
2278
+ top: 0
2279
+ });
2280
+ }
2281
+ MapCoordinate.prototype.$$updateMap = function () {
2282
+ var _a = this.__boundary, minLongitude = _a[0], maxLongitude = _a[1], minLatitude = _a[2], maxLatitude = _a[3];
2283
+ if (this.__config.api == "Eoap") {
2284
+ var xScale = this.__config.width * 0.836 / (maxLongitude - minLongitude);
2285
+ var yScale = this.__config.height * 0.557 / (maxLatitude - minLatitude);
2286
+ this.__map = new Eoap(xScale < yScale ? xScale : yScale, [
2287
+ (minLongitude + maxLongitude) * 0.5 * 0.9778,
2288
+ (minLatitude + maxLatitude) * 0.5 * 1.025
2289
+ ]);
2290
+ }
2291
+ else if (this.__config.api == "Mercator") {
2292
+ var xScale = this.__config.width * 0.72 / (maxLongitude - minLongitude);
2293
+ var yScale = this.__config.height * 0.575 / (maxLatitude - minLatitude);
2294
+ this.__map = new Mercator(xScale < yScale ? xScale : yScale, [
2295
+ (minLongitude + maxLongitude) * 0.5,
2296
+ (minLatitude + maxLatitude) * 0.5
2297
+ ]);
2298
+ }
2299
+ else {
2300
+ throw new Error("Unexpected API types:" + this.__config.api);
2301
+ }
2302
+ };
2303
+ MapCoordinate.prototype.setConfig = function (config) {
2304
+ mergeOption(this.__config, config);
2305
+ this.$$updateMap();
2306
+ return this;
2307
+ };
2308
+ MapCoordinate.prototype.setGeos = function () {
2309
+ var geos = [];
2310
+ for (var _i = 0; _i < arguments.length; _i++) {
2311
+ geos[_i] = arguments[_i];
2312
+ }
2313
+ this.__boundary = getBoundary.apply(void 0, geos);
2314
+ this.$$updateMap();
2315
+ return this;
2316
+ };
2317
+ MapCoordinate.prototype.use = function (λ, φ) {
2318
+ if (this.__map) {
2319
+ var dxyz = this.__map.use(λ, φ);
2320
+ return [
2321
+ this.__config.left + this.__config.width * 0.5 + dxyz[0],
2322
+ this.__config.top + this.__config.height * 0.5 + dxyz[1],
2323
+ ];
2324
+ }
2325
+ else {
2326
+ throw new Error("Geographic data not set");
2327
+ }
2328
+ };
2329
+ return MapCoordinate;
2295
2330
  }());
2296
2331
 
2297
- var toInnerTree = (function (initTree, config) {
2298
- var tempTree = {};
2299
- var temp = config.root(initTree);
2300
- var id, rid;
2301
- id = rid = config.id(temp);
2302
- tempTree[id] = {
2303
- "data": temp,
2304
- "pid": null,
2305
- "id": id,
2306
- "isOpen": true,
2307
- "show": true,
2308
- "deg": 0,
2309
- "children": []
2310
- };
2311
- var num = 1;
2312
- (function createTree(pdata, pid) {
2313
- var children = config.children(pdata, initTree);
2314
- num += children ? children.length : 0;
2315
- for (var flag = 0; children && flag < children.length; flag++) {
2316
- id = config.id(children[flag]);
2317
- tempTree[pid].children.push(id);
2318
- tempTree[id] = {
2319
- "data": children[flag],
2320
- "pid": pid,
2321
- "id": id,
2322
- "isOpen": true,
2323
- "show": true,
2324
- "deg": 0,
2325
- "children": []
2326
- };
2327
- createTree(children[flag], id);
2328
- }
2329
- })(temp, id);
2330
- return {
2331
- rid: rid,
2332
- value: tempTree,
2333
- num: num
2334
- };
2332
+ var toInnerTree = (function (initTree, config) {
2333
+ var tempTree = {};
2334
+ var temp = config.root(initTree);
2335
+ var id, rid;
2336
+ id = rid = config.id(temp);
2337
+ tempTree[id] = {
2338
+ "data": temp,
2339
+ "pid": null,
2340
+ "id": id,
2341
+ "isOpen": true,
2342
+ "show": true,
2343
+ "deg": 0,
2344
+ "children": []
2345
+ };
2346
+ var num = 1;
2347
+ (function createTree(pdata, pid) {
2348
+ var children = config.children(pdata, initTree);
2349
+ num += children ? children.length : 0;
2350
+ for (var flag = 0; children && flag < children.length; flag++) {
2351
+ id = config.id(children[flag]);
2352
+ tempTree[pid].children.push(id);
2353
+ tempTree[id] = {
2354
+ "data": children[flag],
2355
+ "pid": pid,
2356
+ "id": id,
2357
+ "isOpen": true,
2358
+ "show": true,
2359
+ "deg": 0,
2360
+ "children": []
2361
+ };
2362
+ createTree(children[flag], id);
2363
+ }
2364
+ })(temp, id);
2365
+ return {
2366
+ rid: rid,
2367
+ value: tempTree,
2368
+ num: num
2369
+ };
2335
2370
  });
2336
2371
 
2337
- function toPlainTree (initTree, config, noOpens) {
2338
- var treeData = toInnerTree(initTree, config);
2339
- var alltreedata = treeData.value;
2340
- var rootid = treeData.rid;
2341
- if (treeData.num == 1) {
2342
- alltreedata[rootid].left = 0.5;
2343
- alltreedata[rootid].top = 0.5;
2344
- alltreedata[rootid].show = true;
2345
- return {
2346
- deep: 1,
2347
- node: alltreedata,
2348
- root: rootid,
2349
- size: 1
2350
- };
2351
- }
2352
- else {
2353
- var beforeDis_1 = [];
2354
- var size_1 = 0, maxDeep_1 = 0;
2355
- if (noOpens[rootid]) {
2356
- alltreedata[rootid].left = 0.5;
2357
- alltreedata[rootid].top = 0.5;
2358
- alltreedata[rootid].show = true;
2359
- size_1 = 1;
2360
- }
2361
- else {
2362
- (function positionCalc(pNode, deep) {
2363
- if (deep > maxDeep_1)
2364
- maxDeep_1 = deep;
2365
- var flag = 0;
2366
- if (!noOpens[pNode.id]) {
2367
- for (flag = 0; flag < pNode.children.length; flag++)
2368
- positionCalc(alltreedata[pNode.children[flag]], deep + 1);
2369
- }
2370
- alltreedata[pNode.id].left = deep + 0.5;
2371
- if (flag == 0) {
2372
- if (beforeDis_1[deep] == void 0)
2373
- beforeDis_1[deep] = -0.5;
2374
- if (beforeDis_1[deep - 1] == void 0)
2375
- beforeDis_1[deep - 1] = -0.5;
2376
- alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
2377
- var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
2378
- if (pTop - 1 < beforeDis_1[deep - 1])
2379
- alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
2380
- }
2381
- else {
2382
- alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
2383
- }
2384
- if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
2385
- var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
2386
- alltreedata[_pid].top += needUp_1;
2387
- if (beforeDis_1[_deep] < alltreedata[_pid].top)
2388
- beforeDis_1[_deep] = alltreedata[_pid].top;
2389
- for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
2390
- doUp(alltreedata[_pid].children[_flag], _deep + 1);
2391
- }
2392
- })(pNode.id, deep);
2393
- }
2394
- beforeDis_1[deep] = alltreedata[pNode.id].top;
2395
- if (alltreedata[pNode.id].top + 0.5 > size_1)
2396
- size_1 = alltreedata[pNode.id].top + 0.5;
2397
- })(alltreedata[rootid], 0);
2398
- }
2399
- for (var key in noOpens) {
2400
- if (noOpens[key]) {
2401
- alltreedata[key].isOpen = false;
2402
- (function updateHidden(pid, left, top) {
2403
- for (var index = 0; index < alltreedata[pid].children.length; index++) {
2404
- alltreedata[alltreedata[pid].children[index]].left = left;
2405
- alltreedata[alltreedata[pid].children[index]].top = top;
2406
- alltreedata[alltreedata[pid].children[index]].show = false;
2407
- updateHidden(alltreedata[pid].children[index], left, top);
2408
- }
2409
- })(key, alltreedata[key].left, alltreedata[key].top);
2410
- }
2411
- }
2412
- return {
2413
- "node": alltreedata,
2414
- "root": rootid,
2415
- "size": size_1,
2416
- "deep": maxDeep_1 + 1
2417
- };
2418
- }
2372
+ function toPlainTree (initTree, config, noOpens) {
2373
+ var treeData = toInnerTree(initTree, config);
2374
+ var alltreedata = treeData.value;
2375
+ var rootid = treeData.rid;
2376
+ if (treeData.num == 1) {
2377
+ alltreedata[rootid].left = 0.5;
2378
+ alltreedata[rootid].top = 0.5;
2379
+ alltreedata[rootid].show = true;
2380
+ return {
2381
+ deep: 1,
2382
+ node: alltreedata,
2383
+ root: rootid,
2384
+ size: 1
2385
+ };
2386
+ }
2387
+ else {
2388
+ var beforeDis_1 = [];
2389
+ var size_1 = 0, maxDeep_1 = 0;
2390
+ if (noOpens[rootid]) {
2391
+ alltreedata[rootid].left = 0.5;
2392
+ alltreedata[rootid].top = 0.5;
2393
+ alltreedata[rootid].show = true;
2394
+ size_1 = 1;
2395
+ }
2396
+ else {
2397
+ (function positionCalc(pNode, deep) {
2398
+ if (deep > maxDeep_1)
2399
+ maxDeep_1 = deep;
2400
+ var flag = 0;
2401
+ if (!noOpens[pNode.id]) {
2402
+ for (flag = 0; flag < pNode.children.length; flag++)
2403
+ positionCalc(alltreedata[pNode.children[flag]], deep + 1);
2404
+ }
2405
+ alltreedata[pNode.id].left = deep + 0.5;
2406
+ if (flag == 0) {
2407
+ if (beforeDis_1[deep] == void 0)
2408
+ beforeDis_1[deep] = -0.5;
2409
+ if (beforeDis_1[deep - 1] == void 0)
2410
+ beforeDis_1[deep - 1] = -0.5;
2411
+ alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
2412
+ var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
2413
+ if (pTop - 1 < beforeDis_1[deep - 1])
2414
+ alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
2415
+ }
2416
+ else {
2417
+ alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
2418
+ }
2419
+ if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
2420
+ var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
2421
+ alltreedata[_pid].top += needUp_1;
2422
+ if (beforeDis_1[_deep] < alltreedata[_pid].top)
2423
+ beforeDis_1[_deep] = alltreedata[_pid].top;
2424
+ for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
2425
+ doUp(alltreedata[_pid].children[_flag], _deep + 1);
2426
+ }
2427
+ })(pNode.id, deep);
2428
+ }
2429
+ beforeDis_1[deep] = alltreedata[pNode.id].top;
2430
+ if (alltreedata[pNode.id].top + 0.5 > size_1)
2431
+ size_1 = alltreedata[pNode.id].top + 0.5;
2432
+ })(alltreedata[rootid], 0);
2433
+ }
2434
+ for (var key in noOpens) {
2435
+ if (noOpens[key]) {
2436
+ alltreedata[key].isOpen = false;
2437
+ (function updateHidden(pid, left, top) {
2438
+ for (var index = 0; index < alltreedata[pid].children.length; index++) {
2439
+ alltreedata[alltreedata[pid].children[index]].left = left;
2440
+ alltreedata[alltreedata[pid].children[index]].top = top;
2441
+ alltreedata[alltreedata[pid].children[index]].show = false;
2442
+ updateHidden(alltreedata[pid].children[index], left, top);
2443
+ }
2444
+ })(key, alltreedata[key].left, alltreedata[key].top);
2445
+ }
2446
+ }
2447
+ return {
2448
+ "node": alltreedata,
2449
+ "root": rootid,
2450
+ "size": size_1,
2451
+ "deep": maxDeep_1 + 1
2452
+ };
2453
+ }
2419
2454
  }
2420
2455
 
2421
- var Tree = (function () {
2422
- function Tree(config) {
2423
- if (config === void 0) { config = {}; }
2424
- this.name = 'Tree';
2425
- this.__config = initOption(config, {
2426
- root: function (initTree) { return initTree; },
2427
- children: function (parentTree) { return parentTree.children; },
2428
- id: function (treedata) { return treedata.name; }
2429
- });
2430
- }
2431
- Tree.prototype.use = function (initTree, noOpens) {
2432
- if (noOpens === void 0) { noOpens = {}; }
2433
- return toPlainTree(initTree, this.__config, noOpens);
2434
- };
2435
- return Tree;
2456
+ var Tree = (function () {
2457
+ function Tree(config) {
2458
+ if (config === void 0) { config = {}; }
2459
+ this.name = 'Tree';
2460
+ this.__config = initOption(config, {
2461
+ root: function (initTree) { return initTree; },
2462
+ children: function (parentTree) { return parentTree.children; },
2463
+ id: function (treedata) { return treedata.name; }
2464
+ });
2465
+ }
2466
+ Tree.prototype.use = function (initTree, noOpens) {
2467
+ if (noOpens === void 0) { noOpens = {}; }
2468
+ return toPlainTree(initTree, this.__config, noOpens);
2469
+ };
2470
+ return Tree;
2436
2471
  }());
2437
2472
 
2438
- var TreeLayout = (function (_super) {
2439
- __extends(TreeLayout, _super);
2440
- function TreeLayout() {
2441
- var _this = _super !== null && _super.apply(this, arguments) || this;
2442
- _this.name = 'TreeLayout';
2443
- _this.__option = {
2444
- offsetX: 0,
2445
- offsetY: 0,
2446
- duration: 500,
2447
- type: "plain",
2448
- direction: "LR",
2449
- x: 100,
2450
- y: 100,
2451
- width: 100,
2452
- height: 100,
2453
- radius: 100
2454
- };
2455
- _this.__noOpens = {};
2456
- return _this;
2457
- }
2458
- TreeLayout.prototype.setOption = function (option) {
2459
- initOption(option, this.__option);
2460
- return this;
2461
- };
2462
- TreeLayout.prototype.use = function (initTree, noOpens) {
2463
- if (noOpens === void 0) { noOpens = {}; }
2464
- var tree = _super.prototype.use.call(this, initTree, noOpens);
2465
- if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
2466
- for (var key in tree.node) {
2467
- if (!tree.node[key].show) {
2468
- var deep = 0, pid = key;
2469
- do {
2470
- pid = tree.node[pid].pid;
2471
- deep++;
2472
- } while (!tree.node[pid].show);
2473
- tree.node[key].left += this.__option.offsetX * deep;
2474
- tree.node[key].top += this.__option.offsetY * deep;
2475
- }
2476
- }
2477
- }
2478
- if (this.__option.type == 'rect') {
2479
- if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
2480
- var perW = this.__option.height / tree.size;
2481
- var perD = this.__option.width / (tree.deep - 1);
2482
- var balanceW = this.__option.y - this.__option.height * 0.5;
2483
- var flag = this.__option.direction == 'LR' ? 1 : -1;
2484
- for (var key in tree.node) {
2485
- if (tree.deep == 1) {
2486
- tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
2487
- tree.node[key].top = this.__option.y;
2488
- }
2489
- else {
2490
- tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
2491
- tree.node[key].top = tree.node[key].top * perW + balanceW;
2492
- }
2493
- }
2494
- }
2495
- else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
2496
- var perW = this.__option.width / tree.size;
2497
- var perD = this.__option.height / (tree.deep - 1);
2498
- var balanceW = this.__option.x - this.__option.width * 0.5;
2499
- var flag = this.__option.direction == 'TB' ? 1 : -1;
2500
- for (var key in tree.node) {
2501
- tree.node[key].deg = this.__option.direction == 'TB' ? Math.PI * 0.5 : Math.PI * -0.5;
2502
- if (tree.deep == 1) {
2503
- tree.node[key].left = this.__option.x;
2504
- tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
2505
- }
2506
- else {
2507
- var left = tree.node[key].left;
2508
- tree.node[key].left = tree.node[key].top * perW + balanceW;
2509
- tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
2510
- }
2511
- }
2512
- }
2513
- }
2514
- else if (this.__option.type == 'circle') {
2515
- var cx = this.__option.x, cy = this.__option.y;
2516
- var deg = Math.PI * 2 / tree.size;
2517
- var per = this.__option.radius / (tree.deep - 1);
2518
- for (var key in tree.node) {
2519
- if (tree.node[key].left == 0.5) {
2520
- tree.node[key].left = cx;
2521
- tree.node[key].top = cy;
2522
- }
2523
- else {
2524
- var position = rotate$1(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
2525
- tree.node[key].deg = deg * tree.node[key].top;
2526
- tree.node[key].left = position[0];
2527
- tree.node[key].top = position[1];
2528
- }
2529
- }
2530
- }
2531
- return tree;
2532
- };
2533
- TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
2534
- if (noOpens === void 0) { noOpens = {}; }
2535
- this.__rback = renderBack;
2536
- this.__oralTree = initTree;
2537
- this.__noOpens = noOpens;
2538
- this.__preTree = this.use(this.__oralTree, this.__noOpens);
2539
- this.__rback(this.__preTree);
2540
- return this;
2541
- };
2542
- TreeLayout.prototype.unbind = function () {
2543
- this.__rback = function () { return null; };
2544
- this.__oralTree = null;
2545
- this.__preTree = null;
2546
- this.__noOpens = {};
2547
- return this;
2548
- };
2549
- TreeLayout.prototype.doUpdate = function () {
2550
- var _this = this;
2551
- var newTree = this.use(this.__oralTree, this.__noOpens);
2552
- var cacheTree = JSON.parse(JSON.stringify(newTree));
2553
- animation(function (deep) {
2554
- if (_this.__preTree) {
2555
- for (var key in cacheTree.node) {
2556
- if (newTree.node[key].show || _this.__preTree.node[key].show) {
2557
- cacheTree.node[key].show = true;
2558
- cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
2559
- cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
2560
- }
2561
- }
2562
- }
2563
- _this.__rback(cacheTree);
2564
- }, this.__option.duration, function () {
2565
- _this.__preTree = newTree;
2566
- _this.__rback(_this.__preTree);
2567
- });
2568
- return this;
2569
- };
2570
- TreeLayout.prototype.closeNode = function (id) {
2571
- if (!this.__preTree)
2572
- return this;
2573
- this.__noOpens[id] = true;
2574
- this.doUpdate();
2575
- return this;
2576
- };
2577
- TreeLayout.prototype.openNode = function (id) {
2578
- if (!this.__preTree)
2579
- return this;
2580
- this.__noOpens[id] = false;
2581
- this.doUpdate();
2582
- return this;
2583
- };
2584
- TreeLayout.prototype.toggleNode = function (id) {
2585
- if (!this.__preTree)
2586
- return this;
2587
- this.__noOpens[id] = !this.__noOpens[id];
2588
- this.doUpdate();
2589
- return this;
2590
- };
2591
- return TreeLayout;
2473
+ var TreeLayout = (function (_super) {
2474
+ __extends(TreeLayout, _super);
2475
+ function TreeLayout() {
2476
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2477
+ _this.name = 'TreeLayout';
2478
+ _this.__option = {
2479
+ offsetX: 0,
2480
+ offsetY: 0,
2481
+ duration: 500,
2482
+ type: "plain",
2483
+ direction: "LR",
2484
+ x: 100,
2485
+ y: 100,
2486
+ width: 100,
2487
+ height: 100,
2488
+ radius: 100
2489
+ };
2490
+ _this.__noOpens = {};
2491
+ return _this;
2492
+ }
2493
+ TreeLayout.prototype.setOption = function (option) {
2494
+ initOption(option, this.__option);
2495
+ return this;
2496
+ };
2497
+ TreeLayout.prototype.use = function (initTree, noOpens) {
2498
+ if (noOpens === void 0) { noOpens = {}; }
2499
+ var tree = _super.prototype.use.call(this, initTree, noOpens);
2500
+ if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
2501
+ for (var key in tree.node) {
2502
+ if (!tree.node[key].show) {
2503
+ var deep = 0, pid = key;
2504
+ do {
2505
+ pid = tree.node[pid].pid;
2506
+ deep++;
2507
+ } while (!tree.node[pid].show);
2508
+ tree.node[key].left += this.__option.offsetX * deep;
2509
+ tree.node[key].top += this.__option.offsetY * deep;
2510
+ }
2511
+ }
2512
+ }
2513
+ if (this.__option.type == 'rect') {
2514
+ if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
2515
+ var perW = this.__option.height / tree.size;
2516
+ var perD = this.__option.width / (tree.deep - 1);
2517
+ var balanceW = this.__option.y - this.__option.height * 0.5;
2518
+ var flag = this.__option.direction == 'LR' ? 1 : -1;
2519
+ for (var key in tree.node) {
2520
+ if (tree.deep == 1) {
2521
+ tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
2522
+ tree.node[key].top = this.__option.y;
2523
+ }
2524
+ else {
2525
+ tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
2526
+ tree.node[key].top = tree.node[key].top * perW + balanceW;
2527
+ }
2528
+ }
2529
+ }
2530
+ else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
2531
+ var perW = this.__option.width / tree.size;
2532
+ var perD = this.__option.height / (tree.deep - 1);
2533
+ var balanceW = this.__option.x - this.__option.width * 0.5;
2534
+ var flag = this.__option.direction == 'TB' ? 1 : -1;
2535
+ for (var key in tree.node) {
2536
+ tree.node[key].deg = this.__option.direction == 'TB' ? Math.PI * 0.5 : Math.PI * -0.5;
2537
+ if (tree.deep == 1) {
2538
+ tree.node[key].left = this.__option.x;
2539
+ tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
2540
+ }
2541
+ else {
2542
+ var left = tree.node[key].left;
2543
+ tree.node[key].left = tree.node[key].top * perW + balanceW;
2544
+ tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
2545
+ }
2546
+ }
2547
+ }
2548
+ }
2549
+ else if (this.__option.type == 'circle') {
2550
+ var cx = this.__option.x, cy = this.__option.y;
2551
+ var deg = Math.PI * 2 / tree.size;
2552
+ var per = this.__option.radius / (tree.deep - 1);
2553
+ for (var key in tree.node) {
2554
+ if (tree.node[key].left == 0.5) {
2555
+ tree.node[key].left = cx;
2556
+ tree.node[key].top = cy;
2557
+ }
2558
+ else {
2559
+ var position = rotate$1(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
2560
+ tree.node[key].deg = deg * tree.node[key].top;
2561
+ tree.node[key].left = position[0];
2562
+ tree.node[key].top = position[1];
2563
+ }
2564
+ }
2565
+ }
2566
+ return tree;
2567
+ };
2568
+ TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
2569
+ if (noOpens === void 0) { noOpens = {}; }
2570
+ this.__rback = renderBack;
2571
+ this.__oralTree = initTree;
2572
+ this.__noOpens = noOpens;
2573
+ this.__preTree = this.use(this.__oralTree, this.__noOpens);
2574
+ this.__rback(this.__preTree);
2575
+ return this;
2576
+ };
2577
+ TreeLayout.prototype.unbind = function () {
2578
+ this.__rback = function () { return null; };
2579
+ this.__oralTree = null;
2580
+ this.__preTree = null;
2581
+ this.__noOpens = {};
2582
+ return this;
2583
+ };
2584
+ TreeLayout.prototype.doUpdate = function () {
2585
+ var _this = this;
2586
+ var newTree = this.use(this.__oralTree, this.__noOpens);
2587
+ var cacheTree = JSON.parse(JSON.stringify(newTree));
2588
+ animation(function (deep) {
2589
+ if (_this.__preTree) {
2590
+ for (var key in cacheTree.node) {
2591
+ if (newTree.node[key].show || _this.__preTree.node[key].show) {
2592
+ cacheTree.node[key].show = true;
2593
+ cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
2594
+ cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
2595
+ }
2596
+ }
2597
+ }
2598
+ _this.__rback(cacheTree);
2599
+ }, this.__option.duration, function () {
2600
+ _this.__preTree = newTree;
2601
+ _this.__rback(_this.__preTree);
2602
+ });
2603
+ return this;
2604
+ };
2605
+ TreeLayout.prototype.closeNode = function (id) {
2606
+ if (!this.__preTree)
2607
+ return this;
2608
+ this.__noOpens[id] = true;
2609
+ this.doUpdate();
2610
+ return this;
2611
+ };
2612
+ TreeLayout.prototype.openNode = function (id) {
2613
+ if (!this.__preTree)
2614
+ return this;
2615
+ this.__noOpens[id] = false;
2616
+ this.doUpdate();
2617
+ return this;
2618
+ };
2619
+ TreeLayout.prototype.toggleNode = function (id) {
2620
+ if (!this.__preTree)
2621
+ return this;
2622
+ this.__noOpens[id] = !this.__noOpens[id];
2623
+ this.doUpdate();
2624
+ return this;
2625
+ };
2626
+ return TreeLayout;
2592
2627
  }(Tree));
2593
2628
 
2594
- var index = {
2595
- Cardinal: Cardinal,
2596
- Hermite: Hermite,
2597
- Matrix4: Matrix4,
2598
- rotate: rotate$1,
2599
- move: move,
2600
- scale: scale,
2601
- getLoopColors: getLoopColors,
2602
- animation: animation,
2603
- ruler: ruler,
2604
- SVG: SVG,
2605
- Canvas: Canvas,
2606
- RawCanvas: Canvas$1,
2607
- getWebGLContext: getWebGLContext,
2608
- Shader: ShaderObject,
2609
- Texture: TextureObject,
2610
- Buffer: BufferObject,
2611
- Eoap: Eoap,
2612
- Mercator: Mercator,
2613
- throttle: throttle,
2614
- assemble: assemble,
2615
- MapCoordinate: MapCoordinate,
2616
- TreeLayout: TreeLayout,
2617
- initOption: initOption,
2618
- mergeOption: mergeOption
2629
+ var PieLayout = (function () {
2630
+ function PieLayout(config) {
2631
+ if (config === void 0) { config = {}; }
2632
+ this.name = 'PieLayout';
2633
+ this.__option = {
2634
+ cx: 200,
2635
+ cy: 200,
2636
+ radius: [50, 100],
2637
+ duration: 200,
2638
+ };
2639
+ this.__hoverIndex = -1;
2640
+ this.__config = initOption(config, {
2641
+ name: function (pieData, initPie) { return pieData.name; },
2642
+ value: function (pieData, initPie) { return pieData.value; }
2643
+ });
2644
+ }
2645
+ PieLayout.prototype.setOption = function (option) {
2646
+ initOption(option, this.__option);
2647
+ return this;
2648
+ };
2649
+ PieLayout.prototype.use = function (initPie, hoverIndex) {
2650
+ if (hoverIndex === void 0) { hoverIndex = -1; }
2651
+ var pie = {
2652
+ count: initPie.length,
2653
+ cx: this.__option.cx,
2654
+ cy: this.__option.cy,
2655
+ radius: this.__option.radius,
2656
+ hoverIndex: hoverIndex,
2657
+ node: []
2658
+ };
2659
+ var totalValue = 0, names = [], values = [];
2660
+ for (var i = 0; i < initPie.length; i++) {
2661
+ names[i] = this.__config.name(initPie[i], initPie);
2662
+ values[i] = this.__config.value(initPie[i], initPie);
2663
+ totalValue += values[i];
2664
+ }
2665
+ var beginDeg = Math.PI * -0.5, currenDeg;
2666
+ for (var i = 0; i < initPie.length; i++) {
2667
+ currenDeg = values[i] / totalValue * Math.PI * 2;
2668
+ var radius = [this.__option.radius[0], this.__option.radius[1] * (1 + (hoverIndex === i ? 0.05 : 0))];
2669
+ var pdeg = beginDeg + currenDeg * 0.5, pradius = Math.max(this.__option.radius[0], this.__option.radius[1]);
2670
+ var p0 = rotate$1(pie.cx, pie.cy, pdeg, pie.cx + pradius, pie.cy);
2671
+ var p1 = rotate$1(pie.cx, pie.cy, pdeg, pie.cx + pradius + 15, pie.cy);
2672
+ var pflag = p0[0] > pie.cx ? 1 : -1;
2673
+ var p2 = [p1[0] + pflag * 20, p1[1]];
2674
+ var p3 = [p1[0] + pflag * 25, p1[1]];
2675
+ pie.node[i] = {
2676
+ value: values[i],
2677
+ name: names[i],
2678
+ beginDeg: beginDeg,
2679
+ deg: currenDeg,
2680
+ isHover: hoverIndex === i,
2681
+ radius: radius,
2682
+ label: {
2683
+ line: [p0, p1, p2],
2684
+ position: p3,
2685
+ align: pflag === -1 ? "right" : "left"
2686
+ }
2687
+ };
2688
+ beginDeg += currenDeg;
2689
+ }
2690
+ return pie;
2691
+ };
2692
+ PieLayout.prototype.bind = function (initPie, renderBack) {
2693
+ this.__rback = renderBack;
2694
+ this.__oralPie = initPie;
2695
+ this.__prePie = this.use(this.__oralPie, this.__hoverIndex);
2696
+ this.__rback(this.__prePie);
2697
+ return this;
2698
+ };
2699
+ PieLayout.prototype.unbind = function () {
2700
+ this.__rback = function () { return null; };
2701
+ this.__oralPie = null;
2702
+ this.__prePie = null;
2703
+ this.__hoverIndex = -1;
2704
+ return this;
2705
+ };
2706
+ PieLayout.prototype.setHover = function (index) {
2707
+ if (!this.__prePie || this.__hoverIndex === index)
2708
+ return this;
2709
+ this.__hoverIndex = index;
2710
+ this.doUpdate();
2711
+ return this;
2712
+ };
2713
+ PieLayout.prototype.doUpdate = function () {
2714
+ var _this = this;
2715
+ var newPie = this.use(this.__oralPie, this.__hoverIndex);
2716
+ var cachePie = JSON.parse(JSON.stringify(newPie));
2717
+ animation(function (deep) {
2718
+ if (_this.__prePie) {
2719
+ for (var i = 0; i < cachePie.count; i++) {
2720
+ cachePie.node[i].radius[1] = _this.__prePie.node[i].radius[1] + (newPie.node[i].radius[1] - _this.__prePie.node[i].radius[1]) * deep;
2721
+ }
2722
+ }
2723
+ _this.__rback(cachePie);
2724
+ }, this.__option.duration, function () {
2725
+ _this.__prePie = newPie;
2726
+ _this.__rback(_this.__prePie);
2727
+ });
2728
+ return this;
2729
+ };
2730
+ return PieLayout;
2731
+ }());
2732
+
2733
+ var BarLayout = (function () {
2734
+ function BarLayout(config) {
2735
+ if (config === void 0) { config = {}; }
2736
+ this.name = 'BarLayout';
2737
+ this.__option = {
2738
+ x: 50,
2739
+ y: 350,
2740
+ width: 400,
2741
+ height: 300,
2742
+ category: "xAxis",
2743
+ duration: 200
2744
+ };
2745
+ this.__config = initOption(config, {});
2746
+ }
2747
+ BarLayout.prototype.setOption = function (option) {
2748
+ initOption(option, this.__option);
2749
+ return this;
2750
+ };
2751
+ BarLayout.prototype.use = function (initBar) {
2752
+ var bar = {
2753
+ coordinate: {
2754
+ x: this.__option.x,
2755
+ y: this.__option.y,
2756
+ width: this.__option.width,
2757
+ height: this.__option.height,
2758
+ xAxis: {
2759
+ type: this.__option.category === "xAxis" ? "category" : "value",
2760
+ data: []
2761
+ },
2762
+ yAxis: {
2763
+ type: this.__option.category === "xAxis" ? "value" : "category",
2764
+ data: []
2765
+ }
2766
+ },
2767
+ node: []
2768
+ };
2769
+ var maxValue = void 0, minValue = void 0;
2770
+ if (initBar.data) {
2771
+ for (var _i = 0, _a = initBar.data; _i < _a.length; _i++) {
2772
+ var val = _a[_i];
2773
+ if (maxValue === void 0 || val > maxValue)
2774
+ maxValue = val;
2775
+ if (minValue === void 0 || val < minValue)
2776
+ minValue = val;
2777
+ }
2778
+ }
2779
+ else if (initBar.value) {
2780
+ for (var _b = 0, _c = initBar.value; _b < _c.length; _b++) {
2781
+ var item = _c[_b];
2782
+ for (var _d = 0, _e = item.data; _d < _e.length; _d++) {
2783
+ var val = _e[_d];
2784
+ if (maxValue === void 0 || val > maxValue)
2785
+ maxValue = val;
2786
+ if (minValue === void 0 || val < minValue)
2787
+ minValue = val;
2788
+ }
2789
+ }
2790
+ }
2791
+ else {
2792
+ throw new Error('No data leads to parsing errors');
2793
+ }
2794
+ var rulerArray = ruler(maxValue || 0, minValue || 0, 5);
2795
+ var categoryLen;
2796
+ var valueLen;
2797
+ if (this.__option.category === "xAxis") {
2798
+ bar.coordinate.xAxis.data = initBar.category;
2799
+ bar.coordinate.yAxis.data = rulerArray;
2800
+ categoryLen = this.__option.width;
2801
+ valueLen = -1 * this.__option.height;
2802
+ }
2803
+ else {
2804
+ bar.coordinate.xAxis.data = rulerArray;
2805
+ bar.coordinate.yAxis.data = initBar.category;
2806
+ categoryLen = this.__option.height;
2807
+ valueLen = this.__option.width;
2808
+ }
2809
+ var category = [];
2810
+ var categorySingle1Width = categoryLen / initBar.category.length;
2811
+ var categorySingle2Width = categorySingle1Width * 0.9;
2812
+ var categoryStart = categorySingle1Width * 0.05;
2813
+ if (initBar.data) {
2814
+ for (var i = 0; i < initBar.data.length; i++) {
2815
+ category.push([
2816
+ categoryStart + categorySingle1Width * i,
2817
+ categorySingle2Width
2818
+ ]);
2819
+ }
2820
+ }
2821
+ else {
2822
+ var categorySingle3Width = categorySingle2Width / initBar.value.length;
2823
+ var categorySingle4Width = categorySingle3Width * 0.9;
2824
+ var categoryStartBlance = categorySingle3Width * 0.05;
2825
+ for (var i = 0; i < initBar.value[0].data.length; i++) {
2826
+ category[i] = [];
2827
+ for (var j = 0; j < initBar.value.length; j++) {
2828
+ category[i].push([
2829
+ categoryStart + categorySingle1Width * i + categorySingle3Width * j + categoryStartBlance,
2830
+ categorySingle4Width
2831
+ ]);
2832
+ }
2833
+ }
2834
+ }
2835
+ var singleValueLen = valueLen / (rulerArray[rulerArray.length - 1] - rulerArray[0]);
2836
+ var getLenByValue = function (value) {
2837
+ return singleValueLen * (value - rulerArray[0]);
2838
+ };
2839
+ if (this.__option.category === "xAxis") {
2840
+ if (initBar.data) {
2841
+ var nodeBar = [];
2842
+ for (var i = 0; i < initBar.data.length; i++) {
2843
+ nodeBar.push({
2844
+ x: this.__option.x + category[i][0],
2845
+ y: this.__option.y,
2846
+ width: category[i][1],
2847
+ height: getLenByValue(initBar.data[i]),
2848
+ value: initBar.data[i]
2849
+ });
2850
+ }
2851
+ bar.node.push({
2852
+ bar: nodeBar
2853
+ });
2854
+ }
2855
+ else {
2856
+ for (var j = 0; j < initBar.value.length; j++) {
2857
+ var nodeBar = [];
2858
+ for (var i = 0; i < initBar.value[j].data.length; i++) {
2859
+ nodeBar.push({
2860
+ x: this.__option.x + category[i][j][0],
2861
+ y: this.__option.y,
2862
+ width: category[i][j][1],
2863
+ height: getLenByValue(initBar.value[j].data[i]),
2864
+ value: initBar.value[j].data[i]
2865
+ });
2866
+ }
2867
+ bar.node.push({
2868
+ name: initBar.value[j].name,
2869
+ bar: nodeBar
2870
+ });
2871
+ }
2872
+ }
2873
+ }
2874
+ else {
2875
+ if (initBar.data) {
2876
+ var nodeBar = [];
2877
+ for (var i = 0; i < initBar.data.length; i++) {
2878
+ nodeBar.push({
2879
+ x: this.__option.x,
2880
+ y: this.__option.y - this.__option.height + category[i][0],
2881
+ width: getLenByValue(initBar.data[i]),
2882
+ height: category[i][1],
2883
+ value: initBar.data[i]
2884
+ });
2885
+ }
2886
+ bar.node.push({
2887
+ bar: nodeBar
2888
+ });
2889
+ }
2890
+ else {
2891
+ for (var j = 0; j < initBar.value.length; j++) {
2892
+ var nodeBar = [];
2893
+ for (var i = 0; i < initBar.value[j].data.length; i++) {
2894
+ nodeBar.push({
2895
+ x: this.__option.x,
2896
+ y: this.__option.y - this.__option.height + category[i][j][0],
2897
+ width: getLenByValue(initBar.value[j].data[i]),
2898
+ height: category[i][j][1],
2899
+ value: initBar.value[j].data[i]
2900
+ });
2901
+ }
2902
+ bar.node.push({
2903
+ name: initBar.value[j].name,
2904
+ bar: nodeBar
2905
+ });
2906
+ }
2907
+ }
2908
+ }
2909
+ return bar;
2910
+ };
2911
+ BarLayout.prototype.bind = function (initBar, renderBack) {
2912
+ this.__rback = renderBack;
2913
+ this.__oralBar = initBar;
2914
+ this.__preBar = this.use(this.__oralBar);
2915
+ this.__rback(this.__preBar);
2916
+ return this;
2917
+ };
2918
+ BarLayout.prototype.unbind = function () {
2919
+ this.__rback = function () { return null; };
2920
+ this.__oralBar = null;
2921
+ this.__preBar = null;
2922
+ return this;
2923
+ };
2924
+ BarLayout.prototype.doUpdate = function () {
2925
+ var _this = this;
2926
+ var newBar = this.use(this.__oralBar);
2927
+ var cacheBar = JSON.parse(JSON.stringify(newBar));
2928
+ animation(function (deep) {
2929
+ if (_this.__preBar) ;
2930
+ _this.__rback(cacheBar);
2931
+ }, this.__option.duration, function () {
2932
+ _this.__preBar = newBar;
2933
+ _this.__rback(_this.__preBar);
2934
+ });
2935
+ return this;
2936
+ };
2937
+ return BarLayout;
2938
+ }());
2939
+
2940
+ var index = {
2941
+ Cardinal: Cardinal,
2942
+ Hermite: Hermite,
2943
+ Matrix4: Matrix4,
2944
+ rotate: rotate$1,
2945
+ move: move,
2946
+ scale: scale,
2947
+ getLoopColors: getLoopColors,
2948
+ animation: animation,
2949
+ ruler: ruler,
2950
+ SVG: SVG,
2951
+ Canvas: Canvas,
2952
+ RawCanvas: Canvas$1,
2953
+ getWebGLContext: getWebGLContext,
2954
+ Shader: ShaderObject,
2955
+ Texture: TextureObject,
2956
+ Buffer: BufferObject,
2957
+ Eoap: Eoap,
2958
+ Mercator: Mercator,
2959
+ throttle: throttle,
2960
+ assemble: assemble,
2961
+ MapCoordinate: MapCoordinate,
2962
+ TreeLayout: TreeLayout,
2963
+ PieLayout: PieLayout,
2964
+ BarLayout: BarLayout,
2965
+ initOption: initOption,
2966
+ mergeOption: mergeOption
2619
2967
  };
2620
2968
 
2621
2969
  return index;