1 |
- define("echarts/chart/force","require ./base ../data/Graph ../layout/Force zrender/shape/Line zrender/shape/BezierCurve zrender/shape/Image ../util/shape/Icon ../config ../util/ecData zrender/tool/util zrender/config zrender/tool/vector ../chart".split(" "),function(r){function t(a,h,m,n,f){var v=this;e.call(this,a,h,m,n,f);this.__nodePositionMap={};this._graph=new c(!0);this._layout=new p;this._layout.onupdate=function(){v._step()};this._steps=1;this.ondragstart=function(){l.apply(v,arguments)};this.ondragend=function(){d.apply(v,arguments)};this.ondrop=function(){};this.shapeHandler.ondragstart=function(){v.isDragstart=!0};this.onmousemove=function(){b.apply(v,arguments)};this.refresh(n)}function l(a){this.isDragstart&&a.target&&(a.target.fixed=!0,this.isDragstart=!1,this.zr.on(u.EVENT.MOUSEMOVE,this.onmousemove))}function b(){this._layout.temperature=.8;this._step()}function d(a,h){this.isDragend&&a.target&&(a.target.fixed=!1,h.dragIn=!0,this.isDragend=h.needRefresh=!1,this.zr.un(u.EVENT.MOUSEMOVE,this.onmousemove))}var e=r("./base"),c=r("../data/Graph"),p=r("../layout/Force"),q=r("zrender/shape/Line"),g=r("zrender/shape/BezierCurve"),a=r("zrender/shape/Image"),h=r("../util/shape/Icon"),m=r("../config");m.force={zlevel:1,z:2,center:["50%","50%"],size:"80%",preventOverlap:!1,coolDown:.99,minRadius:10,maxRadius:20,ratioScaling:!1,large:!1,useWorker:!1,steps:1,scaling:1,gravity:1.2,symbol:"circle",symbolSize:0,linkSymbol:null,linkSymbolSize:[10,15],draggable:!0,clickable:!0,roam:!1,itemStyle:{normal:{label:{show:!1,position:"inside"},nodeStyle:{brushType:"both",borderColor:"#5182ab",borderWidth:1},linkStyle:{color:"#5182ab",width:1,type:"line"}},emphasis:{label:{show:!1},nodeStyle:{},linkStyle:{opacity:0}}}};var n=r("../util/ecData"),f=r("zrender/tool/util"),u=r("zrender/config"),k=r("zrender/tool/vector");return t.prototype={constructor:t,type:m.CHART_TYPE_FORCE,_init:function(){var a,h=this.component.legend,c=this.series;this.clear();for(var b=0,n=c.length;n>b;b++){var d=c[b];if(d.type===m.CHART_TYPE_FORCE&&(c[b]=this.reformOption(c[b]),a=c[b].name||"",this.selectedMap[a]=h?h.isSelected(a):!0,this.selectedMap[a])){this.buildMark(b);this._initSerie(d,b);break}}this.animationEffect()},_getNodeCategory:function(a,h){return a.categories&&a.categories[h.category||0]},_getNodeQueryTarget:function(a,h,m){m=m||"normal";var c=this._getNodeCategory(a,h)||{};return[h.itemStyle&&h.itemStyle[m],c&&c.itemStyle&&c.itemStyle[m],a.itemStyle[m].nodeStyle]},_getEdgeQueryTarget:function(a,h,m){return m=m||"normal",[h.itemStyle&&h.itemStyle[m],a.itemStyle[m].linkStyle]},_initSerie:function(a,h){this._temperature=1;this._graph=a.data?this._getSerieGraphFromDataMatrix(a):this._getSerieGraphFromNodeLinks(a);this._buildLinkShapes(a,h);this._buildNodeShapes(a,h);var c=!0===a.roam||"move"===a.roam,b=!0===a.roam||"scale"===a.roam;this.zr.modLayer(this.getZlevelBase(),{panable:c,zoomable:b});(this.query("markPoint.effect.show")||this.query("markLine.effect.show"))&&this.zr.modLayer(m.EFFECT_ZLEVEL,{panable:c,zoomable:b});this._initLayout(a);this._step()},_getSerieGraphFromDataMatrix:function(a){for(var h=[],m=0,b=[],n=0;n<a.matrix.length;n++)b[n]=a.matrix[n].slice();for(var d=a.data||a.nodes,n=0;n<d.length;n++){var e={},f=d[n],p;for(p in f)"name"===p?e.id=f.name:e[p]=f[p];var g=this._getNodeCategory(a,f),f=g?g.name:f.name;if(this.selectedMap[f]=this.isSelected(f),this.selectedMap[f])h.push(e),m++;else for(b.splice(m,1),e=0;e<b.length;e++)b[e].splice(m,1)}a=c.fromMatrix(h,b,!0);return a.eachNode(function(a,h){a.layout={size:a.data.value,mass:0};a.rawIndex=h}),a.eachEdge(function(a){a.layout={weight:a.data.weight}}),a},_getSerieGraphFromNodeLinks:function(a){for(var h=new c(!0),m=a.data||a.nodes,b=0,n=m.length;n>b;b++){var d=m[b];if(d&&!d.ignore){var e=this._getNodeCategory(a,d),e=e?e.name:d.name;if(this.selectedMap[e]=this.isSelected(e),this.selectedMap[e])h.addNode(d.name,d).rawIndex=b}}b=0;for(n=a.links.length;n>b;b++){var d=a.links[b],e=d.source,f=d.target;"number"==typeof e&&(e=m[e],e&&(e=e.name));"number"==typeof f&&(f=m[f],f&&(f=f.name));(d=h.addEdge(e,f,d))&&(d.rawIndex=b)}return h.eachNode(function(a){var h=a.data.value;if(null==h)for(var m=h=0;m<a.edges.length;m++)h+=a.edges[m].data.weight||0;a.layout={size:h,mass:0}}),h.eachEdge(function(a){a.layout={weight:null==a.data.weight?1:a.data.weight}}),h},_initLayout:function(a){var h=this._graph,m=h.nodes.length,b=this.query(a,"minRadius"),c=this.query(a,"maxRadius");this._steps=a.steps||1;this._layout.center=this.parseCenter(this.zr,a.center);this._layout.width=this.parsePercent(a.size,this.zr.getWidth());this._layout.height=this.parsePercent(a.size,this.zr.getHeight());this._layout.large=a.large;this._layout.scaling=a.scaling;this._layout.ratioScaling=a.ratioScaling;this._layout.gravity=a.gravity;this._layout.temperature=1;this._layout.coolDown=a.coolDown;this._layout.preventNodeEdgeOverlap=a.preventOverlap;this._layout.preventNodeOverlap=a.preventOverlap;for(var d=1/0,n=-1/0,e=0;m>e;e++)var f=h.nodes[e],n=Math.max(f.layout.size,n),d=Math.min(f.layout.size,d);n-=d;for(e=0;m>e;e++)f=h.nodes[e],0<n?(f.layout.size=(f.layout.size-d)*(c-b)/n+b,f.layout.mass=f.layout.size/c):(f.layout.size=(c-b)/2,f.layout.mass=.5);for(e=0;m>e;e++){f=h.nodes[e];if("undefined"!=typeof this.__nodePositionMap[f.id])f.layout.position=k.create(),k.copy(f.layout.position,this.__nodePositionMap[f.id]);else if("undefined"!=typeof f.data.initial)f.layout.position=k.create(),k.copy(f.layout.position,f.data.initial);else{var d=this._layout.center,b=f.layout,c=d[0],d=d[1],n=.8*Math.min(this._layout.width,this._layout.height),p=k.create(),c=(p[0]=(Math.random()-.5)*n+c,p[1]=(Math.random()-.5)*n+d,p);b.position=c}b=f.shape.style;c=f.layout.size;b.width=b.width||2*c;b.height=b.height||2*c;b.x=-b.width/2;b.y=-b.height/2;k.copy(f.shape.position,f.layout.position)}m=h.edges.length;n=-1/0;for(e=0;m>e;e++)f=h.edges[e],f.layout.weight>n&&(n=f.layout.weight);for(e=0;m>e;e++)f=h.edges[e],f.layout.weight/=n;this._layout.init(h,a.useWorker)},_buildNodeShapes:function(m,b){var c=this._graph;this.query(m,"categories");c.eachNode(function(c){var e=this._getNodeCategory(m,c.data),f=[c.data,e,m],d=this._getNodeQueryTarget(m,c.data),p=this._getNodeQueryTarget(m,c.data,"emphasis"),d=new h({style:{x:0,y:0,color:this.deepQuery(d,"color"),brushType:"both",strokeColor:this.deepQuery(d,"strokeColor")||this.deepQuery(d,"borderColor"),lineWidth:this.deepQuery(d,"lineWidth")||this.deepQuery(d,"borderWidth")},highlightStyle:{color:this.deepQuery(p,"color"),strokeColor:this.deepQuery(p,"strokeColor")||this.deepQuery(p,"borderColor"),lineWidth:this.deepQuery(p,"lineWidth")||this.deepQuery(p,"borderWidth")},clickable:m.clickable,zlevel:this.getZlevelBase(),z:this.getZBase()});d.style.color||(d.style.color=this.getColor(e?e.name:c.id));d.style.iconType=this.deepQuery(f,"symbol");d.style.width=d.style.height=2*(this.deepQuery(f,"symbolSize")||0);d.style.iconType.match("image")&&(d.style.image=d.style.iconType.replace(/^image:\/\//,""),d=new a({style:d.style,highlightStyle:d.highlightStyle,clickable:d.clickable,zlevel:this.getZlevelBase(),z:this.getZBase()}));this.deepQuery(f,"itemStyle.normal.label.show")&&(d.style.text=null==c.data.label?c.id:c.data.label,d.style.textPosition=this.deepQuery(f,"itemStyle.normal.label.position"),d.style.textColor=this.deepQuery(f,"itemStyle.normal.label.textStyle.color"),d.style.textFont=this.getFont(this.deepQuery(f,"itemStyle.normal.label.textStyle")||{}));this.deepQuery(f,"itemStyle.emphasis.label.show")&&(d.highlightStyle.textPosition=this.deepQuery(f,"itemStyle.emphasis.label.position"),d.highlightStyle.textColor=this.deepQuery(f,"itemStyle.emphasis.label.textStyle.color"),d.highlightStyle.textFont=this.getFont(this.deepQuery(f,"itemStyle.emphasis.label.textStyle")||{}));this.deepQuery(f,"draggable")&&(this.setCalculable(d),d.dragEnableTime=0,d.draggable=!0,d.ondragstart=this.shapeHandler.ondragstart,d.ondragover=null);n.pack(d,m,b,c.data,c.rawIndex,c.data.name||"",c.category);this.shapeList.push(d);this.zr.addShape(d);c.shape=d},this)},_buildLinkShapes:function(a,m){for(var d=this._graph,b=d.edges.length,c=0;b>c;c++){var e=d.edges[c],p=e.data,u=e.node1,l=e.node2,k=this._getEdgeQueryTarget(a,p),k=this.deepQuery(k,"type");a.linkSymbol&&"none"!==a.linkSymbol&&(k="line");k=new ("line"===k?q:g)({style:{xStart:0,yStart:0,xEnd:0,yEnd:0},clickable:this.query(a,"clickable"),highlightStyle:{},zlevel:this.getZlevelBase(),z:this.getZBase()});if(f.merge(k.style,this.query(a,"itemStyle.normal.linkStyle"),!0),f.merge(k.highlightStyle,this.query(a,"itemStyle.emphasis.linkStyle"),!0),"undefined"!=typeof p.itemStyle&&(p.itemStyle.normal&&f.merge(k.style,p.itemStyle.normal,!0),p.itemStyle.emphasis&&f.merge(k.highlightStyle,p.itemStyle.emphasis,!0)),k.style.lineWidth=k.style.lineWidth||k.style.width,k.style.strokeColor=k.style.strokeColor||k.style.color,k.highlightStyle.lineWidth=k.highlightStyle.lineWidth||k.highlightStyle.width,k.highlightStyle.strokeColor=k.highlightStyle.strokeColor||k.highlightStyle.color,n.pack(k,a,m,e.data,null==e.rawIndex?c:e.rawIndex,e.data.name||u.id+" - "+l.id,u.id,l.id),this.shapeList.push(k),this.zr.addShape(k),e.shape=k,a.linkSymbol&&"none"!==a.linkSymbol)e=new h({style:{x:-5,y:0,width:a.linkSymbolSize[0],height:a.linkSymbolSize[1],iconType:a.linkSymbol,brushType:"fill",color:k.style.strokeColor},highlightStyle:{brushType:"fill"},position:[0,0],rotation:0}),k._symbolShape=e,this.shapeList.push(e),this.zr.addShape(e)}},_updateLinkShapes:function(){for(var a=k.create(),h=this._graph.edges,m=0,d=h.length;d>m;m++){var c=h[m],b=c.node1.shape,e=c.node2.shape,f=b.position,n=e.position;if(c.shape.style.xStart=f[0],c.shape.style.yStart=f[1],c.shape.style.xEnd=n[0],c.shape.style.yEnd=n[1],"bezier-curve"===c.shape.type&&(c.shape.style.cpX1=(f[0]+n[0])/2-(n[1]-f[1])/4,c.shape.style.cpY1=(f[1]+n[1])/2-(f[0]-n[0])/4),c.shape.modSelf(),c.shape._symbolShape)c=c.shape._symbolShape,k.copy(c.position,e.position),k.sub(a,b.position,e.position),k.normalize(a,a),k.scaleAndAdd(c.position,c.position,a,e.style.width/2+2),c.rotation=Math.PI/2-Math.atan2(a[1],a[0]),c.modSelf()}},_syncNodePositions:function(){for(var a=this._graph,h=0;h<a.nodes.length;h++){var c=a.nodes[h],m=c.layout.position,d=c.data,c=c.shape,b=c.fixed||d.fixX,e=c.fixed||d.fixY;!0===b?b=1:isNaN(b)&&(b=0);!0===e?e=1:isNaN(e)&&(e=0);c.position[0]+=(m[0]-c.position[0])*(1-b);c.position[1]+=(m[1]-c.position[1])*(1-e);k.copy(m,c.position);if(d=d.name)(b=this.__nodePositionMap[d])||(b=this.__nodePositionMap[d]=k.create()),k.copy(b,m);c.modSelf()}},_step:function(){this._syncNodePositions();this._updateLinkShapes();this.zr.refreshNextFrame();.01<this._layout.temperature?this._layout.step(this._steps):this.messageCenter.dispatch(m.EVENT.FORCE_LAYOUT_END,{},{},this.myChart)},refresh:function(a){if(a&&(this.option=a,this.series=this.option.series),this.legend=this.component.legend,this.legend)this.getColor=function(a){return this.legend.getColor(a)},this.isSelected=function(a){return this.legend.isSelected(a)};else{var h={},c=0;this.getColor=function(a){return h[a]?h[a]:(h[a]||(h[a]=this.zr.getColor(c++)),h[a])};this.isSelected=function(){return!0}}this._init()},dispose:function(){this.clear();this.effectList=this.shapeList=null;this._layout.dispose();this._layout=null;this.__nodePositionMap={}},getPosition:function(){var a=[];return this._graph.eachNode(function(h){h.layout&&a.push({name:h.data.name,position:Array.prototype.slice.call(h.layout.position)})}),a}},f.inherits(t,e),r("../chart").define("force",t),t});define("echarts/data/Graph",["require","zrender/tool/util"],function(r){var t=r("zrender/tool/util"),l=function(b){this._directed=b||!1;this.nodes=[];this.edges=[];this._nodesMap={};this._edgesMap={}};l.prototype.isDirected=function(){return this._directed};l.prototype.addNode=function(b,d){if(this._nodesMap[b])return this._nodesMap[b];var e=new l.Node(b,d);return this.nodes.push(e),this._nodesMap[b]=e,e};l.prototype.getNodeById=function(b){return this._nodesMap[b]};l.prototype.addEdge=function(b,d,e){if("string"==typeof b&&(b=this._nodesMap[b]),"string"==typeof d&&(d=this._nodesMap[d]),b&&d){var c=b.id+"-"+d.id;if(this._edgesMap[c])return this._edgesMap[c];e=new l.Edge(b,d,e);return this._directed&&(b.outEdges.push(e),d.inEdges.push(e)),b.edges.push(e),b!==d&&d.edges.push(e),this.edges.push(e),this._edgesMap[c]=e,e}};l.prototype.removeEdge=function(b){var d=b.node1,e=b.node2,c=d.id+"-"+e.id;this._directed&&(d.outEdges.splice(t.indexOf(d.outEdges,b),1),e.inEdges.splice(t.indexOf(e.inEdges,b),1));d.edges.splice(t.indexOf(d.edges,b),1);d!==e&&e.edges.splice(t.indexOf(e.edges,b),1);delete this._edgesMap[c];this.edges.splice(t.indexOf(this.edges,b),1)};l.prototype.getEdge=function(b,d){return"string"!=typeof b&&(b=b.id),"string"!=typeof d&&(d=d.id),this._directed?this._edgesMap[b+"-"+d]:this._edgesMap[b+"-"+d]||this._edgesMap[d+"-"+b]};l.prototype.removeNode=function(b){if("string"!=typeof b||(b=this._nodesMap[b])){delete this._nodesMap[b.id];this.nodes.splice(t.indexOf(this.nodes,b),1);for(var d=0;d<this.edges.length;){var e=this.edges[d];e.node1===b||e.node2===b?this.removeEdge(e):d++}}};l.prototype.filterNode=function(b,d){for(var e=this.nodes.length,c=0;e>c;)b.call(d,this.nodes[c],c)?c++:(this.removeNode(this.nodes[c]),e--)};l.prototype.filterEdge=function(b,d){for(var e=this.edges.length,c=0;e>c;)b.call(d,this.edges[c],c)?c++:(this.removeEdge(this.edges[c]),e--)};l.prototype.eachNode=function(b,d){for(var e=this.nodes.length,c=0;e>c;c++)this.nodes[c]&&b.call(d,this.nodes[c],c)};l.prototype.eachEdge=function(b,d){for(var e=this.edges.length,c=0;e>c;c++)this.edges[c]&&b.call(d,this.edges[c],c)};l.prototype.clear=function(){this.nodes.length=0;this.edges.length=0;this._nodesMap={};this._edgesMap={}};l.prototype.breadthFirstTraverse=function(b,d,e,c){if("string"==typeof d&&(d=this._nodesMap[d]),d){var p="edges";"out"===e?p="outEdges":"in"===e&&(p="inEdges");for(e=0;e<this.nodes.length;e++)this.nodes[e].__visited=!1;if(!b.call(c,d,null))for(d=[d];d.length;){c=d.shift();var q=c[p];for(e=0;e<q.length;e++){var g=q[e],g=g.node1===c?g.node2:g.node1;if(!g.__visited){if(b.call(g,g,c))return;d.push(g);g.__visited=!0}}}}};l.prototype.clone=function(){for(var b=new l(this._directed),d=0;d<this.nodes.length;d++)b.addNode(this.nodes[d].id,this.nodes[d].data);for(d=0;d<this.edges.length;d++){var e=this.edges[d];b.addEdge(e.node1.id,e.node2.id,e.data)}return b};r=function(b,d){this.id=b;this.data=d||null;this.inEdges=[];this.outEdges=[];this.edges=[]};r.prototype.degree=function(){return this.edges.length};r.prototype.inDegree=function(){return this.inEdges.length};r.prototype.outDegree=function(){return this.outEdges.length};return l.Node=r,l.Edge=function(b,d,e){this.node1=b;this.node2=d;this.data=e||null},l.fromMatrix=function(b,d,e){if(d&&d.length&&d[0].length===d.length&&b.length===d.length){for(var c=d.length,p=new l(e),q=0;c>q;q++){var g=p.addNode(b[q].id,b[q]);g.data.value=0;e&&(g.data.outValue=g.data.inValue=0)}for(q=0;c>q;q++)for(b=0;c>b;b++)g=d[q][b],e&&(p.nodes[q].data.outValue+=g,p.nodes[b].data.inValue+=g),p.nodes[q].data.value+=g,p.nodes[b].data.value+=g;for(q=0;c>q;q++)for(b=q;c>b;b++)if(g=d[q][b],0!==g){var a=p.nodes[q],h=p.nodes[b];if(p.addEdge(a,h,{}).data.weight=g,q!==b&&e&&d[b][q])p.addEdge(h,a,{}).data.weight=d[b][q]}return p}},l});define("echarts/layout/Force",["require","./forceLayoutWorker","zrender/tool/vector"],function(r){function t(){if("undefined"!=typeof Worker&&"undefined"!=typeof Blob)try{var c=new Blob([b.getWorkerCode()]);l=window.URL.createObjectURL(c)}catch(d){l=""}return l}var l,b=r("./forceLayoutWorker"),d=r("zrender/tool/vector"),e=window.requestAnimationFrame||window.msRequestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||function(c){setTimeout(c,16)},c="undefined"==typeof Float32Array?Array:Float32Array;r=function(c){"undefined"==typeof l&&t();c=c||{};this.width=c.width||500;this.height=c.height||500;this.center=c.center||[this.width/2,this.height/2];this.ratioScaling=c.ratioScaling||!1;this.scaling=c.scaling||1;this.gravity="undefined"!=typeof c.gravity?c.gravity:1;this.large=c.large||!1;this.preventNodeOverlap=c.preventNodeOverlap||!1;this.preventNodeEdgeOverlap=c.preventNodeEdgeOverlap||!1;this.maxSpeedIncrease=c.maxSpeedIncrease||1;this.onupdate=c.onupdate||function(){};this.temperature=c.temperature||1;this.coolDown=c.coolDown||.99;this._layoutWorker=this._layout=null;var d=this,b=this._$onupdate;this._$onupdate=function(a){b.call(d,a)}};return r.prototype.updateConfig=function(){var c=this.width,d=this.height,b=Math.min(c,d),c={center:this.center,width:this.ratioScaling?c:b,height:this.ratioScaling?d:b,scaling:this.scaling||1,gravity:this.gravity||1,barnesHutOptimize:this.large,preventNodeOverlap:this.preventNodeOverlap,preventNodeEdgeOverlap:this.preventNodeEdgeOverlap,maxSpeedIncrease:this.maxSpeedIncrease};if(this._layoutWorker)this._layoutWorker.postMessage({cmd:"updateConfig",config:c});else for(var a in c)this._layout[a]=c[a]},r.prototype.init=function(d,e){if(l&&e)try{this._layoutWorker||(this._layoutWorker=new Worker(l),this._layoutWorker.onmessage=this._$onupdate),this._layout=null}catch(r){this._layoutWorker=null,this._layout||(this._layout=new b)}else this._layout||(this._layout=new b),this._layoutWorker&&(this._layoutWorker.terminate(),this._layoutWorker=null);this.temperature=1;this.graph=d;for(var g=d.nodes.length,a=new c(2*g),h=new c(g),m=new c(g),n=0;g>n;n++){var f=d.nodes[n];a[2*n]=f.layout.position[0];a[2*n+1]=f.layout.position[1];h[n]="undefined"==typeof f.layout.mass?1:f.layout.mass;m[n]="undefined"==typeof f.layout.size?1:f.layout.size;f.layout.__index=n}for(var g=d.edges.length,f=new c(2*g),u=new c(g),n=0;g>n;n++){var k=d.edges[n];f[2*n]=k.node1.layout.__index;f[2*n+1]=k.node2.layout.__index;u[n]=k.layout.weight||1}this._layoutWorker?this._layoutWorker.postMessage({cmd:"init",nodesPosition:a,nodesMass:h,nodesSize:m,edges:f,edgesWeight:u}):(this._layout.initNodes(a,h,m),this._layout.initEdges(f,u));this.updateConfig()},r.prototype.step=function(b){var q=this.graph.nodes;if(this._layoutWorker){for(var g=new c(2*q.length),a=0;a<q.length;a++){var h=q[a];g[2*a]=h.layout.position[0];g[2*a+1]=h.layout.position[1]}this._layoutWorker.postMessage(g.buffer,[g.buffer]);this._layoutWorker.postMessage({cmd:"update",steps:b,temperature:this.temperature,coolDown:this.coolDown});for(a=0;b>a;a++)this.temperature*=this.coolDown}else{e(this._$onupdate);for(a=0;a<q.length;a++)h=q[a],d.copy(this._layout.nodes[a].position,h.layout.position);for(a=0;b>a;a++)this._layout.temperature=this.temperature,this._layout.update(),this.temperature*=this.coolDown}},r.prototype._$onupdate=function(c){if(this._layoutWorker){c=new Float32Array(c.data);for(var b=0;b<this.graph.nodes.length;b++){var e=this.graph.nodes[b];e.layout.position[0]=c[2*b];e.layout.position[1]=c[2*b+1]}this.onupdate&&this.onupdate()}else if(this._layout){for(b=0;b<this.graph.nodes.length;b++)e=this.graph.nodes[b],d.copy(e.layout.position,this._layout.nodes[b].position);this.onupdate&&this.onupdate()}},r.prototype.dispose=function(){this._layoutWorker&&this._layoutWorker.terminate();this._layout=this._layoutWorker=null},r});define("zrender/shape/BezierCurve",["require","./Base","../tool/util"],function(r){var t=r("./Base"),l=function(b){this.brushTypeOnly="stroke";this.textPosition="end";t.call(this,b)};return l.prototype={type:"bezier-curve",buildPath:function(b,d){b.moveTo(d.xStart,d.yStart);"undefined"!=typeof d.cpX2&&"undefined"!=typeof d.cpY2?b.bezierCurveTo(d.cpX1,d.cpY1,d.cpX2,d.cpY2,d.xEnd,d.yEnd):b.quadraticCurveTo(d.cpX1,d.cpY1,d.xEnd,d.yEnd)},getRect:function(b){if(b.__rect)return b.__rect;var d=Math.min(b.xStart,b.xEnd,b.cpX1),e=Math.min(b.yStart,b.yEnd,b.cpY1),c=Math.max(b.xStart,b.xEnd,b.cpX1),l=Math.max(b.yStart,b.yEnd,b.cpY1),q=b.cpX2,g=b.cpY2;"undefined"!=typeof q&&"undefined"!=typeof g&&(d=Math.min(d,q),e=Math.min(e,g),c=Math.max(c,q),l=Math.max(l,g));q=b.lineWidth||1;return b.__rect={x:d-q,y:e-q,width:c-d+q,height:l-e+q},b.__rect}},r("../tool/util").inherits(l,t),l});define("echarts/layout/forceLayoutWorker",["require","zrender/tool/vector"],function t$$0(t){function l(){this.subRegions=[];this.nSubRegions=0;this.node=null;this.mass=0;this.centerOfMass=null;this.bbox=new q(4);this.size=0}function b(){this.position=c.create();this.force=c.create();this.forcePrev=c.create();this.speed=c.create();this.speedPrev=c.create();this.mass=1;this.outDegree=this.inDegree=0}function d(a,c){this.node1=a;this.node2=c;this.weight=1}function e(){this.barnesHutOptimize=!1;this.barnesHutTheta=1.5;this.preventNodeEdgeOverlap=this.preventNodeOverlap=this.repulsionByDegree=!1;this.strongGravity=!0;this.edgeWeightInfluence=this.scaling=this.gravity=1;this.center=[0,0];this.height=this.width=500;this.maxSpeedIncrease=1;this.nodes=[];this.edges=[];this.bbox=new q(4);this._rootRegion=new l;this._rootRegion.centerOfMass=c.create();this._massArr=null;this._k=0}var c,p="undefined"==typeof window&&"undefined"==typeof t;c=p?{create:function(a,c){var b=new Float32Array(2);return b[0]=a||0,b[1]=c||0,b},dist:function(a,c){var b=c[0]-a[0],d=c[1]-a[1];return Math.sqrt(b*b+d*d)},len:function(a){var c=a[0];a=a[1];return Math.sqrt(c*c+a*a)},scaleAndAdd:function(a,c,b,d){return a[0]=c[0]+b[0]*d,a[1]=c[1]+b[1]*d,a},scale:function(a,c,b){return a[0]=c[0]*b,a[1]=c[1]*b,a},add:function(a,c,b){return a[0]=c[0]+b[0],a[1]=c[1]+b[1],a},sub:function(a,c,b){return a[0]=c[0]-b[0],a[1]=c[1]-b[1],a},dot:function(a,c){return a[0]*c[0]+a[1]*c[1]},normalize:function(a,c){var b=c[0],d=c[1],b=b*b+d*d;return 0<b&&(b=1/Math.sqrt(b),a[0]=c[0]*b,a[1]=c[1]*b),a},negate:function(a,c){return a[0]=-c[0],a[1]=-c[1],a},copy:function(a,c){return a[0]=c[0],a[1]=c[1],a},set:function(a,c,b){return a[0]=c,a[1]=b,a}}:t("zrender/tool/vector");var q="undefined"==typeof Float32Array?Array:Float32Array;if(l.prototype.beforeUpdate=function(){for(var a=0;a<this.nSubRegions;a++)this.subRegions[a].beforeUpdate();this.mass=0;this.centerOfMass&&(this.centerOfMass[0]=0,this.centerOfMass[1]=0);this.nSubRegions=0;this.node=null},l.prototype.afterUpdate=function(){this.subRegions.length=this.nSubRegions;for(var a=0;a<this.nSubRegions;a++)this.subRegions[a].afterUpdate()},l.prototype.addNode=function(a){if(0===this.nSubRegions){if(null==this.node)return void(this.node=a);this._addNodeToSubRegion(this.node);this.node=null}this._addNodeToSubRegion(a);this._updateCenterOfMass(a)},l.prototype.findSubRegion=function(a,c){for(var b=0;b<this.nSubRegions;b++){var d=this.subRegions[b];if(d.contain(a,c))return d}},l.prototype.contain=function(a,c){return this.bbox[0]<=a&&this.bbox[2]>=a&&this.bbox[1]<=c&&this.bbox[3]>=c},l.prototype.setBBox=function(a,c,b,d){this.bbox[0]=a;this.bbox[1]=c;this.bbox[2]=b;this.bbox[3]=d;this.size=(b-a+d-c)/2},l.prototype._newSubRegion=function(){var a=this.subRegions[this.nSubRegions];return a||(a=new l,this.subRegions[this.nSubRegions]=a),this.nSubRegions++,a},l.prototype._addNodeToSubRegion=function(a){var c=this.findSubRegion(a.position[0],a.position[1]),b=this.bbox;if(!c){var d=(b[2]-b[0])/2,e=(b[3]-b[1])/2,g=a.position[0]>=(b[0]+b[2])/2?1:0,k=a.position[1]>=(b[1]+b[3])/2?1:0,c=this._newSubRegion();c.setBBox(g*d+b[0],k*e+b[1],(g+1)*d+b[0],(k+1)*e+b[1])}c.addNode(a)},l.prototype._updateCenterOfMass=function(a){null==this.centerOfMass&&(this.centerOfMass=c.create());var b=this.centerOfMass[0]*this.mass,d=this.centerOfMass[1]*this.mass,b=b+a.position[0]*a.mass,d=d+a.position[1]*a.mass;this.mass+=a.mass;this.centerOfMass[0]=b/this.mass;this.centerOfMass[1]=d/this.mass},e.prototype.nodeToNodeRepulsionFactor=function(a,c,b){return b*b*a/c},e.prototype.edgeToNodeRepulsionFactor=function(a,c,b){return b*a/c},e.prototype.attractionFactor=function(a,c,b){return a*c/b},e.prototype.initNodes=function(a,c,d){this.temperature=1;var e=a.length/2;this.nodes.length=0;for(var f="undefined"!=typeof d,g=0;e>g;g++){var k=new b;k.position[0]=a[2*g];k.position[1]=a[2*g+1];k.mass=c[g];f&&(k.size=d[g]);this.nodes.push(k)}this._massArr=c;f&&(this._sizeArr=d)},e.prototype.initEdges=function(a,c){var b=a.length/2;this.edges.length=0;for(var e="undefined"!=typeof c,f=0;b>f;f++){var g=this.nodes[a[2*f]],k=this.nodes[a[2*f+1]];g&&k&&(g.outDegree++,k.inDegree++,g=new d(g,k),e&&(g.weight=c[f]),this.edges.push(g))}},e.prototype.update=function(){var a=this.nodes.length;if(this.updateBBox(),this._k=.4*this.scaling*Math.sqrt(this.width*this.height/a),this.barnesHutOptimize){this._rootRegion.setBBox(this.bbox[0],this.bbox[1],this.bbox[2],this.bbox[3]);this._rootRegion.beforeUpdate();for(var b=0;a>b;b++)this._rootRegion.addNode(this.nodes[b]);this._rootRegion.afterUpdate()}else{var d=0,e=this._rootRegion.centerOfMass;c.set(e,0,0);for(b=0;a>b;b++){var f=this.nodes[b],d=d+f.mass;c.scaleAndAdd(e,e,f.position,f.mass)}0<d&&c.scale(e,e,1/d)}this.updateForce();this.updatePosition()},e.prototype.updateForce=function(){for(var a=this.nodes.length,b=0;a>b;b++){var d=this.nodes[b];c.copy(d.forcePrev,d.force);c.copy(d.speedPrev,d.speed);c.set(d.force,0,0)}this.updateNodeNodeForce();0<this.gravity&&this.updateGravityForce();this.updateEdgeForce();this.preventNodeEdgeOverlap&&this.updateNodeEdgeForce()},e.prototype.updatePosition=function(){for(var a=this.nodes.length,b=c.create(),d=0;a>d;d++){var e=this.nodes[d],f=e.speed;c.scale(e.force,e.force,1/30);var g=c.len(e.force)+.1,g=Math.min(g,500)/g;c.scale(e.force,e.force,g);c.add(f,f,e.force);c.scale(f,f,this.temperature);c.sub(b,f,e.speedPrev);g=c.len(b);if(0<g){c.scale(b,b,1/g);var k=c.len(e.speedPrev);0<k&&(g=Math.min(g/k,this.maxSpeedIncrease)*k,c.scaleAndAdd(f,e.speedPrev,b,g))}g=c.len(f);g=Math.min(g,100)/(g+.1);c.scale(f,f,g);c.add(e.position,e.position,f)}},e.prototype.updateNodeNodeForce=function(){for(var a=this.nodes.length,c=0;a>c;c++){var b=this.nodes[c];if(this.barnesHutOptimize)this.applyRegionToNodeRepulsion(this._rootRegion,b);else for(var d=c+1;a>d;d++)this.applyNodeToNodeRepulsion(b,this.nodes[d],!1)}},e.prototype.updateGravityForce=function(){for(var a=0;a<this.nodes.length;a++)this.applyNodeGravity(this.nodes[a])},e.prototype.updateEdgeForce=function(){for(var a=0;a<this.edges.length;a++)this.applyEdgeAttraction(this.edges[a])},e.prototype.updateNodeEdgeForce=function(){for(var a=0;a<this.nodes.length;a++)for(var c=0;c<this.edges.length;c++)this.applyEdgeToNodeRepulsion(this.edges[c],this.nodes[a])},e.prototype.applyRegionToNodeRepulsion=function(){var a=c.create();return function(b,d){if(b.node)this.applyNodeToNodeRepulsion(b.node,d,!0);else if(0!==b.mass||0!==d.mass){c.sub(a,d.position,b.centerOfMass);var e=a[0]*a[0]+a[1]*a[1];if(e>this.barnesHutTheta*b.size*b.size)c.scaleAndAdd(d.force,d.force,a,this._k*this._k*(d.mass+b.mass)/(e+1)*2);else for(e=0;e<b.nSubRegions;e++)this.applyRegionToNodeRepulsion(b.subRegions[e],d)}}}(),e.prototype.applyNodeToNodeRepulsion=function(){var a=c.create();return function(b,d,e){if(b!==d&&(0!==b.mass||0!==d.mass)){c.sub(a,b.position,d.position);var f=a[0]*a[0]+a[1]*a[1];if(0!==f){var g,k=b.mass+d.mass,f=Math.sqrt(f);c.scale(a,a,1/f);this.preventNodeOverlap?(f=f-b.size-d.size,0<f?g=this.nodeToNodeRepulsionFactor(k,f,this._k):0>=f&&(g=this._k*this._k*10*k)):g=this.nodeToNodeRepulsionFactor(k,f,this._k);e||c.scaleAndAdd(b.force,b.force,a,2*g);c.scaleAndAdd(d.force,d.force,a,2*-g)}}}}(),e.prototype.applyEdgeAttraction=function(){var a=c.create();return function(b){var d=b.node1,e=b.node2;c.sub(a,d.position,e.position);var f=c.len(a);b=0===this.edgeWeightInfluence?1:1==this.edgeWeightInfluence?b.weight:Math.pow(b.weight,this.edgeWeightInfluence);this.preventOverlap&&(f=f-d.size-e.size,0>=f)||(f=this.attractionFactor(b,f,this._k),c.scaleAndAdd(d.force,d.force,a,-f),c.scaleAndAdd(e.force,e.force,a,f))}}(),e.prototype.applyNodeGravity=function(){var a=c.create();return function(b){c.sub(a,this.center,b.position);this.width>this.height?a[1]*=this.width/this.height:a[0]*=this.height/this.width;var d=c.len(a)/100;this.strongGravity?c.scaleAndAdd(b.force,b.force,a,d*this.gravity*b.mass):c.scaleAndAdd(b.force,b.force,a,this.gravity*b.mass/(d+1))}}(),e.prototype.applyEdgeToNodeRepulsion=function(){var a=c.create(),b=c.create(),d=c.create();return function(e,f){var g=e.node1,k=e.node2;if(g!==f&&k!==f){c.sub(a,k.position,g.position);c.sub(b,f.position,g.position);var l=c.len(a);c.scale(a,a,1/l);var p=c.dot(a,b);0>p||p>l||(c.scaleAndAdd(d,g.position,a,p),l=c.dist(d,f.position)-f.size,l=this.edgeToNodeRepulsionFactor(f.mass,Math.max(l,.1),100),c.sub(a,f.position,d),c.normalize(a,a),c.scaleAndAdd(f.force,f.force,a,l),c.scaleAndAdd(g.force,g.force,a,-l),c.scaleAndAdd(k.force,k.force,a,-l))}}}(),e.prototype.updateBBox=function(){for(var a=1/0,b=1/0,c=-1/0,d=-1/0,e=0;e<this.nodes.length;e++)var g=this.nodes[e].position,a=Math.min(a,g[0]),b=Math.min(b,g[1]),c=Math.max(c,g[0]),d=Math.max(d,g[1]);this.bbox[0]=a;this.bbox[1]=b;this.bbox[2]=c;this.bbox[3]=d},e.getWorkerCode=function(){var a=t$$0.toString();return a.slice(a.indexOf("{")+1,a.lastIndexOf("return"))},p){var g=null;self.onmessage=function(a){if(a.data instanceof ArrayBuffer){if(g)for(var b=new Float32Array(a.data),c=b.length/2,d=0;c>d;d++)a=g.nodes[d],a.position[0]=b[2*d],a.position[1]=b[2*d+1]}else switch(a.data.cmd){case "init":g||(g=new e);g.initNodes(a.data.nodesPosition,a.data.nodesMass,a.data.nodesSize);g.initEdges(a.data.edges,a.data.edgesWeight);break;case "updateConfig":if(g)for(b in a.data.config)g[b]=a.data.config[b];break;case "update":var f=a.data.steps;if(g){c=g.nodes.length;b=new Float32Array(2*c);g.temperature=a.data.temperature;for(d=0;f>d;d++)g.update(),g.temperature*=a.data.coolDown;for(d=0;c>d;d++)a=g.nodes[d],b[2*d]=a.position[0],b[2*d+1]=a.position[1];self.postMessage(b.buffer,[b.buffer])}else a=new Float32Array,self.postMessage(a.buffer,[a.buffer])}}}return e});
|