vislite 1.4.0-alpha.0 → 1.4.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 (83) hide show
  1. package/CHANGELOG +307 -307
  2. package/lib/BarLayout/index.es.js +437 -437
  3. package/lib/BarLayout/index.es.min.js +2 -2
  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 +774 -774
  7. package/lib/Canvas/index.es.min.js +1 -1
  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 +213 -213
  21. package/lib/PieLayout/index.es.min.js +2 -2
  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 +397 -397
  31. package/lib/TreeLayout/index.es.min.js +2 -2
  32. package/lib/animation/index.es.js +110 -106
  33. package/lib/animation/index.es.min.js +3 -3
  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 +2795 -2791
  41. package/lib/index.umd.min.js +5 -5
  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 +51 -51
  55. package/lib/throttle/index.es.min.js +2 -2
  56. package/package/BarLayout/index.ts +2 -2
  57. package/package/PieLayout/index.ts +2 -2
  58. package/package/animation/index.ts +6 -3
  59. package/package/index.ts +84 -84
  60. package/package/throttle/index.ts +2 -2
  61. package/package.json +75 -75
  62. package/src/SVG.ts +55 -55
  63. package/src/common/canvas/gradient.ts +31 -31
  64. package/src/common/svg/default.ts +29 -29
  65. package/src/common/svg/gradient.ts +53 -53
  66. package/src/common/svg/index.ts +332 -332
  67. package/src/common/tree/toPlainTree.ts +135 -135
  68. package/src/common/webgl/texture.ts +98 -98
  69. package/src/layout/BarLayout.ts +248 -248
  70. package/src/layout/PieLayout.ts +141 -141
  71. package/src/layout/TreeLayout.ts +197 -197
  72. package/types/Bar.d.ts +91 -91
  73. package/types/BarConfig.d.ts +4 -4
  74. package/types/BarLayout.d.ts +48 -48
  75. package/types/BarOption.d.ts +31 -31
  76. package/types/Pie.d.ts +73 -73
  77. package/types/PieConfig.d.ts +26 -26
  78. package/types/PieLayout.d.ts +40 -40
  79. package/types/PieOption.d.ts +21 -21
  80. package/types/SVG.d.ts +247 -247
  81. package/types/animation.d.ts +11 -5
  82. package/types/index.d.ts +195 -195
  83. package/types/throttle.d.ts +5 -5
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * TreeLayout of VISLite JavaScript Library v1.4.0-alpha.0
2
+ * TreeLayout of VISLite JavaScript Library v1.4.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  /******************************************************************************
@@ -38,426 +38,426 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
38
38
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
39
39
  };
40
40
 
41
- var toInnerTree = (function (initTree, config) {
42
- var tempTree = {};
43
- var temp = config.root(initTree);
44
- var id, rid;
45
- id = rid = config.id(temp);
46
- tempTree[id] = {
47
- "data": temp,
48
- "pid": null,
49
- "id": id,
50
- "isOpen": true,
51
- "show": true,
52
- "deg": 0,
53
- "children": []
54
- };
55
- var num = 1;
56
- (function createTree(pdata, pid) {
57
- var children = config.children(pdata, initTree);
58
- num += children ? children.length : 0;
59
- for (var flag = 0; children && flag < children.length; flag++) {
60
- id = config.id(children[flag]);
61
- tempTree[pid].children.push(id);
62
- tempTree[id] = {
63
- "data": children[flag],
64
- "pid": pid,
65
- "id": id,
66
- "isOpen": true,
67
- "show": true,
68
- "deg": 0,
69
- "children": []
70
- };
71
- createTree(children[flag], id);
72
- }
73
- })(temp, id);
74
- return {
75
- rid: rid,
76
- value: tempTree,
77
- num: num
78
- };
41
+ var toInnerTree = (function (initTree, config) {
42
+ var tempTree = {};
43
+ var temp = config.root(initTree);
44
+ var id, rid;
45
+ id = rid = config.id(temp);
46
+ tempTree[id] = {
47
+ "data": temp,
48
+ "pid": null,
49
+ "id": id,
50
+ "isOpen": true,
51
+ "show": true,
52
+ "deg": 0,
53
+ "children": []
54
+ };
55
+ var num = 1;
56
+ (function createTree(pdata, pid) {
57
+ var children = config.children(pdata, initTree);
58
+ num += children ? children.length : 0;
59
+ for (var flag = 0; children && flag < children.length; flag++) {
60
+ id = config.id(children[flag]);
61
+ tempTree[pid].children.push(id);
62
+ tempTree[id] = {
63
+ "data": children[flag],
64
+ "pid": pid,
65
+ "id": id,
66
+ "isOpen": true,
67
+ "show": true,
68
+ "deg": 0,
69
+ "children": []
70
+ };
71
+ createTree(children[flag], id);
72
+ }
73
+ })(temp, id);
74
+ return {
75
+ rid: rid,
76
+ value: tempTree,
77
+ num: num
78
+ };
79
79
  });
80
80
 
81
- function toPlainTree (initTree, config, noOpens) {
82
- var treeData = toInnerTree(initTree, config);
83
- var alltreedata = treeData.value;
84
- var rootid = treeData.rid;
85
- if (treeData.num == 1) {
86
- alltreedata[rootid].left = 0.5;
87
- alltreedata[rootid].top = 0.5;
88
- alltreedata[rootid].show = true;
89
- return {
90
- deep: 1,
91
- node: alltreedata,
92
- root: rootid,
93
- size: 1
94
- };
95
- }
96
- else {
97
- var beforeDis_1 = [];
98
- var size_1 = 0, maxDeep_1 = 0;
99
- if (noOpens[rootid]) {
100
- alltreedata[rootid].left = 0.5;
101
- alltreedata[rootid].top = 0.5;
102
- alltreedata[rootid].show = true;
103
- size_1 = 1;
104
- }
105
- else {
106
- (function positionCalc(pNode, deep) {
107
- if (deep > maxDeep_1)
108
- maxDeep_1 = deep;
109
- var flag = 0;
110
- if (!noOpens[pNode.id]) {
111
- for (flag = 0; flag < pNode.children.length; flag++)
112
- positionCalc(alltreedata[pNode.children[flag]], deep + 1);
113
- }
114
- alltreedata[pNode.id].left = deep + 0.5;
115
- if (flag == 0) {
116
- if (beforeDis_1[deep] == void 0)
117
- beforeDis_1[deep] = -0.5;
118
- if (beforeDis_1[deep - 1] == void 0)
119
- beforeDis_1[deep - 1] = -0.5;
120
- alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
121
- var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
122
- if (pTop - 1 < beforeDis_1[deep - 1])
123
- alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
124
- }
125
- else {
126
- alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
127
- }
128
- if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
129
- var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
130
- alltreedata[_pid].top += needUp_1;
131
- if (beforeDis_1[_deep] < alltreedata[_pid].top)
132
- beforeDis_1[_deep] = alltreedata[_pid].top;
133
- for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
134
- doUp(alltreedata[_pid].children[_flag], _deep + 1);
135
- }
136
- })(pNode.id, deep);
137
- }
138
- beforeDis_1[deep] = alltreedata[pNode.id].top;
139
- if (alltreedata[pNode.id].top + 0.5 > size_1)
140
- size_1 = alltreedata[pNode.id].top + 0.5;
141
- })(alltreedata[rootid], 0);
142
- }
143
- for (var key in noOpens) {
144
- if (noOpens[key]) {
145
- alltreedata[key].isOpen = false;
146
- (function updateHidden(pid, left, top) {
147
- for (var index = 0; index < alltreedata[pid].children.length; index++) {
148
- alltreedata[alltreedata[pid].children[index]].left = left;
149
- alltreedata[alltreedata[pid].children[index]].top = top;
150
- alltreedata[alltreedata[pid].children[index]].show = false;
151
- updateHidden(alltreedata[pid].children[index], left, top);
152
- }
153
- })(key, alltreedata[key].left, alltreedata[key].top);
154
- }
155
- }
156
- return {
157
- "node": alltreedata,
158
- "root": rootid,
159
- "size": size_1,
160
- "deep": maxDeep_1 + 1
161
- };
162
- }
81
+ function toPlainTree (initTree, config, noOpens) {
82
+ var treeData = toInnerTree(initTree, config);
83
+ var alltreedata = treeData.value;
84
+ var rootid = treeData.rid;
85
+ if (treeData.num == 1) {
86
+ alltreedata[rootid].left = 0.5;
87
+ alltreedata[rootid].top = 0.5;
88
+ alltreedata[rootid].show = true;
89
+ return {
90
+ deep: 1,
91
+ node: alltreedata,
92
+ root: rootid,
93
+ size: 1
94
+ };
95
+ }
96
+ else {
97
+ var beforeDis_1 = [];
98
+ var size_1 = 0, maxDeep_1 = 0;
99
+ if (noOpens[rootid]) {
100
+ alltreedata[rootid].left = 0.5;
101
+ alltreedata[rootid].top = 0.5;
102
+ alltreedata[rootid].show = true;
103
+ size_1 = 1;
104
+ }
105
+ else {
106
+ (function positionCalc(pNode, deep) {
107
+ if (deep > maxDeep_1)
108
+ maxDeep_1 = deep;
109
+ var flag = 0;
110
+ if (!noOpens[pNode.id]) {
111
+ for (flag = 0; flag < pNode.children.length; flag++)
112
+ positionCalc(alltreedata[pNode.children[flag]], deep + 1);
113
+ }
114
+ alltreedata[pNode.id].left = deep + 0.5;
115
+ if (flag == 0) {
116
+ if (beforeDis_1[deep] == void 0)
117
+ beforeDis_1[deep] = -0.5;
118
+ if (beforeDis_1[deep - 1] == void 0)
119
+ beforeDis_1[deep - 1] = -0.5;
120
+ alltreedata[pNode.id].top = beforeDis_1[deep] + 1;
121
+ var pTop = beforeDis_1[deep] + 1 + (alltreedata[pNode.pid].children.length - 1) * 0.5;
122
+ if (pTop - 1 < beforeDis_1[deep - 1])
123
+ alltreedata[pNode.id].top = beforeDis_1[deep - 1] + 1 - (alltreedata[pNode.pid].children.length - 1) * 0.5;
124
+ }
125
+ else {
126
+ alltreedata[pNode.id].top = (alltreedata[pNode.children[0]].top + alltreedata[pNode.children[flag - 1]].top) * 0.5;
127
+ }
128
+ if (alltreedata[pNode.id].top <= beforeDis_1[deep]) {
129
+ var needUp_1 = beforeDis_1[deep] + 1 - alltreedata[pNode.id].top(function doUp(_pid, _deep) {
130
+ alltreedata[_pid].top += needUp_1;
131
+ if (beforeDis_1[_deep] < alltreedata[_pid].top)
132
+ beforeDis_1[_deep] = alltreedata[_pid].top;
133
+ for (var _flag = 0; _flag < alltreedata[_pid].children.length; _flag++) {
134
+ doUp(alltreedata[_pid].children[_flag], _deep + 1);
135
+ }
136
+ })(pNode.id, deep);
137
+ }
138
+ beforeDis_1[deep] = alltreedata[pNode.id].top;
139
+ if (alltreedata[pNode.id].top + 0.5 > size_1)
140
+ size_1 = alltreedata[pNode.id].top + 0.5;
141
+ })(alltreedata[rootid], 0);
142
+ }
143
+ for (var key in noOpens) {
144
+ if (noOpens[key]) {
145
+ alltreedata[key].isOpen = false;
146
+ (function updateHidden(pid, left, top) {
147
+ for (var index = 0; index < alltreedata[pid].children.length; index++) {
148
+ alltreedata[alltreedata[pid].children[index]].left = left;
149
+ alltreedata[alltreedata[pid].children[index]].top = top;
150
+ alltreedata[alltreedata[pid].children[index]].show = false;
151
+ updateHidden(alltreedata[pid].children[index], left, top);
152
+ }
153
+ })(key, alltreedata[key].left, alltreedata[key].top);
154
+ }
155
+ }
156
+ return {
157
+ "node": alltreedata,
158
+ "root": rootid,
159
+ "size": size_1,
160
+ "deep": maxDeep_1 + 1
161
+ };
162
+ }
163
163
  }
164
164
 
165
- function initOption(setOption, defaultOption) {
166
- for (var key in setOption) {
167
- defaultOption[key] = setOption[key];
168
- }
169
- return defaultOption;
165
+ function initOption(setOption, defaultOption) {
166
+ for (var key in setOption) {
167
+ defaultOption[key] = setOption[key];
168
+ }
169
+ return defaultOption;
170
170
  }
171
171
 
172
- var Tree = (function () {
173
- function Tree(config) {
174
- if (config === void 0) { config = {}; }
175
- this.name = 'Tree';
176
- this.__config = initOption(config, {
177
- root: function (initTree) { return initTree; },
178
- children: function (parentTree) { return parentTree.children; },
179
- id: function (treedata) { return treedata.name; }
180
- });
181
- }
182
- Tree.prototype.use = function (initTree, noOpens) {
183
- if (noOpens === void 0) { noOpens = {}; }
184
- return toPlainTree(initTree, this.__config, noOpens);
185
- };
186
- return Tree;
172
+ var Tree = (function () {
173
+ function Tree(config) {
174
+ if (config === void 0) { config = {}; }
175
+ this.name = 'Tree';
176
+ this.__config = initOption(config, {
177
+ root: function (initTree) { return initTree; },
178
+ children: function (parentTree) { return parentTree.children; },
179
+ id: function (treedata) { return treedata.name; }
180
+ });
181
+ }
182
+ Tree.prototype.use = function (initTree, noOpens) {
183
+ if (noOpens === void 0) { noOpens = {}; }
184
+ return toPlainTree(initTree, this.__config, noOpens);
185
+ };
186
+ return Tree;
187
187
  }());
188
188
 
189
189
  /*!
190
- * animation of OIPage v1.2.0
190
+ * animation of OIPage v1.3.0
191
191
  * git+https://github.com/oi-contrib/OIPage.git
192
192
  */
193
193
 
194
- //当前正在运动的动画的tick函数堆栈
195
- var $timers = [];
196
- //唯一定时器的定时间隔
197
- var $interval = 13;
198
- //定时器ID
199
- var $timerId;
200
-
201
- /**
202
- * 动画轮播
203
- * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
204
- * @param {number} duration 动画时长,可选
205
- * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
206
- *
207
- * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
208
- */
209
- function animation(doback, duration, callback) {
210
- if (arguments.length < 2) duration = 400;
211
- if (arguments.length < 3) callback = function () { };
212
-
213
- var clock = {
214
- //把tick函数推入堆栈
215
- "timer": function (tick, duration, callback) {
216
- if (!tick) {
217
- throw new Error('Tick is required!');
218
- }
219
- var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
220
- $timers.push({
221
- "id": id,
222
- "createTime": new Date(),
223
- "tick": tick,
224
- "duration": duration,
225
- "callback": callback
226
- });
227
- clock.start();
228
- return id;
229
- },
230
-
231
- //开启唯一的定时器timerId
232
- "start": function () {
233
- if (!$timerId) {
234
- $timerId = setInterval(clock.tick, $interval);
235
- }
236
- },
237
-
238
- //被定时器调用,遍历timers堆栈
239
- "tick": function () {
240
- var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
241
-
242
- $timers = [];
243
- $timers.length = 0;
244
-
245
- for (flag = 0; flag < timers.length; flag++) {
246
- //初始化数据
247
- timer = timers[flag];
248
- createTime = timer.createTime;
249
- tick = timer.tick;
250
- duration = timer.duration;
251
- callback = timer.callback;
252
-
253
- //执行
254
- passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
255
- passTime = passTime > 1 ? 1 : passTime;
256
- tick(passTime);
257
- if (passTime < 1 && timer.id) {
258
- //动画没有结束再添加
259
- $timers.push(timer);
260
- } else {
261
- callback(passTime);
262
- }
263
- }
264
- if ($timers.length <= 0) {
265
- clock.stop();
266
- }
267
- },
268
-
269
- //停止定时器,重置timerId=null
270
- "stop": function () {
271
- if ($timerId) {
272
- clearInterval($timerId);
273
- $timerId = null;
274
- }
275
- }
276
- };
277
-
278
- var id = clock.timer(function (deep) {
279
- //其中deep为0-1,表示改变的程度
280
- doback(deep);
281
- }, duration, callback);
282
-
283
- return {
284
- // 一个函数
285
- // 用于在动画结束前结束动画
286
- stop: function () {
287
- var i;
288
- for (i in $timers) {
289
- if ($timers[i].id == id) {
290
- $timers[i].id = void 0;
291
- return;
292
- }
293
- }
294
- }
295
- };
296
-
297
- }
194
+ //当前正在运动的动画的tick函数堆栈
195
+ var $timers = [];
196
+ //唯一定时器的定时间隔
197
+ var $interval = 13;
198
+ //定时器ID
199
+ var $timerId;
298
200
 
299
- function rotate (cx, cy, deg, x, y) {
300
- var cos = Math.cos(deg), sin = Math.sin(deg);
301
- return [
302
- (x - cx) * cos - (y - cy) * sin + cx,
303
- (x - cx) * sin + (y - cy) * cos + cy
304
- ];
305
- }
201
+ /**
202
+ * 动画轮播
203
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
204
+ * @param {number} duration 动画时长,可选
205
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
206
+ *
207
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
208
+ */
209
+ function animation(doback, duration, callback) {
210
+ if (arguments.length < 2) duration = 400;
211
+ if (arguments.length < 3) callback = function () { };
306
212
 
307
- var TreeLayout = (function (_super) {
308
- __extends(TreeLayout, _super);
309
- function TreeLayout() {
310
- var _this = _super !== null && _super.apply(this, arguments) || this;
311
- _this.name = 'TreeLayout';
312
- _this.__option = {
313
- offsetX: 0,
314
- offsetY: 0,
315
- duration: 500,
316
- type: "plain",
317
- direction: "LR",
318
- x: 100,
319
- y: 100,
320
- width: 100,
321
- height: 100,
322
- radius: 100
323
- };
324
- _this.__noOpens = {};
325
- return _this;
326
- }
327
- TreeLayout.prototype.setOption = function (option) {
328
- initOption(option, this.__option);
329
- return this;
330
- };
331
- TreeLayout.prototype.use = function (initTree, noOpens) {
332
- if (noOpens === void 0) { noOpens = {}; }
333
- var tree = _super.prototype.use.call(this, initTree, noOpens);
334
- if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
335
- for (var key in tree.node) {
336
- if (!tree.node[key].show) {
337
- var deep = 0, pid = key;
338
- do {
339
- pid = tree.node[pid].pid;
340
- deep++;
341
- } while (!tree.node[pid].show);
342
- tree.node[key].left += this.__option.offsetX * deep;
343
- tree.node[key].top += this.__option.offsetY * deep;
344
- }
213
+ var clock = {
214
+ //把tick函数推入堆栈
215
+ "timer": function (tick, duration, callback) {
216
+ if (!tick) {
217
+ throw new Error('Tick is required!');
345
218
  }
346
- }
347
- if (this.__option.type == 'rect') {
348
- if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
349
- var perW = this.__option.height / tree.size;
350
- var perD = this.__option.width / (tree.deep - 1);
351
- var balanceW = this.__option.y - this.__option.height * 0.5;
352
- var flag = this.__option.direction == 'LR' ? 1 : -1;
353
- for (var key in tree.node) {
354
- if (tree.deep == 1) {
355
- tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
356
- tree.node[key].top = this.__option.y;
357
- }
358
- else {
359
- tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
360
- tree.node[key].top = tree.node[key].top * perW + balanceW;
361
- }
362
- }
219
+ var id = new Date().valueOf() + "_" + (Math.random() * 1000).toFixed(0);
220
+ $timers.push({
221
+ "id": id,
222
+ "createTime": new Date(),
223
+ "tick": tick,
224
+ "duration": duration,
225
+ "callback": callback
226
+ });
227
+ clock.start();
228
+ return id;
229
+ },
230
+
231
+ //开启唯一的定时器timerId
232
+ "start": function () {
233
+ if (!$timerId) {
234
+ $timerId = setInterval(clock.tick, $interval);
363
235
  }
364
- else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
365
- var perW = this.__option.width / tree.size;
366
- var perD = this.__option.height / (tree.deep - 1);
367
- var balanceW = this.__option.x - this.__option.width * 0.5;
368
- var flag = this.__option.direction == 'TB' ? 1 : -1;
369
- for (var key in tree.node) {
370
- tree.node[key].deg = this.__option.direction == 'TB' ? Math.PI * 0.5 : Math.PI * -0.5;
371
- if (tree.deep == 1) {
372
- tree.node[key].left = this.__option.x;
373
- tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
374
- }
375
- else {
376
- var left = tree.node[key].left;
377
- tree.node[key].left = tree.node[key].top * perW + balanceW;
378
- tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
379
- }
236
+ },
237
+
238
+ //被定时器调用,遍历timers堆栈
239
+ "tick": function () {
240
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
241
+
242
+ $timers = [];
243
+ $timers.length = 0;
244
+
245
+ for (flag = 0; flag < timers.length; flag++) {
246
+ //初始化数据
247
+ timer = timers[flag];
248
+ createTime = timer.createTime;
249
+ tick = timer.tick;
250
+ duration = timer.duration;
251
+ callback = timer.callback;
252
+
253
+ //执行
254
+ passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
255
+ passTime = passTime > 1 ? 1 : passTime;
256
+ tick(passTime);
257
+ if (passTime < 1 && timer.id) {
258
+ //动画没有结束再添加
259
+ $timers.push(timer);
260
+ } else {
261
+ callback(passTime);
380
262
  }
381
263
  }
382
- }
383
- else if (this.__option.type == 'circle') {
384
- var cx = this.__option.x, cy = this.__option.y;
385
- var deg = Math.PI * 2 / tree.size;
386
- var per = this.__option.radius / (tree.deep - 1);
387
- for (var key in tree.node) {
388
- if (tree.node[key].left == 0.5) {
389
- tree.node[key].left = cx;
390
- tree.node[key].top = cy;
391
- }
392
- else {
393
- var position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
394
- tree.node[key].deg = deg * tree.node[key].top;
395
- tree.node[key].left = position[0];
396
- tree.node[key].top = position[1];
397
- }
264
+ if ($timers.length <= 0) {
265
+ clock.stop();
266
+ }
267
+ },
268
+
269
+ //停止定时器,重置timerId=null
270
+ "stop": function () {
271
+ if ($timerId) {
272
+ clearInterval($timerId);
273
+ $timerId = null;
398
274
  }
399
275
  }
400
- return tree;
401
- };
402
- TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
403
- if (noOpens === void 0) { noOpens = {}; }
404
- this.__rback = renderBack;
405
- this.__oralTree = initTree;
406
- this.__noOpens = noOpens;
407
- this.__preTree = this.use(this.__oralTree, this.__noOpens);
408
- this.__rback(this.__preTree);
409
- return this;
410
276
  };
411
- TreeLayout.prototype.unbind = function () {
412
- this.__rback = function () { return null; };
413
- this.__oralTree = null;
414
- this.__preTree = null;
415
- this.__noOpens = {};
416
- return this;
417
- };
418
- TreeLayout.prototype.doUpdate = function () {
419
- var _this = this;
420
- var newTree = this.use(this.__oralTree, this.__noOpens);
421
- var cacheTree = JSON.parse(JSON.stringify(newTree));
422
- animation(function (deep) {
423
- if (_this.__preTree) {
424
- for (var key in cacheTree.node) {
425
- if (newTree.node[key].show || _this.__preTree.node[key].show) {
426
- cacheTree.node[key].show = true;
427
- cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
428
- cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
429
- }
277
+
278
+ var id = clock.timer(function (deep) {
279
+ //其中deep为0-1,表示改变的程度
280
+ doback(deep);
281
+ }, duration, callback);
282
+
283
+ return {
284
+ // 一个函数
285
+ // 用于在动画结束前结束动画
286
+ stop: function () {
287
+ var i;
288
+ for (i in $timers) {
289
+ if ($timers[i].id == id) {
290
+ $timers[i].id = void 0;
291
+ return;
430
292
  }
431
293
  }
432
- _this.__rback(cacheTree);
433
- }, this.__option.duration, function () {
434
- _this.__preTree = newTree;
435
- _this.__rback(_this.__preTree);
436
- });
437
- return this;
438
- };
439
- TreeLayout.prototype.closeNode = function (id) {
440
- if (!this.__preTree)
441
- return this;
442
- this.__noOpens[id] = true;
443
- this.doUpdate();
444
- return this;
445
- };
446
- TreeLayout.prototype.openNode = function (id) {
447
- if (!this.__preTree)
448
- return this;
449
- this.__noOpens[id] = false;
450
- this.doUpdate();
451
- return this;
452
- };
453
- TreeLayout.prototype.toggleNode = function (id) {
454
- if (!this.__preTree)
455
- return this;
456
- this.__noOpens[id] = !this.__noOpens[id];
457
- this.doUpdate();
458
- return this;
294
+ }
459
295
  };
460
- return TreeLayout;
296
+
297
+ }
298
+
299
+ function rotate (cx, cy, deg, x, y) {
300
+ var cos = Math.cos(deg), sin = Math.sin(deg);
301
+ return [
302
+ (x - cx) * cos - (y - cy) * sin + cx,
303
+ (x - cx) * sin + (y - cy) * cos + cy
304
+ ];
305
+ }
306
+
307
+ var TreeLayout = (function (_super) {
308
+ __extends(TreeLayout, _super);
309
+ function TreeLayout() {
310
+ var _this = _super !== null && _super.apply(this, arguments) || this;
311
+ _this.name = 'TreeLayout';
312
+ _this.__option = {
313
+ offsetX: 0,
314
+ offsetY: 0,
315
+ duration: 500,
316
+ type: "plain",
317
+ direction: "LR",
318
+ x: 100,
319
+ y: 100,
320
+ width: 100,
321
+ height: 100,
322
+ radius: 100
323
+ };
324
+ _this.__noOpens = {};
325
+ return _this;
326
+ }
327
+ TreeLayout.prototype.setOption = function (option) {
328
+ initOption(option, this.__option);
329
+ return this;
330
+ };
331
+ TreeLayout.prototype.use = function (initTree, noOpens) {
332
+ if (noOpens === void 0) { noOpens = {}; }
333
+ var tree = _super.prototype.use.call(this, initTree, noOpens);
334
+ if (this.__option.offsetX != 0 || this.__option.offsetY != 0) {
335
+ for (var key in tree.node) {
336
+ if (!tree.node[key].show) {
337
+ var deep = 0, pid = key;
338
+ do {
339
+ pid = tree.node[pid].pid;
340
+ deep++;
341
+ } while (!tree.node[pid].show);
342
+ tree.node[key].left += this.__option.offsetX * deep;
343
+ tree.node[key].top += this.__option.offsetY * deep;
344
+ }
345
+ }
346
+ }
347
+ if (this.__option.type == 'rect') {
348
+ if (this.__option.direction == 'LR' || this.__option.direction == "RL") {
349
+ var perW = this.__option.height / tree.size;
350
+ var perD = this.__option.width / (tree.deep - 1);
351
+ var balanceW = this.__option.y - this.__option.height * 0.5;
352
+ var flag = this.__option.direction == 'LR' ? 1 : -1;
353
+ for (var key in tree.node) {
354
+ if (tree.deep == 1) {
355
+ tree.node[key].left = this.__option.x + this.__option.width * 0.5 * flag;
356
+ tree.node[key].top = this.__option.y;
357
+ }
358
+ else {
359
+ tree.node[key].left = this.__option.x + (tree.node[key].left - 0.5) * perD * flag;
360
+ tree.node[key].top = tree.node[key].top * perW + balanceW;
361
+ }
362
+ }
363
+ }
364
+ else if (this.__option.direction == 'TB' || this.__option.direction == "BT") {
365
+ var perW = this.__option.width / tree.size;
366
+ var perD = this.__option.height / (tree.deep - 1);
367
+ var balanceW = this.__option.x - this.__option.width * 0.5;
368
+ var flag = this.__option.direction == 'TB' ? 1 : -1;
369
+ for (var key in tree.node) {
370
+ tree.node[key].deg = this.__option.direction == 'TB' ? Math.PI * 0.5 : Math.PI * -0.5;
371
+ if (tree.deep == 1) {
372
+ tree.node[key].left = this.__option.x;
373
+ tree.node[key].top = this.__option.y + this.__option.height * 0.5 * flag;
374
+ }
375
+ else {
376
+ var left = tree.node[key].left;
377
+ tree.node[key].left = tree.node[key].top * perW + balanceW;
378
+ tree.node[key].top = this.__option.y + (left - 0.5) * perD * flag;
379
+ }
380
+ }
381
+ }
382
+ }
383
+ else if (this.__option.type == 'circle') {
384
+ var cx = this.__option.x, cy = this.__option.y;
385
+ var deg = Math.PI * 2 / tree.size;
386
+ var per = this.__option.radius / (tree.deep - 1);
387
+ for (var key in tree.node) {
388
+ if (tree.node[key].left == 0.5) {
389
+ tree.node[key].left = cx;
390
+ tree.node[key].top = cy;
391
+ }
392
+ else {
393
+ var position = rotate(cx, cy, deg * tree.node[key].top, cx + (tree.node[key].left - 0.5) * per, cy);
394
+ tree.node[key].deg = deg * tree.node[key].top;
395
+ tree.node[key].left = position[0];
396
+ tree.node[key].top = position[1];
397
+ }
398
+ }
399
+ }
400
+ return tree;
401
+ };
402
+ TreeLayout.prototype.bind = function (initTree, renderBack, noOpens) {
403
+ if (noOpens === void 0) { noOpens = {}; }
404
+ this.__rback = renderBack;
405
+ this.__oralTree = initTree;
406
+ this.__noOpens = noOpens;
407
+ this.__preTree = this.use(this.__oralTree, this.__noOpens);
408
+ this.__rback(this.__preTree);
409
+ return this;
410
+ };
411
+ TreeLayout.prototype.unbind = function () {
412
+ this.__rback = function () { return null; };
413
+ this.__oralTree = null;
414
+ this.__preTree = null;
415
+ this.__noOpens = {};
416
+ return this;
417
+ };
418
+ TreeLayout.prototype.doUpdate = function () {
419
+ var _this = this;
420
+ var newTree = this.use(this.__oralTree, this.__noOpens);
421
+ var cacheTree = JSON.parse(JSON.stringify(newTree));
422
+ animation(function (deep) {
423
+ if (_this.__preTree) {
424
+ for (var key in cacheTree.node) {
425
+ if (newTree.node[key].show || _this.__preTree.node[key].show) {
426
+ cacheTree.node[key].show = true;
427
+ cacheTree.node[key].left = _this.__preTree.node[key].left + (newTree.node[key].left - _this.__preTree.node[key].left) * deep;
428
+ cacheTree.node[key].top = _this.__preTree.node[key].top + (newTree.node[key].top - _this.__preTree.node[key].top) * deep;
429
+ }
430
+ }
431
+ }
432
+ _this.__rback(cacheTree);
433
+ }, this.__option.duration, function () {
434
+ _this.__preTree = newTree;
435
+ _this.__rback(_this.__preTree);
436
+ });
437
+ return this;
438
+ };
439
+ TreeLayout.prototype.closeNode = function (id) {
440
+ if (!this.__preTree)
441
+ return this;
442
+ this.__noOpens[id] = true;
443
+ this.doUpdate();
444
+ return this;
445
+ };
446
+ TreeLayout.prototype.openNode = function (id) {
447
+ if (!this.__preTree)
448
+ return this;
449
+ this.__noOpens[id] = false;
450
+ this.doUpdate();
451
+ return this;
452
+ };
453
+ TreeLayout.prototype.toggleNode = function (id) {
454
+ if (!this.__preTree)
455
+ return this;
456
+ this.__noOpens[id] = !this.__noOpens[id];
457
+ this.doUpdate();
458
+ return this;
459
+ };
460
+ return TreeLayout;
461
461
  }(Tree));
462
462
 
463
463
  export { TreeLayout as default };