MCPcopy
hub / github.com/twitter/labella.js / labella-0.1.1.min.js

File labella-0.1.1.min.js

evaluation/labella-0.1.1.min.js:None–None  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.labella=b()}(this,function(){var a;a=function(){var a=Object.prototype.hasOwnProperty,b=Object.prototype.toString,c=function(a){return"function"==typeof Array.isArray?Array.isArray(a):"[object Array]"===b.call(a)},d=function(c){if(!c||"[object Object]"!==b.call(c))return!1;var d=a.call(c,"constructor"),e=c.constructor&&c.constructor.prototype&&a.call(c.constructor.prototype,"isPrototypeOf");if(c.constructor&&!d&&!e)return!1;var f;for(f in c);return void 0===f||a.call(c,f)};return function e(){var a,b,f,g,h,i,j=arguments[0],k=1,l=arguments.length,m=!1;for("boolean"==typeof j?(m=j,j=arguments[1]||{},k=2):("object"!=typeof j&&"function"!=typeof j||null==j)&&(j={});l>k;++k)if(a=arguments[k],null!=a)for(b in a)f=j[b],g=a[b],j!==g&&(m&&g&&(d(g)||(h=c(g)))?(h?(h=!1,i=f&&c(f)?f:[]):i=f&&d(f)?f:{},j[b]=e(m,i,g)):void 0!==g&&(j[b]=g));return j}}();var b;b=function(){function a(a,b){try{for(var c in b)Object.defineProperty(a.prototype,c,{value:b[c],enumerable:!1})}catch(d){a.prototype=b}}function b(){}function c(a){return k+a in this}function d(a){return a=k+a,a in this&&delete this[a]}function e(){var a=[];return this.forEach(function(b){a.push(b)}),a}function f(){var a=0;for(var b in this)b.charCodeAt(0)===l&&++a;return a}function g(){for(var a in this)if(a.charCodeAt(0)===l)return!1;return!0}function h(){}function i(a){function c(){for(var b,c=d,e=-1,f=c.length;++e<f;)(b=c[e].on)&&b.apply(this,arguments);return a}var d=[],e=new b;return c.on=function(b,c){var f,g=e.get(b);return arguments.length<2?g&&g.on:(g&&(g.on=null,d=d.slice(0,f=d.indexOf(g)).concat(d.slice(f+1)),e.remove(b)),c&&d.push(e.set(b,{on:c})),a)},c}var j={version:"3.4.4"};j.map=function(a){var c=new b;if(a instanceof b)a.forEach(function(a,b){c.set(a,b)});else for(var d in a)c.set(d,a[d]);return c},a(b,{has:c,get:function(a){return this[k+a]},set:function(a,b){return this[k+a]=b},remove:d,keys:e,values:function(){var a=[];return this.forEach(function(b,c){a.push(c)}),a},entries:function(){var a=[];return this.forEach(function(b,c){a.push({key:b,value:c})}),a},size:f,empty:g,forEach:function(a){for(var b in this)b.charCodeAt(0)===l&&a.call(this,b.substring(1),this[b])}});var k="\x00",l=k.charCodeAt(0);return j.dispatch=function(){for(var a=new h,b=-1,c=arguments.length;++b<c;)a[arguments[b]]=i(a);return a},h.prototype.on=function(a,b){var c=a.indexOf("."),d="";if(c>=0&&(d=a.substring(c+1),a=a.substring(0,c)),a)return arguments.length<2?this[a].on(d):this[a].on(d,b);if(2===arguments.length){if(null==b)for(a in this)this.hasOwnProperty(a)&&this[a].on(d,null);return this}},j.dispatch}();var c;c=function(){function a(a,b,c){return function(){var d=c.apply(b,arguments);return d===b?a:d}}var b=function(b,c){for(var d,e=1,f=arguments.length;++e<f;)b[d=arguments[e]]=a(b,c,c[d]);return b};return b}();var d;d=function(a,b,c){var d=function(){var d={};return d.sum=function(a,b){return a.map(b).reduce(function(a,b){return a+b},0)},d.isObject=function(a){return"object"==typeof a&&null!==a},d.isDefined=function(a){return null!==a&&void 0!==a},d.extend=a,d.dispatch=b,d.rebind=c,d.extractKeys=function(a,b){return b.reduce(function(b,c){return b[c]=a[c],b},{})},d}();return d}(a,b,c);var e;e=function(a){var b=function(b,c,d){if(1===arguments.length&&a.isObject(b)){var e=b;this.idealPos=e.idealPos,this.currentPos=null!==e.currentPos&&void 0!==e.currentPos?e.currentPos:e.idealPos,this.width=e.width,this.data=e.data}else this.idealPos=b,this.currentPos=b,this.width=c,this.data=d;this.previousPos=this.currentPos},c=b.prototype;return c.distanceFrom=function(a){var b=this.width/2,c=a.width/2;return Math.max(this.currentPos-b,a.currentPos-c)-Math.min(this.currentPos+b,a.currentPos+c)},c.moveToIdealPosition=function(){return this.currentPos=this.idealPos,this},c.displacement=function(){return this.idealPos-this.currentPos},c.overlapWithNode=function(a,b){return b=null===b||void 0===b?0:b,this.distanceFrom(a)-b<0},c.overlapWithPoint=function(a){var b=this.width/2;return a>=this.currentPos-b&&a<=this.currentPos+b},c.positionBefore=function(a,b){return b=b?b:0,a.currentLeft()-this.width/2-b},c.positionAfter=function(a,b){return b=b?b:0,a.currentRight()+this.width/2+b},c.currentRight=function(){return this.currentPos+this.width/2},c.currentLeft=function(){return this.currentPos-this.width/2},c.idealRight=function(){return this.idealPos+this.width/2},c.idealLeft=function(){return this.idealPos-this.width/2},c.halfWidth=function(){return this.width/2},c.velocity=function(a){return a=a||1,(this.currentPos-this.previousPos)/a},c.kineticEnergy=function(){var a=this.velocity();return a*a},c.createStub=function(a){var c=new b({idealPos:this.idealPos,currentPos:this.currentPos,width:a,data:this.data});return c.child=this,this.parent=c,c},c.isStub=function(){return!!this.child},c.getPathToRoot=function(){for(var a=[],b=this;b;)a.push(b),b=b.parent;return a},c.getPathFromRoot=function(){return this.getPathToRoot().reverse()},c.getRoot=function(){for(var a=this,b=this;b;)a=b,b=b.parent;return a},c.getLevel=function(){for(var a=0,b=this.parent;b;)b=b.parent,a++;return a},c.clone=function(){return new b({idealPos:this.idealPos,currentPos:this.currentPos,width:this.width,data:this.data})},c.isBumping=function(a,b){var c=this.force||0,d=a.force||0;return this.overlapWithNode(a,b)&&(c*d>0||0===c&&0>d||c>0&&0===d||c>0&&0>d)},b}(d);var f;f=function(){var a=function(a){this.nodes=a||[],this.force=0},b=a.prototype;return b.push=function(a){return this.nodes.push(a),this},b.merge=function(b){var c=new a(this.nodes.concat(b.nodes));return c.force=this.force+b.force,c},b.overlapWithGroup=function(a,b){return this.nodes.length>0&&a.nodes.length>0&&this.nodes[this.nodes.length-1].overlapWithNode(a.nodes[0],b)},b.totalForce=function(){return this.nodes.map(function(a){return a.force}).reduce(function(a,b){return a+b},0)},b.assignForceToChildren=function(){var a=this;this.nodes.forEach(function(b){b.force=a.force})},b.isBumping=function(a,b){var c=this.force||0,d=a.force||0;return this.overlapWithGroup(a,b)&&(c*d>0||0===c&&0>d||c>0&&0===d||c>0&&0>d)},a.groupAdjacentNodes=function(b,c){if(b&&b.length>0){for(var d=new a([b[0]]),e=[d],f=1;f<b.length;f++){var g=b[f],h=b[f-1];c(h,g)?d.push(g):(d=new a([g]),e.push(d))}return e}return[]},a.mergeAdjacentGroups=function(a,b){if(a&&a.length>0){for(var c=[],d=a[0],e=1;e<a.length;e++){var f=a[e],g=a[e-1];b(g,f)?d=d.merge(f):(c.push(d),d=f)}return c.push(d),c}return a},a}();var g;g=function(){function a(a){this.springK=a}return a.prototype.computeForce=function(a){return this.springK*a},a}();var h;h=function(a,b,c){var d={damping:.1,epsilon:.003,timestep:1,nodeSpacing:3,minPos:0,maxPos:null,pullForce:new b(1),roundsPerTick:100},e=function(b){function e(a,c){return a.isBumping(c,b.nodeSpacing)}var f={},g=[],h=c.dispatch("start","tick","end"),i=!1,j=0;return b=c.extend({},d,b),f.nodes=function(a){return arguments.length?(g=a,f):g},f.options=function(a){return arguments.length?(b=c.extend(b,a),f):b},f.pushRightToIdealPositions=function(){for(var a=g.length-1;a>=0;a--){var c=g[a];if(c.currentPos<c.idealPos){var d=a===g.length-1?null:g[a+1];if(!d||c.idealRight()<d.currentLeft())c.moveToIdealPosition();else{var e=c.positionBefore(d,b.nodeSpacing);Math.abs(c.idealPos-e)<Math.abs(c.displacement())&&(c.currentPos=e)}}}return f},f.pushLeftToIdealPositions=function(){for(var a=0;a<g.length;a++){var c=g[a];if(c.currentPos>c.idealPos){var d=0===a?null:g[a-1];if(!d||c.idealLeft()>d.currentRight())c.moveToIdealPosition();else{var e=c.positionAfter(d,b.nodeSpacing);Math.abs(c.idealPos-e)<Math.abs(c.displacement())&&(c.currentPos=e)}}}return f},f.pushToIdealPositions=function(a){return a?f.pushRightToIdealPositions().pushLeftToIdealPositions():f.pushLeftToIdealPositions().pushRightToIdealPositions()},f.initialize=function(){if(i)throw"This function cannot be called while the simulator is running. Stop it first.";return g.filter(function(a){return!!a.parent}).forEach(function(a){a.idealPos=a.parent.currentPos}),g.sort(function(a,b){return a.idealPos-b.idealPos}).forEach(function(a,c){a.currentPos=0===c?a.halfWidth():a.positionAfter(g[c-1],b.nodeSpacing),a.previousPos=a.currentPos}),f},f.step=function(){g.forEach(function(a){a.force=b.pullForce.computeForce(a.displacement())});var d=a.groupAdjacentNodes(g,e);for(d.forEach(function(a){if(a.force=a.totalForce(),a.force<0&&c.isDefined(b.minPos)){var d=a.nodes[0].currentLeft()-b.minPos;0===d?a.force=0:0>d&&(a.force=b.pullForce.computeForce(-d))}});d.length>1;){var h=a.mergeAdjacentGroups(d,e);if(h.length===d.length)break;d=h}d.forEach(function(a){a.assignForceToChildren()});for(var i=g.length-1;i>=0;i--){var j=g[i],k=j.currentPos+j.force*b.damping*b.timestep*b.timestep;if(c.isDefined(b.minPos)&&(k=Math.max(b.minPos+j.halfWidth(),k)),c.isDefined(b.maxPos)&&(k=Math.min(b.maxPos-j.halfWidth(),k)),i>0){var l=g[i-1];k=Math.max(j.positionAfter(l,b.nodeSpacing-1),k)}if(i<g.length-1){var m=g[i+1];k=Math.min(j.positionBefore(m,b.nodeSpacing-1),k)}j.previousPos=j.currentPos,j.currentPos=k}return f},f.start=function(a){if(i)throw"This function cannot be called while the simulator is running. Stop it first.";return f.initialize().resume(a)},f.increaseMaxRound=function(a){a?j+=a:j=0},f.resume=function(a){if(f.increaseMaxRound(a),!i){i=!0,h.start({type:"start"});var c=0,d=function(){return i?c>0&&f.isStable()?"simulation stable, energy: "+f.energy():j&&c>=j?"maximum number of rounds reached: "+j:(f.step(),c++,!1):"stopped"},e=function(){for(var a=0;a<b.roundsPerTick;a++){var f=d();if(f)return h.end({type:"end",round:c,maxRound:j,reason:f}),i=!1,void(j=0)}h.tick({type:"tick",round:c,maxRound:j}),setTimeout(e,0)};e()}return f},f.stop=function(){return i=!1,f},f.energy=function(){return c.sum(g,function(a){return a.kineticEnergy()})},f.isStable=function(){return f.energy()<b.epsilon},f.reset=f.initialize,c.rebind(f,h,"on"),f};return e.DEFAULT_OPTIONS=d,e}(f,g,d);var i;!function(a,b){i=function(){return"function"==typeof b?b():b}()}(this,function(){var a=function b(){var a=null,c={},d=arguments;["0","1"].forEach(function(b){var e=d[b];Array.isArray(e)?a=e:e&&"object"==typeof e&&(c=e)}),"function"==typeof c.filter&&(this._filter=c.filter),"function"==typeof c.compare?this._compare=c.compare:"string"==typeof c.compare&&b.compares[c.compare]&&(this._compare=b.compares[c.compare]),this._unique=!!c.unique,c.resume&&a?a.forEach(function(a,b){this.push(a)},this):a&&this.insert.apply(this,a)};return a.create=function(b,c){return new a(b,c)},a.prototype=new Array,a.prototype.constructor=Array.prototype.constructor,a.prototype.insertOne=function(a){var b=this.bsearch(a);return this._unique&&null!=this.key(a,b)?!1:this._filter(a,b)?(this.splice(b+1,0,a),b+1):!1},a.prototype.insert=function(){return Array.prototype.map.call(arguments,function(a){return this.insertOne(a)},this)},a.prototype.remove=function(a){return this.splice(a,1),this},a.prototype.bsearch=function(a){if(!this.length)return-1;for(var b,c=0,d=this.length;d-c>1;){b=Math.floor((c+d)/2),mval=this[b];var e=this._compare(a,mval);if(0==e)return b;e>0?c=b:d=b}return 0==c&&this._compare(this[0],a)>0?-1:c},a.prototype.key=function(a,b){null==b&&(b=this.bsearch(a));var c=b;if(-1==c||this._compare(this[c],a)<0)return c+1<this.length&&0==this._compare(this[c+1],a)?c+1:null;for(;c>=1&&0==this._compare(this[c-1],a);)c--;return c},a.prototype.keys=function(a,b){var c=[];null==b&&(b=this.bsearch(a));for(var d=b;d>=0&&0==this._compare(this[d],a);)c.push(d),d--;var e=this.length;for(d=b+1;e>d&&0==this._compare(this[d],a);)c.push(d),d++;return c.length?c:null},a.prototype.unique=function(a){if(a)return this.filter(function(a,b){return 0==b||0!=this._compare(this[b-1],a)},this);var b=0;return this.map(function(a,c){return 0==c||0!=this._compare(this[c-1],a)?null:c-b++},this).forEach(function(a){null!=a&&this.remove(a)},this),this},a.prototype.toArray=function(){return this.slice()},a.prototype._filter=function(a,b){return!0},a.compares={number:function(a,b){var c=a-b;return c>0?1:0==c?0:-1},string:function(a,b){return a>b?1:a==b?0:-1}},a.prototype._compare=a.compares.string,a});var j;j=function(a){function b(b,c){if(c||(c={}),this.startKey=c.startKey||0,this.endKey=c.endKey||1,this.intervalHash={},this.pointTree=new a({compare:function(a,b){if(null==a)return-1;if(null==b)return 1;var c=a[0]-b[0];return c>0?1:0==c?0:-1}}),this._autoIncrement=0,!b||"number"!=typeof b)throw new Error("you must specify center index as the 2nd argument.");this.root=new f(b,this)}function c(a,b){return b.end<a.idx?(a.left||(a.left=new f(b.start+b.end>>1,this)),c.call(this,a.left,b)):a.idx<b.start?(a.right||(a.right=new f(b.start+b.end>>1,this)),c.call(this,a.right,b)):a.insert(b)}function d(a,b,c){return a?b<a.idx?(a.starts.every(function(a){var d=a.start<=b;return d&&c.push(a.result()),d}),d.call(this,a.left,b,c)):b>a.idx?(a.ends.every(function(a){var d=a.end>=b;return d&&c.push(a.result()),d}),d.call(this,a.right,b,c)):void a.starts.map(function(a){c.push(a.result())}):void 0}function e(a,b,c){if(0>=b-a)throw new Error("end must be greater than start. start: "+a+", end: "+b);var e={},f=[];d.call(this,this.root,a+b>>1,f,!0),f.forEach(function(a){e[a.id]=!0});for(var g=this.pointTree.bsearch([a,null]),h=this.pointTree;g>=0&&h[g][0]==a;)g--;var i=this.pointTree.bsearch([b,null]);if(i>=0){for(var j=h.length-1;j>=i&&h[i][0]<=b;)i++;h.slice(g+1,i).forEach(function(a){var b=a[1];e[b]=!0},this),Object.keys(e).forEach(function(d){var e=this.intervalHash[d];c.push(e.result(a,b))},this)}}function f(b){this.idx=b,this.starts=new a({compare:function(a,b){if(null==a)return-1;if(null==b)return 1;var c=a.start-b.start;return c>0?1:0==c?0:-1}}),this.ends=new a({compare:function(a,b){if(null==a)return-1;if(null==b)return 1;var c=a.end-b.end;return 0>c?1:0==c?0:-1}})}function g(a,b,c,d){if(this.id=b,this.start=a[c],this.end=a[d],this.data=a,"number"!=typeof this.start||"number"!=typeof this.end)throw new Error("start, end must be number. start: "+this.start+", end: "+this.end);if(this.start>=this.end)throw new Error("start must be smaller than end. start: "+this.start+", end: "+this.end)}return b.prototype.add=function(a,b){if(this.intervalHash[b])throw new Error("id "+b+" is already registered.");if(void 0==b){for(;this.intervalHash[this._autoIncrement];)this._autoIncrement++;b=this._autoIncrement}var d=new g(a,b,this.startKey,this.endKey);this.pointTree.insert([d.start,b]),this.pointTree.insert([d.end,b]),this.intervalHash[b]=d,this._autoIncrement++,c.call(this,this.root,d)},b.prototype.search=function(a,b){var c=[];if("number"!=typeof a)throw new Error(a+": invalid input");if(void 0==b)d.call(this,this.root,a,c);else{if("number"!=typeof b)throw new Error(a+","+b+": invalid input");e.call(this,a,b,c)}return c},b.prototype.remove=function(a){},f.prototype.insert=function(a){this.starts.insert(a),this.ends.insert(a)},g.prototype.result=function(a,b){var c={id:this.id,data:this.data};if("number"==typeof a&&"number"==typeof b){var d=Math.max(this.start,a),e=Math.min(this.end,b),f=e-d;c.rate1=f/(b-a),c.rate2=f/(this.end-this.start)}return c},b}(i);var k;k=function(a,b){var c={algorithm:"overlap",layerWidth:1e3,density:.75,nodeSpacing:3,stubWidth:1},d=function(d){var e={};d=a.extend({},c,d),e.options=function(b){return arguments.length?(d=a.extend(d,b),e):d},e.computeRequiredWidth=function(b){return a.sum(b,function(a){return a.width+d.nodeSpacing})-d.nodeSpacing},e.maxWidthPerLayer=function(){return d.density*d.layerWidth},e.needToSplit=function(a){return e.estimateRequiredLayers(a)>1},e.estimateRequiredLayers=function(a){return d.layerWidth?Math.ceil(e.computeRequiredWidth(a)/e.maxWidthPerLayer()):1};var f={simple:function(a){for(var b=e.estimateRequiredLayers(a),c=[],f=0;b>f;f++)c.push([]);return a.forEach(function(a,e){var f=e%b;c[f].push(a);for(var g=a,h=f-1;h>=0;h--)g=g.createStub(d.stubWidth),c[h].push(g)}),c},roundRobin:function(a){var b=[];return b},overlap:function(a){for(var b=[],c=e.maxWidthPerLayer(),f=a.concat(),g=e.computeRequiredWidth(f);g>c;){e.countIdealOverlaps(f);var h=f.concat(),i=g;for(f=[];h.length>2&&i>c;){h.sort(function(a,b){return b.overlapCount-a.overlapCount});var j=h.shift();i-=j.width,i+=d.stubWidth,j.overlaps.forEach(function(a){a.overlapCount--}),f.push(j)}b.push(h),g=e.computeRequiredWidth(f)}f.length>0&&b.push(f);for(var k=b.length-1;k>=1;k--)for(var l=b[k],m=0;m<l.length;m++){var n=l[m];if(!n.isStub())for(var o=n,p=k-1;p>=0;p--)o=o.createStub(d.stubWidth),b[p].push(o)}return b}};return e.countIdealOverlaps=function(a){var c=new b(d.layerWidth/2);return a.forEach(function(a){c.add([a.idealLeft(),a.idealRight(),a])}),a.forEach(function(a){var b=c.search(a.idealLeft(),a.idealRight());a.overlaps=b,a.overlapCount=b.length}),a},e.distribute=function(a){if(!a||0===a.length)return[];if(a=a.concat().sort(function(a,b){return a.idealPos-b.idealPos}),!e.needToSplit(a))return[a];if("function"==typeof d.algorithm)return d.algorithm(a,d);if("none"==d.algorithm)return a;if(f.hasOwnProperty(d.algorithm))return f[d.algorithm](a);throw"Unknown algorithm: "+d.algorithm},e};return d.DEFAULT_OPTIONS=c,d}(d,j);var l;l=function(a){var b=function(){function b(a){return 0===a.length||Array.isArray(a[0])?a:[a]}var c={};return c.displacement=function(c){if(0===c.length)return 0;var d=b(c);return a.sum(d,function(b){return a.sum(b,function(a){return Math.abs(a.displacement())})})},c.overflow=function(c,d,e){if(0===c.length||!a.isDefined(d)&&!a.isDefined(e))return 0;var f=b(c);return a.sum(f,function(b){return a.sum(b,function(b){var c=b.currentLeft(),f=b.currentRight();if(a.isDefined(d)){if(d>=f)return b.width;if(d>c)return d-c}if(a.isDefined(e)){if(c>=e)return b.width;if(f>e)return f-e}return 0})})},c.overDensity=function(c,d,e,f){if(0===c.length)return 0;var g=d*e,h=b(c);return a.sum(h,function(b){var c=a.sum(b,function(a){return a.width+f})-f;return g>=c?0:c-g})},c.overlapCount=function(c,d){if(0===c.length)return 0;var e=b(c);return a.sum(e,function(a){for(var b=0,c=0;c<a.length;c++)for(var e=c+1;e<a.length;e++)a[c].overlapWithNode(a[e],d)&&b++;return b})},c.overlapSpace=function(c){if(0===c.length)return 0;var d=b(c);return a.sum(d,function(a){for(var b=0,c=0;c<a.length;c++)for(var d=c+1;d<a.length;d++){var e=a[c].distanceFrom(a[d]);b+=0>e?Math.abs(e):0}return b})},c.weightedAllocatedSpace=function(c){if(0===c.length)return 0;var d=b(c);return a.sum(d,function(b,c){return c*a.sum(b,function(a){return a.width})})},c}();return b}(d);var m;m=function(a,b,c,d,e){var f={damping:.1,epsilon:.003,timestep:1,nodeSpacing:3,minPos:0,maxPos:null,pullForce:new e(1),roundsPerTick:100,algorithm:"overlap",density:.85,stubWidth:1},g=function(e){var g={},h=d.dispatch("start","tick","endLayer","end"),i=d.extend({},f),j=new b,k=[],l=[],m=null,n=!1;return g.nodes=function(a){return arguments.length?(l=a,m=null,k=[],g):l},g.getLayers=function(){return m},g.options=function(c){if(!arguments.length)return i;i=d.extend(i,c);var e=d.extractKeys(i,Object.keys(b.DEFAULT_OPTIONS));d.isDefined(i.minPos)&&d.isDefined(i.maxPos)?e.layerWidth=i.maxPos-i.minPos:e.layerWidth=null,j.options(e);var f=d.extractKeys(i,Object.keys(a.DEFAULT_OPTIONS));return k.forEach(function(a){a.options(f)}),g},g.options(e),g.distribute=function(){if(n)throw"This function cannot be called while the simulator is running. Stop it first.";m=j.distribute(l);var b=d.extractKeys(i,Object.keys(a.DEFAULT_OPTIONS));return k=m.map(function(c){return new a(b).nodes(c)}),g},g.initialize=function(){if(n)throw"This function cannot be called while the simulator is running. Stop it first.";return k.forEach(function(a){a.initialize()}),g},g.step=function(){return k.forEach(function(a){a.step()}),g},g.stop=function(){return k.forEach(function(a){a.stop()}),g},g.start=function(a){if(n)throw"This function cannot be called while the simulator is running. Stop it first.";return setTimeout(function(){m||g.distribute(),g.initialize().resume(a)},0),g},g.resume=function(a){if(0===m.length)return g;if(!n){var b=0;h.start({type:"start"});var c=function(){var e=k[b];e&&(e.on("tick",function(a){h.tick(d.extend({},a,{layerIndex:b}))}),e.on("end",function(a){h.endLayer(d.extend({},a,{type:"endLayer",layerIndex:b})),b++,b<m.length?c():(h.end({type:"end"}),n=!1)}),b>0?e.start(a):e.resume(a))};c()}return g},g.energy=function(){return d.sum(k,function(a){return a.energy()})},g.isStable=function(){return k.every(function(a){return a.isStable()})},g.reset=g.initialize,g.metrics=function(){return Object.keys(c).map(function(a){return{name:a,value:g.metric(a)}})},g.metric=function(a){switch(a){case"overflow":return c[a](m,i.minPos,i.maxPos);case"overDensity":return c[a](m,i.density,i.layerWidth,i.nodeSpacing-1);case"overlapCount":return c[a](m,i.nodeSpacing-1);default:return c[a]?c[a](m):null}},d.rebind(g,h,"on"),g};return g.DEFAULT_OPTIONS=f,g}(h,k,l,d,g);var n;n=function(a){function b(b){this.options=a.extend({layerGap:60,nodeHeight:10,direction:"down"},b)}function c(a){return"L "+a.join(" ")}function d(a){return"M "+a.join(" ")}function e(a,b,c){return"C "+a.join(" ")+" "+b.join(" ")+" "+c.join(" ")}function f(a,b){var c=(a[1]+b[1])/2;return e([a[0],c],[b[0],c],b)}function g(a,b){var c=(a[0]+b[0])/2;return e([c,a[1]],[c,b[1]],b)}return b.prototype.getWaypoints=function(a){var b=this.options,c=b.direction,d=a.getPathFromRoot(),e=b.nodeHeight+b.layerGap;return"left"===c?[[[0,d[0].idealPos]]].concat(d.map(function(a,c){var d=e*(c+1)*-1;return[[d+b.nodeHeight,a.currentPos],[d,a.currentPos]]})):"right"===c?[[[0,d[0].idealPos]]].concat(d.map(function(a,c){var d=e*(c+1);return[[d-b.nodeHeight,a.currentPos],[d,a.currentPos]]})):"up"===c?[[[d[0].idealPos,0]]].concat(d.map(function(a,c){var d=e*(c+1)*-1;return[[a.currentPos,d+b.nodeHeight],[a.currentPos,d]]})):[[[d[0].idealPos,0]]].concat(d.map(function(a,c){var d=e*(c+1);return[[a.currentPos,d-b.nodeHeight],[a.currentPos,d]]}))},b.prototype.layout=function(a){var b=this.options,c=b.layerGap+b.nodeHeight;switch(b.direction){case"left":a.forEach(function(a){var d=a.getLevel()*c+b.layerGap;a.x=-d-b.nodeHeight,a.y=a.currentPos,a.dx=b.nodeHeight,a.dy=a.width});break;case"right":a.forEach(function(a){var d=a.getLevel()*c+b.layerGap;a.x=d,a.y=a.currentPos,a.dx=b.nodeHeight,a.dy=a.width});break;case"up":a.forEach(function(a){var d=a.getLevel()*c+b.layerGap;a.x=a.currentPos,a.y=-d-b.nodeHeight,a.dx=a.width,a.dy=b.nodeHeight});break;default:case"down":a.forEach(function(a){var d=a.getLevel()*c+b.layerGap;a.x=a.currentPos,a.y=d,a.dx=a.width,a.dy=b.nodeHeight})}return a},b.prototype.generatePath=function(a){var b=this.options,e=b.direction,h=this.getWaypoints(a,e),i=[d(h[0][0])];return"left"===e||"right"===e?h.reduce(function(a,b,d){return i.push(g(a[a.length-1],b[0])),d<h.length-1&&i.push(c(b[1])),b}):h.reduce(function(a,b,d){return i.push(f(a[a.length-1],b[0])),d<h.length-1&&i.push(c(b[1])),b}),i.join(" ")},b}(d);var o;o=function(a,b){var c=function(){var c={},d={minWidth:20,maxWidth:20,minPos:0,maxPos:800};return c.generateNodes=function(c,e){var f=[];e=a.extend({},d,e);for(var g=e.maxPos-e.minPos,h=e.maxWidth-e.minWidth,i=0;c>i;i++)f.push(new b(Math.floor(Math.random()*g)+e.minPos,Math.floor(Math.random()*h)+e.minWidth));return f},c.convertNodesToGraph=function(a){yGap=60;var b={nodes:[],links:[],constraints:[]},c={type:"alignment",axis:"y",offsets:[]};return b.constraints.push(c),b.nodes.push({index:0,x:1,y:yGap,width:1,height:1,fixed:!0}),b.nodes.push({index:0,x:925,y:yGap,width:1,height:1,fixed:!0}),a.forEach(function(a){var d={index:b.nodes.length,x:a.idealPos,y:0,width:1,height:1,fixed:!0};b.nodes.push(d);var e={index:b.nodes.length,x:a.currentPos,y:yGap,width:a.width,height:12,originalNode:a};c.offsets.push({node:e.index,offset:0}),b.nodes.push(e),b.links.push({source:d.index,target:e.index}),b.constraints.push({axis:"y",left:d.index,right:e.index,gap:yGap,equality:!0}),b.constraints.push({axis:"x",left:0,right:e.index,gap:0}),b.constraints.push({axis:"x",left:e.index,right:1,gap:0})}),b},c.updateNodesInGraph=function(a){return graph.nodes.filter(function(a){return a.originalNode}).map(function(a){return a.originalNode.currentPos=a.x,a.originalNode})},c}();return c}(d,e);var p;return p=function(a,b,c,d,e,f,g,h){return{Node:a,NodeGroup:b,Force:c,Simulator:d,Distributor:e,Renderer:f,metrics:g,util:h}}(e,f,m,h,k,n,l,o)});

Callers

nothing calls this directly

Calls 15

bFunction · 0.85
dFunction · 0.85
cFunction · 0.85
gFunction · 0.85
fFunction · 0.85
distanceFromMethod · 0.80
currentLeftMethod · 0.80
currentRightMethod · 0.80
getPathToRootMethod · 0.80
overlapWithNodeMethod · 0.80
displacementMethod · 0.80
getPathFromRootMethod · 0.80

Tested by

no test coverage detected