vislite 1.4.0 → 1.5.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 (85) hide show
  1. package/CHANGELOG +313 -307
  2. package/lib/BarLayout/index.es.js +347 -347
  3. package/lib/BarLayout/index.es.min.js +1 -1
  4. package/lib/Buffer/index.es.js +35 -35
  5. package/lib/Buffer/index.es.min.js +1 -1
  6. package/lib/Canvas/index.es.js +775 -774
  7. package/lib/Canvas/index.es.min.js +2 -2
  8. package/lib/Cardinal/index.es.js +90 -90
  9. package/lib/Cardinal/index.es.min.js +1 -1
  10. package/lib/Eoap/index.es.js +33 -33
  11. package/lib/Eoap/index.es.min.js +1 -1
  12. package/lib/Hermite/index.es.js +35 -35
  13. package/lib/Hermite/index.es.min.js +1 -1
  14. package/lib/MapCoordinate/index.es.js +199 -199
  15. package/lib/MapCoordinate/index.es.min.js +1 -1
  16. package/lib/Matrix4/index.es.js +124 -124
  17. package/lib/Matrix4/index.es.min.js +1 -1
  18. package/lib/Mercator/index.es.js +19 -19
  19. package/lib/Mercator/index.es.min.js +1 -1
  20. package/lib/PieLayout/index.es.js +114 -114
  21. package/lib/PieLayout/index.es.min.js +1 -1
  22. package/lib/RawCanvas/index.es.js +704 -704
  23. package/lib/RawCanvas/index.es.min.js +1 -1
  24. package/lib/SVG/index.es.js +514 -514
  25. package/lib/SVG/index.es.min.js +1 -1
  26. package/lib/Shader/index.es.js +35 -35
  27. package/lib/Shader/index.es.min.js +1 -1
  28. package/lib/Texture/index.es.js +53 -53
  29. package/lib/Texture/index.es.min.js +1 -1
  30. package/lib/TreeLayout/index.es.js +301 -301
  31. package/lib/TreeLayout/index.es.min.js +1 -1
  32. package/lib/animation/index.es.js +3 -3
  33. package/lib/animation/index.es.min.js +1 -1
  34. package/lib/assemble/index.es.js +17 -17
  35. package/lib/assemble/index.es.min.js +1 -1
  36. package/lib/getLoopColors/index.es.js +35 -35
  37. package/lib/getLoopColors/index.es.min.js +1 -1
  38. package/lib/getWebGLContext/index.es.js +62 -62
  39. package/lib/getWebGLContext/index.es.min.js +1 -1
  40. package/lib/index.umd.js +2657 -2656
  41. package/lib/index.umd.min.js +4 -4
  42. package/lib/initOption/index.es.js +6 -6
  43. package/lib/initOption/index.es.min.js +1 -1
  44. package/lib/mergeOption/index.es.js +34 -34
  45. package/lib/mergeOption/index.es.min.js +1 -1
  46. package/lib/move/index.es.js +7 -7
  47. package/lib/move/index.es.min.js +1 -1
  48. package/lib/rotate/index.es.js +7 -7
  49. package/lib/rotate/index.es.min.js +1 -1
  50. package/lib/ruler/index.es.js +137 -137
  51. package/lib/ruler/index.es.min.js +1 -1
  52. package/lib/scale/index.es.js +6 -6
  53. package/lib/scale/index.es.min.js +1 -1
  54. package/lib/throttle/index.es.js +1 -1
  55. package/lib/throttle/index.es.min.js +1 -1
  56. package/package/BarLayout/index.ts +2 -2
  57. package/package/PieLayout/index.ts +2 -2
  58. package/package/animation/index.ts +5 -5
  59. package/package/index.ts +84 -84
  60. package/package/throttle/index.ts +2 -2
  61. package/package.json +75 -75
  62. package/src/Canvas.ts +9 -4
  63. package/src/SVG.ts +55 -55
  64. package/src/common/canvas/gradient.ts +31 -31
  65. package/src/common/svg/default.ts +29 -29
  66. package/src/common/svg/gradient.ts +53 -53
  67. package/src/common/svg/index.ts +332 -332
  68. package/src/common/tree/toPlainTree.ts +135 -135
  69. package/src/common/webgl/texture.ts +98 -98
  70. package/src/layout/BarLayout.ts +248 -248
  71. package/src/layout/PieLayout.ts +141 -141
  72. package/src/layout/TreeLayout.ts +197 -197
  73. package/types/Bar.d.ts +91 -91
  74. package/types/BarConfig.d.ts +4 -4
  75. package/types/BarLayout.d.ts +48 -48
  76. package/types/BarOption.d.ts +31 -31
  77. package/types/CanvasOption.d.ts +5 -0
  78. package/types/Pie.d.ts +73 -73
  79. package/types/PieConfig.d.ts +26 -26
  80. package/types/PieLayout.d.ts +40 -40
  81. package/types/PieOption.d.ts +21 -21
  82. package/types/SVG.d.ts +247 -247
  83. package/types/animation.d.ts +11 -11
  84. package/types/index.d.ts +195 -195
  85. package/types/throttle.d.ts +5 -5
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Canvas of VISLite JavaScript Library v1.4.0
2
+ * Canvas of VISLite JavaScript Library v1.5.0-alpha.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  /******************************************************************************
@@ -49,797 +49,798 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
49
49
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
50
50
  };
51
51
 
52
- var rotate = function (cx, cy, deg, x, y) {
53
- var cos = Math.cos(deg), sin = Math.sin(deg);
54
- return [
55
- +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
56
- +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
57
- ];
58
- };
59
- function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
60
- if (rotateA < 0) {
61
- beginA += rotateA;
62
- rotateA *= -1;
63
- }
64
- var temp = [];
65
- var p;
66
- p = rotate(0, 0, beginA, r1, 0);
67
- temp[0] = p[0];
68
- temp[1] = p[1];
69
- p = rotate(0, 0, rotateA, p[0], p[1]);
70
- temp[2] = p[0];
71
- temp[3] = p[1];
72
- p = rotate(0, 0, beginA, r2, 0);
73
- temp[4] = p[0];
74
- temp[5] = p[1];
75
- p = rotate(0, 0, rotateA, p[0], p[1]);
76
- temp[6] = p[0];
77
- temp[7] = p[1];
78
- 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);
52
+ var rotate = function (cx, cy, deg, x, y) {
53
+ var cos = Math.cos(deg), sin = Math.sin(deg);
54
+ return [
55
+ +((x - cx) * cos - (y - cy) * sin + cx).toFixed(7),
56
+ +((x - cx) * sin + (y - cy) * cos + cy).toFixed(7)
57
+ ];
58
+ };
59
+ function arc (beginA, rotateA, cx, cy, r1, r2, doback) {
60
+ if (rotateA < 0) {
61
+ beginA += rotateA;
62
+ rotateA *= -1;
63
+ }
64
+ var temp = [];
65
+ var p;
66
+ p = rotate(0, 0, beginA, r1, 0);
67
+ temp[0] = p[0];
68
+ temp[1] = p[1];
69
+ p = rotate(0, 0, rotateA, p[0], p[1]);
70
+ temp[2] = p[0];
71
+ temp[3] = p[1];
72
+ p = rotate(0, 0, beginA, r2, 0);
73
+ temp[4] = p[0];
74
+ temp[5] = p[1];
75
+ p = rotate(0, 0, rotateA, p[0], p[1]);
76
+ temp[6] = p[0];
77
+ temp[7] = p[1];
78
+ 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);
79
79
  }
80
80
 
81
- var initText = function (painter, config, x, y, deg) {
82
- painter.beginPath();
83
- painter.translate(x, y);
84
- painter.rotate(deg);
85
- painter.font =
86
- config.fontStyle +
87
- " " +
88
- config.fontWeight +
89
- " " +
90
- config.fontSize +
91
- "px " +
92
- config.fontFamily;
93
- return painter;
94
- };
95
- var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
96
- if (r1 > r2) {
97
- var temp = r1;
98
- r1 = r2;
99
- r2 = temp;
100
- }
101
- beginDeg = beginDeg % (Math.PI * 2);
102
- if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
103
- deg = Math.PI * 2;
104
- }
105
- else {
106
- deg = deg % (Math.PI * 2);
107
- }
108
- arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
109
- if (r < 0)
110
- r = -r;
111
- painter.beginPath();
112
- painter.moveTo(begInnerX, begInnerY);
113
- painter.arc(cx, cy, r1, beginA, endA, false);
114
- if (config.arcEndCap == "round")
115
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
116
- else if (config.arcEndCap == "-round")
117
- painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
118
- else
119
- painter.lineTo(endOuterX, endOuterY);
120
- painter.arc(cx, cy, r2, endA, beginA, true);
121
- if (config.arcStartCap == "round")
122
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
123
- else if (config.arcStartCap == "-round")
124
- painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
125
- else
126
- painter.lineTo(begInnerX, begInnerY);
127
- });
128
- if (config.arcStartCap == "butt")
129
- painter.closePath();
130
- return painter;
131
- };
132
- var initCircle = function (painter, cx, cy, r) {
133
- painter.beginPath();
134
- painter.moveTo(cx + r, cy);
135
- painter.arc(cx, cy, r, 0, Math.PI * 2);
136
- return painter;
137
- };
138
- var initRect = function (painter, config, x, y, width, height) {
139
- painter.beginPath();
140
- var rectRadius = [];
141
- if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
142
- for (var index = 0; index < 4; index++) {
143
- rectRadius.push.apply(rectRadius, config.rectRadius);
144
- }
145
- }
146
- if (rectRadius.length >= 4) {
147
- painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
148
- painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
149
- painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
150
- painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
151
- painter.closePath();
152
- }
153
- else {
154
- painter.rect(x, y, width, height);
155
- }
156
- return painter;
81
+ var initText = function (painter, config, x, y, deg) {
82
+ painter.beginPath();
83
+ painter.translate(x, y);
84
+ painter.rotate(deg);
85
+ painter.font =
86
+ config.fontStyle +
87
+ " " +
88
+ config.fontWeight +
89
+ " " +
90
+ config.fontSize +
91
+ "px " +
92
+ config.fontFamily;
93
+ return painter;
94
+ };
95
+ var initArc = function (painter, config, cx, cy, r1, r2, beginDeg, deg) {
96
+ if (r1 > r2) {
97
+ var temp = r1;
98
+ r1 = r2;
99
+ r2 = temp;
100
+ }
101
+ beginDeg = beginDeg % (Math.PI * 2);
102
+ if (deg >= Math.PI * 1.999999 || deg <= -Math.PI * 1.999999) {
103
+ deg = Math.PI * 2;
104
+ }
105
+ else {
106
+ deg = deg % (Math.PI * 2);
107
+ }
108
+ arc(beginDeg, deg, cx, cy, r1, r2, function (beginA, endA, begInnerX, begInnerY, begOuterX, begOuterY, endInnerX, endInnerY, endOuterX, endOuterY, r) {
109
+ if (r < 0)
110
+ r = -r;
111
+ painter.beginPath();
112
+ painter.moveTo(begInnerX, begInnerY);
113
+ painter.arc(cx, cy, r1, beginA, endA, false);
114
+ if (config.arcEndCap == "round")
115
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, true);
116
+ else if (config.arcEndCap == "-round")
117
+ painter.arc((endInnerX + endOuterX) * 0.5, (endInnerY + endOuterY) * 0.5, r, endA - Math.PI, endA, false);
118
+ else
119
+ painter.lineTo(endOuterX, endOuterY);
120
+ painter.arc(cx, cy, r2, endA, beginA, true);
121
+ if (config.arcStartCap == "round")
122
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, true);
123
+ else if (config.arcStartCap == "-round")
124
+ painter.arc((begInnerX + begOuterX) * 0.5, (begInnerY + begOuterY) * 0.5, r, beginA, beginA - Math.PI, false);
125
+ else
126
+ painter.lineTo(begInnerX, begInnerY);
127
+ });
128
+ if (config.arcStartCap == "butt")
129
+ painter.closePath();
130
+ return painter;
131
+ };
132
+ var initCircle = function (painter, cx, cy, r) {
133
+ painter.beginPath();
134
+ painter.moveTo(cx + r, cy);
135
+ painter.arc(cx, cy, r, 0, Math.PI * 2);
136
+ return painter;
137
+ };
138
+ var initRect = function (painter, config, x, y, width, height) {
139
+ painter.beginPath();
140
+ var rectRadius = [];
141
+ if (Array.isArray(config.rectRadius) && config.rectRadius.length > 0) {
142
+ for (var index = 0; index < 4; index++) {
143
+ rectRadius.push.apply(rectRadius, config.rectRadius);
144
+ }
145
+ }
146
+ if (rectRadius.length >= 4) {
147
+ painter.arc(x + rectRadius[0], y + rectRadius[0], rectRadius[0], Math.PI, Math.PI * 1.5);
148
+ painter.arc(x + width - rectRadius[1], y + rectRadius[1], rectRadius[1], 1.5 * Math.PI, 0);
149
+ painter.arc(x + width - rectRadius[2], y + height - rectRadius[2], rectRadius[2], 0, Math.PI * 0.5);
150
+ painter.arc(x + rectRadius[3], y + height - rectRadius[3], rectRadius[3], 0.5 * Math.PI, Math.PI);
151
+ painter.closePath();
152
+ }
153
+ else {
154
+ painter.rect(x, y, width, height);
155
+ }
156
+ return painter;
157
157
  };
158
158
 
159
- function texts (painter, contents, width, height, doback) {
160
- var lineNumber = 0, content = "";
161
- for (var i = 0; i < contents.length; i++) {
162
- if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
163
- lineNumber += 1;
164
- doback(content, (lineNumber - 0.5) * height);
165
- content = contents[i];
166
- }
167
- else if (i == contents.length - 1) {
168
- lineNumber += 1;
169
- doback(content + contents[i], (lineNumber - 0.5) * height);
170
- }
171
- else {
172
- content += contents[i];
173
- }
174
- }
175
- return lineNumber * height;
159
+ function texts (painter, contents, width, height, doback) {
160
+ var lineNumber = 0, content = "";
161
+ for (var i = 0; i < contents.length; i++) {
162
+ if (painter.measureText(content + contents[i]).width > width || /\n$/.test(content)) {
163
+ lineNumber += 1;
164
+ doback(content, (lineNumber - 0.5) * height);
165
+ content = contents[i];
166
+ }
167
+ else if (i == contents.length - 1) {
168
+ lineNumber += 1;
169
+ doback(content + contents[i], (lineNumber - 0.5) * height);
170
+ }
171
+ else {
172
+ content += contents[i];
173
+ }
174
+ }
175
+ return lineNumber * height;
176
176
  }
177
177
 
178
- function defaultFactory (type) {
179
- var special = {
180
- "fontSize": 16,
181
- "fontFamily": "sans-serif",
182
- "fontWeight": 400,
183
- "fontStyle": "normal",
184
- "arcStartCap": 'butt',
185
- "arcEndCap": 'butt',
186
- "rectRadius": []
187
- };
188
- var init = {
189
- "fillStyle": 'black',
190
- "strokeStyle": 'black',
191
- "lineWidth": 1,
192
- "lineCap": "butt",
193
- "lineJoin": "miter",
194
- "lineDash": [],
195
- "textAlign": 'left',
196
- "textBaseline": 'middle',
197
- "shadowBlur": 0,
198
- "shadowColor": "black"
199
- };
200
- if (type == 'special')
201
- return special;
202
- else if (type == 'init')
203
- return init;
204
- else
205
- return __assign(__assign({}, special), init);
178
+ function defaultFactory (type) {
179
+ var special = {
180
+ "fontSize": 16,
181
+ "fontFamily": "sans-serif",
182
+ "fontWeight": 400,
183
+ "fontStyle": "normal",
184
+ "arcStartCap": 'butt',
185
+ "arcEndCap": 'butt',
186
+ "rectRadius": []
187
+ };
188
+ var init = {
189
+ "fillStyle": 'black',
190
+ "strokeStyle": 'black',
191
+ "lineWidth": 1,
192
+ "lineCap": "butt",
193
+ "lineJoin": "miter",
194
+ "lineDash": [],
195
+ "textAlign": 'left',
196
+ "textBaseline": 'middle',
197
+ "shadowBlur": 0,
198
+ "shadowColor": "black"
199
+ };
200
+ if (type == 'special')
201
+ return special;
202
+ else if (type == 'init')
203
+ return init;
204
+ else
205
+ return __assign(__assign({}, special), init);
206
206
  }
207
207
 
208
- var Painter = (function () {
209
- function Painter(canvas, opts, region, isPainter, scaleSize) {
210
- if (opts === void 0) { opts = {}; }
211
- if (isPainter === void 0) { isPainter = false; }
212
- this.__region = null;
213
- this.__onlyRegion = false;
214
- this.__onlyView = false;
215
- this.__specialConfig = defaultFactory("special");
216
- this.__initConfig = defaultFactory("init");
217
- this.painter = canvas.getContext("2d", opts);
218
- this.__region = region;
219
- this.__isPainter = isPainter;
220
- this.painter.textBaseline = 'middle';
221
- this.painter.textAlign = 'left';
222
- }
223
- Painter.prototype.useConfig = function (key, value) {
224
- if (this.__region && !this.__onlyView) {
225
- if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
226
- this.__region.useConfig(key, value);
227
- }
228
- }
229
- if (this.__isPainter && this.__onlyRegion)
230
- return this;
231
- if (key == 'lineDash') {
232
- if (this.painter.setLineDash)
233
- this.painter.setLineDash(value);
234
- }
235
- else if (key in this.__specialConfig) {
236
- if (key == 'fontSize') {
237
- value = Math.round(value);
238
- }
239
- this.__specialConfig[key] = value;
240
- }
241
- else if (key in this.__initConfig) {
242
- this.painter[key] = value;
243
- }
244
- else {
245
- throw new Error('Illegal configuration item of painter : ' + key + " !");
246
- }
247
- return this;
248
- };
249
- Painter.prototype.fillText = function (text, x, y, deg) {
250
- if (deg === void 0) { deg = 0; }
251
- if (this.__region && !this.__onlyView)
252
- this.__region.fillText(text, x, y, deg);
253
- if (this.__isPainter && this.__onlyRegion)
254
- return this;
255
- this.painter.save();
256
- initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
257
- this.painter.restore();
258
- return this;
259
- };
260
- Painter.prototype.strokeText = function (text, x, y, deg) {
261
- if (deg === void 0) { deg = 0; }
262
- if (this.__region && !this.__onlyView)
263
- this.__region.strokeText(text, x, y, deg);
264
- if (this.__isPainter && this.__onlyRegion)
265
- return this;
266
- this.painter.save();
267
- initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
268
- this.painter.restore();
269
- return this;
270
- };
271
- Painter.prototype.fullText = function (text, x, y, deg) {
272
- if (deg === void 0) { deg = 0; }
273
- if (this.__region && !this.__onlyView)
274
- this.__region.fullText(text, x, y, deg);
275
- if (this.__isPainter && this.__onlyRegion)
276
- return this;
277
- this.painter.save();
278
- initText(this.painter, this.__specialConfig, x, y, deg);
279
- this.painter.fillText(text, 0, 0);
280
- this.painter.strokeText(text, 0, 0);
281
- this.painter.restore();
282
- return this;
283
- };
284
- Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
285
- var _this = this;
286
- if (lineHeight === void 0) { lineHeight = 1.2; }
287
- if (deg === void 0) { deg = 0; }
288
- var h = 0;
289
- if (this.__region && !this.__onlyView)
290
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
291
- if (this.__isPainter && this.__onlyRegion)
292
- return h;
293
- this.painter.save();
294
- initText(this.painter, this.__specialConfig, x, y, deg);
295
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
296
- _this.painter.fillText(content, 0, top);
297
- });
298
- this.painter.restore();
299
- return height;
300
- };
301
- Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
302
- var _this = this;
303
- if (lineHeight === void 0) { lineHeight = 1.2; }
304
- if (deg === void 0) { deg = 0; }
305
- var h = 0;
306
- if (this.__region && !this.__onlyView)
307
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
308
- if (this.__isPainter && this.__onlyRegion)
309
- return h;
310
- this.painter.save();
311
- initText(this.painter, this.__specialConfig, x, y, deg);
312
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
313
- _this.painter.strokeText(content, 0, top);
314
- });
315
- this.painter.restore();
316
- return height;
317
- };
318
- Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
319
- var _this = this;
320
- if (lineHeight === void 0) { lineHeight = 1.2; }
321
- if (deg === void 0) { deg = 0; }
322
- var h = 0;
323
- if (this.__region && !this.__onlyView)
324
- h = this.__region.fillTexts(contents, x, y, width, lineHeight);
325
- if (this.__isPainter && this.__onlyRegion)
326
- return h;
327
- this.painter.save();
328
- initText(this.painter, this.__specialConfig, x, y, deg);
329
- var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
330
- _this.painter.fillText(content, 0, top);
331
- _this.painter.strokeText(content, 0, top);
332
- });
333
- this.painter.restore();
334
- return height;
335
- };
336
- Painter.prototype.beginPath = function () {
337
- if (this.__region && !this.__onlyView)
338
- this.__region.beginPath();
339
- if (this.__isPainter && this.__onlyRegion)
340
- return this;
341
- this.painter.beginPath();
342
- return this;
343
- };
344
- Painter.prototype.closePath = function () {
345
- if (this.__region && !this.__onlyView)
346
- this.__region.closePath();
347
- if (this.__isPainter && this.__onlyRegion)
348
- return this;
349
- this.painter.closePath();
350
- return this;
351
- };
352
- Painter.prototype.moveTo = function (x, y) {
353
- if (this.__region && !this.__onlyView)
354
- this.__region.moveTo(x, y);
355
- if (this.__isPainter && this.__onlyRegion)
356
- return this;
357
- this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
358
- return this;
359
- };
360
- Painter.prototype.lineTo = function (x, y) {
361
- if (this.__region && !this.__onlyView)
362
- this.__region.lineTo(x, y);
363
- if (this.__isPainter && this.__onlyRegion)
364
- return this;
365
- this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
366
- return this;
367
- };
368
- Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
369
- if (this.__region && !this.__onlyView)
370
- this.__region.arc(x, y, r, beginDeg, deg);
371
- if (this.__isPainter && this.__onlyRegion)
372
- return this;
373
- this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
374
- return this;
375
- };
376
- Painter.prototype.fill = function () {
377
- if (this.__region && !this.__onlyView)
378
- this.__region.fill();
379
- if (this.__isPainter && this.__onlyRegion)
380
- return this;
381
- this.painter.fill();
382
- return this;
383
- };
384
- Painter.prototype.stroke = function () {
385
- if (this.__region && !this.__onlyView)
386
- this.__region.stroke();
387
- if (this.__isPainter && this.__onlyRegion)
388
- return this;
389
- this.painter.stroke();
390
- return this;
391
- };
392
- Painter.prototype.full = function () {
393
- if (this.__region && !this.__onlyView)
394
- this.__region.full();
395
- if (this.__isPainter && this.__onlyRegion)
396
- return this;
397
- this.painter.fill();
398
- this.painter.stroke();
399
- return this;
400
- };
401
- Painter.prototype.save = function () {
402
- if (this.__region && !this.__onlyView)
403
- this.__region.save();
404
- if (this.__isPainter && this.__onlyRegion)
405
- return this;
406
- this.painter.save();
407
- return this;
408
- };
409
- Painter.prototype.restore = function () {
410
- if (this.__region && !this.__onlyView)
411
- this.__region.restore();
412
- if (this.__isPainter && this.__onlyRegion)
413
- return this;
414
- this.painter.restore();
415
- return this;
416
- };
417
- Painter.prototype.clip = function () {
418
- if (this.__region && !this.__onlyView)
419
- this.__region.clip();
420
- if (this.__isPainter && this.__onlyRegion)
421
- return this;
422
- this.painter.clip();
423
- return this;
424
- };
425
- Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
426
- if (this.__region && !this.__onlyView)
427
- this.__region.quadraticCurveTo(cpx, cpy, x, y);
428
- if (this.__isPainter && this.__onlyRegion)
429
- return this;
430
- this.painter.quadraticCurveTo(cpx, cpy, x, y);
431
- return this;
432
- };
433
- Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
434
- if (this.__region && !this.__onlyView)
435
- this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
436
- if (this.__isPainter && this.__onlyRegion)
437
- return this;
438
- this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
439
- return this;
440
- };
441
- Painter.prototype.clearRect = function (x, y, w, h) {
442
- if (this.__region && !this.__onlyView)
443
- this.__region.clearRect(x, y, w, h);
444
- if (this.__isPainter && this.__onlyRegion)
445
- return this;
446
- this.painter.clearRect(x, y, w, h);
447
- return this;
448
- };
449
- Painter.prototype.clearCircle = function (cx, cy, r) {
450
- if (this.__region && !this.__onlyView)
451
- this.__region.clearCircle(cx, cy, r);
452
- if (this.__isPainter && this.__onlyRegion)
453
- return this;
454
- this.painter.beginPath();
455
- this.painter.globalCompositeOperation = "destination-out";
456
- this.painter.arc(cx, cy, r, 0, Math.PI * 2);
457
- this.painter.fill();
458
- this.painter.globalCompositeOperation = "source-over";
459
- this.painter.closePath();
460
- return this;
461
- };
462
- Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
463
- if (this.__region && !this.__onlyView)
464
- this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
465
- if (this.__isPainter && this.__onlyRegion)
466
- return this;
467
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
468
- return this;
469
- };
470
- Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
471
- if (this.__region && !this.__onlyView)
472
- this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
473
- if (this.__isPainter && this.__onlyRegion)
474
- return this;
475
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
476
- return this;
477
- };
478
- Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
479
- if (this.__region && !this.__onlyView)
480
- this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
481
- if (this.__isPainter && this.__onlyRegion)
482
- return this;
483
- initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
484
- this.painter.fill();
485
- this.painter.stroke();
486
- return this;
487
- };
488
- Painter.prototype.fillCircle = function (cx, cy, r) {
489
- if (this.__region && !this.__onlyView)
490
- this.__region.fillCircle(cx, cy, r);
491
- if (this.__isPainter && this.__onlyRegion)
492
- return this;
493
- initCircle(this.painter, cx, cy, r).fill();
494
- return this;
495
- };
496
- Painter.prototype.strokeCircle = function (cx, cy, r) {
497
- if (this.__region && !this.__onlyView)
498
- this.__region.strokeCircle(cx, cy, r);
499
- if (this.__isPainter && this.__onlyRegion)
500
- return this;
501
- initCircle(this.painter, cx, cy, r).stroke();
502
- return this;
503
- };
504
- Painter.prototype.fullCircle = function (cx, cy, r) {
505
- if (this.__region && !this.__onlyView)
506
- this.__region.fullCircle(cx, cy, r);
507
- if (this.__isPainter && this.__onlyRegion)
508
- return this;
509
- initCircle(this.painter, cx, cy, r);
510
- this.painter.fill();
511
- this.painter.stroke();
512
- return this;
513
- };
514
- Painter.prototype.fillRect = function (x, y, width, height) {
515
- if (this.__region && !this.__onlyView)
516
- this.__region.fillRect(x, y, width, height);
517
- if (this.__isPainter && this.__onlyRegion)
518
- return this;
519
- initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
520
- return this;
521
- };
522
- Painter.prototype.strokeRect = function (x, y, width, height) {
523
- if (this.__region && !this.__onlyView)
524
- this.__region.strokeRect(x, y, width, height);
525
- if (this.__isPainter && this.__onlyRegion)
526
- return this;
527
- initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
528
- return this;
529
- };
530
- Painter.prototype.fullRect = function (x, y, width, height) {
531
- if (this.__region && !this.__onlyView)
532
- this.__region.fullRect(x, y, width, height);
533
- if (this.__isPainter && this.__onlyRegion)
534
- return this;
535
- initRect(this.painter, this.__specialConfig, x, y, width, height);
536
- this.painter.fill();
537
- this.painter.stroke();
538
- return this;
539
- };
540
- Painter.prototype.draw = function () {
541
- return Promise.resolve();
542
- };
543
- Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
544
- var _this = this;
545
- if (isImage === void 0) { isImage = false; }
546
- return new Promise(function (resolve) {
547
- if (_this.__region && !_this.__onlyView) {
548
- _this.__region.fillRect(x, y, w, h);
549
- }
550
- if (_this.__isPainter && _this.__onlyRegion) {
551
- resolve({});
552
- return;
553
- }
554
- if (typeof img == 'string' && !isImage) {
555
- var imgInstance_1 = new Image();
556
- imgInstance_1.onload = function () {
557
- _this.painter.drawImage(imgInstance_1, x, y, w, h);
558
- resolve({});
559
- };
560
- imgInstance_1.src = img;
561
- }
562
- else {
563
- _this.painter.drawImage(img, x, y, w, h);
564
- resolve({});
565
- }
566
- });
567
- };
568
- Painter.prototype.install = function (methods) {
569
- var _this = this;
570
- var _loop_1 = function (key) {
571
- if (key in this_1) {
572
- throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
573
- }
574
- else {
575
- this_1[key] = function () {
576
- var args = [];
577
- for (var _i = 0; _i < arguments.length; _i++) {
578
- args[_i] = arguments[_i];
579
- }
580
- var value = methods[key].apply(_this, args);
581
- if (value != void 0)
582
- return value;
583
- return _this;
584
- };
585
- }
586
- };
587
- var this_1 = this;
588
- for (var key in methods) {
589
- _loop_1(key);
590
- }
591
- return this;
592
- };
593
- return Painter;
208
+ var Painter = (function () {
209
+ function Painter(canvas, opts, region, isPainter, scaleSize) {
210
+ if (opts === void 0) { opts = {}; }
211
+ if (isPainter === void 0) { isPainter = false; }
212
+ this.__region = null;
213
+ this.__onlyRegion = false;
214
+ this.__onlyView = false;
215
+ this.__specialConfig = defaultFactory("special");
216
+ this.__initConfig = defaultFactory("init");
217
+ this.painter = canvas.getContext("2d", opts);
218
+ this.__region = region;
219
+ this.__isPainter = isPainter;
220
+ this.painter.textBaseline = 'middle';
221
+ this.painter.textAlign = 'left';
222
+ }
223
+ Painter.prototype.useConfig = function (key, value) {
224
+ if (this.__region && !this.__onlyView) {
225
+ if (['fillStyle', 'strokeStyle', 'shadowBlur', 'shadowColor'].indexOf(key) < 0) {
226
+ this.__region.useConfig(key, value);
227
+ }
228
+ }
229
+ if (this.__isPainter && this.__onlyRegion)
230
+ return this;
231
+ if (key == 'lineDash') {
232
+ if (this.painter.setLineDash)
233
+ this.painter.setLineDash(value);
234
+ }
235
+ else if (key in this.__specialConfig) {
236
+ if (key == 'fontSize') {
237
+ value = Math.round(value);
238
+ }
239
+ this.__specialConfig[key] = value;
240
+ }
241
+ else if (key in this.__initConfig) {
242
+ this.painter[key] = value;
243
+ }
244
+ else {
245
+ throw new Error('Illegal configuration item of painter : ' + key + " !");
246
+ }
247
+ return this;
248
+ };
249
+ Painter.prototype.fillText = function (text, x, y, deg) {
250
+ if (deg === void 0) { deg = 0; }
251
+ if (this.__region && !this.__onlyView)
252
+ this.__region.fillText(text, x, y, deg);
253
+ if (this.__isPainter && this.__onlyRegion)
254
+ return this;
255
+ this.painter.save();
256
+ initText(this.painter, this.__specialConfig, x, y, deg).fillText(text, 0, 0);
257
+ this.painter.restore();
258
+ return this;
259
+ };
260
+ Painter.prototype.strokeText = function (text, x, y, deg) {
261
+ if (deg === void 0) { deg = 0; }
262
+ if (this.__region && !this.__onlyView)
263
+ this.__region.strokeText(text, x, y, deg);
264
+ if (this.__isPainter && this.__onlyRegion)
265
+ return this;
266
+ this.painter.save();
267
+ initText(this.painter, this.__specialConfig, x, y, deg).strokeText(text, 0, 0);
268
+ this.painter.restore();
269
+ return this;
270
+ };
271
+ Painter.prototype.fullText = function (text, x, y, deg) {
272
+ if (deg === void 0) { deg = 0; }
273
+ if (this.__region && !this.__onlyView)
274
+ this.__region.fullText(text, x, y, deg);
275
+ if (this.__isPainter && this.__onlyRegion)
276
+ return this;
277
+ this.painter.save();
278
+ initText(this.painter, this.__specialConfig, x, y, deg);
279
+ this.painter.fillText(text, 0, 0);
280
+ this.painter.strokeText(text, 0, 0);
281
+ this.painter.restore();
282
+ return this;
283
+ };
284
+ Painter.prototype.fillTexts = function (contents, x, y, width, lineHeight, deg) {
285
+ var _this = this;
286
+ if (lineHeight === void 0) { lineHeight = 1.2; }
287
+ if (deg === void 0) { deg = 0; }
288
+ var h = 0;
289
+ if (this.__region && !this.__onlyView)
290
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
291
+ if (this.__isPainter && this.__onlyRegion)
292
+ return h;
293
+ this.painter.save();
294
+ initText(this.painter, this.__specialConfig, x, y, deg);
295
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
296
+ _this.painter.fillText(content, 0, top);
297
+ });
298
+ this.painter.restore();
299
+ return height;
300
+ };
301
+ Painter.prototype.strokeTexts = function (contents, x, y, width, lineHeight, deg) {
302
+ var _this = this;
303
+ if (lineHeight === void 0) { lineHeight = 1.2; }
304
+ if (deg === void 0) { deg = 0; }
305
+ var h = 0;
306
+ if (this.__region && !this.__onlyView)
307
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
308
+ if (this.__isPainter && this.__onlyRegion)
309
+ return h;
310
+ this.painter.save();
311
+ initText(this.painter, this.__specialConfig, x, y, deg);
312
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
313
+ _this.painter.strokeText(content, 0, top);
314
+ });
315
+ this.painter.restore();
316
+ return height;
317
+ };
318
+ Painter.prototype.fullTexts = function (contents, x, y, width, lineHeight, deg) {
319
+ var _this = this;
320
+ if (lineHeight === void 0) { lineHeight = 1.2; }
321
+ if (deg === void 0) { deg = 0; }
322
+ var h = 0;
323
+ if (this.__region && !this.__onlyView)
324
+ h = this.__region.fillTexts(contents, x, y, width, lineHeight);
325
+ if (this.__isPainter && this.__onlyRegion)
326
+ return h;
327
+ this.painter.save();
328
+ initText(this.painter, this.__specialConfig, x, y, deg);
329
+ var height = texts(this.painter, contents, width, this.__specialConfig.fontSize * lineHeight, function (content, top) {
330
+ _this.painter.fillText(content, 0, top);
331
+ _this.painter.strokeText(content, 0, top);
332
+ });
333
+ this.painter.restore();
334
+ return height;
335
+ };
336
+ Painter.prototype.beginPath = function () {
337
+ if (this.__region && !this.__onlyView)
338
+ this.__region.beginPath();
339
+ if (this.__isPainter && this.__onlyRegion)
340
+ return this;
341
+ this.painter.beginPath();
342
+ return this;
343
+ };
344
+ Painter.prototype.closePath = function () {
345
+ if (this.__region && !this.__onlyView)
346
+ this.__region.closePath();
347
+ if (this.__isPainter && this.__onlyRegion)
348
+ return this;
349
+ this.painter.closePath();
350
+ return this;
351
+ };
352
+ Painter.prototype.moveTo = function (x, y) {
353
+ if (this.__region && !this.__onlyView)
354
+ this.__region.moveTo(x, y);
355
+ if (this.__isPainter && this.__onlyRegion)
356
+ return this;
357
+ this.painter.moveTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
358
+ return this;
359
+ };
360
+ Painter.prototype.lineTo = function (x, y) {
361
+ if (this.__region && !this.__onlyView)
362
+ this.__region.lineTo(x, y);
363
+ if (this.__isPainter && this.__onlyRegion)
364
+ return this;
365
+ this.painter.lineTo(Math.round(x) + 0.5, Math.round(y) + 0.5);
366
+ return this;
367
+ };
368
+ Painter.prototype.arc = function (x, y, r, beginDeg, deg) {
369
+ if (this.__region && !this.__onlyView)
370
+ this.__region.arc(x, y, r, beginDeg, deg);
371
+ if (this.__isPainter && this.__onlyRegion)
372
+ return this;
373
+ this.painter.arc(x, y, r, beginDeg, beginDeg + deg, deg < 0);
374
+ return this;
375
+ };
376
+ Painter.prototype.fill = function () {
377
+ if (this.__region && !this.__onlyView)
378
+ this.__region.fill();
379
+ if (this.__isPainter && this.__onlyRegion)
380
+ return this;
381
+ this.painter.fill();
382
+ return this;
383
+ };
384
+ Painter.prototype.stroke = function () {
385
+ if (this.__region && !this.__onlyView)
386
+ this.__region.stroke();
387
+ if (this.__isPainter && this.__onlyRegion)
388
+ return this;
389
+ this.painter.stroke();
390
+ return this;
391
+ };
392
+ Painter.prototype.full = function () {
393
+ if (this.__region && !this.__onlyView)
394
+ this.__region.full();
395
+ if (this.__isPainter && this.__onlyRegion)
396
+ return this;
397
+ this.painter.fill();
398
+ this.painter.stroke();
399
+ return this;
400
+ };
401
+ Painter.prototype.save = function () {
402
+ if (this.__region && !this.__onlyView)
403
+ this.__region.save();
404
+ if (this.__isPainter && this.__onlyRegion)
405
+ return this;
406
+ this.painter.save();
407
+ return this;
408
+ };
409
+ Painter.prototype.restore = function () {
410
+ if (this.__region && !this.__onlyView)
411
+ this.__region.restore();
412
+ if (this.__isPainter && this.__onlyRegion)
413
+ return this;
414
+ this.painter.restore();
415
+ return this;
416
+ };
417
+ Painter.prototype.clip = function () {
418
+ if (this.__region && !this.__onlyView)
419
+ this.__region.clip();
420
+ if (this.__isPainter && this.__onlyRegion)
421
+ return this;
422
+ this.painter.clip();
423
+ return this;
424
+ };
425
+ Painter.prototype.quadraticCurveTo = function (cpx, cpy, x, y) {
426
+ if (this.__region && !this.__onlyView)
427
+ this.__region.quadraticCurveTo(cpx, cpy, x, y);
428
+ if (this.__isPainter && this.__onlyRegion)
429
+ return this;
430
+ this.painter.quadraticCurveTo(cpx, cpy, x, y);
431
+ return this;
432
+ };
433
+ Painter.prototype.bezierCurveTo = function (cp1x, cp1y, cp2x, cp2y, x, y) {
434
+ if (this.__region && !this.__onlyView)
435
+ this.__region.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
436
+ if (this.__isPainter && this.__onlyRegion)
437
+ return this;
438
+ this.painter.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
439
+ return this;
440
+ };
441
+ Painter.prototype.clearRect = function (x, y, w, h) {
442
+ if (this.__region && !this.__onlyView)
443
+ this.__region.clearRect(x, y, w, h);
444
+ if (this.__isPainter && this.__onlyRegion)
445
+ return this;
446
+ this.painter.clearRect(x, y, w, h);
447
+ return this;
448
+ };
449
+ Painter.prototype.clearCircle = function (cx, cy, r) {
450
+ if (this.__region && !this.__onlyView)
451
+ this.__region.clearCircle(cx, cy, r);
452
+ if (this.__isPainter && this.__onlyRegion)
453
+ return this;
454
+ this.painter.beginPath();
455
+ this.painter.globalCompositeOperation = "destination-out";
456
+ this.painter.arc(cx, cy, r, 0, Math.PI * 2);
457
+ this.painter.fill();
458
+ this.painter.globalCompositeOperation = "source-over";
459
+ this.painter.closePath();
460
+ return this;
461
+ };
462
+ Painter.prototype.fillArc = function (cx, cy, r1, r2, beginDeg, deg) {
463
+ if (this.__region && !this.__onlyView)
464
+ this.__region.fillArc(cx, cy, r1, r2, beginDeg, deg);
465
+ if (this.__isPainter && this.__onlyRegion)
466
+ return this;
467
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).fill();
468
+ return this;
469
+ };
470
+ Painter.prototype.strokeArc = function (cx, cy, r1, r2, beginDeg, deg) {
471
+ if (this.__region && !this.__onlyView)
472
+ this.__region.strokeArc(cx, cy, r1, r2, beginDeg, deg);
473
+ if (this.__isPainter && this.__onlyRegion)
474
+ return this;
475
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg).stroke();
476
+ return this;
477
+ };
478
+ Painter.prototype.fullArc = function (cx, cy, r1, r2, beginDeg, deg) {
479
+ if (this.__region && !this.__onlyView)
480
+ this.__region.fullArc(cx, cy, r1, r2, beginDeg, deg);
481
+ if (this.__isPainter && this.__onlyRegion)
482
+ return this;
483
+ initArc(this.painter, this.__specialConfig, cx, cy, r1, r2, beginDeg, deg);
484
+ this.painter.fill();
485
+ this.painter.stroke();
486
+ return this;
487
+ };
488
+ Painter.prototype.fillCircle = function (cx, cy, r) {
489
+ if (this.__region && !this.__onlyView)
490
+ this.__region.fillCircle(cx, cy, r);
491
+ if (this.__isPainter && this.__onlyRegion)
492
+ return this;
493
+ initCircle(this.painter, cx, cy, r).fill();
494
+ return this;
495
+ };
496
+ Painter.prototype.strokeCircle = function (cx, cy, r) {
497
+ if (this.__region && !this.__onlyView)
498
+ this.__region.strokeCircle(cx, cy, r);
499
+ if (this.__isPainter && this.__onlyRegion)
500
+ return this;
501
+ initCircle(this.painter, cx, cy, r).stroke();
502
+ return this;
503
+ };
504
+ Painter.prototype.fullCircle = function (cx, cy, r) {
505
+ if (this.__region && !this.__onlyView)
506
+ this.__region.fullCircle(cx, cy, r);
507
+ if (this.__isPainter && this.__onlyRegion)
508
+ return this;
509
+ initCircle(this.painter, cx, cy, r);
510
+ this.painter.fill();
511
+ this.painter.stroke();
512
+ return this;
513
+ };
514
+ Painter.prototype.fillRect = function (x, y, width, height) {
515
+ if (this.__region && !this.__onlyView)
516
+ this.__region.fillRect(x, y, width, height);
517
+ if (this.__isPainter && this.__onlyRegion)
518
+ return this;
519
+ initRect(this.painter, this.__specialConfig, x, y, width, height).fill();
520
+ return this;
521
+ };
522
+ Painter.prototype.strokeRect = function (x, y, width, height) {
523
+ if (this.__region && !this.__onlyView)
524
+ this.__region.strokeRect(x, y, width, height);
525
+ if (this.__isPainter && this.__onlyRegion)
526
+ return this;
527
+ initRect(this.painter, this.__specialConfig, x, y, width, height).stroke();
528
+ return this;
529
+ };
530
+ Painter.prototype.fullRect = function (x, y, width, height) {
531
+ if (this.__region && !this.__onlyView)
532
+ this.__region.fullRect(x, y, width, height);
533
+ if (this.__isPainter && this.__onlyRegion)
534
+ return this;
535
+ initRect(this.painter, this.__specialConfig, x, y, width, height);
536
+ this.painter.fill();
537
+ this.painter.stroke();
538
+ return this;
539
+ };
540
+ Painter.prototype.draw = function () {
541
+ return Promise.resolve();
542
+ };
543
+ Painter.prototype.drawImage = function (img, x, y, w, h, isImage) {
544
+ var _this = this;
545
+ if (isImage === void 0) { isImage = false; }
546
+ return new Promise(function (resolve) {
547
+ if (_this.__region && !_this.__onlyView) {
548
+ _this.__region.fillRect(x, y, w, h);
549
+ }
550
+ if (_this.__isPainter && _this.__onlyRegion) {
551
+ resolve({});
552
+ return;
553
+ }
554
+ if (typeof img == 'string' && !isImage) {
555
+ var imgInstance_1 = new Image();
556
+ imgInstance_1.onload = function () {
557
+ _this.painter.drawImage(imgInstance_1, x, y, w, h);
558
+ resolve({});
559
+ };
560
+ imgInstance_1.src = img;
561
+ }
562
+ else {
563
+ _this.painter.drawImage(img, x, y, w, h);
564
+ resolve({});
565
+ }
566
+ });
567
+ };
568
+ Painter.prototype.install = function (methods) {
569
+ var _this = this;
570
+ var _loop_1 = function (key) {
571
+ if (key in this_1) {
572
+ throw new Error("VISLite Canvas:Method already exists and cannot be overwritten.");
573
+ }
574
+ else {
575
+ this_1[key] = function () {
576
+ var args = [];
577
+ for (var _i = 0; _i < arguments.length; _i++) {
578
+ args[_i] = arguments[_i];
579
+ }
580
+ var value = methods[key].apply(_this, args);
581
+ if (value != void 0)
582
+ return value;
583
+ return _this;
584
+ };
585
+ }
586
+ };
587
+ var this_1 = this;
588
+ for (var key in methods) {
589
+ _loop_1(key);
590
+ }
591
+ return this;
592
+ };
593
+ return Painter;
594
594
  }());
595
595
 
596
- function assemble (begin, end, step, count) {
597
- var val = [];
598
- for (var index = 0; index < count; index++)
599
- val[index] = begin;
600
- return function () {
601
- for (var i = 0; i < count; i++) {
602
- if (val[i] + step < end) {
603
- val[i] = +(val[i] + step).toFixed(7);
604
- break;
605
- }
606
- else if (i < count - 1) {
607
- val[i] = begin;
608
- }
609
- }
610
- return val;
611
- };
596
+ function assemble (begin, end, step, count) {
597
+ var val = [];
598
+ for (var index = 0; index < count; index++)
599
+ val[index] = begin;
600
+ return function () {
601
+ for (var i = 0; i < count; i++) {
602
+ if (val[i] + step < end) {
603
+ val[i] = +(val[i] + step).toFixed(7);
604
+ break;
605
+ }
606
+ else if (i < count - 1) {
607
+ val[i] = begin;
608
+ }
609
+ }
610
+ return val;
611
+ };
612
612
  }
613
613
 
614
- var enhanceGradient = function (gradient, calcStop) {
615
- var enhanceGradient = {
616
- "value": function () {
617
- return gradient;
618
- },
619
- "setColor": function (stop, color) {
620
- gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
621
- return enhanceGradient;
622
- }
623
- };
624
- return enhanceGradient;
625
- };
626
- var linearGradient = function (painter, x0, y0, x1, y1) {
627
- var gradient = painter.createLinearGradient(x0, y0, x1, y1);
628
- return enhanceGradient(gradient);
629
- };
630
- var radialGradient = function (painter, cx, cy, r) {
631
- var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
632
- return enhanceGradient(gradient);
633
- };
634
- var conicGradient = function (painter, cx, cy, startDeg, deg) {
635
- var gradient = painter.createConicGradient(startDeg, cx, cy);
636
- return enhanceGradient(gradient, deg ? function (stop) {
637
- return deg / (Math.PI * 2) * stop;
638
- } : void 0);
614
+ var enhanceGradient = function (gradient, calcStop) {
615
+ var enhanceGradient = {
616
+ "value": function () {
617
+ return gradient;
618
+ },
619
+ "setColor": function (stop, color) {
620
+ gradient.addColorStop(calcStop ? calcStop(stop) : stop, color);
621
+ return enhanceGradient;
622
+ }
623
+ };
624
+ return enhanceGradient;
625
+ };
626
+ var linearGradient = function (painter, x0, y0, x1, y1) {
627
+ var gradient = painter.createLinearGradient(x0, y0, x1, y1);
628
+ return enhanceGradient(gradient);
629
+ };
630
+ var radialGradient = function (painter, cx, cy, r) {
631
+ var gradient = painter.createRadialGradient(cx, cy, 0, cx, cy, r);
632
+ return enhanceGradient(gradient);
633
+ };
634
+ var conicGradient = function (painter, cx, cy, startDeg, deg) {
635
+ var gradient = painter.createConicGradient(startDeg, cx, cy);
636
+ return enhanceGradient(gradient, deg ? function (stop) {
637
+ return deg / (Math.PI * 2) * stop;
638
+ } : void 0);
639
639
  };
640
640
 
641
- var Canvas$1 = (function (_super) {
642
- __extends(Canvas, _super);
643
- function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
644
- if (opts === void 0) { opts = {}; }
645
- if (scaleSize === void 0) { scaleSize = 1; }
646
- var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
647
- willReadFrequently: true,
648
- }) : undefined, true, scaleSize) || this;
649
- _this.name = "Canvas";
650
- _this.__regionList = {};
651
- _this.__regionAssemble = assemble(0, 255, 10, 3);
652
- _this.__scaleSize = scaleSize;
653
- _this.setRegion("");
654
- return _this;
655
- }
656
- Canvas.prototype.config = function (configs) {
657
- for (var key in configs) {
658
- this.useConfig(key, configs[key]);
659
- }
660
- return this;
661
- };
662
- Canvas.prototype.reset = function () {
663
- this.config(defaultFactory());
664
- return this;
665
- };
666
- Canvas.prototype.onlyRegion = function (flag) {
667
- this.__onlyRegion = flag;
668
- return this;
669
- };
670
- Canvas.prototype.onlyView = function (flag) {
671
- this.__onlyView = flag;
672
- return this;
673
- };
674
- Canvas.prototype.setRegion = function (regionName) {
675
- if (this.__region) {
676
- if (regionName) {
677
- if (this.__regionList[regionName] == void 0) {
678
- var tempColor = this.__regionAssemble();
679
- this.__regionList[regionName] =
680
- "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
681
- }
682
- this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
683
- this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
684
- }
685
- else {
686
- this.__region.useConfig("fillStyle", "#000000") &&
687
- this.__region.useConfig("strokeStyle", "#000000");
688
- }
689
- }
690
- return this;
691
- };
692
- Canvas.prototype.getRegion = function (x, y) {
693
- var _this = this;
694
- return new Promise(function (resolve) {
695
- var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
696
- data: [0, 0, 0, 0]
697
- };
698
- var currentRGBA = imgData.data;
699
- var doit = function () {
700
- if (_this.__region) {
701
- for (var key in _this.__regionList) {
702
- if ("rgb(" +
703
- currentRGBA[0] +
704
- "," +
705
- currentRGBA[1] +
706
- "," +
707
- currentRGBA[2] +
708
- ")" ==
709
- _this.__regionList[key]) {
710
- resolve(key);
711
- break;
712
- }
713
- }
714
- }
715
- resolve("");
716
- };
717
- if (currentRGBA) {
718
- doit();
719
- }
720
- else {
721
- imgData.then(function (data) {
722
- currentRGBA = data;
723
- doit();
724
- });
725
- }
726
- });
727
- };
728
- Canvas.prototype.textWidth = function (text) {
729
- this.painter.save();
730
- initText(this.painter, this.__specialConfig, 0, 0, 0);
731
- var width = this.painter.measureText(text + "").width;
732
- this.painter.restore();
733
- return width;
734
- };
735
- Canvas.prototype.getContext = function (isRegion) {
736
- if (isRegion === void 0) { isRegion = false; }
737
- return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
738
- };
739
- Canvas.prototype.getInfo = function () {
740
- return {
741
- width: this.painter.canvas.width / this.__scaleSize,
742
- height: this.painter.canvas.height / this.__scaleSize
743
- };
744
- };
745
- Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
746
- return linearGradient(this.painter, x0, y0, x1, y1);
747
- };
748
- Canvas.prototype.createRadialGradient = function (cx, cy, r) {
749
- return radialGradient(this.painter, cx, cy, r);
750
- };
751
- Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
752
- return conicGradient(this.painter, cx, cy, beginDeg, deg);
753
- };
754
- Canvas.prototype.getColor = function (x, y) {
755
- x *= this.__scaleSize;
756
- y *= this.__scaleSize;
757
- var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
758
- return ("rgba(" +
759
- currentRGBA[0] +
760
- "," +
761
- currentRGBA[1] +
762
- "," +
763
- currentRGBA[2] +
764
- "," +
765
- currentRGBA[3] +
766
- ")");
767
- };
768
- return Canvas;
641
+ var Canvas$1 = (function (_super) {
642
+ __extends(Canvas, _super);
643
+ function Canvas(ViewCanvas, RegionCanvas, opts, scaleSize) {
644
+ if (opts === void 0) { opts = {}; }
645
+ if (scaleSize === void 0) { scaleSize = 1; }
646
+ var _this = _super.call(this, ViewCanvas, opts, RegionCanvas ? new Painter(RegionCanvas, {
647
+ willReadFrequently: true,
648
+ }) : undefined, true, scaleSize) || this;
649
+ _this.name = "Canvas";
650
+ _this.__regionList = {};
651
+ _this.__regionAssemble = assemble(0, 255, 10, 3);
652
+ _this.__scaleSize = scaleSize;
653
+ _this.setRegion("");
654
+ return _this;
655
+ }
656
+ Canvas.prototype.config = function (configs) {
657
+ for (var key in configs) {
658
+ this.useConfig(key, configs[key]);
659
+ }
660
+ return this;
661
+ };
662
+ Canvas.prototype.reset = function () {
663
+ this.config(defaultFactory());
664
+ return this;
665
+ };
666
+ Canvas.prototype.onlyRegion = function (flag) {
667
+ this.__onlyRegion = flag;
668
+ return this;
669
+ };
670
+ Canvas.prototype.onlyView = function (flag) {
671
+ this.__onlyView = flag;
672
+ return this;
673
+ };
674
+ Canvas.prototype.setRegion = function (regionName) {
675
+ if (this.__region) {
676
+ if (regionName) {
677
+ if (this.__regionList[regionName] == void 0) {
678
+ var tempColor = this.__regionAssemble();
679
+ this.__regionList[regionName] =
680
+ "rgb(" + tempColor[0] + "," + tempColor[1] + "," + tempColor[2] + ")";
681
+ }
682
+ this.__region.useConfig("fillStyle", this.__regionList[regionName]) &&
683
+ this.__region.useConfig("strokeStyle", this.__regionList[regionName]);
684
+ }
685
+ else {
686
+ this.__region.useConfig("fillStyle", "#000000") &&
687
+ this.__region.useConfig("strokeStyle", "#000000");
688
+ }
689
+ }
690
+ return this;
691
+ };
692
+ Canvas.prototype.getRegion = function (x, y) {
693
+ var _this = this;
694
+ return new Promise(function (resolve) {
695
+ var imgData = _this.__region ? _this.__region.painter.getImageData(x - 0.5, y - 0.5, 1, 1) : {
696
+ data: [0, 0, 0, 0]
697
+ };
698
+ var currentRGBA = imgData.data;
699
+ var doit = function () {
700
+ if (_this.__region) {
701
+ for (var key in _this.__regionList) {
702
+ if ("rgb(" +
703
+ currentRGBA[0] +
704
+ "," +
705
+ currentRGBA[1] +
706
+ "," +
707
+ currentRGBA[2] +
708
+ ")" ==
709
+ _this.__regionList[key]) {
710
+ resolve(key);
711
+ break;
712
+ }
713
+ }
714
+ }
715
+ resolve("");
716
+ };
717
+ if (currentRGBA) {
718
+ doit();
719
+ }
720
+ else {
721
+ imgData.then(function (data) {
722
+ currentRGBA = data;
723
+ doit();
724
+ });
725
+ }
726
+ });
727
+ };
728
+ Canvas.prototype.textWidth = function (text) {
729
+ this.painter.save();
730
+ initText(this.painter, this.__specialConfig, 0, 0, 0);
731
+ var width = this.painter.measureText(text + "").width;
732
+ this.painter.restore();
733
+ return width;
734
+ };
735
+ Canvas.prototype.getContext = function (isRegion) {
736
+ if (isRegion === void 0) { isRegion = false; }
737
+ return isRegion ? (this.__region ? this.__region.painter : null) : this.painter;
738
+ };
739
+ Canvas.prototype.getInfo = function () {
740
+ return {
741
+ width: this.painter.canvas.width / this.__scaleSize,
742
+ height: this.painter.canvas.height / this.__scaleSize
743
+ };
744
+ };
745
+ Canvas.prototype.createLinearGradient = function (x0, y0, x1, y1) {
746
+ return linearGradient(this.painter, x0, y0, x1, y1);
747
+ };
748
+ Canvas.prototype.createRadialGradient = function (cx, cy, r) {
749
+ return radialGradient(this.painter, cx, cy, r);
750
+ };
751
+ Canvas.prototype.createConicGradient = function (cx, cy, beginDeg, deg) {
752
+ return conicGradient(this.painter, cx, cy, beginDeg, deg);
753
+ };
754
+ Canvas.prototype.getColor = function (x, y) {
755
+ x *= this.__scaleSize;
756
+ y *= this.__scaleSize;
757
+ var currentRGBA = this.painter.getImageData(x - 0.5, y - 0.5, 1, 1).data;
758
+ return ("rgba(" +
759
+ currentRGBA[0] +
760
+ "," +
761
+ currentRGBA[1] +
762
+ "," +
763
+ currentRGBA[2] +
764
+ "," +
765
+ currentRGBA[3] +
766
+ ")");
767
+ };
768
+ return Canvas;
769
769
  }(Painter));
770
770
 
771
- function initOption(setOption, defaultOption) {
772
- for (var key in setOption) {
773
- defaultOption[key] = setOption[key];
774
- }
775
- return defaultOption;
771
+ function initOption(setOption, defaultOption) {
772
+ for (var key in setOption) {
773
+ defaultOption[key] = setOption[key];
774
+ }
775
+ return defaultOption;
776
776
  }
777
777
 
778
- var Canvas = (function (_super) {
779
- __extends(Canvas, _super);
780
- function Canvas(el, option, width, height) {
781
- if (option === void 0) { option = {}; }
782
- if (width === void 0) { width = 0; }
783
- if (height === void 0) { height = 0; }
784
- var _this = this;
785
- if (!el) {
786
- throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
787
- }
788
- option = initOption(option, {
789
- region: true,
790
- willReadFrequently: false
791
- });
792
- width = width || el.clientWidth;
793
- height = height || el.clientHeight;
794
- var ViewCanvas, RegionCanvas = null;
795
- var _el = el;
796
- if (_el._vislite_canvas_) {
797
- ViewCanvas = _el._vislite_canvas_[0];
798
- RegionCanvas = _el._vislite_canvas_[1];
799
- }
800
- else {
801
- ViewCanvas = document.createElement('canvas');
802
- el.appendChild(ViewCanvas);
803
- if (option.region) {
804
- RegionCanvas = document.createElement('canvas');
805
- }
806
- _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
807
- el.setAttribute('vislite', 'Canvas');
808
- }
809
- var canvasArray = [RegionCanvas, ViewCanvas];
810
- for (var index = 0; index < canvasArray.length; index++) {
811
- var canvas = canvasArray[index];
812
- if (canvas) {
813
- canvas.style.width = width + "px";
814
- canvas.setAttribute('width', (index * width + width) + "");
815
- canvas.style.height = height + "px";
816
- canvas.setAttribute('height', (index * height + height) + "");
817
- }
818
- }
819
- _this = _super.call(this, ViewCanvas, RegionCanvas, {
820
- willReadFrequently: option.willReadFrequently,
821
- }, 2) || this;
822
- _this.__canvas = ViewCanvas;
823
- _this.__el = el;
824
- _this.painter.scale(2, 2);
825
- return _this;
826
- }
827
- Canvas.prototype.toDataURL = function () {
828
- var _this = this;
829
- return new Promise(function (resolve) {
830
- resolve(_this.__canvas.toDataURL());
831
- });
832
- };
833
- Canvas.prototype.bind = function (eventName, callback) {
834
- var _this = this;
835
- this.__el.addEventListener(eventName, function (event) {
836
- _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
837
- callback(regionName, event.offsetX, event.offsetY);
838
- });
839
- });
840
- return this;
841
- };
842
- return Canvas;
778
+ var Canvas = (function (_super) {
779
+ __extends(Canvas, _super);
780
+ function Canvas(el, option, width, height) {
781
+ if (option === void 0) { option = {}; }
782
+ if (width === void 0) { width = 0; }
783
+ if (height === void 0) { height = 0; }
784
+ var _this = this;
785
+ if (!el) {
786
+ throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");
787
+ }
788
+ option = initOption(option, {
789
+ scale: 2,
790
+ region: true,
791
+ willReadFrequently: false
792
+ });
793
+ width = width || el.clientWidth;
794
+ height = height || el.clientHeight;
795
+ var ViewCanvas, RegionCanvas = null;
796
+ var _el = el;
797
+ if (_el._vislite_canvas_) {
798
+ ViewCanvas = _el._vislite_canvas_[0];
799
+ RegionCanvas = _el._vislite_canvas_[1];
800
+ }
801
+ else {
802
+ ViewCanvas = document.createElement('canvas');
803
+ el.appendChild(ViewCanvas);
804
+ if (option.region) {
805
+ RegionCanvas = document.createElement('canvas');
806
+ }
807
+ _el._vislite_canvas_ = [ViewCanvas, RegionCanvas];
808
+ el.setAttribute('vislite', 'Canvas');
809
+ }
810
+ var canvasArray = [RegionCanvas, ViewCanvas];
811
+ for (var index = 0; index < canvasArray.length; index++) {
812
+ var canvas = canvasArray[index];
813
+ if (canvas) {
814
+ canvas.style.width = width + "px";
815
+ canvas.setAttribute('width', ((index === 1 ? option.scale : 1) * width) + "");
816
+ canvas.style.height = height + "px";
817
+ canvas.setAttribute('height', ((index === 1 ? option.scale : 1) * height) + "");
818
+ }
819
+ }
820
+ _this = _super.call(this, ViewCanvas, RegionCanvas, {
821
+ willReadFrequently: option.willReadFrequently,
822
+ }, option.scale) || this;
823
+ _this.__canvas = ViewCanvas;
824
+ _this.__el = el;
825
+ _this.painter.scale(option.scale, option.scale);
826
+ return _this;
827
+ }
828
+ Canvas.prototype.toDataURL = function () {
829
+ var _this = this;
830
+ return new Promise(function (resolve) {
831
+ resolve(_this.__canvas.toDataURL());
832
+ });
833
+ };
834
+ Canvas.prototype.bind = function (eventName, callback) {
835
+ var _this = this;
836
+ this.__el.addEventListener(eventName, function (event) {
837
+ _this.getRegion(event.offsetX, event.offsetY).then(function (regionName) {
838
+ callback(regionName, event.offsetX, event.offsetY);
839
+ });
840
+ });
841
+ return this;
842
+ };
843
+ return Canvas;
843
844
  }(Canvas$1));
844
845
 
845
846
  export { Canvas as default };