vislite 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +408 -403
  3. package/LICENSE +20 -20
  4. package/README-en.md +245 -245
  5. package/README.md +245 -245
  6. package/bin/formatArgv.js +30 -30
  7. package/bin/help.js +17 -17
  8. package/bin/run +21 -21
  9. package/bin/skills.js +26 -26
  10. package/lib/BarLayout/index.es.js +348 -348
  11. package/lib/Buffer/index.es.js +34 -34
  12. package/lib/Canvas/index.es.js +804 -804
  13. package/lib/Cardinal/index.es.js +89 -89
  14. package/lib/Eoap/index.es.js +32 -32
  15. package/lib/Hermite/index.es.js +34 -34
  16. package/lib/MapCoordinate/index.es.js +199 -199
  17. package/lib/Matrix4/index.es.js +123 -123
  18. package/lib/Mercator/index.es.js +18 -18
  19. package/lib/PieLayout/index.es.js +115 -115
  20. package/lib/RawCanvas/index.es.js +736 -736
  21. package/lib/SVG/index.es.js +626 -626
  22. package/lib/Shader/index.es.js +34 -34
  23. package/lib/Texture/index.es.js +52 -52
  24. package/lib/TreeLayout/index.es.js +301 -301
  25. package/lib/animation/index.es.js +2 -2
  26. package/lib/assemble/index.es.js +19 -19
  27. package/lib/getLoopColors/index.es.js +34 -34
  28. package/lib/getWebGLContext/index.es.js +61 -61
  29. package/lib/index.umd.js +2797 -2797
  30. package/lib/index.umd.min.js +1 -1
  31. package/lib/initOption/index.es.js +5 -5
  32. package/lib/mergeOption/index.es.js +34 -34
  33. package/lib/move/index.es.js +6 -6
  34. package/lib/rotate/index.es.js +6 -6
  35. package/lib/ruler/index.es.js +136 -136
  36. package/lib/scale/index.es.js +5 -5
  37. package/minialipay/ui-canvas/drawImage.js +35 -35
  38. package/minialipay/ui-canvas/index.acss +4 -4
  39. package/minialipay/ui-canvas/index.axml +3 -3
  40. package/minialipay/ui-canvas/index.d.ts +1 -1
  41. package/minialipay/ui-canvas/index.js +100 -100
  42. package/minialipay/ui-canvas/index.json +6 -6
  43. package/miniprogram/ui-canvas/drawImage.js +35 -35
  44. package/miniprogram/ui-canvas/index.js +125 -125
  45. package/miniprogram/ui-canvas/index.json +4 -4
  46. package/miniprogram/ui-canvas/index.wxml +4 -4
  47. package/miniprogram/ui-canvas/index.wxss +5 -5
  48. package/package/BarLayout/index.ts +2 -2
  49. package/package/Buffer/index.ts +2 -2
  50. package/package/Canvas/index.ts +2 -2
  51. package/package/Cardinal/index.ts +2 -2
  52. package/package/Eoap/index.ts +2 -2
  53. package/package/Hermite/index.ts +2 -2
  54. package/package/MapCoordinate/index.ts +2 -2
  55. package/package/Matrix4/index.ts +2 -2
  56. package/package/Mercator/index.ts +2 -2
  57. package/package/PieLayout/index.ts +2 -2
  58. package/package/RawCanvas/index.ts +2 -2
  59. package/package/SVG/index.ts +2 -2
  60. package/package/Shader/index.ts +2 -2
  61. package/package/Texture/index.ts +2 -2
  62. package/package/TreeLayout/index.ts +2 -2
  63. package/package/animation/index.ts +5 -5
  64. package/package/assemble/index.ts +2 -2
  65. package/package/getLoopColors/index.ts +2 -2
  66. package/package/getWebGLContext/index.ts +40 -40
  67. package/package/index.ts +84 -84
  68. package/package/initOption/index.ts +2 -2
  69. package/package/mergeOption/index.ts +2 -2
  70. package/package/move/index.ts +2 -2
  71. package/package/rotate/index.ts +2 -2
  72. package/package/ruler/index.ts +2 -2
  73. package/package/scale/index.ts +2 -2
  74. package/package/throttle/index.ts +2 -2
  75. package/package.json +79 -79
  76. package/skills/vislite-lib/BarLayout.md +117 -117
  77. package/skills/vislite-lib/Canvas.md +183 -183
  78. package/skills/vislite-lib/Interpolation.md +129 -129
  79. package/skills/vislite-lib/Matrix.md +174 -174
  80. package/skills/vislite-lib/PieLayout.md +131 -131
  81. package/skills/vislite-lib/Projections.md +158 -158
  82. package/skills/vislite-lib/SKILL.md +179 -179
  83. package/skills/vislite-lib/SVG.md +137 -137
  84. package/skills/vislite-lib/TreeLayout.md +176 -176
  85. package/skills/vislite-lib/Utilities.md +261 -261
  86. package/skills/vislite-lib/WebGL.md +106 -106
  87. package/skills/vislite-lib/minialipay/ui-canvas.md +95 -95
  88. package/skills/vislite-lib/miniprogram/ui-canvas.md +98 -98
  89. package/skills/vislite-lib/uniapp/ui-canvas.md +113 -113
  90. package/src/Canvas.ts +89 -89
  91. package/src/Eoap.ts +66 -66
  92. package/src/Matrix4/index.ts +84 -84
  93. package/src/Matrix4/move.ts +12 -12
  94. package/src/Matrix4/rotate.ts +15 -15
  95. package/src/Matrix4/scale.ts +11 -11
  96. package/src/Matrix4/transform.ts +64 -64
  97. package/src/Mercator.ts +27 -27
  98. package/src/SVG.ts +86 -86
  99. package/src/common/assemble.ts +30 -30
  100. package/src/common/canvas/arc.ts +51 -51
  101. package/src/common/canvas/config.ts +176 -176
  102. package/src/common/canvas/default.ts +64 -64
  103. package/src/common/canvas/gradient.ts +31 -31
  104. package/src/common/canvas/index.ts +189 -189
  105. package/src/common/canvas/painter.ts +475 -475
  106. package/src/common/canvas/texts.ts +18 -18
  107. package/src/common/map/getBoundary.ts +15 -15
  108. package/src/common/map/tool.ts +29 -29
  109. package/src/common/option.ts +31 -31
  110. package/src/common/setStyle.ts +5 -5
  111. package/src/common/svg/config.ts +213 -213
  112. package/src/common/svg/default.ts +29 -29
  113. package/src/common/svg/gradient.ts +53 -53
  114. package/src/common/svg/index.ts +420 -420
  115. package/src/common/svg/tool.ts +51 -51
  116. package/src/common/tree/index.ts +25 -25
  117. package/src/common/tree/toInnerTree.ts +61 -61
  118. package/src/common/tree/toPlainTree.ts +135 -135
  119. package/src/common/type.ts +26 -26
  120. package/src/common/webgl/buffer.ts +79 -79
  121. package/src/common/webgl/getWebGLContext.ts +45 -45
  122. package/src/common/webgl/shader.ts +75 -75
  123. package/src/common/webgl/texture.ts +98 -98
  124. package/src/coordinate/MapCoordinate.ts +80 -80
  125. package/src/getLoopColors.ts +42 -42
  126. package/src/interpolation/Cardinal.ts +110 -110
  127. package/src/interpolation/Hermite.ts +65 -65
  128. package/src/layout/BarLayout.ts +249 -249
  129. package/src/layout/PieLayout.ts +146 -146
  130. package/src/layout/TreeLayout.ts +200 -200
  131. package/src/move.ts +7 -7
  132. package/src/rotate.ts +7 -7
  133. package/src/ruler.ts +209 -209
  134. package/src/scale.ts +6 -6
  135. package/types/Bar.d.ts +91 -91
  136. package/types/BarConfig.d.ts +4 -4
  137. package/types/BarLayout.d.ts +48 -48
  138. package/types/BarOption.d.ts +31 -31
  139. package/types/Buffer.d.ts +30 -30
  140. package/types/Canvas.d.ts +379 -379
  141. package/types/CanvasConfig.d.ts +61 -61
  142. package/types/CanvasOption.d.ts +13 -13
  143. package/types/CanvasOpts.d.ts +9 -9
  144. package/types/Cardinal.d.ts +20 -20
  145. package/types/Gradient.d.ts +20 -20
  146. package/types/Hermite.d.ts +25 -25
  147. package/types/Map.d.ts +9 -9
  148. package/types/MapConfig.d.ts +27 -27
  149. package/types/MapCoordinate.d.ts +22 -22
  150. package/types/Matrix4.d.ts +79 -79
  151. package/types/Pie.d.ts +73 -73
  152. package/types/PieConfig.d.ts +26 -26
  153. package/types/PieLayout.d.ts +40 -40
  154. package/types/PieOption.d.ts +21 -21
  155. package/types/SVG.d.ts +282 -282
  156. package/types/SVGConfig.d.ts +54 -54
  157. package/types/Shader.d.ts +22 -22
  158. package/types/Texture.d.ts +22 -22
  159. package/types/Tree.d.ts +74 -74
  160. package/types/TreeConfig.d.ts +52 -52
  161. package/types/TreeLayout.d.ts +71 -71
  162. package/types/TreeOption.d.ts +48 -48
  163. package/types/animation.d.ts +26 -26
  164. package/types/assemble.d.ts +14 -14
  165. package/types/getLoopColors.d.ts +13 -13
  166. package/types/getWebGLContext.d.ts +7 -7
  167. package/types/index.d.ts +220 -220
  168. package/types/module.d.ts +110 -110
  169. package/types/move.d.ts +15 -15
  170. package/types/option.d.ts +12 -12
  171. package/types/painterConfig.d.ts +14 -14
  172. package/types/rotate.d.ts +15 -15
  173. package/types/ruler.d.ts +24 -24
  174. package/types/scale.d.ts +15 -15
  175. package/types/throttle.d.ts +6 -6
  176. package/types/ui-canvas.d.ts +4 -4
  177. package/types/uni-canvas.d.ts +3 -3
  178. package/uni-app/drawImage.js +19 -19
  179. package/uni-app/ui-canvas.vue +295 -295
@@ -22,650 +22,650 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
22
22
 
23
23
  var XLINK_ATTRIBUTE = ["href", "title", "show", "type", "role", "actuate"];
24
24
 
25
- var setLineAttr = function (el, config) {
26
- setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
27
- setAttribute(el, "stroke-width", config.lineWidth + "");
28
- setAttribute(el, "stroke-linecap", config.lineCap + "");
29
- setAttribute(el, "stroke-linejoin", config.lineJoin + "");
30
- };
31
- function toNode(tagname) {
32
- return document.createElementNS('http://www.w3.org/2000/svg', tagname);
33
- }
34
- var _setAttribute = function (el, key, value) {
35
- if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
36
- el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
37
- }
38
- else {
39
- el.setAttribute(key, value + "");
40
- }
41
- };
42
- var setAttribute = _setAttribute;
43
- function getAttribute(el, key) {
44
- if (XLINK_ATTRIBUTE.indexOf(key) > -1)
45
- key = 'xlink:' + key;
46
- return el.getAttribute(key);
47
- }
48
- function full(el, config) {
49
- setLineAttr(el, config);
50
- _setAttribute(el, "stroke", config.strokeStyle);
51
- _setAttribute(el, "fill", config.fillStyle);
52
- }
53
- function fill(el, config) {
54
- _setAttribute(el, "fill", config.fillStyle);
55
- }
56
- function stroke(el, config) {
57
- setLineAttr(el, config);
58
- _setAttribute(el, "stroke", config.strokeStyle);
59
- _setAttribute(el, "fill", "none");
25
+ var setLineAttr = function (el, config) {
26
+ setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
27
+ setAttribute(el, "stroke-width", config.lineWidth + "");
28
+ setAttribute(el, "stroke-linecap", config.lineCap + "");
29
+ setAttribute(el, "stroke-linejoin", config.lineJoin + "");
30
+ };
31
+ function toNode(tagname) {
32
+ return document.createElementNS('http://www.w3.org/2000/svg', tagname);
33
+ }
34
+ var _setAttribute = function (el, key, value) {
35
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1) {
36
+ el.setAttributeNS("http://www.w3.org/1999/xlink", 'xlink:' + key, value + "");
37
+ }
38
+ else {
39
+ el.setAttribute(key, value + "");
40
+ }
41
+ };
42
+ var setAttribute = _setAttribute;
43
+ function getAttribute(el, key) {
44
+ if (XLINK_ATTRIBUTE.indexOf(key) > -1)
45
+ key = 'xlink:' + key;
46
+ return el.getAttribute(key);
47
+ }
48
+ function full(el, config) {
49
+ setLineAttr(el, config);
50
+ _setAttribute(el, "stroke", config.strokeStyle);
51
+ _setAttribute(el, "fill", config.fillStyle);
52
+ }
53
+ function fill(el, config) {
54
+ _setAttribute(el, "fill", config.fillStyle);
55
+ }
56
+ function stroke(el, config) {
57
+ setLineAttr(el, config);
58
+ _setAttribute(el, "stroke", config.strokeStyle);
59
+ _setAttribute(el, "fill", "none");
60
60
  }
61
61
 
62
- function setStyle (el, styles) {
63
- for (var key in styles) {
64
- el.style[key] = styles[key];
65
- }
62
+ function setStyle (el, styles) {
63
+ for (var key in styles) {
64
+ el.style[key] = styles[key];
65
+ }
66
66
  }
67
67
 
68
- var rotate$1 = function (cx, cy, deg, x, y) {
69
- var cos = Math.cos(deg), sin = Math.sin(deg);
70
- return [
71
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
72
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
73
- ];
74
- };
75
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
76
- if (rotateA < 0) {
77
- beginA += rotateA;
78
- rotateA *= -1;
79
- }
80
- var temp = [];
81
- var p;
82
- p = rotate$1(0, 0, beginA, r1, 0);
83
- temp[0] = p[0];
84
- temp[1] = p[1];
85
- p = rotate$1(0, 0, rotateA, p[0], p[1]);
86
- temp[2] = p[0];
87
- temp[3] = p[1];
88
- p = rotate$1(0, 0, beginA, r2, 0);
89
- temp[4] = p[0];
90
- temp[5] = p[1];
91
- p = rotate$1(0, 0, rotateA, p[0], p[1]);
92
- temp[6] = p[0];
93
- temp[7] = p[1];
94
- 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);
68
+ var rotate$1 = function (cx, cy, deg, x, y) {
69
+ var cos = Math.cos(deg), sin = Math.sin(deg);
70
+ return [
71
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
72
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
73
+ ];
74
+ };
75
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
76
+ if (rotateA < 0) {
77
+ beginA += rotateA;
78
+ rotateA *= -1;
79
+ }
80
+ var temp = [];
81
+ var p;
82
+ p = rotate$1(0, 0, beginA, r1, 0);
83
+ temp[0] = p[0];
84
+ temp[1] = p[1];
85
+ p = rotate$1(0, 0, rotateA, p[0], p[1]);
86
+ temp[2] = p[0];
87
+ temp[3] = p[1];
88
+ p = rotate$1(0, 0, beginA, r2, 0);
89
+ temp[4] = p[0];
90
+ temp[5] = p[1];
91
+ p = rotate$1(0, 0, rotateA, p[0], p[1]);
92
+ temp[6] = p[0];
93
+ temp[7] = p[1];
94
+ 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);
95
95
  }
96
96
 
97
- var initDefs = function (el) {
98
- var defs = el.getElementsByTagName('defs');
99
- if (defs.length <= 0) {
100
- var newDefs = toNode("defs");
101
- el.appendChild(newDefs);
102
- return newDefs;
103
- }
104
- else {
105
- return defs[0];
106
- }
107
- };
108
- var initText = function (el, config, x, y, deg) {
109
- if (el.nodeName.toLowerCase() !== "text")
110
- throw new Error("Need a <text> !");
111
- setAttribute(el, "dy", {
112
- top: config["fontSize"] * 0.5,
113
- middle: 0,
114
- bottom: -config["fontSize"] * 0.5,
115
- }[config.textBaseline]);
116
- setStyle(el, {
117
- "text-anchor": {
118
- left: "start",
119
- right: "end",
120
- center: "middle",
121
- }[config.textAlign],
122
- "dominant-baseline": "central",
123
- "font-size": config["fontSize"] + "px",
124
- "font-family": config["fontFamily"],
125
- });
126
- setAttribute(el, "x", x);
127
- setAttribute(el, "y", y);
128
- if (typeof deg == "number") {
129
- deg = deg % 360;
130
- setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
131
- }
132
- };
133
- var initCircle = function (el, cx, cy, r) {
134
- if (el.nodeName.toLowerCase() !== "circle")
135
- throw new Error("Need a <circle> !");
136
- setAttribute(el, "cx", cx);
137
- setAttribute(el, "cy", cy);
138
- setAttribute(el, "r", r);
139
- };
140
- var initPath = function (el, path) {
141
- if (el.nodeName.toLowerCase() !== "path")
142
- throw new Error("Need a <path> !");
143
- setAttribute(el, "d", path);
144
- };
145
- var initRect = function (el, config, x, y, width, height) {
146
- if (el.nodeName.toLowerCase() !== "path")
147
- throw new Error("Need a <path> !");
148
- var rectRadius = [];
149
- if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
150
- for (var index = 0; index < 4; index++) {
151
- rectRadius.push.apply(rectRadius, config.rectRadius);
152
- }
153
- }
154
- if (height < 0) {
155
- height *= -1;
156
- y -= height;
157
- }
158
- if (width < 0) {
159
- width *= -1;
160
- x -= width;
161
- }
162
- var d = "";
163
- if (rectRadius.length >= 4) {
164
- d = "M" + (x + rectRadius[0]) + " " + y;
165
- d += "L" + (x + width - rectRadius[1]) + " " + y;
166
- d += "A" + rectRadius[1] + " " + rectRadius[1] + " 0 0 1 " + (x + width) + " " + (y + rectRadius[1]);
167
- d += "L" + (x + width) + " " + (y + height - rectRadius[2]);
168
- d += "A" + rectRadius[2] + " " + rectRadius[2] + " 0 0 1 " + (x + width - rectRadius[2]) + " " + (y + height);
169
- d += "L" + (x + rectRadius[3]) + " " + (y + height);
170
- d += "A" + rectRadius[3] + " " + rectRadius[3] + " 0 0 1 " + x + " " + (y + height - rectRadius[3]);
171
- d += "L" + x + " " + (y + rectRadius[0]);
172
- d += "A" + rectRadius[0] + " " + rectRadius[0] + " 0 0 1 " + (x + rectRadius[0]) + " " + y;
173
- }
174
- else {
175
- d = "M" + x + " " + y;
176
- d += "L" + (x + width) + " " + y;
177
- d += "L" + (x + width) + " " + (y + height);
178
- d += "L" + x + " " + (y + height);
179
- d += "Z";
180
- }
181
- setAttribute(el, "d", d);
182
- };
183
- var initArc = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
184
- if (el.nodeName.toLowerCase() !== "path")
185
- throw new Error("Need a <path> !");
186
- beginDeg = (beginDeg / 180) * Math.PI;
187
- deg = (deg / 180) * Math.PI;
188
- beginDeg = beginDeg % (Math.PI * 2);
189
- if (r1 > r2) {
190
- var temp = r1;
191
- r1 = r2;
192
- r2 = temp;
193
- }
194
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
195
- deg = Math.PI * 1.999999;
196
- }
197
- else {
198
- deg = deg % (Math.PI * 2);
199
- }
200
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
201
- var f = endA - beginA > Math.PI ? 1 : 0;
202
- var d = "M" + begInnerX + " " + begInnerY;
203
- if (r < 0)
204
- r = -r;
205
- d +=
206
- "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
207
- if (config.arcEndCap == "round")
208
- d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
209
- else if (config.arcEndCap == "-round")
210
- d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
211
- else
212
- d += "L" + endOuterX + " " + endOuterY;
213
- d +=
214
- "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
215
- if (config.arcStartCap == "round")
216
- d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
217
- else if (config.arcStartCap == "-round")
218
- d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
219
- else
220
- d += "L" + begInnerX + " " + begInnerY;
221
- if (config.arcStartCap == "butt")
222
- d += "Z";
223
- setAttribute(el, "d", d);
224
- });
97
+ var initDefs = function (el) {
98
+ var defs = el.getElementsByTagName('defs');
99
+ if (defs.length <= 0) {
100
+ var newDefs = toNode("defs");
101
+ el.appendChild(newDefs);
102
+ return newDefs;
103
+ }
104
+ else {
105
+ return defs[0];
106
+ }
107
+ };
108
+ var initText = function (el, config, x, y, deg) {
109
+ if (el.nodeName.toLowerCase() !== "text")
110
+ throw new Error("Need a <text> !");
111
+ setAttribute(el, "dy", {
112
+ top: config["fontSize"] * 0.5,
113
+ middle: 0,
114
+ bottom: -config["fontSize"] * 0.5,
115
+ }[config.textBaseline]);
116
+ setStyle(el, {
117
+ "text-anchor": {
118
+ left: "start",
119
+ right: "end",
120
+ center: "middle",
121
+ }[config.textAlign],
122
+ "dominant-baseline": "central",
123
+ "font-size": config["fontSize"] + "px",
124
+ "font-family": config["fontFamily"],
125
+ });
126
+ setAttribute(el, "x", x);
127
+ setAttribute(el, "y", y);
128
+ if (typeof deg == "number") {
129
+ deg = deg % 360;
130
+ setAttribute(el, "transform", "rotate(" + deg + "," + x + "," + y + ")");
131
+ }
132
+ };
133
+ var initCircle = function (el, cx, cy, r) {
134
+ if (el.nodeName.toLowerCase() !== "circle")
135
+ throw new Error("Need a <circle> !");
136
+ setAttribute(el, "cx", cx);
137
+ setAttribute(el, "cy", cy);
138
+ setAttribute(el, "r", r);
139
+ };
140
+ var initPath = function (el, path) {
141
+ if (el.nodeName.toLowerCase() !== "path")
142
+ throw new Error("Need a <path> !");
143
+ setAttribute(el, "d", path);
144
+ };
145
+ var initRect = function (el, config, x, y, width, height) {
146
+ if (el.nodeName.toLowerCase() !== "path")
147
+ throw new Error("Need a <path> !");
148
+ var rectRadius = [];
149
+ if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
150
+ for (var index = 0; index < 4; index++) {
151
+ rectRadius.push.apply(rectRadius, config.rectRadius);
152
+ }
153
+ }
154
+ if (height < 0) {
155
+ height *= -1;
156
+ y -= height;
157
+ }
158
+ if (width < 0) {
159
+ width *= -1;
160
+ x -= width;
161
+ }
162
+ var d = "";
163
+ if (rectRadius.length >= 4) {
164
+ d = "M" + (x + rectRadius[0]) + " " + y;
165
+ d += "L" + (x + width - rectRadius[1]) + " " + y;
166
+ d += "A" + rectRadius[1] + " " + rectRadius[1] + " 0 0 1 " + (x + width) + " " + (y + rectRadius[1]);
167
+ d += "L" + (x + width) + " " + (y + height - rectRadius[2]);
168
+ d += "A" + rectRadius[2] + " " + rectRadius[2] + " 0 0 1 " + (x + width - rectRadius[2]) + " " + (y + height);
169
+ d += "L" + (x + rectRadius[3]) + " " + (y + height);
170
+ d += "A" + rectRadius[3] + " " + rectRadius[3] + " 0 0 1 " + x + " " + (y + height - rectRadius[3]);
171
+ d += "L" + x + " " + (y + rectRadius[0]);
172
+ d += "A" + rectRadius[0] + " " + rectRadius[0] + " 0 0 1 " + (x + rectRadius[0]) + " " + y;
173
+ }
174
+ else {
175
+ d = "M" + x + " " + y;
176
+ d += "L" + (x + width) + " " + y;
177
+ d += "L" + (x + width) + " " + (y + height);
178
+ d += "L" + x + " " + (y + height);
179
+ d += "Z";
180
+ }
181
+ setAttribute(el, "d", d);
182
+ };
183
+ var initArc = function (el, config, cx, cy, r1, r2, beginDeg, deg) {
184
+ if (el.nodeName.toLowerCase() !== "path")
185
+ throw new Error("Need a <path> !");
186
+ beginDeg = (beginDeg / 180) * Math.PI;
187
+ deg = (deg / 180) * Math.PI;
188
+ beginDeg = beginDeg % (Math.PI * 2);
189
+ if (r1 > r2) {
190
+ var temp = r1;
191
+ r1 = r2;
192
+ r2 = temp;
193
+ }
194
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
195
+ deg = Math.PI * 1.999999;
196
+ }
197
+ else {
198
+ deg = deg % (Math.PI * 2);
199
+ }
200
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
201
+ var f = endA - beginA > Math.PI ? 1 : 0;
202
+ var d = "M" + begInnerX + " " + begInnerY;
203
+ if (r < 0)
204
+ r = -r;
205
+ d +=
206
+ "A" + r1 + " " + r1 + " 0 " + f + " 1 " + endInnerX + " " + endInnerY;
207
+ if (config.arcEndCap == "round")
208
+ d += "A" + r + " " + r + " " + " 0 1 0 " + endOuterX + " " + endOuterY;
209
+ else if (config.arcEndCap == "-round")
210
+ d += "A" + r + " " + r + " " + " 0 1 1 " + endOuterX + " " + endOuterY;
211
+ else
212
+ d += "L" + endOuterX + " " + endOuterY;
213
+ d +=
214
+ "A" + r2 + " " + r2 + " 0 " + f + " 0 " + begOuterX + " " + begOuterY;
215
+ if (config.arcStartCap == "round")
216
+ d += "A" + r + " " + r + " " + " 0 1 0 " + begInnerX + " " + begInnerY;
217
+ else if (config.arcStartCap == "-round")
218
+ d += "A" + r + " " + r + " " + " 0 1 1 " + begInnerX + " " + begInnerY;
219
+ else
220
+ d += "L" + begInnerX + " " + begInnerY;
221
+ if (config.arcStartCap == "butt")
222
+ d += "Z";
223
+ setAttribute(el, "d", d);
224
+ });
225
225
  };
226
226
 
227
- function rotate (cx, cy, deg, x, y) {
228
- var cos = Math.cos(deg), sin = Math.sin(deg);
229
- return [
230
- (x - cx) * cos - (y - cy) * sin + cx,
231
- (x - cx) * sin + (y - cy) * cos + cy
232
- ];
227
+ function rotate (cx, cy, deg, x, y) {
228
+ var cos = Math.cos(deg), sin = Math.sin(deg);
229
+ return [
230
+ (x - cx) * cos - (y - cy) * sin + cx,
231
+ (x - cx) * sin + (y - cy) * cos + cy
232
+ ];
233
233
  }
234
234
 
235
- var enhanceGradient = function (gradient, gradientId) {
236
- var enhanceGradient = {
237
- "value": function () {
238
- return "url(#" + gradientId + ")";
239
- },
240
- "setColor": function (stop, color) {
241
- var stopEl = toNode("stop");
242
- gradient.appendChild(stopEl);
243
- setAttribute(stopEl, "offset", (stop * 100) + "%");
244
- setAttribute(stopEl, "style", "stop-color:" + color + ";");
245
- return enhanceGradient;
246
- }
247
- };
248
- return enhanceGradient;
249
- };
250
- var linearGradient = function (el, x0, y0, x1, y1) {
251
- var defs = initDefs(el);
252
- var gradientId = "visliteLg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
253
- var linearGradient = toNode("linearGradient");
254
- defs.appendChild(linearGradient);
255
- setAttribute(linearGradient, "id", gradientId);
256
- setAttribute(linearGradient, "x1", x0 + "%");
257
- setAttribute(linearGradient, "y1", y0 + "%");
258
- setAttribute(linearGradient, "x2", x1 + "%");
259
- setAttribute(linearGradient, "y2", y1 + "%");
260
- return enhanceGradient(linearGradient, gradientId);
261
- };
262
- var radialGradient = function (el, cx, cy, r) {
263
- var defs = initDefs(el);
264
- var gradientId = "visliteRg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
265
- var radialGradient = toNode("radialGradient");
266
- defs.appendChild(radialGradient);
267
- setAttribute(radialGradient, "id", gradientId);
268
- setAttribute(radialGradient, "cx", cx + "%");
269
- setAttribute(radialGradient, "cy", cy + "%");
270
- setAttribute(radialGradient, "r", r + "%");
271
- return enhanceGradient(radialGradient, gradientId);
235
+ var enhanceGradient = function (gradient, gradientId) {
236
+ var enhanceGradient = {
237
+ "value": function () {
238
+ return "url(#" + gradientId + ")";
239
+ },
240
+ "setColor": function (stop, color) {
241
+ var stopEl = toNode("stop");
242
+ gradient.appendChild(stopEl);
243
+ setAttribute(stopEl, "offset", (stop * 100) + "%");
244
+ setAttribute(stopEl, "style", "stop-color:" + color + ";");
245
+ return enhanceGradient;
246
+ }
247
+ };
248
+ return enhanceGradient;
249
+ };
250
+ var linearGradient = function (el, x0, y0, x1, y1) {
251
+ var defs = initDefs(el);
252
+ var gradientId = "visliteLg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
253
+ var linearGradient = toNode("linearGradient");
254
+ defs.appendChild(linearGradient);
255
+ setAttribute(linearGradient, "id", gradientId);
256
+ setAttribute(linearGradient, "x1", x0 + "%");
257
+ setAttribute(linearGradient, "y1", y0 + "%");
258
+ setAttribute(linearGradient, "x2", x1 + "%");
259
+ setAttribute(linearGradient, "y2", y1 + "%");
260
+ return enhanceGradient(linearGradient, gradientId);
261
+ };
262
+ var radialGradient = function (el, cx, cy, r) {
263
+ var defs = initDefs(el);
264
+ var gradientId = "visliteRg" + new Date().valueOf() + "" + (Math.random() * 1000000).toFixed(0);
265
+ var radialGradient = toNode("radialGradient");
266
+ defs.appendChild(radialGradient);
267
+ setAttribute(radialGradient, "id", gradientId);
268
+ setAttribute(radialGradient, "cx", cx + "%");
269
+ setAttribute(radialGradient, "cy", cy + "%");
270
+ setAttribute(radialGradient, "r", r + "%");
271
+ return enhanceGradient(radialGradient, gradientId);
272
272
  };
273
273
 
274
- function defaultFactory () {
275
- return {
276
- fillStyle: "rgb(0,0,0)",
277
- strokeStyle: "rgb(0,0,0)",
278
- textAlign: "left",
279
- textBaseline: "middle",
280
- "fontSize": 16,
281
- "fontFamily": "sans-serif",
282
- "arcStartCap": "butt",
283
- "arcEndCap": "butt",
284
- lineDash: [],
285
- lineWidth: 1,
286
- lineCap: "butt",
287
- lineJoin: "miter",
288
- "rectRadius": []
289
- };
274
+ function defaultFactory () {
275
+ return {
276
+ fillStyle: "rgb(0,0,0)",
277
+ strokeStyle: "rgb(0,0,0)",
278
+ textAlign: "left",
279
+ textBaseline: "middle",
280
+ "fontSize": 16,
281
+ "fontFamily": "sans-serif",
282
+ "arcStartCap": "butt",
283
+ "arcEndCap": "butt",
284
+ lineDash: [],
285
+ lineWidth: 1,
286
+ lineCap: "butt",
287
+ lineJoin: "miter",
288
+ "rectRadius": []
289
+ };
290
290
  }
291
291
 
292
- function initOption(setOption, defaultOption) {
293
- for (var key in setOption) {
294
- defaultOption[key] = setOption[key];
295
- }
296
- return defaultOption;
292
+ function initOption(setOption, defaultOption) {
293
+ for (var key in setOption) {
294
+ defaultOption[key] = setOption[key];
295
+ }
296
+ return defaultOption;
297
297
  }
298
298
 
299
- var SVG$1 = (function () {
300
- function SVG(svg) {
301
- this.name = "SVG";
302
- this.__config = defaultFactory();
303
- this.__path = "";
304
- this.__currentPosition = [];
305
- this.__transform_history = [];
306
- this.__transform_current = "";
307
- this.__svg = svg;
308
- }
309
- SVG.prototype.config = function (params) {
310
- if (typeof params !== "object") {
311
- return this.__config[params];
312
- }
313
- else {
314
- for (var key in params) {
315
- this.__config[key] = params[key];
316
- }
317
- }
318
- return this;
319
- };
320
- SVG.prototype.reset = function (config) {
321
- if (config === void 0) { config = {}; }
322
- this.config(initOption(config, defaultFactory()));
323
- return this;
324
- };
325
- SVG.prototype.useEl = function (el) {
326
- this.__useEl = el;
327
- return this;
328
- };
329
- SVG.prototype.getEl = function () {
330
- return this.__useEl;
331
- };
332
- SVG.prototype.appendEl = function (el, context) {
333
- context = context || this.__svg;
334
- if (typeof el == "string")
335
- el = toNode(el);
336
- context.appendChild(el);
337
- this.__useEl = el;
338
- return this;
339
- };
340
- SVG.prototype.appendBoard = function (el, context) {
341
- var _el = el;
342
- if (typeof el == "string")
343
- _el =
344
- {
345
- text: "text",
346
- path: "path",
347
- arc: "path",
348
- circle: "circle",
349
- rect: "path",
350
- }[el] || "";
351
- if (_el == "")
352
- throw new Error("Unsupported drawing method:" + el);
353
- return this.appendEl(_el, context);
354
- };
355
- SVG.prototype.remove = function () {
356
- if (!this.__useEl) {
357
- throw new Error("Currently, no node can be deleted.");
358
- }
359
- else {
360
- this.__useEl.parentNode.removeChild(this.__useEl);
361
- }
362
- return this;
363
- };
364
- SVG.prototype.attr = function (params) {
365
- if (!this.__useEl)
366
- throw new Error("Currently, no node can be modified or viewed.");
367
- if (typeof params !== "object") {
368
- return getAttribute(this.__useEl, params);
369
- }
370
- else {
371
- for (var key in params) {
372
- setAttribute(this.__useEl, key, params[key]);
373
- }
374
- return this;
375
- }
376
- };
377
- SVG.prototype.fillText = function (text, x, y, deg) {
378
- if (deg === void 0) { deg = 0; }
379
- initText(this.__useEl, this.__config, x, y, deg);
380
- this.attr({
381
- transform: this.__transform_current
382
- });
383
- this.__useEl.textContent = text;
384
- fill(this.__useEl, this.__config);
385
- return this;
386
- };
387
- SVG.prototype.strokeText = function (text, x, y, deg) {
388
- if (deg === void 0) { deg = 0; }
389
- initText(this.__useEl, this.__config, x, y, deg);
390
- this.attr({
391
- transform: this.__transform_current
392
- });
393
- this.__useEl.textContent = text;
394
- stroke(this.__useEl, this.__config);
395
- return this;
396
- };
397
- SVG.prototype.fullText = function (text, x, y, deg) {
398
- if (deg === void 0) { deg = 0; }
399
- initText(this.__useEl, this.__config, x, y, deg);
400
- this.attr({
401
- transform: this.__transform_current
402
- });
403
- this.__useEl.textContent = text;
404
- full(this.__useEl, this.__config);
405
- return this;
406
- };
407
- SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
408
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
409
- this.attr({
410
- transform: this.__transform_current
411
- });
412
- fill(this.__useEl, this.__config);
413
- return this;
414
- };
415
- SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
416
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
417
- this.attr({
418
- transform: this.__transform_current
419
- });
420
- stroke(this.__useEl, this.__config);
421
- return this;
422
- };
423
- SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
424
- initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
425
- this.attr({
426
- transform: this.__transform_current
427
- });
428
- full(this.__useEl, this.__config);
429
- return this;
430
- };
431
- SVG.prototype.fillCircle = function (cx, cy, r) {
432
- initCircle(this.__useEl, cx, cy, r);
433
- this.attr({
434
- transform: this.__transform_current
435
- });
436
- fill(this.__useEl, this.__config);
437
- return this;
438
- };
439
- SVG.prototype.strokeCircle = function (cx, cy, r) {
440
- initCircle(this.__useEl, cx, cy, r);
441
- this.attr({
442
- transform: this.__transform_current
443
- });
444
- stroke(this.__useEl, this.__config);
445
- return this;
446
- };
447
- SVG.prototype.fullCircle = function (cx, cy, r) {
448
- initCircle(this.__useEl, cx, cy, r);
449
- this.attr({
450
- transform: this.__transform_current
451
- });
452
- full(this.__useEl, this.__config);
453
- return this;
454
- };
455
- SVG.prototype.fillRect = function (x, y, width, height) {
456
- initRect(this.__useEl, this.__config, x, y, width, height);
457
- this.attr({
458
- transform: this.__transform_current
459
- });
460
- fill(this.__useEl, this.__config);
461
- return this;
462
- };
463
- SVG.prototype.strokeRect = function (x, y, width, height) {
464
- initRect(this.__useEl, this.__config, x, y, width, height);
465
- this.attr({
466
- transform: this.__transform_current
467
- });
468
- stroke(this.__useEl, this.__config);
469
- return this;
470
- };
471
- SVG.prototype.fullRect = function (x, y, width, height) {
472
- initRect(this.__useEl, this.__config, x, y, width, height);
473
- this.attr({
474
- transform: this.__transform_current
475
- });
476
- full(this.__useEl, this.__config);
477
- return this;
478
- };
479
- SVG.prototype.beginPath = function () {
480
- this.__currentPosition = [];
481
- this.__path = "";
482
- return this;
483
- };
484
- SVG.prototype.closePath = function () {
485
- this.__path += "Z";
486
- return this;
487
- };
488
- SVG.prototype.moveTo = function (x, y) {
489
- this.__currentPosition = [x, y];
490
- this.__path += "M" + x + " " + y;
491
- return this;
492
- };
493
- SVG.prototype.lineTo = function (x, y) {
494
- this.__currentPosition = [x, y];
495
- this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
496
- return this;
497
- };
498
- SVG.prototype.fill = function () {
499
- initPath(this.__useEl, this.__path);
500
- this.attr({
501
- transform: this.__transform_current
502
- });
503
- fill(this.__useEl, this.__config);
504
- return this;
505
- };
506
- SVG.prototype.stroke = function () {
507
- initPath(this.__useEl, this.__path);
508
- this.attr({
509
- transform: this.__transform_current
510
- });
511
- stroke(this.__useEl, this.__config);
512
- return this;
513
- };
514
- SVG.prototype.full = function () {
515
- initPath(this.__useEl, this.__path);
516
- this.attr({
517
- transform: this.__transform_current
518
- });
519
- full(this.__useEl, this.__config);
520
- return this;
521
- };
522
- SVG.prototype.save = function () {
523
- this.__transform_history.push(this.__transform_current);
524
- return this;
525
- };
526
- SVG.prototype.restore = function () {
527
- if (this.__transform_history.length > 0)
528
- this.__transform_current = this.__transform_history.pop();
529
- return this;
530
- };
531
- SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
532
- var begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y);
533
- var endPosition = rotate(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
534
- if (this.__path == "") {
535
- this.__path += "M" + begPosition[0] + "," + begPosition[1];
536
- }
537
- else if (begPosition[0] != this.__currentPosition[0] ||
538
- begPosition[1] != this.__currentPosition[1]) {
539
- this.__path += "L" + begPosition[0] + "," + begPosition[1];
540
- }
541
- this.__path +=
542
- "A" +
543
- r +
544
- "," +
545
- r +
546
- " 0 " +
547
- (deg > 180 || deg < -180 ? 1 : 0) +
548
- "," +
549
- (deg > 0 ? 1 : 0) +
550
- " " +
551
- endPosition[0] +
552
- "," +
553
- endPosition[1];
554
- return this;
555
- };
556
- SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
557
- this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
558
- return this;
559
- };
560
- SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
561
- this.__path +=
562
- "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
563
- return this;
564
- };
565
- SVG.prototype.bind = function (eventType, callback) {
566
- this.__useEl.addEventListener(eventType, function (event) {
567
- callback.call(this, event, this);
568
- }, false);
569
- return this;
570
- };
571
- SVG.prototype.createLinearGradient = function (x0, y0, x1, y1) {
572
- return linearGradient(this.__svg, x0, y0, x1, y1);
573
- };
574
- SVG.prototype.createRadialGradient = function (cx, cy, r) {
575
- return radialGradient(this.__svg, cx, cy, r);
576
- };
577
- SVG.prototype.translate = function (dx, dy) {
578
- this.__transform_current += ' translate(' + dx + ',' + dy + ')';
579
- return this;
580
- };
581
- SVG.prototype.rotate = function (deg) {
582
- this.__transform_current += ' rotate(' + deg + ')';
583
- return this;
584
- };
585
- SVG.prototype.install = function (methods) {
586
- var _this = this;
587
- var _loop_1 = function (key) {
588
- if (key in this_1) {
589
- throw new Error("VISLite SVG:Method already exists and cannot be overwritten.");
590
- }
591
- else {
592
- this_1[key] = function () {
593
- var args = [];
594
- for (var _i = 0; _i < arguments.length; _i++) {
595
- args[_i] = arguments[_i];
596
- }
597
- var value = methods[key].apply(_this, args);
598
- if (value != void 0)
599
- return value;
600
- return _this;
601
- };
602
- }
603
- };
604
- var this_1 = this;
605
- for (var key in methods) {
606
- _loop_1(key);
607
- }
608
- return this;
609
- };
610
- return SVG;
299
+ var SVG$1 = (function () {
300
+ function SVG(svg) {
301
+ this.name = "SVG";
302
+ this.__config = defaultFactory();
303
+ this.__path = "";
304
+ this.__currentPosition = [];
305
+ this.__transform_history = [];
306
+ this.__transform_current = "";
307
+ this.__svg = svg;
308
+ }
309
+ SVG.prototype.config = function (params) {
310
+ if (typeof params !== "object") {
311
+ return this.__config[params];
312
+ }
313
+ else {
314
+ for (var key in params) {
315
+ this.__config[key] = params[key];
316
+ }
317
+ }
318
+ return this;
319
+ };
320
+ SVG.prototype.reset = function (config) {
321
+ if (config === void 0) { config = {}; }
322
+ this.config(initOption(config, defaultFactory()));
323
+ return this;
324
+ };
325
+ SVG.prototype.useEl = function (el) {
326
+ this.__useEl = el;
327
+ return this;
328
+ };
329
+ SVG.prototype.getEl = function () {
330
+ return this.__useEl;
331
+ };
332
+ SVG.prototype.appendEl = function (el, context) {
333
+ context = context || this.__svg;
334
+ if (typeof el == "string")
335
+ el = toNode(el);
336
+ context.appendChild(el);
337
+ this.__useEl = el;
338
+ return this;
339
+ };
340
+ SVG.prototype.appendBoard = function (el, context) {
341
+ var _el = el;
342
+ if (typeof el == "string")
343
+ _el =
344
+ {
345
+ text: "text",
346
+ path: "path",
347
+ arc: "path",
348
+ circle: "circle",
349
+ rect: "path",
350
+ }[el] || "";
351
+ if (_el == "")
352
+ throw new Error("Unsupported drawing method:" + el);
353
+ return this.appendEl(_el, context);
354
+ };
355
+ SVG.prototype.remove = function () {
356
+ if (!this.__useEl) {
357
+ throw new Error("Currently, no node can be deleted.");
358
+ }
359
+ else {
360
+ this.__useEl.parentNode.removeChild(this.__useEl);
361
+ }
362
+ return this;
363
+ };
364
+ SVG.prototype.attr = function (params) {
365
+ if (!this.__useEl)
366
+ throw new Error("Currently, no node can be modified or viewed.");
367
+ if (typeof params !== "object") {
368
+ return getAttribute(this.__useEl, params);
369
+ }
370
+ else {
371
+ for (var key in params) {
372
+ setAttribute(this.__useEl, key, params[key]);
373
+ }
374
+ return this;
375
+ }
376
+ };
377
+ SVG.prototype.fillText = function (text, x, y, deg) {
378
+ if (deg === void 0) { deg = 0; }
379
+ initText(this.__useEl, this.__config, x, y, deg);
380
+ this.attr({
381
+ transform: this.__transform_current
382
+ });
383
+ this.__useEl.textContent = text;
384
+ fill(this.__useEl, this.__config);
385
+ return this;
386
+ };
387
+ SVG.prototype.strokeText = function (text, x, y, deg) {
388
+ if (deg === void 0) { deg = 0; }
389
+ initText(this.__useEl, this.__config, x, y, deg);
390
+ this.attr({
391
+ transform: this.__transform_current
392
+ });
393
+ this.__useEl.textContent = text;
394
+ stroke(this.__useEl, this.__config);
395
+ return this;
396
+ };
397
+ SVG.prototype.fullText = function (text, x, y, deg) {
398
+ if (deg === void 0) { deg = 0; }
399
+ initText(this.__useEl, this.__config, x, y, deg);
400
+ this.attr({
401
+ transform: this.__transform_current
402
+ });
403
+ this.__useEl.textContent = text;
404
+ full(this.__useEl, this.__config);
405
+ return this;
406
+ };
407
+ SVG.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
408
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
409
+ this.attr({
410
+ transform: this.__transform_current
411
+ });
412
+ fill(this.__useEl, this.__config);
413
+ return this;
414
+ };
415
+ SVG.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
416
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
417
+ this.attr({
418
+ transform: this.__transform_current
419
+ });
420
+ stroke(this.__useEl, this.__config);
421
+ return this;
422
+ };
423
+ SVG.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
424
+ initArc(this.__useEl, this.__config, cx, cy, r1, r2, beginDeg, deg);
425
+ this.attr({
426
+ transform: this.__transform_current
427
+ });
428
+ full(this.__useEl, this.__config);
429
+ return this;
430
+ };
431
+ SVG.prototype.fillCircle = function (cx, cy, r) {
432
+ initCircle(this.__useEl, cx, cy, r);
433
+ this.attr({
434
+ transform: this.__transform_current
435
+ });
436
+ fill(this.__useEl, this.__config);
437
+ return this;
438
+ };
439
+ SVG.prototype.strokeCircle = function (cx, cy, r) {
440
+ initCircle(this.__useEl, cx, cy, r);
441
+ this.attr({
442
+ transform: this.__transform_current
443
+ });
444
+ stroke(this.__useEl, this.__config);
445
+ return this;
446
+ };
447
+ SVG.prototype.fullCircle = function (cx, cy, r) {
448
+ initCircle(this.__useEl, cx, cy, r);
449
+ this.attr({
450
+ transform: this.__transform_current
451
+ });
452
+ full(this.__useEl, this.__config);
453
+ return this;
454
+ };
455
+ SVG.prototype.fillRect = function (x, y, width, height) {
456
+ initRect(this.__useEl, this.__config, x, y, width, height);
457
+ this.attr({
458
+ transform: this.__transform_current
459
+ });
460
+ fill(this.__useEl, this.__config);
461
+ return this;
462
+ };
463
+ SVG.prototype.strokeRect = function (x, y, width, height) {
464
+ initRect(this.__useEl, this.__config, x, y, width, height);
465
+ this.attr({
466
+ transform: this.__transform_current
467
+ });
468
+ stroke(this.__useEl, this.__config);
469
+ return this;
470
+ };
471
+ SVG.prototype.fullRect = function (x, y, width, height) {
472
+ initRect(this.__useEl, this.__config, x, y, width, height);
473
+ this.attr({
474
+ transform: this.__transform_current
475
+ });
476
+ full(this.__useEl, this.__config);
477
+ return this;
478
+ };
479
+ SVG.prototype.beginPath = function () {
480
+ this.__currentPosition = [];
481
+ this.__path = "";
482
+ return this;
483
+ };
484
+ SVG.prototype.closePath = function () {
485
+ this.__path += "Z";
486
+ return this;
487
+ };
488
+ SVG.prototype.moveTo = function (x, y) {
489
+ this.__currentPosition = [x, y];
490
+ this.__path += "M" + x + " " + y;
491
+ return this;
492
+ };
493
+ SVG.prototype.lineTo = function (x, y) {
494
+ this.__currentPosition = [x, y];
495
+ this.__path += (this.__path == "" ? "M" : "L") + x + " " + y;
496
+ return this;
497
+ };
498
+ SVG.prototype.fill = function () {
499
+ initPath(this.__useEl, this.__path);
500
+ this.attr({
501
+ transform: this.__transform_current
502
+ });
503
+ fill(this.__useEl, this.__config);
504
+ return this;
505
+ };
506
+ SVG.prototype.stroke = function () {
507
+ initPath(this.__useEl, this.__path);
508
+ this.attr({
509
+ transform: this.__transform_current
510
+ });
511
+ stroke(this.__useEl, this.__config);
512
+ return this;
513
+ };
514
+ SVG.prototype.full = function () {
515
+ initPath(this.__useEl, this.__path);
516
+ this.attr({
517
+ transform: this.__transform_current
518
+ });
519
+ full(this.__useEl, this.__config);
520
+ return this;
521
+ };
522
+ SVG.prototype.save = function () {
523
+ this.__transform_history.push(this.__transform_current);
524
+ return this;
525
+ };
526
+ SVG.prototype.restore = function () {
527
+ if (this.__transform_history.length > 0)
528
+ this.__transform_current = this.__transform_history.pop();
529
+ return this;
530
+ };
531
+ SVG.prototype.arc = function (x, y, r, beginDeg, deg) {
532
+ var begPosition = rotate(x, y, (beginDeg / 180) * Math.PI, x + r, y);
533
+ var endPosition = rotate(x, y, ((beginDeg + deg) / 180) * Math.PI, x + r, y);
534
+ if (this.__path == "") {
535
+ this.__path += "M" + begPosition[0] + "," + begPosition[1];
536
+ }
537
+ else if (begPosition[0] != this.__currentPosition[0] ||
538
+ begPosition[1] != this.__currentPosition[1]) {
539
+ this.__path += "L" + begPosition[0] + "," + begPosition[1];
540
+ }
541
+ this.__path +=
542
+ "A" +
543
+ r +
544
+ "," +
545
+ r +
546
+ " 0 " +
547
+ (deg > 180 || deg < -180 ? 1 : 0) +
548
+ "," +
549
+ (deg > 0 ? 1 : 0) +
550
+ " " +
551
+ endPosition[0] +
552
+ "," +
553
+ endPosition[1];
554
+ return this;
555
+ };
556
+ SVG.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
557
+ this.__path += "Q" + cpx + " " + cpy + "," + x + " " + y;
558
+ return this;
559
+ };
560
+ SVG.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
561
+ this.__path +=
562
+ "C" + cp1x + " " + cp1y + "," + cp2x + " " + cp2y + "," + x + " " + y;
563
+ return this;
564
+ };
565
+ SVG.prototype.bind = function (eventType, callback) {
566
+ this.__useEl.addEventListener(eventType, function (event) {
567
+ callback.call(this, event, this);
568
+ }, false);
569
+ return this;
570
+ };
571
+ SVG.prototype.createLinearGradient = function (x0, y0, x1, y1) {
572
+ return linearGradient(this.__svg, x0, y0, x1, y1);
573
+ };
574
+ SVG.prototype.createRadialGradient = function (cx, cy, r) {
575
+ return radialGradient(this.__svg, cx, cy, r);
576
+ };
577
+ SVG.prototype.translate = function (dx, dy) {
578
+ this.__transform_current += ' translate(' + dx + ',' + dy + ')';
579
+ return this;
580
+ };
581
+ SVG.prototype.rotate = function (deg) {
582
+ this.__transform_current += ' rotate(' + deg + ')';
583
+ return this;
584
+ };
585
+ SVG.prototype.install = function (methods) {
586
+ var _this = this;
587
+ var _loop_1 = function (key) {
588
+ if (key in this_1) {
589
+ throw new Error("VISLite SVG:Method already exists and cannot be overwritten.");
590
+ }
591
+ else {
592
+ this_1[key] = function () {
593
+ var args = [];
594
+ for (var _i = 0; _i < arguments.length; _i++) {
595
+ args[_i] = arguments[_i];
596
+ }
597
+ var value = methods[key].apply(_this, args);
598
+ if (value != void 0)
599
+ return value;
600
+ return _this;
601
+ };
602
+ }
603
+ };
604
+ var this_1 = this;
605
+ for (var key in methods) {
606
+ _loop_1(key);
607
+ }
608
+ return this;
609
+ };
610
+ return SVG;
611
611
  }());
612
612
 
613
- var SVG = (function (_super) {
614
- __extends(SVG, _super);
615
- function SVG(el) {
616
- var _this = this;
617
- if (!el) {
618
- throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
619
- }
620
- var width = el.clientWidth, height = el.clientHeight;
621
- var ViewSVG;
622
- var _el = el;
623
- if (_el._vislite_svg_) {
624
- ViewSVG = _el._vislite_svg_[0];
625
- }
626
- else {
627
- ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
628
- el.appendChild(ViewSVG);
629
- ViewSVG.setAttribute("width", width + "");
630
- ViewSVG.setAttribute("height", height + "");
631
- ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
632
- _el._vislite_svg_ = [ViewSVG];
633
- el.setAttribute('vislite', 'SVG');
634
- }
635
- _this = _super.call(this, ViewSVG) || this;
636
- _this.__el = el;
637
- return _this;
638
- }
639
- SVG.prototype.toDataURL = function () {
640
- var _this = this;
641
- return new Promise(function (resolve, reject) {
642
- var width = _this.__el.clientWidth, height = _this.__el.clientHeight;
643
- var img = document.createElement('img');
644
- img.setAttribute('width', width + "");
645
- img.setAttribute('height', height + "");
646
- var innerSVG = _this.__svg.innerHTML.replace(/"/g, "'");
647
- var base64_svg = "data:image/svg+xml;charset=utf-8," + encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='" + width + "' height='" + height + "'>" + innerSVG + "</svg>");
648
- img.setAttribute('src', base64_svg);
649
- img.onload = function () {
650
- var canvas = document.createElement('canvas');
651
- canvas.setAttribute('width', width + "");
652
- canvas.setAttribute('height', height + "");
653
- var painter = canvas.getContext('2d');
654
- if (painter)
655
- painter.drawImage(img, 0, 0, width, height);
656
- try {
657
- resolve(canvas.toDataURL());
658
- }
659
- catch (e) {
660
- reject(e);
661
- }
662
- };
663
- img.onerror = function (e) {
664
- reject(e);
665
- };
666
- });
667
- };
668
- return SVG;
613
+ var SVG = (function (_super) {
614
+ __extends(SVG, _super);
615
+ function SVG(el) {
616
+ var _this = this;
617
+ if (!el) {
618
+ throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");
619
+ }
620
+ var width = el.clientWidth, height = el.clientHeight;
621
+ var ViewSVG;
622
+ var _el = el;
623
+ if (_el._vislite_svg_) {
624
+ ViewSVG = _el._vislite_svg_[0];
625
+ }
626
+ else {
627
+ ViewSVG = document.createElementNS("http://www.w3.org/2000/svg", 'svg');
628
+ el.appendChild(ViewSVG);
629
+ ViewSVG.setAttribute("width", width + "");
630
+ ViewSVG.setAttribute("height", height + "");
631
+ ViewSVG.setAttribute("viewBox", "0 0 " + width + " " + height);
632
+ _el._vislite_svg_ = [ViewSVG];
633
+ el.setAttribute('vislite', 'SVG');
634
+ }
635
+ _this = _super.call(this, ViewSVG) || this;
636
+ _this.__el = el;
637
+ return _this;
638
+ }
639
+ SVG.prototype.toDataURL = function () {
640
+ var _this = this;
641
+ return new Promise(function (resolve, reject) {
642
+ var width = _this.__el.clientWidth, height = _this.__el.clientHeight;
643
+ var img = document.createElement('img');
644
+ img.setAttribute('width', width + "");
645
+ img.setAttribute('height', height + "");
646
+ var innerSVG = _this.__svg.innerHTML.replace(/"/g, "'");
647
+ var base64_svg = "data:image/svg+xml;charset=utf-8," + encodeURIComponent("<svg xmlns='http://www.w3.org/2000/svg' width='" + width + "' height='" + height + "'>" + innerSVG + "</svg>");
648
+ img.setAttribute('src', base64_svg);
649
+ img.onload = function () {
650
+ var canvas = document.createElement('canvas');
651
+ canvas.setAttribute('width', width + "");
652
+ canvas.setAttribute('height', height + "");
653
+ var painter = canvas.getContext('2d');
654
+ if (painter)
655
+ painter.drawImage(img, 0, 0, width, height);
656
+ try {
657
+ resolve(canvas.toDataURL());
658
+ }
659
+ catch (e) {
660
+ reject(e);
661
+ }
662
+ };
663
+ img.onerror = function (e) {
664
+ reject(e);
665
+ };
666
+ });
667
+ };
668
+ return SVG;
669
669
  }(SVG$1));
670
670
 
671
671
  export { SVG as default };