UNPKG

vislite

Version:

灵活、快速、简单的数据可视化交互式跨端前端库

1 lines 6.57 kB
var t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])},t(e,o)};"function"==typeof SuppressedError&&SuppressedError;function e(t,e){for(var o in t)e[o]=t[o];return e}var o=function(){function t(t){void 0===t&&(t={}),this.name="Tree",this.__config=e(t,{root:function(t){return t},children:function(t){return t.children},id:function(t){return t.name}})}return t.prototype.use=function(t,e){return void 0===e&&(e={}),function(t,e,o){void 0===o&&(o={});var n=function(t,e){var o,n,i={},r=e.root(t);o=n=e.id(r),i[o]={data:r,pid:null,id:o,isOpen:!0,show:!0,deg:0,children:[]};var s=1;return function n(r,p){var h=e.children(r,t);s+=h?h.length:0;for(var d=0;h&&d<h.length;d++)o=e.id(h[d]),i[p].children.push(o),i[o]={data:h[d],pid:p,id:o,isOpen:!0,show:!0,deg:0,children:[]},n(h[d],o)}(r,o),{rid:n,value:i,num:s}}(t,e),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 s=[],p=0,h=0;for(var d in o[r]?(i[r].left=.5,i[r].top=.5,i[r].show=!0,p=1):function t(e,n){n>h&&(h=n);var r=0;if(!o[e.id])for(r=0;r<e.children.length;r++)t(i[e.children[r]],n+1);if(i[e.id].left=n+.5,0==r?(null==s[n]&&(s[n]=-.5),null==s[n-1]&&(s[n-1]=-.5),i[e.id].top=s[n]+1,s[n]+1+.5*(i[e.pid].children.length-1)-1<s[n-1]&&(i[e.id].top=s[n-1]+1-.5*(i[e.pid].children.length-1))):i[e.id].top=.5*(i[e.children[0]].top+i[e.children[r-1]].top),i[e.id].top<=s[n])var d=s[n]+1-i[e.id].top((function t(e,o){i[e].top+=d,s[o]<i[e].top&&(s[o]=i[e].top);for(var n=0;n<i[e].children.length;n++)t(i[e].children[n],o+1)}))(e.id,n);s[n]=i[e.id].top,i[e.id].top+.5>p&&(p=i[e.id].top+.5)}(i[r],0),o)o[d]&&(i[d].isOpen=!1,function t(e,o,n){for(var r=0;r<i[e].children.length;r++)i[i[e].children[r]].left=o,i[i[e].children[r]].top=n,i[i[e].children[r]].show=!1,t(i[e].children[r],o,n)}(d,i[d].left,i[d].top));return{node:i,root:r,size:p,deep:h+1}}(t,this.__config,e)},t}();let n,i=[];function r(t,e,o,n,i){var r=Math.cos(o),s=Math.sin(o);return[(n-t)*r-(i-e)*s+t,(n-t)*s+(i-e)*r+e]}var s=function(o){function s(){var t=null!==o&&o.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(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(s,o),s.prototype.setOption=function(t){return e(t,this.__option),this},s.prototype.use=function(t,e){void 0===e&&(e={});var n=o.prototype.use.call(this,t,e);if(0!=this.__option.offsetX||0!=this.__option.offsetY)for(var i in n.node)if(!n.node[i].show){var s=0,p=i;do{p=n.node[p].pid,s++}while(!n.node[p].show);n.node[i].left+=this.__option.offsetX*s,n.node[i].top+=this.__option.offsetY*s}if("rect"==this.__option.type){if("LR"==this.__option.direction||"RL"==this.__option.direction){var h=this.__option.height/n.size,d=this.__option.width/(n.deep-1),_=this.__option.y-.5*this.__option.height,l="LR"==this.__option.direction?1:-1;for(var i in n.node)1==n.deep?(n.node[i].left=this.__option.x+.5*this.__option.width*l,n.node[i].top=this.__option.y):(n.node[i].left=this.__option.x+(n.node[i].left-.5)*d*l,n.node[i].top=n.node[i].top*h+_)}else if("TB"==this.__option.direction||"BT"==this.__option.direction){h=this.__option.width/n.size,d=this.__option.height/(n.deep-1),_=this.__option.x-.5*this.__option.width,l="TB"==this.__option.direction?1:-1;for(var i in n.node)if(n.node[i].deg="TB"==this.__option.direction?.5*Math.PI:-.5*Math.PI,1==n.deep)n.node[i].left=this.__option.x,n.node[i].top=this.__option.y+.5*this.__option.height*l;else{var a=n.node[i].left;n.node[i].left=n.node[i].top*h+_,n.node[i].top=this.__option.y+(a-.5)*d*l}}}else if("circle"==this.__option.type){var u=this.__option.x,f=this.__option.y,c=2*Math.PI/n.size,v=this.__option.radius/(n.deep-1);for(var i in n.node)if(.5==n.node[i].left)n.node[i].left=u,n.node[i].top=f;else{var T=r(u,f,c*n.node[i].top,u+(n.node[i].left-.5)*v,f);n.node[i].deg=c*n.node[i].top,n.node[i].left=T[0],n.node[i].top=T[1]}}return n},s.prototype.bind=function(t,e,o){return void 0===o&&(o={}),this.__rback=e,this.__oralTree=t,this.__noOpens=o,this.__preTree=this.use(this.__oralTree,this.__noOpens),this.__rback(this.__preTree),this},s.prototype.unbind=function(){return this.__rback=function(){return null},this.__oralTree=null,this.__preTree=null,this.__noOpens={},this},s.prototype.doUpdate=function(){var t=this,e=this.use(this.__oralTree,this.__noOpens),o=JSON.parse(JSON.stringify(e));return function(t,e,o){arguments.length<2&&(e=400),arguments.length<3&&(o=function(){});let r={timer:function(t,e,o){if(!t)throw new Error("Tick is required!");let n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return i.push({id:n,createTime:new Date,pauseTime:-1,pauseKeepTime:0,status:"running",tick:t,duration:e,callback:o}),r.start(),n},start:function(){if(!n)try{n=globalThis&&globalThis.requestAnimationFrame?globalThis.requestAnimationFrame((function t(){r.tick(),n&&(n=globalThis.requestAnimationFrame(t))})):setInterval(r.tick,13)}catch(t){n=setInterval(r.tick,13)}},tick:function(){let t,e,o,n,s,p,h,d=i;for(i=[],i.length=0,e=0;e<d.length;e++)s=d[e],t=s.createTime,o=s.tick,p=s.duration,n=s.callback,h=(+(new Date).valueOf()-t.valueOf()-s.pauseKeepTime)/p,h=h>1?1:h,"running"===s.status&&o(h),(h<1||"paused"===s.status)&&s.id?i.push(s):n(h);i.length<=0&&r.stop()},stop:function(){if(n){try{globalThis&&globalThis.requestAnimationFrame?globalThis.cancelAnimationFrame(n):clearInterval(n)}catch(t){clearInterval(n)}n=null}}},s=r.timer((function(e){t(e)}),e,o)}((function(n){if(t.__preTree)for(var i in o.node)(e.node[i].show||t.__preTree.node[i].show)&&(o.node[i].show=!0,o.node[i].left=t.__preTree.node[i].left+(e.node[i].left-t.__preTree.node[i].left)*n,o.node[i].top=t.__preTree.node[i].top+(e.node[i].top-t.__preTree.node[i].top)*n);t.__rback(o)}),this.__option.duration,(function(){t.__preTree=e,t.__rback(t.__preTree)})),this},s.prototype.closeNode=function(t){return this.__preTree?(this.__noOpens[t]=!0,this.doUpdate(),this):this},s.prototype.openNode=function(t){return this.__preTree?(this.__noOpens[t]=!1,this.doUpdate(),this):this},s.prototype.toggleNode=function(t){return this.__preTree?(this.__noOpens[t]=!this.__noOpens[t],this.doUpdate(),this):this},s}(o);export{s as default};