vislite 1.2.0-alpha.3 → 1.2.0-alpha.4

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 (65) hide show
  1. package/CHANGELOG +13 -4
  2. package/lib/Buffer/index.es.js +1 -1
  3. package/lib/Buffer/index.es.min.js +1 -1
  4. package/lib/Canvas/index.es.js +4 -2
  5. package/lib/Canvas/index.es.min.js +2 -2
  6. package/lib/Cardinal/index.es.js +1 -1
  7. package/lib/Cardinal/index.es.min.js +1 -1
  8. package/lib/Eoap/index.es.js +1 -1
  9. package/lib/Eoap/index.es.min.js +1 -1
  10. package/lib/Hermite/index.es.js +1 -1
  11. package/lib/Hermite/index.es.min.js +1 -1
  12. package/lib/Matrix4/index.es.js +1 -1
  13. package/lib/Matrix4/index.es.min.js +1 -1
  14. package/lib/Mercator/index.es.js +1 -1
  15. package/lib/Mercator/index.es.min.js +1 -1
  16. package/lib/RawCanvas/index.es.js +4 -2
  17. package/lib/RawCanvas/index.es.min.js +2 -2
  18. package/lib/SVG/index.es.js +12 -8
  19. package/lib/SVG/index.es.min.js +2 -2
  20. package/lib/Shader/index.es.js +1 -1
  21. package/lib/Shader/index.es.min.js +1 -1
  22. package/lib/Texture/index.es.js +1 -1
  23. package/lib/Texture/index.es.min.js +1 -1
  24. package/lib/TreeLayout/index.es.js +38 -8
  25. package/lib/TreeLayout/index.es.min.js +2 -2
  26. package/lib/animation/index.es.js +38 -8
  27. package/lib/animation/index.es.min.js +2 -2
  28. package/lib/assemble/index.es.js +1 -1
  29. package/lib/assemble/index.es.min.js +1 -1
  30. package/lib/getLoopColors/index.es.js +1 -1
  31. package/lib/getLoopColors/index.es.min.js +1 -1
  32. package/lib/getWebGLContext/index.es.js +1 -1
  33. package/lib/getWebGLContext/index.es.min.js +1 -1
  34. package/lib/index.umd.js +76 -33
  35. package/lib/index.umd.min.js +2 -2
  36. package/lib/initOption/index.es.js +1 -1
  37. package/lib/initOption/index.es.min.js +1 -1
  38. package/lib/mergeOption/index.es.js +1 -1
  39. package/lib/mergeOption/index.es.min.js +1 -1
  40. package/lib/move/index.es.js +1 -1
  41. package/lib/move/index.es.min.js +1 -1
  42. package/lib/rotate/index.es.js +1 -1
  43. package/lib/rotate/index.es.min.js +1 -1
  44. package/lib/ruler/index.es.js +1 -1
  45. package/lib/ruler/index.es.min.js +1 -1
  46. package/lib/scale/index.es.js +1 -1
  47. package/lib/scale/index.es.min.js +1 -1
  48. package/lib/throttle/index.es.js +25 -25
  49. package/lib/throttle/index.es.min.js +2 -2
  50. package/package/animation/index.ts +1 -1
  51. package/package/throttle/index.ts +1 -1
  52. package/package.json +7 -2
  53. package/src/common/canvas/painter.ts +9 -3
  54. package/src/common/svg/config.ts +194 -190
  55. package/src/common/svg/index.ts +350 -347
  56. package/src/common/svg/tool.ts +42 -44
  57. package/src/layout/TreeLayout.ts +1 -1
  58. package/types/CanvasConfig.d.ts +116 -106
  59. package/types/SVGConfig.d.ts +89 -79
  60. package/types/animation.d.ts +2 -6
  61. package/types/painterConfig.d.ts +5 -3
  62. package/types/throttle.d.ts +2 -4
  63. package/types/throttleOption.d.ts +1 -22
  64. package/src/animation.ts +0 -99
  65. package/src/throttle.ts +0 -53
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * TreeLayout of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * TreeLayout of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
- var t=function(o,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=o[e])},t(o,e)};"function"==typeof SuppressedError&&SuppressedError;function o(t,o){for(var e in t)o[e]=t[e];return o}var e,n=function(){function t(t){void 0===t&&(t={}),this.name="Tree",this.__config=o(t,{root:function(t){return t},children:function(t){return t.children},id:function(t){return t.name}})}return t.prototype.use=function(t,o){return void 0===o&&(o={}),function(t,o,e){var n=function(t,o){var e,n,i={},r=o.root(t);e=n=o.id(r),i[e]={data:r,pid:null,id:e,isOpen:!0,show:!0,children:[]};var p=1;return function n(r,s){var _=o.children(r,t);p+=_?_.length:0;for(var h=0;_&&h<_.length;h++)e=o.id(_[h]),i[s].children.push(e),i[e]={data:_[h],pid:s,id:e,isOpen:!0,show:!0,children:[]},n(_[h],e)}(r,e),{rid:n,value:i,num:p}}(t,o),i=n.value,r=n.rid;if(1==n.num)return i[r].left=.5,i[r].top=.5,i[r].show=!0,{deep:1,node:i,root:r,size:1};var p=[],s=0,_=0;for(var h in e[r]?(i[r].left=.5,i[r].top=.5,i[r].show=!0,s=1):function t(o,n){n>_&&(_=n);var r=0;if(!e[o.id])for(r=0;r<o.children.length;r++)t(i[o.children[r]],n+1);if(i[o.id].left=n+.5,0==r?(null==p[n]&&(p[n]=-.5),null==p[n-1]&&(p[n-1]=-.5),i[o.id].top=p[n]+1,p[n]+1+.5*(i[o.pid].children.length-1)-1<p[n-1]&&(i[o.id].top=p[n-1]+1-.5*(i[o.pid].children.length-1))):i[o.id].top=.5*(i[o.children[0]].top+i[o.children[r-1]].top),i[o.id].top<=p[n])var h=p[n]+1-i[o.id].top((function t(o,e){i[o].top+=h,p[e]<i[o].top&&(p[e]=i[o].top);for(var n=0;n<i[o].children.length;n++)t(i[o].children[n],e+1)}))(o.id,n);p[n]=i[o.id].top,i[o.id].top+.5>s&&(s=i[o.id].top+.5)}(i[r],0),e)e[h]&&(i[h].isOpen=!1,function t(o,e,n){for(var r=0;r<i[o].children.length;r++)i[i[o].children[r]].left=e,i[i[o].children[r]].top=n,i[i[o].children[r]].show=!1,t(i[o].children[r],e,n)}(h,i[h].left,i[h].top));return{node:i,root:r,size:s,deep:_+1}}(t,this.__config,o)},t}(),i=[];function r(t,o,e,n,i){var r=Math.cos(e),p=Math.sin(e);return[(n-t)*r-(i-o)*p+t,(n-t)*p+(i-o)*r+o]}var p=function(n){function p(){var t=null!==n&&n.apply(this,arguments)||this;return t.name="TreeLayout",t.__option={offsetX:0,offsetY:0,duration:500,type:"plain",direction:"LR",x:100,y:100,width:100,height:100,radius:100},t.__noOpens={},t}return function(o,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=o}t(o,e),o.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(p,n),p.prototype.setOption=function(t){return o(t,this.__option),this},p.prototype.use=function(t,o){void 0===o&&(o={});var e=n.prototype.use.call(this,t,o);if(0!=this.__option.offsetX||0!=this.__option.offsetY)for(var i in e.node)if(!e.node[i].show){var p=0,s=i;do{s=e.node[s].pid,p++}while(!e.node[s].show);e.node[i].left+=this.__option.offsetX*p,e.node[i].top+=this.__option.offsetY*p}if("rect"==this.__option.type){if("LR"==this.__option.direction||"RL"==this.__option.direction){var _=this.__option.height/e.size,h=this.__option.width/(e.deep-1),d=this.__option.y-.5*this.__option.height,f="LR"==this.__option.direction?1:-1;for(var i in e.node)1==e.deep?(e.node[i].left=this.__option.x+.5*this.__option.width*f,e.node[i].top=this.__option.y):(e.node[i].left=this.__option.x+(e.node[i].left-.5)*h*f,e.node[i].top=e.node[i].top*_+d)}else if("TB"==this.__option.direction||"BT"==this.__option.direction){_=this.__option.width/e.size,h=this.__option.height/(e.deep-1),d=this.__option.x-.5*this.__option.width,f="TB"==this.__option.direction?1:-1;for(var i in e.node)if(1==e.deep)e.node[i].left=this.__option.x,e.node[i].top=this.__option.y+.5*this.__option.height*f;else{var l=e.node[i].left;e.node[i].left=e.node[i].top*_+d,e.node[i].top=this.__option.y+(l-.5)*h*f}}}else if("circle"==this.__option.type){var u=this.__option.x,c=this.__option.y,a=2*Math.PI/e.size,v=this.__option.radius/(e.deep-1);for(var i in e.node)if(.5==e.node[i].left)e.node[i].left=u,e.node[i].top=c;else{var y=r(u,c,a*e.node[i].top,u+(e.node[i].left-.5)*v,c);e.node[i].left=y[0],e.node[i].top=y[1]}}return e},p.prototype.bind=function(t,o,e){return void 0===e&&(e={}),this.__rback=o,this.__oralTree=t,this.__noOpens=e,this.__preTree=this.use(this.__oralTree,this.__noOpens),this.__rback(this.__preTree),this},p.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralTree=null,this.__preTree=null,this.__noOpens={},this},p.prototype.doUpdate=function(){var t=this,o=this.use(this.__oralTree,this.__noOpens),n=JSON.parse(JSON.stringify(o));!function(t,o,n){void 0===o&&(o=400),void 0===n&&(n=function(){});var r={timer:function(t,o,e){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return i.push({id:n,createTime:new Date,tick:t,duration:o,callback:e}),r.start(),n},start:function(){e||(e=setInterval(r.tick,13))},tick:function(){var t,o,e,n,p,s,_,h=i;for((i=[]).length=0,o=0;o<h.length;o++)t=(p=h[o]).createTime,e=p.tick,s=p.duration,n=p.callback,e(_=(_=(+(new Date).valueOf()-t.valueOf())/s)>1?1:_),_<1&&p.id?i.push(p):n(_);i.length<=0&&r.stop()},stop:function(){e&&(clearInterval(e),e=null)}},p=r.timer((function(o){t(o)}),o,n)}((function(e){if(t.__preTree)for(var i in n.node)(o.node[i].show||t.__preTree.node[i].show)&&(n.node[i].show=!0,n.node[i].left=t.__preTree.node[i].left+(o.node[i].left-t.__preTree.node[i].left)*e,n.node[i].top=t.__preTree.node[i].top+(o.node[i].top-t.__preTree.node[i].top)*e);t.__rback(n)}),this.__option.duration,(function(){t.__preTree=o,t.__rback(t.__preTree)}))},p.prototype.closeNode=function(t){return this.__preTree?(this.__noOpens[t]=!0,this.doUpdate(),this):this},p.prototype.openNode=function(t){return this.__preTree?(this.__noOpens[t]=!1,this.doUpdate(),this):this},p.prototype.toggleNode=function(t){return this.__preTree?(this.__noOpens[t]=!this.__noOpens[t],this.doUpdate(),this):this},p}(n);export{p as default};
5
+ var t=function(o,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o}||function(t,o){for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(t[e]=o[e])},t(o,e)};"function"==typeof SuppressedError&&SuppressedError;function o(t,o){for(var e in t)o[e]=t[e];return o}var e,n=function(){function t(t){void 0===t&&(t={}),this.name="Tree",this.__config=o(t,{root:function(t){return t},children:function(t){return t.children},id:function(t){return t.name}})}return t.prototype.use=function(t,o){return void 0===o&&(o={}),function(t,o,e){var n=function(t,o){var e,n,i={},r=o.root(t);e=n=o.id(r),i[e]={data:r,pid:null,id:e,isOpen:!0,show:!0,children:[]};var p=1;return function n(r,s){var _=o.children(r,t);p+=_?_.length:0;for(var h=0;_&&h<_.length;h++)e=o.id(_[h]),i[s].children.push(e),i[e]={data:_[h],pid:s,id:e,isOpen:!0,show:!0,children:[]},n(_[h],e)}(r,e),{rid:n,value:i,num:p}}(t,o),i=n.value,r=n.rid;if(1==n.num)return i[r].left=.5,i[r].top=.5,i[r].show=!0,{deep:1,node:i,root:r,size:1};var p=[],s=0,_=0;for(var h in e[r]?(i[r].left=.5,i[r].top=.5,i[r].show=!0,s=1):function t(o,n){n>_&&(_=n);var r=0;if(!e[o.id])for(r=0;r<o.children.length;r++)t(i[o.children[r]],n+1);if(i[o.id].left=n+.5,0==r?(null==p[n]&&(p[n]=-.5),null==p[n-1]&&(p[n-1]=-.5),i[o.id].top=p[n]+1,p[n]+1+.5*(i[o.pid].children.length-1)-1<p[n-1]&&(i[o.id].top=p[n-1]+1-.5*(i[o.pid].children.length-1))):i[o.id].top=.5*(i[o.children[0]].top+i[o.children[r-1]].top),i[o.id].top<=p[n])var h=p[n]+1-i[o.id].top((function t(o,e){i[o].top+=h,p[e]<i[o].top&&(p[e]=i[o].top);for(var n=0;n<i[o].children.length;n++)t(i[o].children[n],e+1)}))(o.id,n);p[n]=i[o.id].top,i[o.id].top+.5>s&&(s=i[o.id].top+.5)}(i[r],0),e)e[h]&&(i[h].isOpen=!1,function t(o,e,n){for(var r=0;r<i[o].children.length;r++)i[i[o].children[r]].left=e,i[i[o].children[r]].top=n,i[i[o].children[r]].show=!1,t(i[o].children[r],e,n)}(h,i[h].left,i[h].top));return{node:i,root:r,size:s,deep:_+1}}(t,this.__config,o)},t}(),i=[];function r(t,o,e,n,i){var r=Math.cos(e),p=Math.sin(e);return[(n-t)*r-(i-o)*p+t,(n-t)*p+(i-o)*r+o]}var p=function(n){function p(){var t=null!==n&&n.apply(this,arguments)||this;return t.name="TreeLayout",t.__option={offsetX:0,offsetY:0,duration:500,type:"plain",direction:"LR",x:100,y:100,width:100,height:100,radius:100},t.__noOpens={},t}return function(o,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=o}t(o,e),o.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(p,n),p.prototype.setOption=function(t){return o(t,this.__option),this},p.prototype.use=function(t,o){void 0===o&&(o={});var e=n.prototype.use.call(this,t,o);if(0!=this.__option.offsetX||0!=this.__option.offsetY)for(var i in e.node)if(!e.node[i].show){var p=0,s=i;do{s=e.node[s].pid,p++}while(!e.node[s].show);e.node[i].left+=this.__option.offsetX*p,e.node[i].top+=this.__option.offsetY*p}if("rect"==this.__option.type){if("LR"==this.__option.direction||"RL"==this.__option.direction){var _=this.__option.height/e.size,h=this.__option.width/(e.deep-1),d=this.__option.y-.5*this.__option.height,f="LR"==this.__option.direction?1:-1;for(var i in e.node)1==e.deep?(e.node[i].left=this.__option.x+.5*this.__option.width*f,e.node[i].top=this.__option.y):(e.node[i].left=this.__option.x+(e.node[i].left-.5)*h*f,e.node[i].top=e.node[i].top*_+d)}else if("TB"==this.__option.direction||"BT"==this.__option.direction){_=this.__option.width/e.size,h=this.__option.height/(e.deep-1),d=this.__option.x-.5*this.__option.width,f="TB"==this.__option.direction?1:-1;for(var i in e.node)if(1==e.deep)e.node[i].left=this.__option.x,e.node[i].top=this.__option.y+.5*this.__option.height*f;else{var l=e.node[i].left;e.node[i].left=e.node[i].top*_+d,e.node[i].top=this.__option.y+(l-.5)*h*f}}}else if("circle"==this.__option.type){var u=this.__option.x,c=this.__option.y,a=2*Math.PI/e.size,v=this.__option.radius/(e.deep-1);for(var i in e.node)if(.5==e.node[i].left)e.node[i].left=u,e.node[i].top=c;else{var y=r(u,c,a*e.node[i].top,u+(e.node[i].left-.5)*v,c);e.node[i].left=y[0],e.node[i].top=y[1]}}return e},p.prototype.bind=function(t,o,e){return void 0===e&&(e={}),this.__rback=o,this.__oralTree=t,this.__noOpens=e,this.__preTree=this.use(this.__oralTree,this.__noOpens),this.__rback(this.__preTree),this},p.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralTree=null,this.__preTree=null,this.__noOpens={},this},p.prototype.doUpdate=function(){var t=this,o=this.use(this.__oralTree,this.__noOpens),n=JSON.parse(JSON.stringify(o));!function(t,o,n){arguments.length<2&&(o=400),arguments.length<3&&(n=function(){});var r={timer:function(t,o,e){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return i.push({id:n,createTime:new Date,tick:t,duration:o,callback:e}),r.start(),n},start:function(){e||(e=setInterval(r.tick,13))},tick:function(){var t,o,e,n,p,s,_,h=i;for((i=[]).length=0,o=0;o<h.length;o++)t=(p=h[o]).createTime,e=p.tick,s=p.duration,n=p.callback,e(_=(_=(+(new Date).valueOf()-t.valueOf())/s)>1?1:_),_<1&&p.id?i.push(p):n(_);i.length<=0&&r.stop()},stop:function(){e&&(clearInterval(e),e=null)}},p=r.timer((function(o){t(o)}),o,n)}((function(e){if(t.__preTree)for(var i in n.node)(o.node[i].show||t.__preTree.node[i].show)&&(n.node[i].show=!0,n.node[i].left=t.__preTree.node[i].left+(o.node[i].left-t.__preTree.node[i].left)*e,n.node[i].top=t.__preTree.node[i].top+(o.node[i].top-t.__preTree.node[i].top)*e);t.__rback(n)}),this.__option.duration,(function(){t.__preTree=o,t.__rback(t.__preTree)}))},p.prototype.closeNode=function(t){return this.__preTree?(this.__noOpens[t]=!0,this.doUpdate(),this):this},p.prototype.openNode=function(t){return this.__preTree?(this.__noOpens[t]=!1,this.doUpdate(),this):this},p.prototype.toggleNode=function(t){return this.__preTree?(this.__noOpens[t]=!this.__noOpens[t],this.doUpdate(),this):this},p}(n);export{p as default};
@@ -1,14 +1,28 @@
1
1
  /*!
2
- * animation of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * animation of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
+ //当前正在运动的动画的tick函数堆栈
5
6
  var $timers = [];
7
+ //唯一定时器的定时间隔
6
8
  var $interval = 13;
9
+ //定时器ID
7
10
  var $timerId;
8
- function animation (doback, duration, callback) {
9
- if (duration === void 0) { duration = 400; }
10
- if (callback === void 0) { callback = function () { }; }
11
+
12
+ /**
13
+ * 动画轮播
14
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
15
+ * @param {number} duration 动画时长,可选
16
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
17
+ *
18
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
19
+ */
20
+ function animation(doback, duration, callback) {
21
+ if (arguments.length < 2) duration = 400;
22
+ if (arguments.length < 3) callback = function () { };
23
+
11
24
  var clock = {
25
+ //把tick函数推入堆栈
12
26
  "timer": function (tick, duration, callback) {
13
27
  if (!tick) {
14
28
  throw new Error('Tick is required!');
@@ -24,29 +38,37 @@ function animation (doback, duration, callback) {
24
38
  clock.start();
25
39
  return id;
26
40
  },
41
+
42
+ //开启唯一的定时器timerId
27
43
  "start": function () {
28
44
  if (!$timerId) {
29
45
  $timerId = setInterval(clock.tick, $interval);
30
46
  }
31
47
  },
48
+
49
+ //被定时器调用,遍历timers堆栈
32
50
  "tick": function () {
33
- var createTime, flag, tick, callback, timer, duration, passTime;
34
- var timers = $timers;
51
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
52
+
35
53
  $timers = [];
36
54
  $timers.length = 0;
55
+
37
56
  for (flag = 0; flag < timers.length; flag++) {
57
+ //初始化数据
38
58
  timer = timers[flag];
39
59
  createTime = timer.createTime;
40
60
  tick = timer.tick;
41
61
  duration = timer.duration;
42
62
  callback = timer.callback;
63
+
64
+ //执行
43
65
  passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
44
66
  passTime = passTime > 1 ? 1 : passTime;
45
67
  tick(passTime);
46
68
  if (passTime < 1 && timer.id) {
69
+ //动画没有结束再添加
47
70
  $timers.push(timer);
48
- }
49
- else {
71
+ } else {
50
72
  callback(passTime);
51
73
  }
52
74
  }
@@ -54,6 +76,8 @@ function animation (doback, duration, callback) {
54
76
  clock.stop();
55
77
  }
56
78
  },
79
+
80
+ //停止定时器,重置timerId=null
57
81
  "stop": function () {
58
82
  if ($timerId) {
59
83
  clearInterval($timerId);
@@ -61,9 +85,14 @@ function animation (doback, duration, callback) {
61
85
  }
62
86
  }
63
87
  };
88
+
64
89
  var id = clock.timer(function (deep) {
90
+ //其中deep为0-1,表示改变的程度
65
91
  doback(deep);
66
92
  }, duration, callback);
93
+
94
+ // 返回一个函数
95
+ // 用于在动画结束前结束动画
67
96
  return function () {
68
97
  var i;
69
98
  for (i in $timers) {
@@ -73,6 +102,7 @@ function animation (doback, duration, callback) {
73
102
  }
74
103
  }
75
104
  };
105
+
76
106
  }
77
107
 
78
108
  export { animation as default };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * animation of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
- var t,e=[];function i(i,n,r){void 0===n&&(n=400),void 0===r&&(r=function(){});var a={timer:function(t,i,n){if(!t)throw new Error("Tick is required!");var r=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return e.push({id:r,createTime:new Date,tick:t,duration:i,callback:n}),a.start(),r},start:function(){t||(t=setInterval(a.tick,13))},tick:function(){var t,i,n,r,o,u,c,f=e;for((e=[]).length=0,i=0;i<f.length;i++)t=(o=f[i]).createTime,n=o.tick,u=o.duration,r=o.callback,n(c=(c=(+(new Date).valueOf()-t.valueOf())/u)>1?1:c),c<1&&o.id?e.push(o):r(c);e.length<=0&&a.stop()},stop:function(){t&&(clearInterval(t),t=null)}},o=a.timer((function(t){i(t)}),n,r);return function(){var t;for(t in e)if(e[t].id==o)return void(e[t].id=void 0)}}export{i as default};
5
+ var t,e=[];function n(n,r,i){arguments.length<2&&(r=400),arguments.length<3&&(i=function(){});var a={timer:function(t,n,r){if(!t)throw new Error("Tick is required!");var i=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return e.push({id:i,createTime:new Date,tick:t,duration:n,callback:r}),a.start(),i},start:function(){t||(t=setInterval(a.tick,13))},tick:function(){var t,n,r,i,o,u,c,l=e;for((e=[]).length=0,n=0;n<l.length;n++)t=(o=l[n]).createTime,r=o.tick,u=o.duration,i=o.callback,r(c=(c=(+(new Date).valueOf()-t.valueOf())/u)>1?1:c),c<1&&o.id?e.push(o):i(c);e.length<=0&&a.stop()},stop:function(){t&&(clearInterval(t),t=null)}},o=a.timer((function(t){n(t)}),r,i);return function(){var t;for(t in e)if(e[t].id==o)return void(e[t].id=void 0)}}export{n as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * assemble of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * assemble of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function assemble (begin, end, step, count) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * assemble of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * assemble of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function r(r,t,e,f){for(var n=[],o=0;o<f;o++)n[o]=r;return function(){for(var o=0;o<f;o++){if(n[o]+e<t){n[o]=+(n[o]+e).toFixed(7);break}o<f-1&&(n[o]=r)}return n}}export{r as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * getLoopColors of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * getLoopColors of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function getLoopColors (num, alpha) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * getLoopColors of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * getLoopColors of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function r(r,a){void 0===a&&(a=1);var g=["rgba(84,112,198,"+a+")","rgba(145,204,117,"+a+")","rgba(250,200,88,"+a+")","rgba(238,102,102,"+a+")","rgba(115,192,222,"+a+")","rgba(59,162,114,"+a+")","rgba(252,132,82,"+a+")","rgba(154,96,180,"+a+")","rgba(234,124,204,"+a+")"],t=[];if(r<=g.length)return g;if(r%g.length==0)for(var e=0;e<r/g.length;e++)t=t.concat(g);else{for(var n=1;n<r/g.length;n++)t=t.concat(g);if(r%g.length==1)t=t.concat(g[4]);else for(var o=0;o<r%g.length;o++)t=t.concat(g[o])}return t}export{r as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * getWebGLContext of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * getWebGLContext of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  function getWebGLContext (canvas, scale, opts, mode) {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * getWebGLContext of VISLite JavaScript Library v1.2.0-alpha.3
2
+ * getWebGLContext of VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  var e=function(e,t,i){if(void 0===t&&(t=1),!e)throw new Error("VISLite getWebGLContext:The mount point requires an HTMLElement type but encountered null.");var n,r=e.clientWidth,a=e.clientHeight,o=e;return o._vislite_canvas_?n=o._vislite_canvas_:(n=document.createElement("canvas"),e.appendChild(n),o._vislite_canvas_=n,e.setAttribute("vislite","WebGL")),n.style.width=r+"px",n.setAttribute("width",r+""),n.style.height=a+"px",n.setAttribute("height",a+""),function(e,t,i,n){void 0===i&&(i={}),void 0===n&&(n="scaleToFill");for(var r=["experimental-webgl","webkit-3d","moz-webgl"],a=e.getContext("webgl",i),o=0;o<r.length;o++){try{a=e.getContext(r[o],i)}catch(e){}if(a)break}if(!a)throw new Error("Non canvas or browser does not support webgl.");var l=a.canvas.width,s=a.canvas.height,c=t,v=t;"aspectFit"==n?l>s?c*=s/l:s>l&&(v*=l/s):"aspectFill"==n&&(l>s?v*=l/s:s>l&&(c*=s/l));var h=l*c,u=s*v;return a.viewport(.5*(l-h),.5*(s-u),h,u),a.depthFunc(a.LEQUAL),a.enable(a.DEPTH_TEST),a}(n,t,{},i)};export{e as default};
package/lib/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v1.2.0-alpha.3
2
+ * VISLite JavaScript Library v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  */
5
5
  (function (global, factory) {
@@ -293,13 +293,27 @@
293
293
  return colors;
294
294
  }
295
295
 
296
+ //当前正在运动的动画的tick函数堆栈
296
297
  var $timers = [];
298
+ //唯一定时器的定时间隔
297
299
  var $interval = 13;
300
+ //定时器ID
298
301
  var $timerId;
299
- function animation (doback, duration, callback) {
300
- if (duration === void 0) { duration = 400; }
301
- if (callback === void 0) { callback = function () { }; }
302
+
303
+ /**
304
+ * 动画轮播
305
+ * @param {function} doback 轮询函数,有一个形参deep,0-1,表示执行进度
306
+ * @param {number} duration 动画时长,可选
307
+ * @param {function} callback 动画结束回调,可选,有一个形参deep,0-1,表示执行进度
308
+ *
309
+ * @returns {function} 返回一个函数,调用该函数,可以提前结束动画
310
+ */
311
+ function animation(doback, duration, callback) {
312
+ if (arguments.length < 2) duration = 400;
313
+ if (arguments.length < 3) callback = function () { };
314
+
302
315
  var clock = {
316
+ //把tick函数推入堆栈
303
317
  "timer": function (tick, duration, callback) {
304
318
  if (!tick) {
305
319
  throw new Error('Tick is required!');
@@ -315,29 +329,37 @@
315
329
  clock.start();
316
330
  return id;
317
331
  },
332
+
333
+ //开启唯一的定时器timerId
318
334
  "start": function () {
319
335
  if (!$timerId) {
320
336
  $timerId = setInterval(clock.tick, $interval);
321
337
  }
322
338
  },
339
+
340
+ //被定时器调用,遍历timers堆栈
323
341
  "tick": function () {
324
- var createTime, flag, tick, callback, timer, duration, passTime;
325
- var timers = $timers;
342
+ var createTime, flag, tick, callback, timer, duration, passTime, timers = $timers;
343
+
326
344
  $timers = [];
327
345
  $timers.length = 0;
346
+
328
347
  for (flag = 0; flag < timers.length; flag++) {
348
+ //初始化数据
329
349
  timer = timers[flag];
330
350
  createTime = timer.createTime;
331
351
  tick = timer.tick;
332
352
  duration = timer.duration;
333
353
  callback = timer.callback;
354
+
355
+ //执行
334
356
  passTime = (+new Date().valueOf() - createTime.valueOf()) / duration;
335
357
  passTime = passTime > 1 ? 1 : passTime;
336
358
  tick(passTime);
337
359
  if (passTime < 1 && timer.id) {
360
+ //动画没有结束再添加
338
361
  $timers.push(timer);
339
- }
340
- else {
362
+ } else {
341
363
  callback(passTime);
342
364
  }
343
365
  }
@@ -345,6 +367,8 @@
345
367
  clock.stop();
346
368
  }
347
369
  },
370
+
371
+ //停止定时器,重置timerId=null
348
372
  "stop": function () {
349
373
  if ($timerId) {
350
374
  clearInterval($timerId);
@@ -352,9 +376,14 @@
352
376
  }
353
377
  }
354
378
  };
379
+
355
380
  var id = clock.timer(function (deep) {
381
+ //其中deep为0-1,表示改变的程度
356
382
  doback(deep);
357
383
  }, duration, callback);
384
+
385
+ // 返回一个函数
386
+ // 用于在动画结束前结束动画
358
387
  return function () {
359
388
  var i;
360
389
  for (i in $timers) {
@@ -364,6 +393,7 @@
364
393
  }
365
394
  }
366
395
  };
396
+
367
397
  }
368
398
 
369
399
  function ruler (maxValue, minValue, num, option) {
@@ -562,7 +592,6 @@
562
592
  function full(el, config) {
563
593
  _setAttribute(el, "stroke", config.strokeStyle);
564
594
  _setAttribute(el, "fill", config.fillStyle);
565
- _setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
566
595
  }
567
596
  function fill(el, config) {
568
597
  _setAttribute(el, "fill", config.fillStyle);
@@ -570,7 +599,6 @@
570
599
  function stroke(el, config) {
571
600
  _setAttribute(el, "stroke", config.strokeStyle);
572
601
  _setAttribute(el, "fill", "none");
573
- _setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
574
602
  }
575
603
 
576
604
  function setStyle (el, styles) {
@@ -651,10 +679,14 @@
651
679
  setAttribute(el, "cy", cy);
652
680
  setAttribute(el, "r", r);
653
681
  };
654
- var initPath = function (el, path) {
682
+ var initPath = function (el, path, config) {
655
683
  if (el.nodeName.toLowerCase() !== "path")
656
684
  throw new Error("Need a <path> !");
657
685
  setAttribute(el, "d", path);
686
+ setAttribute(el, "stroke-dasharray", config.lineDash.join(','));
687
+ setAttribute(el, "stroke-width", config.lineWidth + "");
688
+ setAttribute(el, "stroke-linecap", config.lineCap + "");
689
+ setAttribute(el, "stroke-linejoin", config.lineJoin + "");
658
690
  };
659
691
  var initRect$1 = function (el, x, y, width, height) {
660
692
  if (el.nodeName.toLowerCase() !== "rect")
@@ -761,7 +793,6 @@
761
793
  this.__config = {
762
794
  fillStyle: "#000",
763
795
  strokeStyle: "#000",
764
- lineWidth: 1,
765
796
  textAlign: "left",
766
797
  textBaseline: "middle",
767
798
  "fontSize": 16,
@@ -769,6 +800,9 @@
769
800
  "arcStartCap": "butt",
770
801
  "arcEndCap": "butt",
771
802
  lineDash: [],
803
+ lineWidth: 1,
804
+ lineCap: "butt",
805
+ lineJoin: "miter"
772
806
  };
773
807
  this.__path = "";
774
808
  this.__currentPosition = [];
@@ -923,17 +957,17 @@
923
957
  return this;
924
958
  };
925
959
  SVG.prototype.fill = function () {
926
- initPath(this.__useEl, this.__path);
960
+ initPath(this.__useEl, this.__path, this.__config);
927
961
  fill(this.__useEl, this.__config);
928
962
  return this;
929
963
  };
930
964
  SVG.prototype.stroke = function () {
931
- initPath(this.__useEl, this.__path);
965
+ initPath(this.__useEl, this.__path, this.__config);
932
966
  stroke(this.__useEl, this.__config);
933
967
  return this;
934
968
  };
935
969
  SVG.prototype.full = function () {
936
- initPath(this.__useEl, this.__path);
970
+ initPath(this.__useEl, this.__path, this.__config);
937
971
  full(this.__useEl, this.__config);
938
972
  return this;
939
973
  };
@@ -1104,9 +1138,11 @@
1104
1138
  "fillStyle": 'black',
1105
1139
  "strokeStyle": 'black',
1106
1140
  "lineWidth": 1,
1141
+ "lineCap": "butt",
1142
+ "lineJoin": "miter",
1143
+ "lineDash": [],
1107
1144
  "textAlign": 'left',
1108
1145
  "textBaseline": 'middle',
1109
- "lineDash": [],
1110
1146
  "shadowBlur": 0,
1111
1147
  "shadowColor": "black"
1112
1148
  };
@@ -2002,47 +2038,54 @@
2002
2038
  return Mercator;
2003
2039
  }());
2004
2040
 
2005
- function throttle (callback, option) {
2006
- if (option === void 0) { option = {}; }
2007
- option = initOption(option, {
2041
+ function throttle(callback, _option) {
2042
+
2043
+ // 缺省值
2044
+ var option = {
2008
2045
  time: 200,
2009
2046
  keep: false,
2010
2047
  opportunity: "end"
2011
- });
2012
- var hadInterval = false;
2013
- var hadClick = false;
2014
- var oneClick = false;
2015
- var arg;
2048
+ };
2049
+
2050
+ // 校对
2051
+ if (_option) {
2052
+ for (var key in _option) {
2053
+ option[key] = _option[key];
2054
+ }
2055
+ }
2056
+
2057
+ var hadInterval = false, hadClick = false, oneClick = false, arg;
2016
2058
  return function () {
2017
- var _this = this;
2059
+ const _this = this;
2018
2060
  arg = arguments;
2061
+
2062
+ // 如果前置任务都完成了
2019
2063
  if (!hadInterval) {
2020
2064
  if (option.opportunity != 'end') {
2021
2065
  callback.apply(_this, arg);
2022
2066
  }
2023
2067
  hadInterval = true;
2024
- var interval_1 = setInterval(function () {
2068
+
2069
+ var interval = setInterval(() => {
2025
2070
  if (hadClick) {
2026
2071
  if (!option.keep) {
2027
2072
  callback.apply(_this, arg);
2028
2073
  }
2029
- }
2030
- else {
2074
+ } else {
2031
2075
  if (option.opportunity != 'begin') {
2032
- if (oneClick || option.opportunity == 'end')
2033
- callback.apply(_this, arg);
2076
+ if (oneClick || option.opportunity == 'end') callback.apply(_this, arg);
2034
2077
  }
2035
2078
  hadInterval = false;
2036
2079
  oneClick = false;
2037
- clearInterval(interval_1);
2080
+ clearInterval(interval);
2038
2081
  }
2039
2082
  hadClick = false;
2040
2083
  }, option.time);
2041
- }
2042
- else {
2084
+ } else {
2043
2085
  hadClick = true;
2044
2086
  oneClick = true;
2045
2087
  }
2088
+
2046
2089
  };
2047
2090
  }
2048
2091