vislite 0.8.0 → 0.8.1-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 (79) hide show
  1. package/CHANGELOG +212 -209
  2. package/README.md +136 -144
  3. package/lib/Buffer/index.umd.js +36 -36
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +691 -691
  6. package/lib/Canvas/index.umd.min.js +2 -2
  7. package/lib/Cardinal/index.umd.js +91 -91
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +34 -34
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +286 -286
  12. package/lib/Geometry/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +36 -36
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +125 -125
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +20 -20
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +634 -634
  20. package/lib/OralCanvas/index.es.min.js +2 -2
  21. package/lib/OralWebGL/index.es.js +552 -552
  22. package/lib/OralWebGL/index.es.min.js +2 -2
  23. package/lib/SVG/index.umd.js +471 -471
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +61 -61
  26. package/lib/Shader/index.umd.min.js +2 -2
  27. package/lib/Texture/index.umd.js +54 -54
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +368 -368
  30. package/lib/TreeLayout/index.umd.min.js +2 -2
  31. package/lib/WebGL/index.umd.js +599 -599
  32. package/lib/WebGL/index.umd.min.js +2 -2
  33. package/lib/animation/index.umd.js +73 -73
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +40 -40
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +36 -36
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +63 -63
  40. package/lib/getWebGLContext/index.umd.min.js +2 -2
  41. package/lib/index.umd.js +2955 -2955
  42. package/lib/index.umd.min.js +2 -2
  43. package/lib/move/index.umd.js +8 -8
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +30 -30
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +8 -8
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +138 -138
  50. package/lib/ruler/index.umd.min.js +2 -2
  51. package/lib/scale/index.umd.js +7 -7
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +49 -49
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +120 -120
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/miniprogram/ui-canvas/drawImage.js +34 -0
  58. package/miniprogram/ui-canvas/index.js +10 -2
  59. package/package/getWebGLContext/index.ts +40 -40
  60. package/package.json +70 -70
  61. package/src/Canvas.ts +72 -72
  62. package/src/Geometry.ts +210 -210
  63. package/src/WebGL.ts +66 -66
  64. package/src/common/canvas/index.ts +183 -183
  65. package/src/common/canvas/painter.ts +446 -446
  66. package/src/common/geometry/prism-horizontal.ts +50 -50
  67. package/src/common/geometry/prism-vertical.ts +55 -55
  68. package/src/common/geometry/tool/circle.ts +17 -17
  69. package/src/common/geometry/tool/rotateLine.ts +48 -48
  70. package/src/common/geometry/tool/triangles.ts +23 -23
  71. package/src/common/webgl/getWebGLContext.ts +45 -45
  72. package/src/common/webgl/index.ts +227 -227
  73. package/types/Canvas.d.ts +318 -318
  74. package/types/Geometry.d.ts +132 -132
  75. package/types/WebGLOption.d.ts +14 -14
  76. package/types/getWebGLContext.d.ts +4 -4
  77. package/types/ui-canvas.d.ts +4 -4
  78. package/uni-app/drawImage.js +17 -17
  79. package/uni-app/ui-canvas.vue +290 -290
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.8.0
2
+ * VISLite JavaScript Library v0.8.1-alpha.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
6
6
  * Released under the MIT license
7
7
  * https://zxl20070701.github.io/notebook/home.html
8
8
  *
9
- * Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
9
+ * Publish Date: Tue Apr 02 2024 14:46:44 GMT+0800 (China Standard Time)
10
10
  */
11
11
  (function (global, factory) {
12
12
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -50,384 +50,384 @@
50
50
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
51
51
  };
52
52
 
53
- var toInnerTree = (function (initTree, config) {
54
- var tempTree = {};
55
- var temp = config.root(initTree);
56
- var id, rid;
57
- id = rid = config.id(temp);
58
- tempTree[id] = {
59
- "data": temp,
60
- "pid": null,
61
- "id": id,
62
- "isOpen": true,
63
- "show": true,
64
- "children": []
65
- };
66
- var num = 1;
67
- (function createTree(pdata, pid) {
68
- var children = config.children(pdata, initTree);
69
- num += children ? children.length : 0;
70
- for (var flag = 0; children && flag < children.length; flag++) {
71
- id = config.id(children[flag]);
72
- tempTree[pid].children.push(id);
73
- tempTree[id] = {
74
- "data": children[flag],
75
- "pid": pid,
76
- "id": id,
77
- "isOpen": true,
78
- "show": true,
79
- "children": []
80
- };
81
- createTree(children[flag], id);
82
- }
83
- })(temp, id);
84
- return {
85
- rid: rid,
86
- value: tempTree,
87
- num: num
88
- };
53
+ var toInnerTree = (function (initTree, config) {
54
+ var tempTree = {};
55
+ var temp = config.root(initTree);
56
+ var id, rid;
57
+ id = rid = config.id(temp);
58
+ tempTree[id] = {
59
+ "data": temp,
60
+ "pid": null,
61
+ "id": id,
62
+ "isOpen": true,
63
+ "show": true,
64
+ "children": []
65
+ };
66
+ var num = 1;
67
+ (function createTree(pdata, pid) {
68
+ var children = config.children(pdata, initTree);
69
+ num += children ? children.length : 0;
70
+ for (var flag = 0; children && flag < children.length; flag++) {
71
+ id = config.id(children[flag]);
72
+ tempTree[pid].children.push(id);
73
+ tempTree[id] = {
74
+ "data": children[flag],
75
+ "pid": pid,
76
+ "id": id,
77
+ "isOpen": true,
78
+ "show": true,
79
+ "children": []
80
+ };
81
+ createTree(children[flag], id);
82
+ }
83
+ })(temp, id);
84
+ return {
85
+ rid: rid,
86
+ value: tempTree,
87
+ num: num
88
+ };
89
89
  });
90
90
 
91
- function toPlainTree (initTree, config, noOpens) {
92
- var treeData = toInnerTree(initTree, config);
93
- var alltreedata = treeData.value;
94
- var rootid = treeData.rid;
95
- if (treeData.num == 1) {
96
- alltreedata[rootid].left = 0.5;
97
- alltreedata[rootid].top = 0.5;
98
- alltreedata[rootid].show = true;
99
- return {
100
- deep: 1,
101
- node: alltreedata,
102
- root: rootid,
103
- size: 1
104
- };
105
- }
106
- else {
107
- var beforeDis_1 = [];
108
- var size_1 = 0, maxDeep_1 = 0;
109
- if (noOpens[rootid]) {
110
- alltreedata[rootid].left = 0.5;
111
- alltreedata[rootid].top = 0.5;
112
- alltreedata[rootid].show = true;
113
- size_1 = 1;
114
- }
115
- else {
116
- (function positionCalc(pNode, deep) {
117
- if (deep > maxDeep_1)
118
- maxDeep_1 = deep;
119
- var flag = 0;
120
- if (!noOpens[pNode.id]) {
121
- for (flag = 0; flag < pNode.children.length; flag++)
122
- positionCalc(alltreedata[pNode.children[flag]], deep + 1);
123
- }
124
- alltreedata[pNode.id].left = deep + 0.5;
125
- if (flag == 0) {
126
- if (beforeDis_1[deep] == void 0)
127
- beforeDis_1[deep] = -0.5;
128
- if (beforeDis_1[deep - 1] == void 0)
129
- beforeDis_1[deep - 1] = -0.5;
130
- alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
131
- var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
132
- if (pTop - 1 < beforeDis_1[deep - 1])
133
- alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
134
- }
135
- else {
136
- alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
137
- }
138
- if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
139
- var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
140
- alltreedata[_pid].top += needUp_1;
141
- if (beforeDis_1[_deep] < alltreedata[_pid].top)
142
- beforeDis_1[_deep] = alltreedata[_pid].top;
143
- for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
144
- doUp(alltreedata[_pid].children[_flag], _deep + 1);
145
- }
146
- })(pNode.id, deep);
147
- }
148
- beforeDis_1[deep] = alltreedata[pNode.id].top;
149
- if (alltreedata[pNode.id].top + 0.5 > size_1)
150
- size_1 = alltreedata[pNode.id].top + 0.5;
151
- })(alltreedata[rootid], 0);
152
- }
153
- for (var key in noOpens) {
154
- if (noOpens[key]) {
155
- alltreedata[key].isOpen = false;
156
- (function updateHidden(pid, left, top) {
157
- for (var index = 0; index < alltreedata[pid].children.length; index++) {
158
- alltreedata[alltreedata[pid].children[index]].left = left;
159
- alltreedata[alltreedata[pid].children[index]].top = top;
160
- alltreedata[alltreedata[pid].children[index]].show = false;
161
- updateHidden(alltreedata[pid].children[index], left, top);
162
- }
163
- })(key, alltreedata[key].left, alltreedata[key].top);
164
- }
165
- }
166
- return {
167
- "node": alltreedata,
168
- "root": rootid,
169
- "size": size_1,
170
- "deep": maxDeep_1 + 1
171
- };
172
- }
91
+ function toPlainTree (initTree, config, noOpens) {
92
+ var treeData = toInnerTree(initTree, config);
93
+ var alltreedata = treeData.value;
94
+ var rootid = treeData.rid;
95
+ if (treeData.num == 1) {
96
+ alltreedata[rootid].left = 0.5;
97
+ alltreedata[rootid].top = 0.5;
98
+ alltreedata[rootid].show = true;
99
+ return {
100
+ deep: 1,
101
+ node: alltreedata,
102
+ root: rootid,
103
+ size: 1
104
+ };
105
+ }
106
+ else {
107
+ var beforeDis_1 = [];
108
+ var size_1 = 0, maxDeep_1 = 0;
109
+ if (noOpens[rootid]) {
110
+ alltreedata[rootid].left = 0.5;
111
+ alltreedata[rootid].top = 0.5;
112
+ alltreedata[rootid].show = true;
113
+ size_1 = 1;
114
+ }
115
+ else {
116
+ (function positionCalc(pNode, deep) {
117
+ if (deep > maxDeep_1)
118
+ maxDeep_1 = deep;
119
+ var flag = 0;
120
+ if (!noOpens[pNode.id]) {
121
+ for (flag = 0; flag < pNode.children.length; flag++)
122
+ positionCalc(alltreedata[pNode.children[flag]], deep + 1);
123
+ }
124
+ alltreedata[pNode.id].left = deep + 0.5;
125
+ if (flag == 0) {
126
+ if (beforeDis_1[deep] == void 0)
127
+ beforeDis_1[deep] = -0.5;
128
+ if (beforeDis_1[deep - 1] == void 0)
129
+ beforeDis_1[deep - 1] = -0.5;
130
+ alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
131
+ var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
132
+ if (pTop - 1 < beforeDis_1[deep - 1])
133
+ alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
134
+ }
135
+ else {
136
+ alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
137
+ }
138
+ if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
139
+ var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
140
+ alltreedata[_pid].top += needUp_1;
141
+ if (beforeDis_1[_deep] < alltreedata[_pid].top)
142
+ beforeDis_1[_deep] = alltreedata[_pid].top;
143
+ for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
144
+ doUp(alltreedata[_pid].children[_flag], _deep + 1);
145
+ }
146
+ })(pNode.id, deep);
147
+ }
148
+ beforeDis_1[deep] = alltreedata[pNode.id].top;
149
+ if (alltreedata[pNode.id].top + 0.5 > size_1)
150
+ size_1 = alltreedata[pNode.id].top + 0.5;
151
+ })(alltreedata[rootid], 0);
152
+ }
153
+ for (var key in noOpens) {
154
+ if (noOpens[key]) {
155
+ alltreedata[key].isOpen = false;
156
+ (function updateHidden(pid, left, top) {
157
+ for (var index = 0; index < alltreedata[pid].children.length; index++) {
158
+ alltreedata[alltreedata[pid].children[index]].left = left;
159
+ alltreedata[alltreedata[pid].children[index]].top = top;
160
+ alltreedata[alltreedata[pid].children[index]].show = false;
161
+ updateHidden(alltreedata[pid].children[index], left, top);
162
+ }
163
+ })(key, alltreedata[key].left, alltreedata[key].top);
164
+ }
165
+ }
166
+ return {
167
+ "node": alltreedata,
168
+ "root": rootid,
169
+ "size": size_1,
170
+ "deep": maxDeep_1 + 1
171
+ };
172
+ }
173
173
  }
174
174
 
175
- function mergeOption (option, defaultOption) {
176
- for (var key in option) {
177
- defaultOption[key] = option[key];
178
- }
179
- return defaultOption;
175
+ function mergeOption (option, defaultOption) {
176
+ for (var key in option) {
177
+ defaultOption[key] = option[key];
178
+ }
179
+ return defaultOption;
180
180
  }
181
181
 
182
- var Tree = (function () {
183
- function Tree(config) {
184
- if (config === void 0) { config = {}; }
185
- this.name = 'Tree';
186
- this.__config = mergeOption(config, {
187
- root: function (initTree) { return initTree; },
188
- children: function (parentTree) { return parentTree.children; },
189
- id: function (treedata) { return treedata.name; }
190
- });
191
- }
192
- Tree.prototype.use = function (initTree, noOpens) {
193
- if (noOpens === void 0) { noOpens = {}; }
194
- return toPlainTree(initTree, this.__config, noOpens);
195
- };
196
- return Tree;
182
+ var Tree = (function () {
183
+ function Tree(config) {
184
+ if (config === void 0) { config = {}; }
185
+ this.name = 'Tree';
186
+ this.__config = mergeOption(config, {
187
+ root: function (initTree) { return initTree; },
188
+ children: function (parentTree) { return parentTree.children; },
189
+ id: function (treedata) { return treedata.name; }
190
+ });
191
+ }
192
+ Tree.prototype.use = function (initTree, noOpens) {
193
+ if (noOpens === void 0) { noOpens = {}; }
194
+ return toPlainTree(initTree, this.__config, noOpens);
195
+ };
196
+ return Tree;
197
197
  }());
198
198
 
199
- var $timers = [];
200
- var $interval = 13;
201
- var $timerId;
202
- function animation (doback, duration, callback) {
203
- if (duration === void 0) { duration = 400; }
204
- if (callback === void 0) { callback = function () { }; }
205
- var clock = {
206
- "timer": function (tick, duration, callback) {
207
- if (!tick) {
208
- throw new Error('Tick is required!');
209
- }
210
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
211
- $timers.push({
212
- "id": id,
213
- "createTime": new Date(),
214
- "tick": tick,
215
- "duration": duration,
216
- "callback": callback
217
- });
218
- clock.start();
219
- return id;
220
- },
221
- "start": function () {
222
- if (!$timerId) {
223
- $timerId = setInterval(clock.tick, $interval);
224
- }
225
- },
226
- "tick": function () {
227
- var createTime, flag, tick, callback, timer, duration, passTime;
228
- var timers = $timers;
229
- $timers = [];
230
- $timers.length = 0;
231
- for (flag = 0; flag < timers.length; flag++) {
232
- timer = timers[flag];
233
- createTime = timer.createTime;
234
- tick = timer.tick;
235
- duration = timer.duration;
236
- callback = timer.callback;
237
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
238
- passTime = passTime > 1 ? 1 : passTime;
239
- tick(passTime);
240
- if (passTime < 1 && timer.id) {
241
- $timers.push(timer);
242
- }
243
- else {
244
- callback(passTime);
245
- }
246
- }
247
- if ($timers.length <= 0) {
248
- clock.stop();
249
- }
250
- },
251
- "stop": function () {
252
- if ($timerId) {
253
- clearInterval($timerId);
254
- $timerId = null;
255
- }
256
- }
257
- };
258
- var id = clock.timer(function (deep) {
259
- doback(deep);
260
- }, duration, callback);
261
- return function () {
262
- var i;
263
- for (i in $timers) {
264
- if ($timers[i].id == id) {
265
- $timers[i].id = void 0;
266
- return;
267
- }
268
- }
269
- };
199
+ var $timers = [];
200
+ var $interval = 13;
201
+ var $timerId;
202
+ function animation (doback, duration, callback) {
203
+ if (duration === void 0) { duration = 400; }
204
+ if (callback === void 0) { callback = function () { }; }
205
+ var clock = {
206
+ "timer": function (tick, duration, callback) {
207
+ if (!tick) {
208
+ throw new Error('Tick is required!');
209
+ }
210
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
211
+ $timers.push({
212
+ "id": id,
213
+ "createTime": new Date(),
214
+ "tick": tick,
215
+ "duration": duration,
216
+ "callback": callback
217
+ });
218
+ clock.start();
219
+ return id;
220
+ },
221
+ "start": function () {
222
+ if (!$timerId) {
223
+ $timerId = setInterval(clock.tick, $interval);
224
+ }
225
+ },
226
+ "tick": function () {
227
+ var createTime, flag, tick, callback, timer, duration, passTime;
228
+ var timers = $timers;
229
+ $timers = [];
230
+ $timers.length = 0;
231
+ for (flag = 0; flag < timers.length; flag++) {
232
+ timer = timers[flag];
233
+ createTime = timer.createTime;
234
+ tick = timer.tick;
235
+ duration = timer.duration;
236
+ callback = timer.callback;
237
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
238
+ passTime = passTime > 1 ? 1 : passTime;
239
+ tick(passTime);
240
+ if (passTime < 1 && timer.id) {
241
+ $timers.push(timer);
242
+ }
243
+ else {
244
+ callback(passTime);
245
+ }
246
+ }
247
+ if ($timers.length <= 0) {
248
+ clock.stop();
249
+ }
250
+ },
251
+ "stop": function () {
252
+ if ($timerId) {
253
+ clearInterval($timerId);
254
+ $timerId = null;
255
+ }
256
+ }
257
+ };
258
+ var id = clock.timer(function (deep) {
259
+ doback(deep);
260
+ }, duration, callback);
261
+ return function () {
262
+ var i;
263
+ for (i in $timers) {
264
+ if ($timers[i].id == id) {
265
+ $timers[i].id = void 0;
266
+ return;
267
+ }
268
+ }
269
+ };
270
270
  }
271
271
 
272
- function rotate (cx, cy, deg, x, y) {
273
- var cos = Math.cos(deg), sin = Math.sin(deg);
274
- return [
275
- (x - cx) * cos - (y - cy) * sin + cx,
276
- (x - cx) * sin + (y - cy) * cos + cy
277
- ];
272
+ function rotate (cx, cy, deg, x, y) {
273
+ var cos = Math.cos(deg), sin = Math.sin(deg);
274
+ return [
275
+ (x - cx) * cos - (y - cy) * sin + cx,
276
+ (x - cx) * sin + (y - cy) * cos + cy
277
+ ];
278
278
  }
279
279
 
280
- var TreeLayout = (function (_super) {
281
- __extends(TreeLayout, _super);
282
- function TreeLayout() {
283
- var _this = _super !== null && _super.apply(this, arguments) || this;
284
- _this.name = 'TreeLayout';
285
- _this.__option = {
286
- offsetX: 0,
287
- offsetY: 0,
288
- duration: 500,
289
- type: "plain",
290
- direction: "LR",
291
- x: 100,
292
- y: 100,
293
- width: 100,
294
- height: 100,
295
- radius: 100
296
- };
297
- _this.__noOpens = {};
298
- return _this;
299
- }
300
- TreeLayout.prototype.setOption = function (option) {
301
- mergeOption(option, this.__option);
302
- return this;
303
- };
304
- TreeLayout.prototype.use = function (initTree, noOpens) {
305
- if (noOpens === void 0) { noOpens = {}; }
306
- var tree = _super.prototype.use.call(this, initTree, noOpens);
307
- if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
308
- for (var key in tree.node) {
309
- if (!tree.node[key].show) {
310
- var deep = 0, pid = key;
311
- do {
312
- pid = tree.node[pid].pid;
313
- deep++;
314
- } while (!tree.node[pid].show);
315
- tree.node[key].left += this.__option.offsetX * deep;
316
- tree.node[key].top += this.__option.offsetY * deep;
317
- }
318
- }
319
- }
320
- if (this.__option.type == 'rect') {
321
- if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
322
- var perW = this.__option.height / tree.size;
323
- var perD = this.__option.width / (tree.deep - 1);
324
- var balanceW = this.__option.y - this.__option.height * 0.5;
325
- var flag = this.__option.direction == 'LR' ? 1 : -1;
326
- for (var key in tree.node) {
327
- if (tree.deep == 1) {
328
- tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
329
- tree.node[key].top = this.__option.y;
330
- }
331
- else {
332
- tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
333
- tree.node[key].top = tree.node[key].top * perW + balanceW;
334
- }
335
- }
336
- }
337
- else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
338
- var perW = this.__option.width / tree.size;
339
- var perD = this.__option.height / (tree.deep - 1);
340
- var balanceW = this.__option.x - this.__option.width * 0.5;
341
- var flag = this.__option.direction == 'TB' ? 1 : -1;
342
- for (var key in tree.node) {
343
- if (tree.deep == 1) {
344
- tree.node[key].left = this.__option.x;
345
- tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
346
- }
347
- else {
348
- var left = tree.node[key].left;
349
- tree.node[key].left = tree.node[key].top * perW + balanceW;
350
- tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
351
- }
352
- }
353
- }
354
- }
355
- else if (this.__option.type == 'circle') {
356
- var cx = this.__option.x, cy = this.__option.y;
357
- var deg = Math.PI * 2 / tree.size;
358
- var per = this.__option.radius / (tree.deep - 1);
359
- for (var key in tree.node) {
360
- if (tree.node[key].left == 0.5) {
361
- tree.node[key].left = cx;
362
- tree.node[key].top = cy;
363
- }
364
- else {
365
- var position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
366
- tree.node[key].left = position[0];
367
- tree.node[key].top = position[1];
368
- }
369
- }
370
- }
371
- return tree;
372
- };
373
- TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
374
- if (noOpens === void 0) { noOpens = {}; }
375
- this.__rback = renderBack;
376
- this.__oralTree = initTree;
377
- this.__noOpens = noOpens;
378
- this.__preTree = this.use(this.__oralTree, this.__noOpens);
379
- this.__rback(this.__preTree);
380
- return this;
381
- };
382
- TreeLayout.prototype.unbind = function () {
383
- this.__rback = function () { return null; };
384
- this.__oralTree = null;
385
- this.__preTree = null;
386
- this.__noOpens = {};
387
- return this;
388
- };
389
- TreeLayout.prototype.doUpdate = function () {
390
- var _this = this;
391
- var newTree = this.use(this.__oralTree, this.__noOpens);
392
- var cacheTree = JSON.parse(JSON.stringify(newTree));
393
- animation(function (deep) {
394
- if (_this.__preTree) {
395
- for (var key in cacheTree.node) {
396
- if (newTree.node[key].show || _this.__preTree.node[key].show) {
397
- cacheTree.node[key].show = true;
398
- cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
399
- cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
400
- }
401
- }
402
- }
403
- _this.__rback(cacheTree);
404
- }, this.__option.duration, function () {
405
- _this.__preTree = newTree;
406
- _this.__rback(_this.__preTree);
407
- });
408
- };
409
- TreeLayout.prototype.closeNode = function (id) {
410
- if (!this.__preTree)
411
- return this;
412
- this.__noOpens[id] = true;
413
- this.doUpdate();
414
- return this;
415
- };
416
- TreeLayout.prototype.openNode = function (id) {
417
- if (!this.__preTree)
418
- return this;
419
- this.__noOpens[id] = false;
420
- this.doUpdate();
421
- return this;
422
- };
423
- TreeLayout.prototype.toggleNode = function (id) {
424
- if (!this.__preTree)
425
- return this;
426
- this.__noOpens[id] = !this.__noOpens[id];
427
- this.doUpdate();
428
- return this;
429
- };
430
- return TreeLayout;
280
+ var TreeLayout = (function (_super) {
281
+ __extends(TreeLayout, _super);
282
+ function TreeLayout() {
283
+ var _this = _super !== null && _super.apply(this, arguments) || this;
284
+ _this.name = 'TreeLayout';
285
+ _this.__option = {
286
+ offsetX: 0,
287
+ offsetY: 0,
288
+ duration: 500,
289
+ type: "plain",
290
+ direction: "LR",
291
+ x: 100,
292
+ y: 100,
293
+ width: 100,
294
+ height: 100,
295
+ radius: 100
296
+ };
297
+ _this.__noOpens = {};
298
+ return _this;
299
+ }
300
+ TreeLayout.prototype.setOption = function (option) {
301
+ mergeOption(option, this.__option);
302
+ return this;
303
+ };
304
+ TreeLayout.prototype.use = function (initTree, noOpens) {
305
+ if (noOpens === void 0) { noOpens = {}; }
306
+ var tree = _super.prototype.use.call(this, initTree, noOpens);
307
+ if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
308
+ for (var key in tree.node) {
309
+ if (!tree.node[key].show) {
310
+ var deep = 0, pid = key;
311
+ do {
312
+ pid = tree.node[pid].pid;
313
+ deep++;
314
+ } while (!tree.node[pid].show);
315
+ tree.node[key].left += this.__option.offsetX * deep;
316
+ tree.node[key].top += this.__option.offsetY * deep;
317
+ }
318
+ }
319
+ }
320
+ if (this.__option.type == 'rect') {
321
+ if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
322
+ var perW = this.__option.height / tree.size;
323
+ var perD = this.__option.width / (tree.deep - 1);
324
+ var balanceW = this.__option.y - this.__option.height * 0.5;
325
+ var flag = this.__option.direction == 'LR' ? 1 : -1;
326
+ for (var key in tree.node) {
327
+ if (tree.deep == 1) {
328
+ tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
329
+ tree.node[key].top = this.__option.y;
330
+ }
331
+ else {
332
+ tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
333
+ tree.node[key].top = tree.node[key].top * perW + balanceW;
334
+ }
335
+ }
336
+ }
337
+ else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
338
+ var perW = this.__option.width / tree.size;
339
+ var perD = this.__option.height / (tree.deep - 1);
340
+ var balanceW = this.__option.x - this.__option.width * 0.5;
341
+ var flag = this.__option.direction == 'TB' ? 1 : -1;
342
+ for (var key in tree.node) {
343
+ if (tree.deep == 1) {
344
+ tree.node[key].left = this.__option.x;
345
+ tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
346
+ }
347
+ else {
348
+ var left = tree.node[key].left;
349
+ tree.node[key].left = tree.node[key].top * perW + balanceW;
350
+ tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
351
+ }
352
+ }
353
+ }
354
+ }
355
+ else if (this.__option.type == 'circle') {
356
+ var cx = this.__option.x, cy = this.__option.y;
357
+ var deg = Math.PI * 2 / tree.size;
358
+ var per = this.__option.radius / (tree.deep - 1);
359
+ for (var key in tree.node) {
360
+ if (tree.node[key].left == 0.5) {
361
+ tree.node[key].left = cx;
362
+ tree.node[key].top = cy;
363
+ }
364
+ else {
365
+ var position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
366
+ tree.node[key].left = position[0];
367
+ tree.node[key].top = position[1];
368
+ }
369
+ }
370
+ }
371
+ return tree;
372
+ };
373
+ TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
374
+ if (noOpens === void 0) { noOpens = {}; }
375
+ this.__rback = renderBack;
376
+ this.__oralTree = initTree;
377
+ this.__noOpens = noOpens;
378
+ this.__preTree = this.use(this.__oralTree, this.__noOpens);
379
+ this.__rback(this.__preTree);
380
+ return this;
381
+ };
382
+ TreeLayout.prototype.unbind = function () {
383
+ this.__rback = function () { return null; };
384
+ this.__oralTree = null;
385
+ this.__preTree = null;
386
+ this.__noOpens = {};
387
+ return this;
388
+ };
389
+ TreeLayout.prototype.doUpdate = function () {
390
+ var _this = this;
391
+ var newTree = this.use(this.__oralTree, this.__noOpens);
392
+ var cacheTree = JSON.parse(JSON.stringify(newTree));
393
+ animation(function (deep) {
394
+ if (_this.__preTree) {
395
+ for (var key in cacheTree.node) {
396
+ if (newTree.node[key].show || _this.__preTree.node[key].show) {
397
+ cacheTree.node[key].show = true;
398
+ cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
399
+ cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
400
+ }
401
+ }
402
+ }
403
+ _this.__rback(cacheTree);
404
+ }, this.__option.duration, function () {
405
+ _this.__preTree = newTree;
406
+ _this.__rback(_this.__preTree);
407
+ });
408
+ };
409
+ TreeLayout.prototype.closeNode = function (id) {
410
+ if (!this.__preTree)
411
+ return this;
412
+ this.__noOpens[id] = true;
413
+ this.doUpdate();
414
+ return this;
415
+ };
416
+ TreeLayout.prototype.openNode = function (id) {
417
+ if (!this.__preTree)
418
+ return this;
419
+ this.__noOpens[id] = false;
420
+ this.doUpdate();
421
+ return this;
422
+ };
423
+ TreeLayout.prototype.toggleNode = function (id) {
424
+ if (!this.__preTree)
425
+ return this;
426
+ this.__noOpens[id] = !this.__noOpens[id];
427
+ this.doUpdate();
428
+ return this;
429
+ };
430
+ return TreeLayout;
431
431
  }(Tree));
432
432
 
433
433
  return TreeLayout;