mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-02 13:30:23 -05:00
1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
|
(function(undefined){"use strict";function Supervisor(sigInst,options){var _this=this,workerFn=sigInst.getForceAtlas2Worker&&sigInst.getForceAtlas2Worker();if(options=options||{},_root.URL=_root.URL||_root.webkitURL,this.sigInst=sigInst,this.graph=this.sigInst.graph,this.ppn=10,this.ppe=3,this.config={},this.shouldUseWorker=options.worker===!1?!1:!0&&webWorkers,this.workerUrl=options.workerUrl,this.started=!1,this.running=!1,this.shouldUseWorker){if(this.workerUrl)this.worker=new Worker(this.workerUrl);else{var blob=this.makeBlob(workerFn);this.worker=new Worker(URL.createObjectURL(blob))}this.worker.postMessage=this.worker.webkitPostMessage||this.worker.postMessage}else eval(workerFn);var msgName=this.worker?"message":"newCoords";(this.worker||document).addEventListener(msgName,function(t){_this.nodesByteArray=new Float32Array(t.data.nodes),_this.running&&(_this.applyLayoutChanges(),_this.sendByteArrayToWorker(),_this.sigInst.refresh())}),this.graphToByteArrays()}if("undefined"==typeof sigma)throw"sigma is not declared";var _root=this,webWorkers="Worker"in _root;Supervisor.prototype.makeBlob=function(t){var e;try{e=new Blob([t],{type:"application/javascript"})}catch(r){_root.BlobBuilder=_root.BlobBuilder||_root.WebKitBlobBuilder||_root.MozBlobBuilder,e=new BlobBuilder,e.append(t),e=e.getBlob()}return e},Supervisor.prototype.graphToByteArrays=function(){var t,e,r,o=this.graph.nodes(),i=this.graph.edges(),n=o.length*this.ppn,s=i.length*this.ppe,a={};for(this.nodesByteArray=new Float32Array(n),this.edgesByteArray=new Float32Array(s),t=e=0,r=o.length;r>t;t++)a[o[t].id]=e,this.nodesByteArray[e]=o[t].x,this.nodesByteArray[e+1]=o[t].y,this.nodesByteArray[e+2]=0,this.nodesByteArray[e+3]=0,this.nodesByteArray[e+4]=0,this.nodesByteArray[e+5]=0,this.nodesByteArray[e+6]=1+this.graph.degree(o[t].id),this.nodesByteArray[e+7]=1,this.nodesByteArray[e+8]=o[t].size,this.nodesByteArray[e+9]=0,e+=this.ppn;for(t=e=0,r=i.length;r>t;t++)this.edgesByteArray[e]=a[i[t].source],this.edgesByteArray[e+1]=a[i[t].target],this.edgesByteArray[e+2]=i[t].weight||0,e+=this.ppe},Supervisor.prototype.applyLayoutChanges=function(){for(var t=this.graph.nodes(),e=0,r=0,o=this.nodesByteArray.length;o>r;r+=this.ppn)t[e].x=this.nodesByteArray[r],t[e].y=this.nodesByteArray[r+1],e++},Supervisor.prototype.sendByteArrayToWorker=function(t){var e={action:t||"loop",nodes:this.nodesByteArray.buffer},r=[this.nodesByteArray.buffer];"start"===t&&(e.config=this.config||{},e.edges=this.edgesByteArray.buffer,r.push(this.edgesByteArray.buffer)),this.shouldUseWorker?this.worker.postMessage(e,r):_root.postMessage(e,"*")},Supervisor.prototype.start=function(){this.running||(this.running=!0,this.started?this.sendByteArrayToWorker():(this.sendByteArrayToWorker("start"),this.started=!0))},Supervisor.prototype.stop=function(){this.running&&(this.running=!1)},Supervisor.prototype.killWorker=function(){this.worker&&this.worker.terminate()},Supervisor.prototype.configure=function(t){if(this.config=t,this.started){var e={action:"config",config:this.config};this.shouldUseWorker?this.worker.postMessage(e):_root.postMessage(e,"*")}},sigma.prototype.startForceAtlas2=function(t){return this.supervisor||(this.supervisor=new Supervisor(this,t)),t&&this.supervisor.configure(t),this.supervisor.start(),this},sigma.prototype.stopForceAtlas2=function(){return this.supervisor?(this.supervisor.stop(),this):this},sigma.prototype.killForceAtlas2=function(){return this.supervisor?(this.supervisor.stop(),this.supervisor.killWorker(),this.supervisor=null,this):this},sigma.prototype.configForceAtlas2=function(t){return this.supervisor||(this.supervisor=new Supervisor(this,t)),this.supervisor.configure(t),this},sigma.prototype.isForceAtlas2Running=function(){return this.supervisor&&this.supervisor.running}}).call(this),function(undefined){"use strict";function no_crush(t){var e,r,o,i=["x","y","dx","dy","old_dx","old_dy","mass","convergence","size","fixed"],n=["source","target","weight"];for(r=0,o=i.length;o>r;r++)e=new RegExp("np\\(([^,]*), '"+i[r]+"'\\)","g"),t=t.replace(e,0===r?"$1":"$1 + "+r);for(r=0,o=n
|