From a978821ee361f5060ed0371ba45f7dc1caf0b83b Mon Sep 17 00:00:00 2001 From: tgdwyer Date: Fri, 11 Apr 2014 15:18:09 +1000 Subject: [PATCH] update graphs for alex. --- WebCola/cola.v2.min.js | 4 +- WebCola/examples/egonetwork.html | 96 +++++++++++++++++++++------- WebCola/examples/friendnetworks.html | 69 +++++++++++++++----- 3 files changed, 130 insertions(+), 39 deletions(-) diff --git a/WebCola/cola.v2.min.js b/WebCola/cola.v2.min.js index a5742f74..10cb4e67 100644 --- a/WebCola/cola.v2.min.js +++ b/WebCola/cola.v2.min.js @@ -1,2 +1,2 @@ -!function(a,b){"object"==typeof exports?module.exports=b(require("d3")):"function"==typeof define&&define.amd?define(["d3"],b):a.cola=b(a.d3)}(this,function(a){var b;!function(a){var b=function(){function a(){this.locks={}}return a.prototype.add=function(a,b){isNaN(b[0])||isNaN(b[1]),this.locks[a]=b},a.prototype.clear=function(){this.locks={}},a.prototype.isEmpty=function(){for(var a in this.locks)return!1;return!0},a.prototype.apply=function(a){for(var b in this.locks)a(b,this.locks[b])},a}();a.Locks=b;var c=function(){function a(a,c,e){"undefined"==typeof e&&(e=null),this.D=c,this.G=e,this.threshold=1e-4,this.random=new d,this.project=null,this.x=a,this.k=a.length;var f=this.n=a[0].length;this.H=new Array(this.k),this.g=new Array(this.k),this.Hd=new Array(this.k),this.a=new Array(this.k),this.b=new Array(this.k),this.c=new Array(this.k),this.d=new Array(this.k),this.e=new Array(this.k),this.ia=new Array(this.k),this.ib=new Array(this.k),this.xtmp=new Array(this.k),this.locks=new b,this.minD=Number.MAX_VALUE;for(var g,h=f;h--;)for(g=f;--g>h;){var i=c[h][g];i>0&&id;++d){c[d]=new Array(a);for(var e=0;a>e;++e)c[d][e]=b(d,e)}return c},a.prototype.offsetDir=function(){for(var a=this,b=new Array(this.k),c=0,d=0;dc)){for(var d,e=new Array(this.k),f=new Array(this.k),g=new Array(this.k),h=0,i=0;c>i;++i){for(d=0;dj;++j)if(i!==j){for(;;){var k=0;for(d=0;d1e-9)break;var m=this.offsetDir();for(d=0;d1&&n>o||!isFinite(o))for(d=0;d1&&(p=1);var q=o*o,r=p*(n-o)/(q*n),s=-p/(q*n*n*n);for(isFinite(r)||console.log(r),d=0;de;++e)c+=a.dotProd(this.g[e],b[e]),a.rightMultiply(this.H[e],b[e],this.Hd[e]),d+=a.dotProd(b[e],this.Hd[e]);return 0!==d&&isFinite(d)?c/d:0},a.prototype.reduceStress=function(){this.computeDerivatives(this.x);for(var a=this.computeStepSize(this.g),b=0;be;++e)for(var f=0;d>f;++f)b[e][f]=a[e][f]},a.prototype.stepAndProject=function(b,c,d,e){a.copy(b,c),this.takeDescentStep(c[0],d[0],e),this.project&&this.project[0](b[0],b[1],c[0]),this.takeDescentStep(c[1],d[1],e),this.project&&this.project[1](c[0],b[1],c[1])},a.mApply=function(a,b,c){for(var d=a;d-->0;)for(var e=b;e-->0;)c(d,e)},a.prototype.matrixApply=function(b){a.mApply(this.k,this.n,b)},a.prototype.computeNextPosition=function(a,b){var c=this;this.computeDerivatives(a);var d=this.computeStepSize(this.g);this.stepAndProject(a,b,this.g,d);for(var e=0;e0;){var d=this.rungeKutta();c=Math.abs(b/d-1)b;++b)for(var d=b+1,e=this.n;e>d;++d){for(var f=0,g=0;g>16)/this.range},a.prototype.getNextBetween=function(a,b){return a+this.getNext()*(b-a)},a}();a.PseudoRandom=d}(b||(b={}));var c,d=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c};!function(a){function b(a,b,c){return(b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y)}function c(a,c,d){return b(a,c,d)>0}function e(a,c,d){return b(a,c,d)<0}function g(a){var c,d=a.slice(0).sort(function(a,b){return a.x!==b.x?b.x-a.x:b.y-a.y}),e=a.length,f=0,g=d[0].x;for(c=1;e>c&&d[c].x===g;++c);var h=c-1,i=[];if(i.push(d[f]),h===e-1)d[h].y!==d[f].y&&i.push(d[h]);else{var j,k=e-1,l=d[e-1].x;for(c=e-2;c>=0&&d[c].x===l;c--);for(j=c+1,c=h;++c<=j;)if(!(b(d[f],d[j],d[c])>=0&&j>c)){for(;i.length>1&&!(b(i[i.length-2],i[i.length-1],d[c])>0);)i.length-=1;c!=f&&i.push(d[c])}k!=j&&i.push(d[k]);var m=i.length;for(c=j;--c>=h;)if(!(b(d[k],d[h],d[c])>=0&&c>h)){for(;i.length>m&&!(b(i[i.length-2],i[i.length-1],d[c])>0);)i.length-=1;c!=f&&i.push(d[c])}}return i}function h(a,b,c){b.slice(0).sort(function(b,c){return Math.atan2(b.y-a.y,b.x-a.x)-Math.atan2(c.y-a.y,c.x-a.x)}).forEach(c)}function i(a,b){return{rtan:j(a,b),ltan:k(a,b)}}function j(a,b){var d,f,g,h,i,j=b.length-1;if(e(a,b[1],b[0])&&!c(a,b[j-1],b[0]))return 0;for(d=0,f=j;;){if(f-d===1)return c(a,b[d],b[f])?d:f;if(g=Math.floor((d+f)/2),i=e(a,b[g+1],b[g]),i&&!c(a,b[g-1],b[g]))return g;h=c(a,b[d+1],b[d]),h?i?f=g:c(a,b[d],b[g])?f=g:d=g:i&&e(a,b[d],b[g])?f=g:d=g}}function k(a,b){var d,f,g,h,i,j=b.length-1;if(c(a,b[j-1],b[0])&&!e(a,b[1],b[0]))return 0;for(d=0,f=j;;){if(f-d===1)return e(a,b[d],b[f])?d:f;if(g=Math.floor((d+f)/2),i=e(a,b[g+1],b[g]),c(a,b[g-1],b[g])&&!i)return g;h=e(a,b[d+1],b[d]),h?i?e(a,b[d],b[g])?f=g:d=g:f=g:i?d=g:c(a,b[d],b[g])?f=g:d=g}}function l(a,b,c,d,e,f){var g,h;g=c(b[0],a),h=d(a[g],b);for(var i=!1;!i;){for(i=!0;;){if(g===a.length-1&&(g=0),e(b[h],a[g],a[g+1]))break;++g}for(;;){if(0===h&&(h=b.length-1),f(a[g],b[h],b[h-1]))break;--h,i=!1}}return{t1:g,t2:h}}function m(a,b){var c=n(b,a);return{t1:c.t2,t2:c.t1}}function n(a,b){return l(a,b,j,k,c,e)}function o(a,b){return l(a,b,k,k,e,e)}function p(a,b){return l(a,b,j,j,c,c)}function q(a,b){for(var c=[],d=1,e=b.length;e>d;++d){var g=f.Rectangle.lineIntersection(a.x1,a.y1,a.x2,a.y2,b[d-1].x,b[d-1].y,b[d].x,b[d].y);g&&c.push(g)}return c}function r(a,c){for(var d=a.length-1,e=c.length-1,f=new z,g=0;d>g;++g)for(var h=0;e>h;++h){var i=a[0==g?d-1:g-1],j=a[g],k=a[g+1],l=c[0==h?e-1:h-1],m=c[h],n=c[h+1],o=b(i,j,m),p=b(j,l,m),q=b(j,m,n),r=b(l,m,j),s=b(m,i,j),t=b(m,j,k);o>=0&&p>=0&&0>q&&r>=0&&s>=0&&0>t?f.ll=new y(g,h):0>=o&&0>=p&&q>0&&0>=r&&0>=s&&t>0?f.rr=new y(g,h):0>=o&&p>0&&0>=q&&r>=0&&0>s&&t>=0?f.rl=new y(g,h):o>=0&&0>p&&q>=0&&0>=r&&s>0&&0>=t&&(f.lr=new y(g,h))}return f}function s(a,b){for(var c=1,d=b.length;d>c;++c)if(e(b[c-1],b[c],a))return!1;return!0}function t(a,b){return!a.every(function(a){return!s(a,b)})}function u(a,b){if(t(a,b))return!0;if(t(b,a))return!0;for(var c=1,d=a.length;d>c;++c){var e=a[c],f=a[c-1];if(q(new w(f.x,f.y,e.x,e.y),b).length>0)return!0}return!1}var v=function(){function a(){}return a}();a.Point=v;var w=function(){function a(a,b,c,d){this.x1=a,this.y1=b,this.x2=c,this.y2=d}return a}();a.LineSegment=w;var x=function(a){function b(){a.apply(this,arguments)}return d(b,a),b}(v);a.PolyPoint=x,a.isLeft=b,a.ConvexHull=g,a.clockwiseRadialSweep=h,a.tangent_PolyPolyC=l,a.LRtangent_PolyPolyC=m,a.RLtangent_PolyPolyC=n,a.LLtangent_PolyPolyC=o,a.RRtangent_PolyPolyC=p;var y=function(){function a(a,b){this.t1=a,this.t2=b}return a}();a.BiTangent=y;var z=function(){function a(){}return a}();a.BiTangents=z;var A=function(a){function b(){a.apply(this,arguments)}return d(b,a),b}(v);a.TVGPoint=A;var B=function(){function a(a,b,c,d){this.id=a,this.polyid=b,this.polyvertid=c,this.p=d,d.vv=this}return a}();a.VisibilityVertex=B;var C=function(){function a(a,b){this.source=a,this.target=b}return a.prototype.length=function(){var a=this.source.p.x-this.target.p.x,b=this.source.p.y-this.target.p.y;return Math.sqrt(a*a+b*b)},a}();a.VisibilityEdge=C;var D=function(){function b(b,c){if(this.P=b,this.V=[],this.E=[],c)this.V=c.V.slice(0),this.E=c.E.slice(0);else{for(var d=b.length,e=0;d>e;e++)for(var f=b[e],g=0;g0&&this.E.push(new C(f[g-1].vv,i))}for(var e=0;d-1>e;e++)for(var j=b[e],g=e+1;d>g;g++){var k=b[g],l=a.tangents(j,k);for(var m in l){var n=l[m],o=j[n.t1],p=k[n.t2];this.addEdgeIfVisible(o,p,e,g)}}}}return b.prototype.addEdgeIfVisible=function(a,b,c,d){this.intersectsPolys(new w(a.x,a.y,b.x,b.y),c,d)||this.E.push(new C(a.vv,b.vv))},b.prototype.addPoint=function(a,b){var c=this.P.length;this.V.push(new B(this.V.length,c,0,a));for(var d=0;c>d;++d)if(d!==b){var e=this.P[d],f=i(a,e);this.addEdgeIfVisible(a,e[f.ltan],b,d),this.addEdgeIfVisible(a,e[f.rtan],b,d)}return a.vv},b.prototype.intersectsPolys=function(a,b,c){for(var d=0,e=this.P.length;e>d;++d)if(d!=b&&d!=c&&q(a,this.P[d]).length>0)return!0;return!1},b}();a.TangentVisibilityGraph=D,a.tangents=r,a.polysOverlap=u}(c||(c={}));var b;!function(a){function b(a,b){var c={};for(var d in a)c[d]={};for(var d in b)c[d]={};return Object.keys(c).length}function c(a,b){var c=0;for(var d in a)"undefined"!=typeof b[d]&&++c;return c}function d(a,b,c,d){for(var e=new Array(a),f=0;a>f;++f)e[f]={};return b.forEach(function(a){e[c(a)][d(a)]={},e[d(a)][c(a)]={}}),e}function e(a,b,c,e,f,g,h){var i=d(a,b,f,g);b.forEach(function(a){var b=i[f(a)],d=i[g(a)];h(a,1+c*e(b,d))})}function f(a,d,f,g,h,i){"undefined"==typeof i&&(i=1),e(a,d,i,function(a,d){return Math.sqrt(b(a,d)-c(a,d))},f,g,h)}function g(a,d,f,g,h,i){"undefined"==typeof i&&(i=1),e(a,d,i,function(a,d){return Math.min(Object.keys(a).length,Object.keys(d).length)<1.1?0:c(a,d)/b(a,d)},f,g,h)}function h(a,b,c,d,e,f){var g=i(a,b,e,f),h={};g.filter(function(a){return a.length>1}).forEach(function(a){return a.forEach(function(b){return h[b]=a})});var j=[];return b.forEach(function(a){var b=h[e(a)],g=h[f(a)];b&&g&&b.component===g.component||j.push({axis:c,left:e(a),right:f(a),gap:d(a)})}),j}function i(a,b,c,d){function e(a){g[a]=k,h[a]=k,i[a]=!0,k+=1,l.push(a);for(var b=f[a],c=0;c=0;--c){var n=l[c];if(i[n]=!1,j.push(n),n===a){l.length=c;break}}m.push(j)}}for(var f=new Array(a),g=new Array(a),h=new Array(a),i=new Array(a),j=0;a>j;++j)f[j]=[],g[j]=-1,h[j]=0,i[j]=!1;for(var j=0;jj;++j)g[j]<0&&e(j);return m}a.symmetricDiffLinkLengths=f,a.jaccardLinkLengths=g,a.generateDirectedEdgeConstraints=h}(b||(b={}));var e;!function(a){function b(a,c){for(var d in a){var e=a[d];e.getEdges(c),b(e.children,c)}}function c(a,b,d){for(var e in a){var f=a[e];if(f.isLeaf())b.leaves||(b.leaves=[]),b.leaves.push(f.id);else{var g=b;f.gid=d.length,f.isIsland()||(g={id:f.gid},b.groups||(b.groups=[]),b.groups.push(f.gid),d.push(g)),c(f.children,g,d)}}}function d(a,b){var c={};for(var d in a)d in b&&(c[d]=a[d]);return c}function e(a,b){return Object.keys(d(a,b)).length}function f(b,c){for(var d=new a.Configuration(b,c);d.greedyMerge(););var e=[];return{groups:d.getGroupHierarchy(e),powerEdges:e}}var g=function(){function a(a,b){var c=this;this.modules=new Array(a),this.roots=new Array(a);for(var d=0;a>d;++d)this.roots[d]=this.modules[d]=new h(d,{},{},{});this.R=b.length,b.forEach(function(a){var b=c.modules[a.source],d=c.modules[a.target];b.outgoing[d.id]=d,d.incoming[b.id]=b})}return a.prototype.merge=function(a,b){var c=d(a.incoming,b.incoming),e=d(a.outgoing,b.outgoing),f={};f[a.id]=a,f[b.id]=b;var g=new h(this.modules.length,e,c,f);this.modules.push(g);var i=function(c,d,e){for(var f in c){var h=c[f];h[d][g.id]=g,delete h[d][a.id],delete h[d][b.id],delete a[e][f],delete b[e][f]}};return i(e,"incoming","outgoing"),i(c,"outgoing","incoming"),this.R-=Object.keys(c).length+Object.keys(e).length,delete this.roots[a.id],delete this.roots[b.id],this.roots[g.id]=g,g},a.prototype.rootMerges=function(){for(var a=Object.keys(this.roots),b=a.length,c=new Array(b*(b-1)),d=0,e=0,f=b-1;f>e;++e)for(var g=e+1;b>g;++g){var h=this.roots[a[e]],i=this.roots[a[g]];c[d++]={nEdges:this.nEdges(h,i),a:h,b:i}}return c},a.prototype.greedyMerge=function(){var a=this.rootMerges().sort(function(a,b){return a.nEdges-b.nEdges}),b=a[0];return b.nEdges>=this.R?!1:(this.merge(b.a,b.b),!0)},a.prototype.nEdges=function(a,b){return this.R-e(a.outgoing,b.outgoing)-e(a.incoming,b.incoming)},a.prototype.getGroupHierarchy=function(a){var b=this,d=[],e={};c(this.roots,e,d);var f=this.allEdges();return f.forEach(function(c){var e=b.modules[c.source],f=b.modules[c.target];a.push({source:c.source="undefined"==typeof e.gid?c.source:d[e.gid],target:c.target="undefined"==typeof f.gid?c.target:d[f.gid]})}),d},a.prototype.allEdges=function(){var a=[];return b(this.roots,a),a},a}();a.Configuration=g;var h=function(){function a(a,b,c,d){this.id=a,this.outgoing=b,this.incoming=c,this.children=d}return a.prototype.getEdges=function(a){for(var b in this.outgoing)a.push({source:this.id,target:this.outgoing[b].id})},a.prototype.isLeaf=function(){return 0==Object.keys(this.children).length},a.prototype.isIsland=function(){return 0==Object.keys(this.outgoing).length&&0==Object.keys(this.incoming).length},a}();a.Module=h,a.getGroups=f}(e||(e={}));var f,g=function(){function a(a){this.elem=a,this.subheaps=[]}return a.prototype.toString=function(a){for(var b="",c=!1,d=0;da;++a)this.ps.addVariable(this.vars[a]);this.posn=this.ps.getPosn()},a.prototype.compute_lm=function(a,b,c){var d=this,e=a.dfdv();return a.visitNeighbours(b,function(b,f){var g=d.compute_lm(f,a,c);f===b.right?(e+=g*b.left.scale,b.lm=g):(e+=g*b.right.scale,b.lm=-g),c(b)}),e/a.scale},a.prototype.populateSplitBlock=function(a,b){var c=this;a.visitNeighbours(b,function(b,d){d.offset=a.offset+(d===b.right?b.gap:-b.gap),c.addVariable(d),c.populateSplitBlock(d,a)})},a.prototype.traverse=function(a,b,c,d){var e=this;"undefined"==typeof c&&(c=this.vars[0]),"undefined"==typeof d&&(d=null),c.visitNeighbours(d,function(d,f){b.push(a(d)),e.traverse(a,b,f,c)})},a.prototype.findMinLM=function(){var a=null;return this.compute_lm(this.vars[0],null,function(b){!b.equality&&(null===a||b.lmd;++d){var f=a.vars[d];f.offset+=c,this.addVariable(f)}this.posn=this.ps.getPosn()},a.prototype.cost=function(){for(var a=0,b=this.vars.length;b--;){var c=this.vars[b],d=c.position()-c.desiredPosition;a+=d*d*c.weight}return a},a}();a.Block=e;var f=function(){function a(a){this.vs=a;var b=a.length;for(this.list=new Array(b);b--;){var c=new e(a[b]);this.list[b]=c,c.blockInd=b}}return a.prototype.cost=function(){for(var a=0,b=this.list.length;b--;)a+=this.list[b].cost();return a},a.prototype.insert=function(a){a.blockInd=this.list.length,this.list.push(a)},a.prototype.remove=function(a){var b=this.list.length-1,c=this.list[b];this.list.length=b,a!==c&&(this.list[a.blockInd]=c,c.blockInd=a.blockInd)},a.prototype.merge=function(a){var b=a.left.block,c=a.right.block,d=a.right.offset-a.left.offset-a.gap;b.vars.lengthg;++g){var h=d[g];if(!h.unsatisfiable){var i=h.slack();if((h.equality||b>i)&&(b=i,c=h,f=g,h.equality))break}}return f!==e&&(b=0?this.inactive.push(b):this.bs.merge(b)}}},a.prototype.solve=function(){this.satisfy();for(var a=Number.MAX_VALUE,b=this.bs.cost();Math.abs(a-b)>1e-4;)this.satisfy(),a=b,b=this.bs.cost();return b},a.LAGRANGIAN_TOLERANCE=-1e-4,a.ZERO_UPPERBOUND=-1e-10,a}();a.Solver=g}(f||(f={}));var f;!function(a){function b(a){return a.bounds=a.leaves.reduce(function(a,b){return b.bounds.union(a)},q.empty()),"undefined"!=typeof a.groups&&(a.bounds=a.groups.reduce(function(a,c){return b(c).union(a)},a.bounds)),a.bounds}function c(a,b,c,d){var e=b.rayIntersection(c.cx(),c.cy());e||(e={x:b.cx(),y:b.cy()});var f=c.rayIntersection(b.cx(),b.cy());f||(f={x:c.cx(),y:c.cy()});var g=f.x-e.x,h=f.y-e.y,i=Math.sqrt(g*g+h*h),j=i-d;a.sourceIntersection=e,a.targetIntersection=f,a.arrowStart={x:e.x+j*g/i,y:e.y+j*h/i}}function e(a,b,c){var d=b.rayIntersection(a.x,a.y);d||(d={x:b.cx(),y:b.cy()});var e=d.x-a.x,f=d.y-a.y,g=Math.sqrt(e*e+f*f);return{x:d.x-c*e/g,y:d.y-c*f/g}}function f(a,b){return a.pos>b.pos?1:a.pos=i);var k=new Array(j);for(h=0;i>h;++h){var l=b[h],m=new r(c[h],l,d.getCentre(l));k[h]=new s(!0,m,d.getOpen(l)),k[h+i]=new s(!1,m,d.getClose(l))}k.sort(f);var n=new Array,o=g();for(h=0;j>h;++h){var p=k[h],m=p.v;if(p.isOpen)o.insert(m),d.findNeighbours(m,o);else{o.remove(m);var q=function(b,c){var f=(d.getSize(b.r)+d.getSize(c.r))/2+e;n.push(new a.Constraint(b.v,c.v,f))},t=function(a,b,c){for(var d,e=m[a].iterator();null!==(d=e[a]());)c(d,m),d[b].remove(m)};t("prev","next",function(a,b){return q(a,b)}),t("next","prev",function(a,b){return q(b,a)})}}return console.assert(0===o.size),n}function j(a,b){var c=function(c,d){for(var e,f=b.findIter(a);null!==(e=f[c]());){var g=e.r.overlapX(a.r);if((0>=g||g<=e.r.overlapY(a.r))&&(a[c].insert(e),e[d].insert(a)),0>=g)break}};c("next","prev"),c("prev","next")}function k(a,b){var c=function(c,d){var e=b.findIter(a)[c]();null!==e&&e.r.overlapX(a.r)>0&&(a[c].insert(e),e[d].insert(a))};c("next","prev"),c("prev","next")}function l(a,b){return i(a,b,t,1e-6)}function m(a,b){return i(a,b,u,1e-6)}function n(a){return h(a,t,1e-6)}function o(a){return h(a,u,1e-6)}function p(b){var c=b.map(function(b){return new a.Variable(b.cx())}),d=a.generateXConstraints(b,c),e=new a.Solver(c,d);e.solve(),c.forEach(function(a,c){return b[c].setXCentre(a.position())}),c=b.map(function(b){return new a.Variable(b.cy())}),d=a.generateYConstraints(b,c),e=new a.Solver(c,d),e.solve(),c.forEach(function(a,c){return b[c].setYCentre(a.position())})}a.computeGroupBounds=b;var q=function(){function a(a,b,c,d){this.x=a,this.X=b,this.y=c,this.Y=d}return a.empty=function(){return new a(Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY)},a.prototype.cx=function(){return(this.x+this.X)/2},a.prototype.cy=function(){return(this.y+this.Y)/2},a.prototype.overlapX=function(a){var b=this.cx(),c=a.cx();return c>=b&&a.x=c&&this.x=b&&a.y=c&&this.yg;++g){var h=a.lineIntersection(d,e,b,c,f[g][0],f[g][1],f[g][2],f[g][3]);if(null!==h)return{x:h.x,y:h.y}}return null},a.prototype.vertices=function(){return[{x:this.x,y:this.y},{x:this.X,y:this.y},{x:this.X,y:this.Y},{x:this.x,y:this.Y},{x:this.x,y:this.y}]},a.lineIntersection=function(a,b,c,d,e,f,g,h){var i=c-a,j=g-e,k=d-b,l=h-f,m=l*i-j*k;if(0==m)return null;var n=a-e,o=b-f,p=j*o-l*n,q=p/m,r=i*o-k*n,s=r/m;return q>=0&&1>=q&&s>=0&&1>=s?{x:a+q*i,y:b+q*k}:null},a.prototype.inflate=function(b){return new a(this.x-b,this.X+b,this.y-b,this.Y+b)},a}();a.Rectangle=q,a.makeEdgeBetween=c,a.makeEdgeTo=e;var r=function(){function a(a,b,c){this.v=a,this.r=b,this.pos=c,this.prev=g(),this.next=g()}return a}(),s=function(){function a(a,b,c){this.isOpen=a,this.v=b,this.pos=c}return a}(),t={getCentre:function(a){return a.cx()},getOpen:function(a){return a.y},getClose:function(a){return a.Y},getSize:function(a){return a.width()},makeRect:function(a,b,c,d){return new q(c-d/2,c+d/2,a,b)},findNeighbours:j},u={getCentre:function(a){return a.cy()},getOpen:function(a){return a.x},getClose:function(a){return a.X},getSize:function(a){return a.height()},makeRect:function(a,b,c,d){return new q(a,b,c-d/2,c+d/2)},findNeighbours:k};a.generateXConstraints=l,a.generateYConstraints=m,a.generateXGroupConstraints=n,a.generateYGroupConstraints=o,a.removeOverlaps=p;var v=function(a){function b(b,c){a.call(this,0,c),this.index=b}return d(b,a),b}(a.Variable),w=function(){function c(c,d,e,f,g){"undefined"==typeof e&&(e=null),"undefined"==typeof f&&(f=null),"undefined"==typeof g&&(g=!1);var h=this;if(this.nodes=c,this.groups=d,this.rootGroup=e,this.avoidOverlaps=g,this.variables=c.map(function(a,b){return a.variable=new v(b,1)}),f&&this.createConstraints(f),g&&e&&"undefined"!=typeof e.groups){c.forEach(function(b){if(!b.width||!b.height)return void(b.bounds=new a.Rectangle(b.x,b.x,b.y,b.y));var c=b.width/2,d=b.height/2;b.bounds=new a.Rectangle(b.x-c,b.x+c,b.y-d,b.y+d)}),b(e);var i=c.length;d.forEach(function(a){h.variables[i]=a.minVar=new v(i++,.01),h.variables[i]=a.maxVar=new v(i++,.01)})}}return c.prototype.createSeparation=function(b){return new a.Constraint(this.nodes[b.left].variable,this.nodes[b.right].variable,b.gap,"undefined"!=typeof b.equality?b.equality:!1)},c.prototype.makeFeasible=function(a){var b=this;if(this.avoidOverlaps){var c="x",d="width";"x"===a.axis&&(c="y",d="height");var e=a.offsets.map(function(a){return b.nodes[a.node]}).sort(function(a,b){return a[c]-b[c]}),f=null;e.forEach(function(a){f&&(a[c]=f[c]+f[d]+1),f=a})}},c.prototype.createAlignment=function(b){var c=this,d=this.nodes[b.offsets[0].node].variable;this.makeFeasible(b);var e="x"===b.axis?this.xConstraints:this.yConstraints;b.offsets.slice(1).forEach(function(b){var f=c.nodes[b.node].variable;e.push(new a.Constraint(d,f,b.offset,!0))})},c.prototype.createConstraints=function(a){var b=this,c=function(a){return"undefined"==typeof a.type||"separation"===a.type};this.xConstraints=a.filter(function(a){return"x"===a.axis&&c(a)}).map(function(a){return b.createSeparation(a)}),this.yConstraints=a.filter(function(a){return"y"===a.axis&&c(a)}).map(function(a){return b.createSeparation(a)}),a.filter(function(a){return"alignment"===a.type}).forEach(function(a){return b.createAlignment(a)})},c.prototype.setupVariablesAndBounds=function(a,b,c,d){this.nodes.forEach(function(e,f){e.fixed?(e.variable.weight=1e3,c[f]=d(e)):e.variable.weight=1;var g=(e.width||0)/2,h=(e.height||0)/2,i=a[f],j=b[f];e.bounds=new q(i-g,i+g,j-h,j+h)})},c.prototype.xProject=function(a,b,c){(this.rootGroup||this.avoidOverlaps||this.xConstraints)&&this.project(a,b,a,c,function(a){return a.px},this.xConstraints,n,function(a){return a.bounds.setXCentre(c[a.variable.index]=a.variable.position())},function(a){a.bounds.x=c[a.minVar.index]=a.minVar.position(),a.bounds.X=c[a.maxVar.index]=a.maxVar.position()})},c.prototype.yProject=function(a,b,c){(this.rootGroup||this.yConstraints)&&this.project(a,b,b,c,function(a){return a.py},this.yConstraints,o,function(a){return a.bounds.setYCentre(c[a.variable.index]=a.variable.position())},function(a){a.bounds.y=c[a.minVar.index]=a.minVar.position(),a.bounds.Y=c[a.maxVar.index]=a.maxVar.position()})},c.prototype.projectFunctions=function(){var a=this;return[function(b,c,d){return a.xProject(b,c,d)},function(b,c,d){return a.yProject(b,c,d)}]},c.prototype.project=function(a,c,d,e,f,g,h,i,j){this.setupVariablesAndBounds(a,c,e,f),this.rootGroup&&this.avoidOverlaps&&(b(this.rootGroup),g=g.concat(h(this.rootGroup))),this.solve(this.variables,g,d,e),this.nodes.forEach(i),this.rootGroup&&this.avoidOverlaps&&this.groups.forEach(j) -},c.prototype.solve=function(b,c,d,e){var f=new a.Solver(b,c);f.setStartingPositions(d),f.setDesiredPositions(e),f.solve()},c}();a.Projection=w}(f||(f={}));var j;!function(a){var b=function(){function a(a,b){this.id=a,this.distance=b}return a}(),c=function(){function a(a){this.id=a,this.neighbours=[]}return a}(),d=function(){function a(a,d,e,f,g){this.n=a,this.es=d,this.neighbours=new Array(this.n);for(var h=this.n;h--;)this.neighbours[h]=new c(h);for(h=this.es.length;h--;){var i=this.es[h],j=e(i),k=f(i),l=g(i);this.neighbours[j].neighbours.push(new b(k,l)),this.neighbours[k].neighbours.push(new b(j,l))}}return a.prototype.DistanceMatrix=function(){for(var a=new Array(this.n),b=0;bl&&(j.d=l,j.prev=g,j.q=c.reduceKey(j.q,j))}}return e},a}();a.Calculator=d}(j||(j={}));var b;!function(b){function d(a){a.fixed|=2,a.px=a.x,a.py=a.y}function e(a){a.fixed&=-7}return"undefined"==typeof f&&(f=b.vpsc),b.d3adaptor=function(){function g(a,b){a.length=b}function h(a){return a}function k(a){return"number"==typeof a.source?a.source:a.source.index}function l(a){return"number"==typeof a.target?a.target:a.target.index}function m(b){b.px=a.event.x,b.py=a.event.y,q.resume()}var n,o,p,q={},r=a.dispatch("start","tick","end"),s=[1,1],t=20,u=!1,v=!0,w=!1,x=[],y=[],z=[],A=null,B=[],C=[],D=null,E=null,F=null,G=1e-5,H=10;return q.tick=function(){if(G>o)return r.end({type:"end",alpha:o=0}),delete p,w=!1,!0;{var a,b=x.length;B.length}for(E.locks.clear(),i=0;b>i;++i)if(a=x[i],a.fixed){("undefined"==typeof a.px||"undefined"==typeof a.py)&&(a.px=a.x,a.py=a.y);var c=[a.px,a.py];E.locks.add(i,c)}var d=E.rungeKutta();for(0===d?o=0:"undefined"!=typeof p&&p>d-G&&(o=p/d-1),p=d,i=0;b>i;++i)a=x[i],a.fixed?(a.x=a.px,a.y=a.py):(a.x=E.x[0][i],a.y=E.x[1][i]);r.tick({type:"tick",alpha:o})},q.nodes=function(a){if(!arguments.length){if(0===x.length&&B.length>0){var b=0;B.forEach(function(a){b=Math.max(b,a.source,a.target)}),x=new Array(++b);for(var c=0;b>c;++c)x[c]={}}return x}return x=a,q},q.groups=function(a){return arguments.length?(y=a,A={},y.forEach(function(a){"undefined"!=typeof a.leaves&&a.leaves.forEach(function(b,c){(a.leaves[c]=x[b]).parent=a}),"undefined"!=typeof a.groups&&a.groups.forEach(function(b,c){(a.groups[c]=y[b]).parent=a})}),A.leaves=x.filter(function(a){return"undefined"==typeof a.parent}),A.groups=y.filter(function(a){return"undefined"==typeof a.parent}),q):y},q.avoidOverlaps=function(a){return arguments.length?(u=a,q):u},q.handleDisconnected=function(a){return arguments.length?(v=a,q):v},q.flowLayout=function(a,b){return arguments.length||(a="y"),F={axis:a,getMinSeparation:"number"==typeof b?function(){return b}:b},q},q.links=function(a){return arguments.length?(B=a,q):B},q.constraints=function(a){return arguments.length?(C=a,q):C},q.distanceMatrix=function(a){return arguments.length?(D=a,q):D},q.size=function(a){return arguments.length?(s=a,q):s},q.defaultNodeSize=function(a){return arguments.length?(H=a,q):H},q.linkDistance=function(a){return arguments.length?(t="function"==typeof a?a:+a,q):"function"==typeof t?t():t},q.convergenceThreshold=function(a){return arguments.length?(G="function"==typeof a?a:+a,q):G},q.alpha=function(b){return arguments.length?(b=+b,o?o=b>0?b:0:b>0&&(w||(w=!0,r.start({type:"start",alpha:o=b}),a.timer(q.tick))),q):o},q.symmetricDiffLinkLengths=function(a,c){return b.symmetricDiffLinkLengths(this.nodes().length,B,k,l,g,c),function(b){return a*b.length}},q.jaccardLinkLengths=function(a,c){return b.jaccardLinkLengths(this.nodes().length,B,k,l,g,c),function(b){return a*b.length}},q.start=function(){var a,c=this.nodes().length,d=c+2*y.length,e=(B.length,s[0]),g=s[1],h=new Array(d),i=new Array(d);z=new Array(d);var j=null,m=this.avoidOverlaps();x.forEach(function(a,b){a.index=b,"undefined"==typeof a.x&&(a.x=e/2,a.y=g/2),h[b]=a.x,i[b]=a.y});var n;if(D)n=D;else{var o=function(b){return"function"==typeof t?+t.call(this,b,a):t};n=new b.shortestpaths.Calculator(d,B,k,l,o).DistanceMatrix(),j=b.Descent.createSquareMatrix(d,function(){return 2}),B.forEach(function(a){j[k(a)][l(a)]=j[l(a)][k(a)]=1})}var p=b.Descent.createSquareMatrix(d,function(a,b){return n[a][b]});if(A&&"undefined"!=typeof A.groups){var a=c;y.forEach(function(){j[a][a+1]=j[a+1][a]=1e-6,p[a][a+1]=p[a+1][a]=.1,h[a]=0,i[a++]=0,h[a]=0,i[a++]=0})}else A={leaves:x,groups:[]};F&&(C=(C||[]).concat(b.generateDirectedEdgeConstraints(c,B,F.axis,F.getMinSeparation,k,l)));var r=arguments.length>0?arguments[0]:0,u=arguments.length>1?arguments[1]:0,w=arguments.length>2?arguments[2]:0;return this.avoidOverlaps(!1),E=new b.Descent([h,i],p),E.threshold=G,E.run(r),C.length>0&&(E.project=new f.Projection(x,y,A,C).projectFunctions()),E.run(u),this.avoidOverlaps(m),m&&(E.project=new f.Projection(x,y,A,C,!0).projectFunctions()),E.G=j,E.run(w),B.forEach(function(a){"number"==typeof a.source&&(a.source=x[a.source]),"number"==typeof a.target&&(a.target=x[a.target])}),x.forEach(function(a,b){a.x=h[b],a.y=i[b]}),!D&&v&&(b.applyPacking(b.separateGraphs(x,B),e,g,H),x.forEach(function(a,b){E.x[0][b]=a.x,E.x[1][b]=a.y})),q.resume()},q.resume=function(){return q.alpha(.1)},q.stop=function(){return q.alpha(0)},q.routeEdge=function(a,b){var d=[],e=new c.TangentVisibilityGraph(a.P,{V:a.V,E:a.E}),g={x:b.source.x,y:b.source.y},h={x:b.target.x,y:b.target.y},i=e.addPoint(g,b.source.id),k=e.addPoint(h,b.target.id);e.addEdgeIfVisible(g,h,b.source.id,b.target.id);var l=e.E.map(function(a){return{source:a.source.id,target:a.target.id,length:a.length()}}),m=new j.Calculator(e.V.length,l),n=m.PathFromNodeToNode(i.id,k.id);if(1===n.length||n.length===e.V.length)f.makeEdgeBetween(b,b.source.innerBounds,b.target.innerBounds,5),d=[{x:b.sourceIntersection.x,y:b.sourceIntersection.y},{x:b.arrowStart.x,y:b.arrowStart.y}];else{for(var o=n.length-2,p=e.V[n[o]].p,q=e.V[n[0]].p,d=[b.source.innerBounds.rayIntersection(p.x,p.y)],r=o;r>=0;--r)d.push(e.V[n[r]].p);d.push(f.makeEdgeTo(q,b.target.innerBounds,5))}return d},q.drag=function(){return n||(n=a.behavior.drag().origin(h).on("dragstart.d3adaptor",d).on("drag.d3adaptor",m).on("dragend.d3adaptor",e)),arguments.length?void this.call(n):n},q.linkId=function(a){return k(a)+"-"+l(a)},a.rebind(q,r,"on")},b}(b||(b={})),RBTree=function(a){var b=function(a){var c=b.m[a];if(c.mod)return c.mod.exports;var d=c.mod={exports:{}};return c(d,d.exports),d.exports};return b.m={},b.m["./treebase"]=function(a){function b(){}function c(a){this._tree=a,this._ancestors=[],this._cursor=null}b.prototype.clear=function(){this._root=null,this.size=0},b.prototype.find=function(a){for(var b=this._root;null!==b;){var c=this._comparator(a,b.data);if(0===c)return b.data;b=b.get_child(c>0)}return null},b.prototype.findIter=function(a){for(var b=this._root,c=this.iterator();null!==b;){var d=this._comparator(a,b.data);if(0===d)return c._cursor=b,c;c._ancestors.push(b),b=b.get_child(d>0)}return null},b.prototype.lowerBound=function(a){return this._bound(a,this._comparator)},b.prototype.upperBound=function(a){function b(a,b){return c(b,a)}var c=this._comparator;return this._bound(a,b)},b.prototype.min=function(){var a=this._root;if(null===a)return null;for(;null!==a.left;)a=a.left;return a.data},b.prototype.max=function(){var a=this._root;if(null===a)return null;for(;null!==a.right;)a=a.right;return a.data},b.prototype.iterator=function(){return new c(this)},b.prototype.each=function(a){for(var b,c=this.iterator();null!==(b=c.next());)a(b)},b.prototype.reach=function(a){for(var b,c=this.iterator();null!==(b=c.prev());)a(b)},b.prototype._bound=function(a,b){for(var c=this._root,d=this.iterator();null!==c;){var e=this._comparator(a,c.data);if(0===e)return d._cursor=c,d;d._ancestors.push(c),c=c.get_child(e>0)}for(var f=d._ancestors.length-1;f>=0;--f)if(c=d._ancestors[f],b(a,c.data)>0)return d._cursor=c,d._ancestors.length=f,d;return d._ancestors.length=0,d},c.prototype.data=function(){return null!==this._cursor?this._cursor.data:null},c.prototype.next=function(){if(null===this._cursor){var a=this._tree._root;null!==a&&this._minNode(a)}else if(null===this._cursor.right){var b;do{if(b=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.right===b)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return null!==this._cursor?this._cursor.data:null},c.prototype.prev=function(){if(null===this._cursor){var a=this._tree._root;null!==a&&this._maxNode(a)}else if(null===this._cursor.left){var b;do{if(b=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.left===b)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return null!==this._cursor?this._cursor.data:null},c.prototype._minNode=function(a){for(;null!==a.left;)this._ancestors.push(a),a=a.left;this._cursor=a},c.prototype._maxNode=function(a){for(;null!==a.right;)this._ancestors.push(a),a=a.right;this._cursor=a},a.exports=b},b.m.__main__=function(a){function c(a){this.data=a,this.left=null,this.right=null,this.red=!0}function d(a){this._root=null,this._comparator=a,this.size=0}function e(a){return null!==a&&a.red}function f(a,b){var c=a.get_child(!b);return a.set_child(!b,c.get_child(b)),c.set_child(b,a),a.red=!0,c.red=!1,c}function g(a,b){return a.set_child(!b,f(a.get_child(!b),!b)),f(a,b)}var h=b("./treebase");c.prototype.get_child=function(a){return a?this.right:this.left},c.prototype.set_child=function(a,b){a?this.right=b:this.left=b},d.prototype=new h,d.prototype.insert=function(a){var b=!1;if(null===this._root)this._root=new c(a),b=!0,this.size++;else{var d=new c(void 0),h=0,i=0,j=null,k=d,l=null,m=this._root;for(k.right=this._root;;){if(null===m?(m=new c(a),l.set_child(h,m),b=!0,this.size++):e(m.left)&&e(m.right)&&(m.red=!0,m.left.red=!1,m.right.red=!1),e(m)&&e(l)){var n=k.right===j;m===l.get_child(i)?k.set_child(n,f(j,!i)):k.set_child(n,g(j,!i))}var o=this._comparator(m.data,a);if(0===o)break;i=h,h=0>o,null!==j&&(k=j),j=l,l=m,m=m.get_child(h)}this._root=d.right}return this._root.red=!1,b},d.prototype.remove=function(a){if(null===this._root)return!1;var b=new c(void 0),d=b;d.right=this._root;for(var h=null,i=null,j=null,k=1;null!==d.get_child(k);){var l=k;i=h,h=d,d=d.get_child(k);var m=this._comparator(a,d.data);if(k=m>0,0===m&&(j=d),!e(d)&&!e(d.get_child(k)))if(e(d.get_child(!k))){var n=f(d,k);h.set_child(l,n),h=n}else if(!e(d.get_child(!k))){var o=h.get_child(!l);if(null!==o)if(e(o.get_child(!l))||e(o.get_child(l))){var p=i.right===h;e(o.get_child(l))?i.set_child(p,g(h,l)):e(o.get_child(!l))&&i.set_child(p,f(h,l));var q=i.get_child(p);q.red=!0,d.red=!0,q.left.red=!1,q.right.red=!1}else h.red=!1,o.red=!0,d.red=!0}}return null!==j&&(j.data=d.data,h.set_child(h.right===d,d.get_child(null===d.left)),this.size--),this._root=b.right,null!==this._root&&(this._root.red=!1),null!==j},a.exports=d},b("__main__")}(window);var b;return function(a){var b={};return b.PADDING=10,b.GOLDEN_SECTION=(1+Math.sqrt(5))/2,b.FLOAT_EPSILON=1e-5,a.applyPacking=function(a,c,d,e,f){function g(a){function b(a){for(var b=Number.MAX_VALUE,c=Number.MAX_VALUE,d=0,f=0,g=0;gp||Math.abs(g-h)>b.FLOAT_EPSILON;){var e=d-(d-c)/b.GOLDEN_SECTION,f=c+(d-c)/b.GOLDEN_SECTION,g=j(a,e),h=j(a,f);g>h?c=e:d=f}}function j(a,b){r=[],n=0,o=0,q=t;for(var c=0;c=a.height&&r[e].x+r[e].width+a.width+b.PADDING-c<=b.FLOAT_EPSILON){d=r[e];break}void 0!==d?(a.x=d.x+d.width+b.PADDING,a.y=d.bottom,a.space_left=a.height,a.bottom=a.y,d.space_left-=a.height+b.PADDING,d.bottom+=a.height+b.PADDING):(a.y=q,q+=a.height+b.PADDING,a.x=s,a.bottom=a.y,a.space_left=a.height),a.y+a.height-o>-b.FLOAT_EPSILON&&(o=a.y+a.height-t),a.x+a.width-n>-b.FLOAT_EPSILON&&(n=a.x+a.width-s)}function l(a){var c=0;return a.forEach(function(a){return c+=a.width+b.PADDING}),c}function m(){return n/o}var n,o,p,q,r,s=0,t=0,u=c,v=d,f="undefined"!=typeof f?f:1,e="undefined"!=typeof e?e:6;0!=a.length&&(g(a),i(a),h(a))},a.separateGraphs=function(a,b){function c(a,b){if(void 0===d[a.index]){b&&(f++,graphs.push({array:[]})),d[a.index]=f,graphs[f-1].array.push(a);var g=e[a.index];if(g)for(var h=0;hh;){var i=c[h][g];i>0&&id;++d){c[d]=new Array(a);for(var e=0;a>e;++e)c[d][e]=b(d,e)}return c},a.prototype.offsetDir=function(){for(var a=this,b=new Array(this.k),c=0,d=0;dc)){for(var d,e=new Array(this.k),f=new Array(this.k),g=new Array(this.k),h=0,i=0;c>i;++i){for(d=0;dj;++j)if(i!==j){for(;;){var k=0;for(d=0;d1e-9)break;var m=this.offsetDir();for(d=0;d1&&n>o||!isFinite(o))for(d=0;d1&&(p=1);var q=o*o,r=p*(n-o)/(q*n),s=-p/(q*n*n*n);for(isFinite(r)||console.log(r),d=0;de;++e)c+=a.dotProd(this.g[e],b[e]),a.rightMultiply(this.H[e],b[e],this.Hd[e]),d+=a.dotProd(b[e],this.Hd[e]);return 0!==d&&isFinite(d)?c/d:0},a.prototype.reduceStress=function(){this.computeDerivatives(this.x);for(var a=this.computeStepSize(this.g),b=0;be;++e)for(var f=0;d>f;++f)b[e][f]=a[e][f]},a.prototype.stepAndProject=function(b,c,d,e){a.copy(b,c),this.takeDescentStep(c[0],d[0],e),this.project&&this.project[0](b[0],b[1],c[0]),this.takeDescentStep(c[1],d[1],e),this.project&&this.project[1](c[0],b[1],c[1])},a.mApply=function(a,b,c){for(var d=a;d-->0;)for(var e=b;e-->0;)c(d,e)},a.prototype.matrixApply=function(b){a.mApply(this.k,this.n,b)},a.prototype.computeNextPosition=function(a,b){var c=this;this.computeDerivatives(a);var d=this.computeStepSize(this.g);this.stepAndProject(a,b,this.g,d);for(var e=0;e0;){var d=this.rungeKutta();c=Math.abs(b/d-1)b;++b)for(var d=b+1,e=this.n;e>d;++d){for(var f=0,g=0;g>16)/this.range},a.prototype.getNextBetween=function(a,b){return a+this.getNext()*(b-a)},a}();a.PseudoRandom=d}(b||(b={}));var c,d=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c};!function(a){function b(a,b,c){return(b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y)}function c(a,c,d){return b(a,c,d)>0}function e(a,c,d){return b(a,c,d)<0}function g(a){var c,d=a.slice(0).sort(function(a,b){return a.x!==b.x?b.x-a.x:b.y-a.y}),e=a.length,f=0,g=d[0].x;for(c=1;e>c&&d[c].x===g;++c);var h=c-1,i=[];if(i.push(d[f]),h===e-1)d[h].y!==d[f].y&&i.push(d[h]);else{var j,k=e-1,l=d[e-1].x;for(c=e-2;c>=0&&d[c].x===l;c--);for(j=c+1,c=h;++c<=j;)if(!(b(d[f],d[j],d[c])>=0&&j>c)){for(;i.length>1&&!(b(i[i.length-2],i[i.length-1],d[c])>0);)i.length-=1;c!=f&&i.push(d[c])}k!=j&&i.push(d[k]);var m=i.length;for(c=j;--c>=h;)if(!(b(d[k],d[h],d[c])>=0&&c>h)){for(;i.length>m&&!(b(i[i.length-2],i[i.length-1],d[c])>0);)i.length-=1;c!=f&&i.push(d[c])}}return i}function h(a,b,c){b.slice(0).sort(function(b,c){return Math.atan2(b.y-a.y,b.x-a.x)-Math.atan2(c.y-a.y,c.x-a.x)}).forEach(c)}function i(a,b){return{rtan:j(a,b),ltan:k(a,b)}}function j(a,b){var d,f,g,h,i,j=b.length-1;if(e(a,b[1],b[0])&&!c(a,b[j-1],b[0]))return 0;for(d=0,f=j;;){if(f-d===1)return c(a,b[d],b[f])?d:f;if(g=Math.floor((d+f)/2),i=e(a,b[g+1],b[g]),i&&!c(a,b[g-1],b[g]))return g;h=c(a,b[d+1],b[d]),h?i?f=g:c(a,b[d],b[g])?f=g:d=g:i?e(a,b[d],b[g])?f=g:d=g:d=g}}function k(a,b){var d,f,g,h,i,j=b.length-1;if(c(a,b[j-1],b[0])&&!e(a,b[1],b[0]))return 0;for(d=0,f=j;;){if(f-d===1)return e(a,b[d],b[f])?d:f;if(g=Math.floor((d+f)/2),i=e(a,b[g+1],b[g]),c(a,b[g-1],b[g])&&!i)return g;h=e(a,b[d+1],b[d]),h?i?e(a,b[d],b[g])?f=g:d=g:f=g:i?d=g:c(a,b[d],b[g])?f=g:d=g}}function l(a,b,c,d,e,f){var g,h;g=c(b[0],a),h=d(a[g],b);for(var i=!1;!i;){for(i=!0;;){if(g===a.length-1&&(g=0),e(b[h],a[g],a[g+1]))break;++g}for(;;){if(0===h&&(h=b.length-1),f(a[g],b[h],b[h-1]))break;--h,i=!1}}return{t1:g,t2:h}}function m(a,b){var c=n(b,a);return{t1:c.t2,t2:c.t1}}function n(a,b){return l(a,b,j,k,c,e)}function o(a,b){return l(a,b,k,k,e,e)}function p(a,b){return l(a,b,j,j,c,c)}function q(a,b){for(var c=[],d=1,e=b.length;e>d;++d){var g=f.Rectangle.lineIntersection(a.x1,a.y1,a.x2,a.y2,b[d-1].x,b[d-1].y,b[d].x,b[d].y);g&&c.push(g)}return c}function r(a,c){for(var d=a.length-1,e=c.length-1,f=new z,g=0;d>g;++g)for(var h=0;e>h;++h){var i=a[0==g?d-1:g-1],j=a[g],k=a[g+1],l=c[0==h?e-1:h-1],m=c[h],n=c[h+1],o=b(i,j,m),p=b(j,l,m),q=b(j,m,n),r=b(l,m,j),s=b(m,i,j),t=b(m,j,k);o>=0&&p>=0&&0>q&&r>=0&&s>=0&&0>t?f.ll=new y(g,h):0>=o&&0>=p&&q>0&&0>=r&&0>=s&&t>0?f.rr=new y(g,h):0>=o&&p>0&&0>=q&&r>=0&&0>s&&t>=0?f.rl=new y(g,h):o>=0&&0>p&&q>=0&&0>=r&&s>0&&0>=t&&(f.lr=new y(g,h))}return f}function s(a,b){for(var c=1,d=b.length;d>c;++c)if(e(b[c-1],b[c],a))return!1;return!0}function t(a,b){return!a.every(function(a){return!s(a,b)})}function u(a,b){if(t(a,b))return!0;if(t(b,a))return!0;for(var c=1,d=a.length;d>c;++c){var e=a[c],f=a[c-1];if(q(new w(f.x,f.y,e.x,e.y),b).length>0)return!0}return!1}var v=function(){function a(){}return a}();a.Point=v;var w=function(){function a(a,b,c,d){this.x1=a,this.y1=b,this.x2=c,this.y2=d}return a}();a.LineSegment=w;var x=function(a){function b(){a.apply(this,arguments)}return d(b,a),b}(v);a.PolyPoint=x,a.isLeft=b,a.ConvexHull=g,a.clockwiseRadialSweep=h,a.tangent_PolyPolyC=l,a.LRtangent_PolyPolyC=m,a.RLtangent_PolyPolyC=n,a.LLtangent_PolyPolyC=o,a.RRtangent_PolyPolyC=p;var y=function(){function a(a,b){this.t1=a,this.t2=b}return a}();a.BiTangent=y;var z=function(){function a(){}return a}();a.BiTangents=z;var A=function(a){function b(){a.apply(this,arguments)}return d(b,a),b}(v);a.TVGPoint=A;var B=function(){function a(a,b,c,d){this.id=a,this.polyid=b,this.polyvertid=c,this.p=d,d.vv=this}return a}();a.VisibilityVertex=B;var C=function(){function a(a,b){this.source=a,this.target=b}return a.prototype.length=function(){var a=this.source.p.x-this.target.p.x,b=this.source.p.y-this.target.p.y;return Math.sqrt(a*a+b*b)},a}();a.VisibilityEdge=C;var D=function(){function b(b,c){if(this.P=b,this.V=[],this.E=[],c)this.V=c.V.slice(0),this.E=c.E.slice(0);else{for(var d=b.length,e=0;d>e;e++)for(var f=b[e],g=0;g0&&this.E.push(new C(f[g-1].vv,i))}for(var e=0;d-1>e;e++)for(var j=b[e],g=e+1;d>g;g++){var k=b[g],l=a.tangents(j,k);for(var m in l){var n=l[m],o=j[n.t1],p=k[n.t2];this.addEdgeIfVisible(o,p,e,g)}}}}return b.prototype.addEdgeIfVisible=function(a,b,c,d){this.intersectsPolys(new w(a.x,a.y,b.x,b.y),c,d)||this.E.push(new C(a.vv,b.vv))},b.prototype.addPoint=function(a,b){var c=this.P.length;this.V.push(new B(this.V.length,c,0,a));for(var d=0;c>d;++d)if(d!==b){var e=this.P[d],f=i(a,e);this.addEdgeIfVisible(a,e[f.ltan],b,d),this.addEdgeIfVisible(a,e[f.rtan],b,d)}return a.vv},b.prototype.intersectsPolys=function(a,b,c){for(var d=0,e=this.P.length;e>d;++d)if(d!=b&&d!=c&&q(a,this.P[d]).length>0)return!0;return!1},b}();a.TangentVisibilityGraph=D,a.tangents=r,a.polysOverlap=u}(c||(c={}));var b;!function(a){function b(a,b){var c={};for(var d in a)c[d]={};for(var d in b)c[d]={};return Object.keys(c).length}function c(a,b){var c=0;for(var d in a)"undefined"!=typeof b[d]&&++c;return c}function d(a,b,c,d){for(var e=new Array(a),f=0;a>f;++f)e[f]={};return b.forEach(function(a){e[c(a)][d(a)]={},e[d(a)][c(a)]={}}),e}function e(a,b,c,e,f,g,h){var i=d(a,b,f,g);b.forEach(function(a){var b=i[f(a)],d=i[g(a)];h(a,1+c*e(b,d))})}function f(a,d,f,g,h,i){"undefined"==typeof i&&(i=1),e(a,d,i,function(a,d){return Math.sqrt(b(a,d)-c(a,d))},f,g,h)}function g(a,d,f,g,h,i){"undefined"==typeof i&&(i=1),e(a,d,i,function(a,d){return Math.min(Object.keys(a).length,Object.keys(d).length)<1.1?0:c(a,d)/b(a,d)},f,g,h)}function h(a,b,c,d,e,f){var g=i(a,b,e,f),h={};g.filter(function(a){return a.length>1}).forEach(function(a){return a.forEach(function(b){return h[b]=a})});var j=[];return b.forEach(function(a){var b=h[e(a)],g=h[f(a)];b&&g&&b.component===g.component||j.push({axis:c,left:e(a),right:f(a),gap:d(a)})}),j}function i(a,b,c,d){function e(a){g[a]=k,h[a]=k,i[a]=!0,k+=1,l.push(a);for(var b=f[a],c=0;c=0;--c){var n=l[c];if(i[n]=!1,j.push(n),n===a){l.length=c;break}}m.push(j)}}for(var f=new Array(a),g=new Array(a),h=new Array(a),i=new Array(a),j=0;a>j;++j)f[j]=[],g[j]=-1,h[j]=0,i[j]=!1;for(var j=0;jj;++j)g[j]<0&&e(j);return m}a.symmetricDiffLinkLengths=f,a.jaccardLinkLengths=g,a.generateDirectedEdgeConstraints=h}(b||(b={}));var e;!function(a){function b(a,c){for(var d in a){var e=a[d];e.getEdges(c),b(e.children,c)}}function c(a,b,d){for(var e in a){var f=a[e];if(f.isLeaf())b.leaves||(b.leaves=[]),b.leaves.push(f.id);else{var g=b;f.gid=d.length,f.isIsland()||(g={id:f.gid},b.groups||(b.groups=[]),b.groups.push(f.gid),d.push(g)),c(f.children,g,d)}}}function d(a,b){var c={};for(var d in a)d in b&&(c[d]=a[d]);return c}function e(a,b){return Object.keys(d(a,b)).length}function f(b,c){for(var d=new a.Configuration(b,c);d.greedyMerge(););var e=[];return{groups:d.getGroupHierarchy(e),powerEdges:e}}var g=function(){function a(a,b){var c=this;this.modules=new Array(a),this.roots=new Array(a);for(var d=0;a>d;++d)this.roots[d]=this.modules[d]=new h(d,{},{},{});this.R=b.length,b.forEach(function(a){var b=c.modules[a.source],d=c.modules[a.target];b.outgoing[d.id]=d,d.incoming[b.id]=b})}return a.prototype.merge=function(a,b){var c=d(a.incoming,b.incoming),e=d(a.outgoing,b.outgoing),f={};f[a.id]=a,f[b.id]=b;var g=new h(this.modules.length,e,c,f);this.modules.push(g);var i=function(c,d,e){for(var f in c){var h=c[f];h[d][g.id]=g,delete h[d][a.id],delete h[d][b.id],delete a[e][f],delete b[e][f]}};return i(e,"incoming","outgoing"),i(c,"outgoing","incoming"),this.R-=Object.keys(c).length+Object.keys(e).length,delete this.roots[a.id],delete this.roots[b.id],this.roots[g.id]=g,g},a.prototype.rootMerges=function(){for(var a=Object.keys(this.roots),b=a.length,c=new Array(b*(b-1)),d=0,e=0,f=b-1;f>e;++e)for(var g=e+1;b>g;++g){var h=this.roots[a[e]],i=this.roots[a[g]];c[d++]={nEdges:this.nEdges(h,i),a:h,b:i}}return c},a.prototype.greedyMerge=function(){var a=this.rootMerges().sort(function(a,b){return a.nEdges-b.nEdges}),b=a[0];return b.nEdges>=this.R?!1:(this.merge(b.a,b.b),!0)},a.prototype.nEdges=function(a,b){return this.R-e(a.outgoing,b.outgoing)-e(a.incoming,b.incoming)},a.prototype.getGroupHierarchy=function(a){var b=this,d=[],e={};c(this.roots,e,d);var f=this.allEdges();return f.forEach(function(c){var e=b.modules[c.source],f=b.modules[c.target];a.push({source:c.source="undefined"==typeof e.gid?c.source:d[e.gid],target:c.target="undefined"==typeof f.gid?c.target:d[f.gid]})}),d},a.prototype.allEdges=function(){var a=[];return b(this.roots,a),a},a}();a.Configuration=g;var h=function(){function a(a,b,c,d){this.id=a,this.outgoing=b,this.incoming=c,this.children=d}return a.prototype.getEdges=function(a){for(var b in this.outgoing)a.push({source:this.id,target:this.outgoing[b].id})},a.prototype.isLeaf=function(){return 0==Object.keys(this.children).length},a.prototype.isIsland=function(){return 0==Object.keys(this.outgoing).length&&0==Object.keys(this.incoming).length},a}();a.Module=h,a.getGroups=f}(e||(e={}));var f,g=function(){function a(a){this.elem=a,this.subheaps=[]}return a.prototype.toString=function(a){for(var b="",c=!1,d=0;da;++a)this.ps.addVariable(this.vars[a]);this.posn=this.ps.getPosn()},a.prototype.compute_lm=function(a,b,c){var d=this,e=a.dfdv();return a.visitNeighbours(b,function(b,f){var g=d.compute_lm(f,a,c);f===b.right?(e+=g*b.left.scale,b.lm=g):(e+=g*b.right.scale,b.lm=-g),c(b)}),e/a.scale},a.prototype.populateSplitBlock=function(a,b){var c=this;a.visitNeighbours(b,function(b,d){d.offset=a.offset+(d===b.right?b.gap:-b.gap),c.addVariable(d),c.populateSplitBlock(d,a)})},a.prototype.traverse=function(a,b,c,d){"undefined"==typeof c&&(c=this.vars[0]),"undefined"==typeof d&&(d=null);var e=this;c.visitNeighbours(d,function(d,f){b.push(a(d)),e.traverse(a,b,f,c)})},a.prototype.findMinLM=function(){var a=null;return this.compute_lm(this.vars[0],null,function(b){!b.equality&&(null===a||b.lmd;++d){var f=a.vars[d];f.offset+=c,this.addVariable(f)}this.posn=this.ps.getPosn()},a.prototype.cost=function(){for(var a=0,b=this.vars.length;b--;){var c=this.vars[b],d=c.position()-c.desiredPosition;a+=d*d*c.weight}return a},a}();a.Block=e;var f=function(){function a(a){this.vs=a;var b=a.length;for(this.list=new Array(b);b--;){var c=new e(a[b]);this.list[b]=c,c.blockInd=b}}return a.prototype.cost=function(){for(var a=0,b=this.list.length;b--;)a+=this.list[b].cost();return a},a.prototype.insert=function(a){a.blockInd=this.list.length,this.list.push(a)},a.prototype.remove=function(a){var b=this.list.length-1,c=this.list[b];this.list.length=b,a!==c&&(this.list[a.blockInd]=c,c.blockInd=a.blockInd)},a.prototype.merge=function(a){var b=a.left.block,c=a.right.block,d=a.right.offset-a.left.offset-a.gap;b.vars.lengthg;++g){var h=d[g];if(!h.unsatisfiable){var i=h.slack();if((h.equality||b>i)&&(b=i,c=h,f=g,h.equality))break}}return f!==e&&(b=0?this.inactive.push(b):this.bs.merge(b)}}},a.prototype.solve=function(){this.satisfy();for(var a=Number.MAX_VALUE,b=this.bs.cost();Math.abs(a-b)>1e-4;)this.satisfy(),a=b,b=this.bs.cost();return b},a.LAGRANGIAN_TOLERANCE=-1e-4,a.ZERO_UPPERBOUND=-1e-10,a}();a.Solver=g}(f||(f={}));var f;!function(a){function b(a){return a.bounds=a.leaves.reduce(function(a,b){return b.bounds.union(a)},q.empty()),"undefined"!=typeof a.groups&&(a.bounds=a.groups.reduce(function(a,c){return b(c).union(a)},a.bounds)),a.bounds}function c(a,b,c,d){var e=b.rayIntersection(c.cx(),c.cy());e||(e={x:b.cx(),y:b.cy()});var f=c.rayIntersection(b.cx(),b.cy());f||(f={x:c.cx(),y:c.cy()});var g=f.x-e.x,h=f.y-e.y,i=Math.sqrt(g*g+h*h),j=i-d;a.sourceIntersection=e,a.targetIntersection=f,a.arrowStart={x:e.x+j*g/i,y:e.y+j*h/i}}function e(a,b,c){var d=b.rayIntersection(a.x,a.y);d||(d={x:b.cx(),y:b.cy()});var e=d.x-a.x,f=d.y-a.y,g=Math.sqrt(e*e+f*f);return{x:d.x-c*e/g,y:d.y-c*f/g}}function f(a,b){return a.pos>b.pos?1:a.pos=i);var k=new Array(j);for(h=0;i>h;++h){var l=b[h],m=new r(c[h],l,d.getCentre(l));k[h]=new s(!0,m,d.getOpen(l)),k[h+i]=new s(!1,m,d.getClose(l))}k.sort(f);var n=new Array,o=g();for(h=0;j>h;++h){var p=k[h],m=p.v;if(p.isOpen)o.insert(m),d.findNeighbours(m,o);else{o.remove(m);var q=function(b,c){var f=(d.getSize(b.r)+d.getSize(c.r))/2+e;n.push(new a.Constraint(b.v,c.v,f))},t=function(a,b,c){for(var d,e=m[a].iterator();null!==(d=e[a]());)c(d,m),d[b].remove(m)};t("prev","next",function(a,b){return q(a,b)}),t("next","prev",function(a,b){return q(b,a)})}}return console.assert(0===o.size),n}function j(a,b){var c=function(c,d){for(var e,f=b.findIter(a);null!==(e=f[c]());){var g=e.r.overlapX(a.r);if((0>=g||g<=e.r.overlapY(a.r))&&(a[c].insert(e),e[d].insert(a)),0>=g)break}};c("next","prev"),c("prev","next")}function k(a,b){var c=function(c,d){var e=b.findIter(a)[c]();null!==e&&e.r.overlapX(a.r)>0&&(a[c].insert(e),e[d].insert(a))};c("next","prev"),c("prev","next")}function l(a,b){return i(a,b,t,1e-6)}function m(a,b){return i(a,b,u,1e-6)}function n(a){return h(a,t,1e-6)}function o(a){return h(a,u,1e-6)}function p(b){var c=b.map(function(b){return new a.Variable(b.cx())}),d=a.generateXConstraints(b,c),e=new a.Solver(c,d);e.solve(),c.forEach(function(a,c){return b[c].setXCentre(a.position())}),c=b.map(function(b){return new a.Variable(b.cy())}),d=a.generateYConstraints(b,c),e=new a.Solver(c,d),e.solve(),c.forEach(function(a,c){return b[c].setYCentre(a.position())})}a.computeGroupBounds=b;var q=function(){function a(a,b,c,d){this.x=a,this.X=b,this.y=c,this.Y=d}return a.empty=function(){return new a(Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY)},a.prototype.cx=function(){return(this.x+this.X)/2},a.prototype.cy=function(){return(this.y+this.Y)/2},a.prototype.overlapX=function(a){var b=this.cx(),c=a.cx();return c>=b&&a.x=c&&this.x=b&&a.y=c&&this.yg;++g){var h=a.lineIntersection(d,e,b,c,f[g][0],f[g][1],f[g][2],f[g][3]);if(null!==h)return{x:h.x,y:h.y}}return null},a.prototype.vertices=function(){return[{x:this.x,y:this.y},{x:this.X,y:this.y},{x:this.X,y:this.Y},{x:this.x,y:this.Y},{x:this.x,y:this.y}]},a.lineIntersection=function(a,b,c,d,e,f,g,h){var i=c-a,j=g-e,k=d-b,l=h-f,m=l*i-j*k;if(0==m)return null;var n=a-e,o=b-f,p=j*o-l*n,q=p/m,r=i*o-k*n,s=r/m;return q>=0&&1>=q&&s>=0&&1>=s?{x:a+q*i,y:b+q*k}:null},a.prototype.inflate=function(b){return new a(this.x-b,this.X+b,this.y-b,this.Y+b)},a}();a.Rectangle=q,a.makeEdgeBetween=c,a.makeEdgeTo=e;var r=function(){function a(a,b,c){this.v=a,this.r=b,this.pos=c,this.prev=g(),this.next=g()}return a}(),s=function(){function a(a,b,c){this.isOpen=a,this.v=b,this.pos=c}return a}(),t={getCentre:function(a){return a.cx()},getOpen:function(a){return a.y},getClose:function(a){return a.Y},getSize:function(a){return a.width()},makeRect:function(a,b,c,d){return new q(c-d/2,c+d/2,a,b)},findNeighbours:j},u={getCentre:function(a){return a.cy()},getOpen:function(a){return a.x},getClose:function(a){return a.X},getSize:function(a){return a.height()},makeRect:function(a,b,c,d){return new q(a,b,c-d/2,c+d/2)},findNeighbours:k};a.generateXConstraints=l,a.generateYConstraints=m,a.generateXGroupConstraints=n,a.generateYGroupConstraints=o,a.removeOverlaps=p;var v=function(a){function b(b,c){a.call(this,0,c),this.index=b}return d(b,a),b}(a.Variable),w=function(){function c(c,d,e,f,g){"undefined"==typeof e&&(e=null),"undefined"==typeof f&&(f=null),"undefined"==typeof g&&(g=!1);var h=this;if(this.nodes=c,this.groups=d,this.rootGroup=e,this.avoidOverlaps=g,this.variables=c.map(function(a,b){return a.variable=new v(b,1)}),f&&this.createConstraints(f),g&&e&&"undefined"!=typeof e.groups){c.forEach(function(b){if(!b.width||!b.height)return b.bounds=new a.Rectangle(b.x,b.x,b.y,b.y),void 0;var c=b.width/2,d=b.height/2;b.bounds=new a.Rectangle(b.x-c,b.x+c,b.y-d,b.y+d)}),b(e);var i=c.length;d.forEach(function(a){h.variables[i]=a.minVar=new v(i++,.01),h.variables[i]=a.maxVar=new v(i++,.01)})}}return c.prototype.createSeparation=function(b){return new a.Constraint(this.nodes[b.left].variable,this.nodes[b.right].variable,b.gap,"undefined"!=typeof b.equality?b.equality:!1)},c.prototype.makeFeasible=function(a){var b=this;if(this.avoidOverlaps){var c="x",d="width";"x"===a.axis&&(c="y",d="height");var e=a.offsets.map(function(a){return b.nodes[a.node]}).sort(function(a,b){return a[c]-b[c]}),f=null;e.forEach(function(a){f&&(a[c]=f[c]+f[d]+1),f=a})}},c.prototype.createAlignment=function(b){var c=this,d=this.nodes[b.offsets[0].node].variable;this.makeFeasible(b);var e="x"===b.axis?this.xConstraints:this.yConstraints;b.offsets.slice(1).forEach(function(b){var f=c.nodes[b.node].variable;e.push(new a.Constraint(d,f,b.offset,!0))})},c.prototype.createConstraints=function(a){var b=this,c=function(a){return"undefined"==typeof a.type||"separation"===a.type};this.xConstraints=a.filter(function(a){return"x"===a.axis&&c(a)}).map(function(a){return b.createSeparation(a)}),this.yConstraints=a.filter(function(a){return"y"===a.axis&&c(a)}).map(function(a){return b.createSeparation(a)}),a.filter(function(a){return"alignment"===a.type}).forEach(function(a){return b.createAlignment(a)})},c.prototype.setupVariablesAndBounds=function(a,b,c,d){this.nodes.forEach(function(e,f){e.fixed?(e.variable.weight=1e3,c[f]=d(e)):e.variable.weight=1;var g=(e.width||0)/2,h=(e.height||0)/2,i=a[f],j=b[f];e.bounds=new q(i-g,i+g,j-h,j+h)})},c.prototype.xProject=function(a,b,c){(this.rootGroup||this.avoidOverlaps||this.xConstraints)&&this.project(a,b,a,c,function(a){return a.px},this.xConstraints,n,function(a){return a.bounds.setXCentre(c[a.variable.index]=a.variable.position())},function(a){a.bounds.x=c[a.minVar.index]=a.minVar.position(),a.bounds.X=c[a.maxVar.index]=a.maxVar.position()})},c.prototype.yProject=function(a,b,c){(this.rootGroup||this.yConstraints)&&this.project(a,b,b,c,function(a){return a.py},this.yConstraints,o,function(a){return a.bounds.setYCentre(c[a.variable.index]=a.variable.position())},function(a){a.bounds.y=c[a.minVar.index]=a.minVar.position(),a.bounds.Y=c[a.maxVar.index]=a.maxVar.position()})},c.prototype.projectFunctions=function(){var a=this;return[function(b,c,d){return a.xProject(b,c,d)},function(b,c,d){return a.yProject(b,c,d)}]},c.prototype.project=function(a,c,d,e,f,g,h,i,j){this.setupVariablesAndBounds(a,c,e,f),this.rootGroup&&this.avoidOverlaps&&(b(this.rootGroup),g=g.concat(h(this.rootGroup))),this.solve(this.variables,g,d,e),this.nodes.forEach(i),this.rootGroup&&this.avoidOverlaps&&this.groups.forEach(j) +},c.prototype.solve=function(b,c,d,e){var f=new a.Solver(b,c);f.setStartingPositions(d),f.setDesiredPositions(e),f.solve()},c}();a.Projection=w}(f||(f={}));var j;!function(a){var b=function(){function a(a,b){this.id=a,this.distance=b}return a}(),c=function(){function a(a){this.id=a,this.neighbours=[]}return a}(),d=function(){function a(a,d,e,f,g){this.n=a,this.es=d,this.neighbours=new Array(this.n);for(var h=this.n;h--;)this.neighbours[h]=new c(h);for(h=this.es.length;h--;){var i=this.es[h],j=e(i),k=f(i),l=g(i);this.neighbours[j].neighbours.push(new b(k,l)),this.neighbours[k].neighbours.push(new b(j,l))}}return a.prototype.DistanceMatrix=function(){for(var a=new Array(this.n),b=0;bl&&(j.d=l,j.prev=g,j.q=c.reduceKey(j.q,j))}}return e},a}();a.Calculator=d}(j||(j={}));var b;!function(b){function d(a){a.fixed|=2,a.px=a.x,a.py=a.y}function e(a){a.fixed&=-7}return"undefined"==typeof f&&(f=b.vpsc),b.d3adaptor=function(){function g(a,b){a.length=b}function h(a){return a}function k(a){return"number"==typeof a.source?a.source:a.source.index}function l(a){return"number"==typeof a.target?a.target:a.target.index}function m(b){b.px=a.event.x,b.py=a.event.y,q.resume()}var n,o,p,q={},r=a.dispatch("start","tick","end"),s=[1,1],t=20,u=!1,v=!0,w=!1,x=[],y=[],z=[],A=null,B=[],C=[],D=null,E=null,F=null,G=1e-5,H=10;return q.tick=function(){if(G>o)return r.end({type:"end",alpha:o=0}),delete p,w=!1,!0;{var a,b=x.length;B.length}for(E.locks.clear(),i=0;b>i;++i)if(a=x[i],a.fixed){("undefined"==typeof a.px||"undefined"==typeof a.py)&&(a.px=a.x,a.py=a.y);var c=[a.px,a.py];E.locks.add(i,c)}var d=E.rungeKutta();for(0===d?o=0:"undefined"!=typeof p&&p>d-G&&(o=p/d-1),p=d,i=0;b>i;++i)a=x[i],a.fixed?(a.x=a.px,a.y=a.py):(a.x=E.x[0][i],a.y=E.x[1][i]);r.tick({type:"tick",alpha:o})},q.nodes=function(a){if(!arguments.length){if(0===x.length&&B.length>0){var b=0;B.forEach(function(a){b=Math.max(b,a.source,a.target)}),x=new Array(++b);for(var c=0;b>c;++c)x[c]={}}return x}return x=a,q},q.groups=function(a){return arguments.length?(y=a,A={},y.forEach(function(a){"undefined"!=typeof a.leaves&&a.leaves.forEach(function(b,c){(a.leaves[c]=x[b]).parent=a}),"undefined"!=typeof a.groups&&a.groups.forEach(function(b,c){(a.groups[c]=y[b]).parent=a})}),A.leaves=x.filter(function(a){return"undefined"==typeof a.parent}),A.groups=y.filter(function(a){return"undefined"==typeof a.parent}),q):y},q.avoidOverlaps=function(a){return arguments.length?(u=a,q):u},q.handleDisconnected=function(a){return arguments.length?(v=a,q):v},q.flowLayout=function(a,b){return arguments.length||(a="y"),F={axis:a,getMinSeparation:"number"==typeof b?function(){return b}:b},q},q.links=function(a){return arguments.length?(B=a,q):B},q.constraints=function(a){return arguments.length?(C=a,q):C},q.distanceMatrix=function(a){return arguments.length?(D=a,q):D},q.size=function(a){return arguments.length?(s=a,q):s},q.defaultNodeSize=function(a){return arguments.length?(H=a,q):H},q.linkDistance=function(a){return arguments.length?(t="function"==typeof a?a:+a,q):"function"==typeof t?t():t},q.convergenceThreshold=function(a){return arguments.length?(G="function"==typeof a?a:+a,q):G},q.alpha=function(b){return arguments.length?(b=+b,o?o=b>0?b:0:b>0&&(w||(w=!0,r.start({type:"start",alpha:o=b}),a.timer(q.tick))),q):o},q.symmetricDiffLinkLengths=function(a,c){return b.symmetricDiffLinkLengths(this.nodes().length,B,k,l,g,c),function(b){return a*b.length}},q.jaccardLinkLengths=function(a,c){return b.jaccardLinkLengths(this.nodes().length,B,k,l,g,c),function(b){return a*b.length}},q.start=function(){var a,c=this.nodes().length,d=c+2*y.length,e=(B.length,s[0]),g=s[1],h=new Array(d),i=new Array(d);z=new Array(d);var j=null,m=this.avoidOverlaps();x.forEach(function(a,b){a.index=b,"undefined"==typeof a.x&&(a.x=e/2,a.y=g/2),h[b]=a.x,i[b]=a.y});var n;if(D)n=D;else{var o=function(b){return"function"==typeof t?+t.call(this,b,a):t};n=new b.shortestpaths.Calculator(d,B,k,l,o).DistanceMatrix(),j=b.Descent.createSquareMatrix(d,function(){return 2}),B.forEach(function(a){j[k(a)][l(a)]=j[l(a)][k(a)]=1})}var p=b.Descent.createSquareMatrix(d,function(a,b){return n[a][b]});if(A&&"undefined"!=typeof A.groups){var a=c;y.forEach(function(){j[a][a+1]=j[a+1][a]=1e-6,p[a][a+1]=p[a+1][a]=.1,h[a]=0,i[a++]=0,h[a]=0,i[a++]=0})}else A={leaves:x,groups:[]};F&&(C=(C||[]).concat(b.generateDirectedEdgeConstraints(c,B,F.axis,F.getMinSeparation,k,l)));var r=arguments.length>0?arguments[0]:0,u=arguments.length>1?arguments[1]:0,w=arguments.length>2?arguments[2]:0;return this.avoidOverlaps(!1),E=new b.Descent([h,i],p),E.threshold=G,E.run(r),C.length>0&&(E.project=new f.Projection(x,y,A,C).projectFunctions()),E.run(u),this.avoidOverlaps(m),m&&(E.project=new f.Projection(x,y,A,C,!0).projectFunctions()),E.G=j,E.run(w),B.forEach(function(a){"number"==typeof a.source&&(a.source=x[a.source]),"number"==typeof a.target&&(a.target=x[a.target])}),x.forEach(function(a,b){a.x=h[b],a.y=i[b]}),!D&&v&&(b.applyPacking(b.separateGraphs(x,B),e,g,H),x.forEach(function(a,b){E.x[0][b]=a.x,E.x[1][b]=a.y})),q.resume()},q.resume=function(){return q.alpha(.1)},q.stop=function(){return q.alpha(0)},q.routeEdge=function(a,b){var d=[],e=new c.TangentVisibilityGraph(a.P,{V:a.V,E:a.E}),g={x:b.source.x,y:b.source.y},h={x:b.target.x,y:b.target.y},i=e.addPoint(g,b.source.id),k=e.addPoint(h,b.target.id);e.addEdgeIfVisible(g,h,b.source.id,b.target.id);var l=e.E.map(function(a){return{source:a.source.id,target:a.target.id,length:a.length()}}),m=new j.Calculator(e.V.length,l),n=m.PathFromNodeToNode(i.id,k.id);if(1===n.length||n.length===e.V.length)f.makeEdgeBetween(b,b.source.innerBounds,b.target.innerBounds,5),d=[{x:b.sourceIntersection.x,y:b.sourceIntersection.y},{x:b.arrowStart.x,y:b.arrowStart.y}];else{for(var o=n.length-2,p=e.V[n[o]].p,q=e.V[n[0]].p,d=[b.source.innerBounds.rayIntersection(p.x,p.y)],r=o;r>=0;--r)d.push(e.V[n[r]].p);d.push(f.makeEdgeTo(q,b.target.innerBounds,5))}return d},q.drag=function(){return n||(n=a.behavior.drag().origin(h).on("dragstart.d3adaptor",d).on("drag.d3adaptor",m).on("dragend.d3adaptor",e)),arguments.length?(this.call(n),void 0):n},q.linkId=function(a){return k(a)+"-"+l(a)},a.rebind(q,r,"on")},b}(b||(b={})),RBTree=function(a){var b=function(a){var c=b.m[a];if(c.mod)return c.mod.exports;var d=c.mod={exports:{}};return c(d,d.exports),d.exports};return b.m={},b.m["./treebase"]=function(a){function b(){}function c(a){this._tree=a,this._ancestors=[],this._cursor=null}b.prototype.clear=function(){this._root=null,this.size=0},b.prototype.find=function(a){for(var b=this._root;null!==b;){var c=this._comparator(a,b.data);if(0===c)return b.data;b=b.get_child(c>0)}return null},b.prototype.findIter=function(a){for(var b=this._root,c=this.iterator();null!==b;){var d=this._comparator(a,b.data);if(0===d)return c._cursor=b,c;c._ancestors.push(b),b=b.get_child(d>0)}return null},b.prototype.lowerBound=function(a){return this._bound(a,this._comparator)},b.prototype.upperBound=function(a){function b(a,b){return c(b,a)}var c=this._comparator;return this._bound(a,b)},b.prototype.min=function(){var a=this._root;if(null===a)return null;for(;null!==a.left;)a=a.left;return a.data},b.prototype.max=function(){var a=this._root;if(null===a)return null;for(;null!==a.right;)a=a.right;return a.data},b.prototype.iterator=function(){return new c(this)},b.prototype.each=function(a){for(var b,c=this.iterator();null!==(b=c.next());)a(b)},b.prototype.reach=function(a){for(var b,c=this.iterator();null!==(b=c.prev());)a(b)},b.prototype._bound=function(a,b){for(var c=this._root,d=this.iterator();null!==c;){var e=this._comparator(a,c.data);if(0===e)return d._cursor=c,d;d._ancestors.push(c),c=c.get_child(e>0)}for(var f=d._ancestors.length-1;f>=0;--f)if(c=d._ancestors[f],b(a,c.data)>0)return d._cursor=c,d._ancestors.length=f,d;return d._ancestors.length=0,d},c.prototype.data=function(){return null!==this._cursor?this._cursor.data:null},c.prototype.next=function(){if(null===this._cursor){var a=this._tree._root;null!==a&&this._minNode(a)}else if(null===this._cursor.right){var b;do{if(b=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.right===b)}else this._ancestors.push(this._cursor),this._minNode(this._cursor.right);return null!==this._cursor?this._cursor.data:null},c.prototype.prev=function(){if(null===this._cursor){var a=this._tree._root;null!==a&&this._maxNode(a)}else if(null===this._cursor.left){var b;do{if(b=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.left===b)}else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left);return null!==this._cursor?this._cursor.data:null},c.prototype._minNode=function(a){for(;null!==a.left;)this._ancestors.push(a),a=a.left;this._cursor=a},c.prototype._maxNode=function(a){for(;null!==a.right;)this._ancestors.push(a),a=a.right;this._cursor=a},a.exports=b},b.m.__main__=function(a){function c(a){this.data=a,this.left=null,this.right=null,this.red=!0}function d(a){this._root=null,this._comparator=a,this.size=0}function e(a){return null!==a&&a.red}function f(a,b){var c=a.get_child(!b);return a.set_child(!b,c.get_child(b)),c.set_child(b,a),a.red=!0,c.red=!1,c}function g(a,b){return a.set_child(!b,f(a.get_child(!b),!b)),f(a,b)}var h=b("./treebase");c.prototype.get_child=function(a){return a?this.right:this.left},c.prototype.set_child=function(a,b){a?this.right=b:this.left=b},d.prototype=new h,d.prototype.insert=function(a){var b=!1;if(null===this._root)this._root=new c(a),b=!0,this.size++;else{var d=new c(void 0),h=0,i=0,j=null,k=d,l=null,m=this._root;for(k.right=this._root;;){if(null===m?(m=new c(a),l.set_child(h,m),b=!0,this.size++):e(m.left)&&e(m.right)&&(m.red=!0,m.left.red=!1,m.right.red=!1),e(m)&&e(l)){var n=k.right===j;m===l.get_child(i)?k.set_child(n,f(j,!i)):k.set_child(n,g(j,!i))}var o=this._comparator(m.data,a);if(0===o)break;i=h,h=0>o,null!==j&&(k=j),j=l,l=m,m=m.get_child(h)}this._root=d.right}return this._root.red=!1,b},d.prototype.remove=function(a){if(null===this._root)return!1;var b=new c(void 0),d=b;d.right=this._root;for(var h=null,i=null,j=null,k=1;null!==d.get_child(k);){var l=k;i=h,h=d,d=d.get_child(k);var m=this._comparator(a,d.data);if(k=m>0,0===m&&(j=d),!e(d)&&!e(d.get_child(k)))if(e(d.get_child(!k))){var n=f(d,k);h.set_child(l,n),h=n}else if(!e(d.get_child(!k))){var o=h.get_child(!l);if(null!==o)if(e(o.get_child(!l))||e(o.get_child(l))){var p=i.right===h;e(o.get_child(l))?i.set_child(p,g(h,l)):e(o.get_child(!l))&&i.set_child(p,f(h,l));var q=i.get_child(p);q.red=!0,d.red=!0,q.left.red=!1,q.right.red=!1}else h.red=!1,o.red=!0,d.red=!0}}return null!==j&&(j.data=d.data,h.set_child(h.right===d,d.get_child(null===d.left)),this.size--),this._root=b.right,null!==this._root&&(this._root.red=!1),null!==j},a.exports=d},b("__main__")}(window);var b;return function(a){var b={};return b.PADDING=10,b.GOLDEN_SECTION=(1+Math.sqrt(5))/2,b.FLOAT_EPSILON=1e-5,a.applyPacking=function(a,c,d,e,f){function g(a){function b(a){for(var b=Number.MAX_VALUE,c=Number.MAX_VALUE,d=0,f=0,g=0;gp||Math.abs(g-h)>b.FLOAT_EPSILON;){var e=d-(d-c)/b.GOLDEN_SECTION,f=c+(d-c)/b.GOLDEN_SECTION,g=j(a,e),h=j(a,f);g>h?c=e:d=f}}function j(a,b){r=[],n=0,o=0,q=t;for(var c=0;c=a.height&&r[e].x+r[e].width+a.width+b.PADDING-c<=b.FLOAT_EPSILON){d=r[e];break}void 0!==d?(a.x=d.x+d.width+b.PADDING,a.y=d.bottom,a.space_left=a.height,a.bottom=a.y,d.space_left-=a.height+b.PADDING,d.bottom+=a.height+b.PADDING):(a.y=q,q+=a.height+b.PADDING,a.x=s,a.bottom=a.y,a.space_left=a.height),a.y+a.height-o>-b.FLOAT_EPSILON&&(o=a.y+a.height-t),a.x+a.width-n>-b.FLOAT_EPSILON&&(n=a.x+a.width-s)}function l(a){var c=0;return a.forEach(function(a){return c+=a.width+b.PADDING}),c}function m(){return n/o}var n,o,p,q,r,s=0,t=0,u=c,v=d,f="undefined"!=typeof f?f:1,e="undefined"!=typeof e?e:6;0!=a.length&&(g(a),i(a),h(a))},a.separateGraphs=function(a,b){function c(a,b){if(void 0===d[a.index]){b&&(f++,graphs.push({array:[]})),d[a.index]=f,graphs[f-1].array.push(a);var g=e[a.index];if(g)for(var h=0;h -

Egocentric Network

+ +
Jonica’s network
+
Alex’s network
@@ -41,6 +76,13 @@

Egocentric Network

var color = d3.scale.category20(); var connected = true; + //var button; + document.onkeyup = keyhandler; + function keyhandler(e) { + if (e.keyCode === 32) { + disconnectNode0(); + } + } function disconnectNode0() { if (connected) { egosvg1.disconnectNode0(); @@ -48,20 +90,19 @@

Egocentric Network

egosvg1.restart(); egosvg2.restart(); connected = false; - button.text("Connect Self"); + //button.text("Connect Self"); } else { egosvg1.connectNode0(); egosvg2.connectNode0(); - //egosvg1.restart(); - //egosvg2.restart(); + egosvg1.restart(); + egosvg2.restart(); connected = true; - button.text("Disconnect Self"); + //button.text("Disconnect Self"); } } var body = d3.select("body"); - var button = body.append("center").append("button").attr("id", "removeSelfButton").text("Disconnect Self").on("click", disconnectNode0); - body.append("br"); + var egosvg = (function () { function egosvg(file) { @@ -102,13 +143,16 @@

Egocentric Network

}); this.d3cola.stop(); this.d3cola.on("tick", null); - this.d3cola.links(this.edges).start(30); + this.d3cola.links(this.edges) + .linkDistance(this.d3cola.symmetricDiffLinkLengths(8)).start(0, 0, 10); this.link.data(this.d3cola.links(), function (d) { return d.source.index + "-" + d.target.index; }).exit().remove(); }; egosvg.prototype.connectNode0 = function () { + this.d3cola.stop(); + this.d3cola.on("tick", null); var node0; var node0edges = this.d3cola.nodes().filter(function (d, i) { if (i == 0) { @@ -120,11 +164,10 @@

Egocentric Network

return { source: node0, target: d }; }); this.edges = this.edges.concat(node0edges); + this.edges.forEach(function (l) { + delete l.length; + }); - //this.d3cola.stop(); - //this.d3cola.on("tick", null); - this.d3cola.links(this.edges) - .linkDistance(this.d3cola.symmetricDiffLinkLengths(8)).start(); var _this = this; this.link = this.edgegroup.selectAll(".link") .data(this.edges, function (d) { @@ -132,17 +175,22 @@

Egocentric Network

}); this.link.enter().append("line") .attr("class", "link") - .style("stroke-width", function (d) { return Math.sqrt(d.value); }); + .style("stroke-width", function (d) { return Math.sqrt(d.value); }).attr("x1", function (d) { return d.source.x; }) + .attr("y1", function (d) { return d.source.y; }) + .attr("x2", function (d) { return d.target.x; }) + .attr("y2", function (d) { return d.target.y; }); + this.d3cola.links(this.edges) + .linkDistance(this.d3cola.symmetricDiffLinkLengths(8)).start(0, 0, 30); }; egosvg.prototype.restart = function () { var _this = this; - _this.link.transition().duration(1000).attr("x1", function (d) { return d.source.x; }) + _this.link.transition().duration(2000).attr("x1", function (d) { return d.source.x; }) .attr("y1", function (d) { return d.source.y; }) .attr("x2", function (d) { return d.target.x; }) .attr("y2", function (d) { return d.target.y; }); - _this.node.transition().duration(1000).attr("cx", function (d) { return d.x; }) + _this.node.transition().duration(2000).attr("cx", function (d) { return d.x; }) .attr("cy", function (d) { return d.y; }).each("end", function () { _this.d3cola.on("tick", function () { regularTick(_this.link, _this.node) }); }); @@ -196,10 +244,14 @@

Egocentric Network

})(); var egosvg1 = new egosvg("graphdata/alex/no_partner_matrix.txt"); var egosvg2 = new egosvg("graphdata/alex/alex_network_sym.txt"); + egosvg1.svg.attr("class", "leftsvg"); + egosvg2.svg.attr("class", "rightsvg"); var counter = 0; function allDone() { - if (++counter === 2) + if (++counter === 2) { + //button = body.append("center").append("button").attr("id", "removeSelfButton").html("Disconnect Self").on("click", disconnectNode0); body.append("p").html(''); + } //body.append("p").html(''); } diff --git a/WebCola/examples/friendnetworks.html b/WebCola/examples/friendnetworks.html index 9ba261e1..bdcf2d35 100644 --- a/WebCola/examples/friendnetworks.html +++ b/WebCola/examples/friendnetworks.html @@ -16,7 +16,24 @@ stroke: #999; stroke-opacity: .8; } - + svg { + position: absolute; + left: 0px; + } + .leftheading { + position: relative; + left: 0px; + width: 300px; + float: left; + font-size: 20px; + } + .rightheading { + position: relative; + left: 20px; + width: 150px; + float: left; + font-size: 20px; + } #leftButton { position: relative; left: 0px; @@ -31,15 +48,20 @@ } .logo { - text-align: left; - font-size: 20px; + position: absolute; + left: 200px; + top: 260px; + font-size: 16px; opacity: 0.5; } -

Friend Networks

+ +
Acquaintances
+
Close Friends
+

@@ -50,15 +72,29 @@

Friend Networks

var color = d3.scale.category20(); var leftvisible = true; + document.onkeyup = keyhandler; + var visible = false; + function keyhandler(e) { + if (e.keyCode === 65 && visible) { + showhideleft(); + } + if (e.keyCode === 76 && visible) { + showhideright(); + } + if (e.keyCode === 32 && !visible) { + go(); + visible = true; + } + } function showhideleft() { if (leftvisible) { egosvg1.svg.transition().duration(1000).attr("opacity", 0); leftvisible = false; - leftbutton.text("show"); + //leftbutton.text("show"); } else { egosvg1.svg.transition().duration(1000).attr("opacity", 1); leftvisible = true; - leftbutton.text("hide"); + //leftbutton.text("hide"); } } var rightvisible = true; @@ -75,9 +111,9 @@

Friend Networks

} var body = d3.select("body"); - var leftbutton = body.append("button").attr("id", "leftButton").html("hide").on("click", showhideleft); - var rightbutton = body.append("button").attr("id", "rightButton").html("hide").on("click", showhideright); - body.append("br"); + //var leftbutton = body.append("button").attr("id", "leftButton").html("hide").on("click", showhideleft); + //var rightbutton = body.append("button").attr("id", "rightButton").html("hide").on("click", showhideright); + //body.append("br"); var egosvg = (function () { function egosvg(file, edgelength, gender) { @@ -161,12 +197,15 @@

Friend Networks

})(); var egosvg1, egosvg2; - d3.text("graphdata/alex/Full_Network_Sym/gender.txt", - function (error, text) { - var gender = text.split('\n').map(function (s) { return Number(s.trim()) }); - egosvg1 = new egosvg("graphdata/alex/Full_Network_Sym/acquaint_core.txt", 25, gender); - egosvg2 = new egosvg("graphdata/alex/Full_Network_Sym/closef_core.txt", 6, gender); - }); + function go() { + d3.text("graphdata/alex/Full_Network_Sym/gender.txt", + function (error, text) { + var gender = text.split('\n').map(function (s) { return Number(s.trim()) }); + egosvg1 = new egosvg("graphdata/alex/Full_Network_Sym/acquaint_core.txt", 25, gender); + egosvg2 = new egosvg("graphdata/alex/Full_Network_Sym/closef_core.txt", 6, gender); + egosvg2.svg.style("left", "300px"); + }); + } var counter = 0; function allDone() {