var $_={fn:function(){return function(){}},merge:function(){var E={};for(var D=0,A=arguments.length;D<A;D++){var B=arguments[D];if(typeof B!="object"){continue}for(var C in B){var G=B[C],F=E[C];E[C]=(F&&typeof G=="object"&&typeof F=="object")?this.merge(F,G):this.unlink(G)}}return E},unlink:function(C){var B=null;if(this.isArray(C)){B=[];for(var D=0,A=C.length;D<A;D++){B[D]=this.unlink(C[D])}}else{if(this.isObject(C)){B={};for(var E in C){B[E]=this.unlink(C[E])}}else{return C}}return B},isArray:function(A){return A.constructor.toString().match(/array/i)},isString:function(A){return A.constructor.toString().match(/string/i)},isObject:function(A){return A.constructor.toString().match(/object/i)}};var Canvas=function(B,A,C){this.canvasId=B;if((this.canvas=document.getElementById(this.canvasId))&&this.canvas.getContext){this.ctx=this.canvas.getContext("2d");this.ctx.fillStyle=A||"white";this.ctx.strokeStyle=C||"white";this.setPosition();this.translateToCenter()}else{throw"Canvas object could not initialize."}};Canvas.prototype={getContext:function(){return this.ctx},setPosition:function(){var A=this.canvas;var B=curtop=0;if(A.offsetParent){B=A.offsetLeft;curtop=A.offsetTop;while(A=A.offsetParent){B+=A.offsetLeft;curtop+=A.offsetTop}}this.position={x:B,y:curtop}},getPosition:function(){return this.position},clear:function(){var A=this.getSize();this.ctx.clearRect(-A.x/2,-A.y/2,A.x,A.y)},drawMainCircle:function(){var A=this.ctx;A.beginPath();A.arc(0,0,this.getSmallerSize()/2,0,Math.PI*2,true);A.stroke();A.closePath()},translateToCenter:function(){this.ctx.translate(this.canvas.width/2,this.canvas.height/2)},getSize:function(){var B=this.canvas.width;var A=this.canvas.height;return{x:B,y:A}},path:function(A,B){this.ctx.beginPath();B(this.ctx);this.ctx[A]();this.ctx.closePath()},getSmallerSize:function(){var A=this.getSize();return(A.x<=A.y)?A.x:A.y}};var Complex=function(){if(arguments.length>1){this.x=arguments[0];this.y=arguments[1]}else{this.x=null;this.y=null}};Complex.prototype={clone:function(){return new Complex(this.x,this.y)},toPolar:function(){var A=this.norm();var B=Math.atan2(this.y,this.x);if(B<0){B+=Math.PI*2}return new Polar(B,A)},norm:function(){return Math.sqrt(this.squaredNorm())},squaredNorm:function(){return this.x*this.x+this.y*this.y},add:function(A){return new Complex(this.x+A.x,this.y+A.y)},prod:function(A){return new Complex(this.x*A.x-this.y*A.y,this.y*A.x+this.x*A.y)},conjugate:function(){return new Complex(this.x,-this.y)},div:function(B){var A=B.squaredNorm();return new Complex(this.x*B.x+this.y*B.y,this.y*B.x-this.x*B.y).$scale(1/A)},scale:function(A){return new Complex(this.x*A,this.y*A)},equals:function(A){return this.x==A.x&&this.y==A.y},$add:function(A){this.x+=A.x;this.y+=A.y;return this},$prod:function(C){var A=this.x,B=this.y;this.x=A*C.x-B*C.y;this.y=B*C.x+A*C.y;return this},$conjugate:function(){this.y=-this.y;return this},$scale:function(A){this.x*=A;this.y*=A;return this},$div:function(D){var A=this.x,C=this.y;var B=D.squaredNorm();this.x=A*D.x+C*D.y;this.y=C*D.x-A*D.y;return this.$scale(1/B)},moebiusTransformation:function(C){var A=this.add(C);var B=C.$conjugate().$prod(this);B.x++;A.$div(B);return A}};Complex.KER=new Complex(0,0);var Polar=function(B,A){this.theta=B;this.rho=A};Polar.prototype={toComplex:function(){return new Complex(Math.cos(this.theta),Math.sin(this.theta)).scale(this.rho)},add:function(A){return new Polar(this.theta+A.theta,this.rho+A.rho)},scale:function(A){return new Polar(this.theta,this.rho*A)},equals:function(A){return this.theta==A.theta&&this.rho==A.rho},interpolate:function(C,H){var F=Math.PI*2;var B=function(J){return(J<0)?(J%F)+F:J%F};var E=B(this.theta),G=B(C.theta);var D;if(Math.abs(E-G)>Math.PI){if(E-G>0){D=B((G+((E-F)-G)*H))}else{D=B((G-F+(E-(G-F))*H))}}else{D=B((G+(E-G)*H))}var I=(D);var A=(this.rho-C.rho)*H+C.rho;return new Polar(I,A)}};Polar.KER=new Polar(0,0);var Config={labelContainer:"label_container",drawMainCircle:true,allowVariableNodeDiameters:false,transformNodes:true,nodeRangeDiameters:{min:10,max:55},nodeRangeValues:{min:1,max:35},fps:40,animationTime:1500,nodeRadius:4};var GraphUtil={filter:function(B){if(!B||!$_.isString(B)){return function(){return true}}var A=B.split(" ");return function(D){for(var C=0;C<A.length;C++){if(D[A[C]]){return false}}return true}},clean:function(A){this.eachNode(A,function(B){B._flag=false})},eachNode:function(E,D,A){var C=this.filter(A);for(var B in E.nodes){if(C(E.nodes[B])){D(E.nodes[B])}}},eachAdjacency:function(D,E,A){var B=D.adjacencies,C=this.filter(A);for(var F in B){if(C(B[F])){E(B[F],F)}}},computeLevels:function(F,G,C){var D=this.filter(C);this.eachNode(F,function(H){H._flag=false;H._depth=-1},C);var B=F.getNode(G);B._depth=0;var A=[B];while(A.length!=0){var E=A.pop();E._flag=true;this.eachAdjacency(E,function(H){var I=H.nodeTo;if(I._flag==false&&D(I)){if(I._depth<0){I._depth=E._depth+1}A.unshift(I)}},C)}},getNode:function(A,B){return A.getNode(B)},eachBFS:function(F,G,E,B){var C=this.filter(B);this.clean(F);var A=[F.getNode(G)];while(A.length!=0){var D=A.pop();D._flag=true;E(D,D._depth);this.eachAdjacency(D,function(H){var I=H.nodeTo;if(I._flag==false&&C(I)){I._flag=true;A.unshift(I)}},B)}},eachSubnode:function(E,C,D,A){var F=C._depth,B=this.filter(A);this.eachAdjacency(C,function(G){var H=G.nodeTo;if(H._depth>F&&B(H)){D(H)}},A)},getParents:function(D,C){var B=C.adjacencies;var A=new Array();this.eachAdjacency(C,function(E){var F=E.nodeTo;if(F._depth<C._depth){A.push(F)}});return A},getSubnodes:function(E,G,F,A){var B=new Array(),D=this,C=E.getNode(G);(function(J,I){var H=arguments.callee;if(!F||F<=I._depth){B.push(I)}D.eachSubnode(J,I,function(K){H(J,K)},A)})(E,C);return B},getClosestNodeToOrigin:function(C,D,A){var B=null;this.eachNode(C,function(E){B=(B==null||E[D].rho<B[D].rho)?E:B},A);return B},moebiusTransformation:function(C,E,D,B,A){this.eachNode(C,function(G){for(var F=0;F<D.length;F++){var I=E[F].scale(-1),H=B?B:D[F];G[D[F]]=G[H].toComplex().moebiusTransformation(I).toPolar()}},A)}};var GraphOp={options:{type:"nothing",duration:2000,fps:30},removeNode:function(H,D,B){var I=$_.merge(H.controller,this.options,B);var C=$_.isString(D)?[D]:D;switch(I.type){case"nothing":for(var E=0;E<C.length;E++){H.graph.removeNode(C[E])}break;case"replot":this.removeNode(H,C,{type:"nothing"});GraphPlot.clearLabels(H);H.refresh(true);break;case"fade:seq":case"fade":var G=GraphPlot,F=this;for(var E=0;E<C.length;E++){var A=H.graph.getNode(C[E]);A.endAlpha=0}G.animate(H,$_.merge(I,{modes:["fade:nodes"],onComplete:function(){F.removeNode(H,C,{type:"nothing"});G.clearLabels(H);H.reposition();G.animate(H,$_.merge(I,{modes:["linear"],hideLabels:true}))}}));break;case"fade:con":var G=GraphPlot,F=this;for(var E=0;E<C.length;E++){var A=H.graph.getNode(C[E]);A.endAlpha=0;A.ignore=true}H.reposition();G.animate(H,$_.merge(I,{modes:["fade:nodes","linear"],hideLabels:true,onComplete:function(){F.removeNode(H,C,{type:"nothing"})}}));break;case"iter":var F=this,G=GraphPlot;G.sequence(H,{condition:function(){return C.length!=0},step:function(){F.removeNode(H,C.shift(),{type:"nothing"});G.clearLabels(H)},onComplete:function(){I.onComplete()},duration:Math.ceil(I.duration/C.length)});break;default:this.doError()}},removeEdge:function(G,C,A){var I=$_.merge(G.controller,this.options,A);var H=$_.isString(C[0])?[C]:C;switch(I.type){case"nothing":for(var B=0;B<H.length;B++){G.graph.removeAdjacence(H[B][0],H[B][1])}break;case"replot":this.removeEdge(G,H,{type:"nothing"});G.refresh(true);break;case"fade:seq":case"fade":var F=GraphPlot,E=this;for(var B=0;B<H.length;B++){var D=G.graph.getAdjacence(H[B][0],H[B][1]);if(D){D[0].endAlpha=0;D[1].endAlpha=0}}F.animate(G,$_.merge(I,{modes:["fade:vertex"],onComplete:function(){E.removeEdge(G,H,{type:"nothing"});G.reposition();F.animate(G,$_.merge(I,{modes:["linear"],hideLabels:true}))}}));break;case"fade:con":var F=GraphPlot,E=this;for(var B=0;B<H.length;B++){var D=G.graph.getAdjacence(H[B][0],H[B][1]);if(D){D[0].endAlpha=0;D[0].ignore=true;D[1].endAlpha=0;D[1].ignore=true}}G.reposition();F.animate(G,$_.merge(I,{modes:["fade:vertex","linear"],onComplete:function(){E.removeEdge(G,H,{type:"nothing"})}}));break;case"iter":var E=this,F=GraphPlot;F.sequence(G,{condition:function(){return H.length!=0},step:function(){E.removeEdge(G,H.shift(),{type:"nothing"});F.clearLabels(G)},onComplete:function(){I.onComplete()},duration:Math.ceil(I.duration/H.length)});break;default:this.doError()}},sum:function(H,J,B){var K=$_.merge(H.controller,this.options,B),F=H.root;H.root=B.id||H.root;switch(K.type){case"nothing":var I=H.construct(J),E=GraphUtil;E.eachNode(I,function(L){E.eachAdjacency(L,function(M){H.graph.addAdjacence(M.nodeFrom,M.nodeTo,M.data)})});break;case"replot":this.sum(H,J,{type:"nothing"});H.refresh(true);break;case"fade:seq":case"fade":case"fade:con":var E=GraphUtil,G=GraphPlot,D=this,I=H.construct(J);var A=this.preprocessSum(H,I);var C=!A?["fade:nodes"]:["fade:nodes","fade:vertex"];H.reposition();if(K.type!="fade:con"){G.animate(H,$_.merge(K,{modes:["linear"],hideLabels:true,onComplete:function(){G.animate(H,$_.merge(K,{modes:C,onComplete:function(){K.onComplete()}}))}}))}else{E.eachNode(H.graph,function(L){if(L.id!=F&&L.pos.equals(Polar.KER)){L.pos=L.startPos=L.endPos}});G.animate(H,$_.merge(K,{modes:["linear"].concat(C),hideLabels:true,onComplete:function(){K.onComplete()}}))}break;default:this.doError()}},morph:function(H,J,B){var K=$_.merge(H.controller,this.options,B),F=H.root;H.root=B.id||H.root;switch(K.type){case"nothing":var I=H.construct(J),E=GraphUtil;E.eachNode(I,function(L){E.eachAdjacency(L,function(M){H.graph.addAdjacence(M.nodeFrom,M.nodeTo,M.data)})});E.eachNode(H.graph,function(L){E.eachAdjacency(L,function(M){if(!I.getAdjacence(M.nodeFrom.id,M.nodeTo.id)){H.graph.removeAdjacence(M.nodeFrom.id,M.nodeTo.id)}if(!H.graph.hasNode(L.id)){H.graph.removeNode(L.id)}})});break;case"replot":this.morph(H,J,{type:"nothing"});H.refresh(true);break;case"fade:seq":case"fade":case"fade:con":var E=GraphUtil,G=GraphPlot,D=this,I=H.construct(J);var A=this.preprocessSum(H,I);E.eachNode(H.graph,function(L){if(!I.hasNode(L.id)){L.alpha=1;L.startAlpha=1;L.endAlpha=0;L.ignore=true}});E.eachNode(H.graph,function(L){if(L.ignore){return}E.eachAdjacency(L,function(M){if(M.nodeFrom.ignore||M.nodeTo.ignore){return}var N=I.getNode(M.nodeFrom.id);var O=I.getNode(M.nodeTo.id);if(!N.adjacentTo(O)){var P=H.graph.getAdjacence(N.id,O.id);A=true;P[0].alpha=1;P[0].startAlpha=1;P[0].endAlpha=0;P[0].ignore=true;P[1].alpha=1;P[1].startAlpha=1;P[1].endAlpha=0;P[1].ignore=true}})});var C=!A?["fade:nodes"]:["fade:nodes","fade:vertex"];H.reposition();E.eachNode(H.graph,function(L){if(L.id!=F&&L.pos.equals(Polar.KER)){L.pos=L.startPos=L.endPos}});G.animate(H,$_.merge(K,{modes:["polar"].concat(C),hideLabels:true,onComplete:function(){E.eachNode(H.graph,function(L){if(L.ignore){H.graph.removeNode(L.id)}});E.eachNode(H.graph,function(L){E.eachAdjacency(L,function(M){if(M.ignore){H.graph.removeAdjacence(M.nodeFrom.id,M.nodeTo.id)}})});K.onComplete()}}));break;default:this.doError()}},preprocessSum:function(A,C){var B=GraphUtil;B.eachNode(C,function(E){if(!A.graph.hasNode(E.id)){A.graph.addNode(E);var F=A.graph.getNode(E.id);F.alpha=0;F.startAlpha=0;F.endAlpha=1}});var D=false;B.eachNode(C,function(E){B.eachAdjacency(E,function(F){var G=A.graph.getNode(F.nodeFrom.id);var H=A.graph.getNode(F.nodeTo.id);if(!G.adjacentTo(H)){var I=A.graph.addAdjacence(G,H,F.data);if(G.startAlpha==G.endAlpha&&H.startAlpha==H.endAlpha){D=true;I[0].alpha=0;I[0].startAlpha=0;I[0].endAlpha=1;I[1].alpha=0;I[1].startAlpha=0;I[1].endAlpha=1}}})});return D}};var GraphPlot={Interpolator:{moebius:function(B,C,A){A=A.clone();B.pos=B.startPos.toComplex().moebiusTransformation(A).toPolar()},linear:function(A,D){var C=A.startPos.toComplex();var B=A.endPos.toComplex();A.pos=((B.$add(C.scale(-1))).$scale(D).$add(C)).toPolar()},"fade:nodes":function(A,D){if(A.endAlpha!=A.alpha){var C=A.startAlpha;var B=A.endAlpha;A.alpha=C+(B-C)*D}},"fade:vertex":function(A,D){var C=A.adjacencies;for(var B in C){this["fade:nodes"](C[B],D)}},polar:function(A,D){var C=A.startPos;var B=A.endPos;A.pos=B.interpolate(C,D)}},labelsHidden:false,labelContainer:false,labels:{},getLabelContainer:function(){return this.labelContainer?this.labelContainer:this.labelContainer=document.getElementById(Config.labelContainer)},getLabel:function(A){return(A in this.labels&&this.labels[A]!=null)?this.labels[A]:this.labels[A]=document.getElementById(A)},hideLabels:function(B){var A=this.getLabelContainer();if(B){A.style.display="none"}else{A.style.display=""}this.labelsHidden=B},clearLabels:function(A){for(var B in this.labels){if(!A.graph.hasNode(B)){this.disposeLabel(B);delete this.labels[B]}}},disposeLabel:function(B){var A=this.getLabel(B);if(A&&A.parentNode){A.parentNode.removeChild(A)}},sequence:function(A,C){C=$_.merge({condition:function(){return false},step:$_.fn(),onComplete:$_.fn(),duration:200},C);var B=setInterval(function(){if(C.condition()){C.step()}else{clearInterval(B);C.onComplete()}A.refresh(true)},C.duration)},animate:function(L,B,A){var F=this,M=L.graph,H=GraphUtil,I=Animation,E=B.duration||I.duration,C=B.fps||I.fps;var K=M.getNode(L.root);var J=I.duration,D=I.fps;I.duration=E;I.fps=C;if(B.hideLabels){this.hideLabels(true)}var G={compute:function(O){var N=A?A.scale(-O):null;H.eachNode(M,function(Q){for(var P=0;P<B.modes.length;P++){F.Interpolator[B.modes[P]](Q,O,N)}});F.plot(L,B)},complete:function(){H.eachNode(M,function(N){N.startPos=N.pos;N.startAlpha=N.alpha});if(B.hideLabels){F.hideLabels(false)}F.plot(L,B);B.onComplete();B.onAfterCompute();I.duration=J;I.fps=D}};Animation.controller=G;Animation.start()},plot:function(H,B){var E=H.graph,C=H.canvas,A=H.root;var F=this,I=C.getContext(),G=GraphUtil;C.clear();if(Config.drawMainCircle){C.drawMainCircle()}var D=!!E.getNode(A).visited;G.eachNode(E,function(J){G.eachAdjacency(J,function(K){if(!!K.nodeTo.visited===D){B.onBeforePlotLine(K);I.save();I.globalAlpha=Math.min(Math.min(J.alpha,K.nodeTo.alpha),K.alpha);F.plotLine(K,C);I.restore();B.onAfterPlotLine(K)}});I.save();I.globalAlpha=J.alpha;F.plotNode(J,C);if(!F.labelsHidden&&I.globalAlpha>=0.95){F.plotLabel(C,J,B)}else{if(!F.labelsHidden&&I.globalAlpha<0.95){F.hideLabel(J)}}I.restore();J.visited=!D})},plotNode:function(B,A){var D=A.getSmallerSize()/2;var C=B.pos.toComplex(),E=C.scale(D);A.path("fill",function(G){var F=Config.transformNodes?B._radius*(1-C.squaredNorm()):B._radius;if(F>=4){G.arc(E.x,E.y,F,0,Math.PI*2,true)}})},plotLine:function(L,D){var E=L.nodeFrom,C=L.nodeTo,I=L.data;var M=E.pos.toComplex(),H=C.pos.toComplex();var G=this.computeArcThroughTwoPoints(M,H);var F=D.getSmallerSize()/2;var K=Math.atan2(H.y-G.y,H.x-G.x);var J=Math.atan2(M.y-G.y,M.x-G.x);var B=this.sense(K,J);var A=D.getContext();A.save();D.path("stroke",function(N){if(G.a>1000||G.b>1000||G.ratio>1000){var P=M.scale(F),O=H.scale(F);N.moveTo(P.x,P.y);N.lineTo(O.x,O.y)}else{N.arc(G.x*F,G.y*F,G.ratio*F,K,J,B)}});A.restore()},computeArcThroughTwoPoints:function(M,L){var E=(M.x*L.y-M.y*L.x),A=E;var D=M.squaredNorm(),C=L.squaredNorm();if(E==0){return{x:0,y:0,ratio:1001}}var K=(M.y*(C)-L.y*(D)+M.y-L.y)/E;var I=(L.x*(D)-M.x*(C)+L.x-M.x)/A;var J=-K/2;var H=-I/2;var G=(K*K+I*I)/4-1;if(G<0){return{x:0,y:0,ratio:1001}}var F=Math.sqrt(G);var B={x:J,y:H,ratio:F,a:K,b:I};return B},plotLabel:function(C,E,G){var B=E.id,K=this.getLabel(B);if(!K&&!(K=document.getElementById(B))){K=document.createElement("div");var A=this.getLabelContainer();A.appendChild(K);K.id=B;K.className="node";K.style.position="absolute";G.onCreateLabel(K,E)}var J=E.pos.toComplex();var H=C.getSize();var F=C.getSmallerSize()/2;var I=C.getPosition();var D={x:Math.round(J.x*F+I.x+H.x/2),y:Math.round(J.y*F+I.y+H.y/2)};K.style.left=D.x+"px";K.style.top=D.y+"px";K.style.display="";G.onPlaceLabel(K,E)},hideLabel:function(A){var B;if(B=this.getLabel(A.id)){B.style.display="none"}},sense:function(A,B){return(A<B)?((A+Math.PI>B)?false:true):((B+Math.PI>A)?true:false)}};var Hypertree=function(C,A){var B={onBeforeCompute:$_.fn(),onAfterCompute:$_.fn(),onCreateLabel:$_.fn(),onPlaceLabel:$_.fn(),onCreateElement:$_.fn(),onComplete:$_.fn(),onBeforePlotLine:$_.fn(),onAfterPlotLine:$_.fn(),request:false};this.controller=$_.merge(B,A);this.graph=new Graph();this.json=null;this.canvas=C;this.root=null;this.busy=false;Animation.fps=Config.fps;Animation.duration=Config.animationTime};Hypertree.prototype={construct:function(B){var C=(typeof B=="object"&&B.constructor.toString().match(/array/i));var A=new Graph();if(!C){(function(D,F){D.addNode(F);for(var E=0,G=F.children;E<G.length;E++){D.addAdjacence(F,G[E]);arguments.callee(D,G[E])}})(A,B)}else{(function(E,H){var K=function(M){for(var L=0;L<H.length;L++){if(H[L].id==M){return H[L]}}};for(var G=0;G<H.length;G++){E.addNode(H[G]);for(var F=0,D=H[G].adjacencies;F<D.length;F++){var I=D[F],J;if(typeof D[F]!="string"){J=I.data;I=I.nodeTo}E.addAdjacence(H[G],K(I),J)}}})(A,B)}return A},loadTree:function(A){this.graph=this.construct(A)},loadGraph:function(A){this.graph=this.construct(A)},flagRoot:function(A){this.unflagRoot();this.graph.nodes[A]._root=true},unflagRoot:function(){GraphUtil.eachNode(this.graph,function(A){A._root=false})},getRoot:function(){var A=false;GraphUtil.eachNode(this.graph,function(B){if(B._root){A=B}});return A},loadTreeFromJSON:function(A){this.json=A;this.loadTree(A);this.root=A.id},loadGraphFromJSON:function(B,A){this.json=B;this.loadGraph(B);this.root=B[A?A:0].id},refresh:function(A){if(A){this.reposition();GraphUtil.eachNode(this.graph,function(B){B.startPos=B.pos=B.endPos})}else{this.compute()}this.plot()},reposition:function(){this.compute("endPos");var A=this.graph.getNode(this.root).pos.toComplex().$scale(-1);GraphUtil.moebiusTransformation(this.graph,[A],["endPos"],"endPos","ignore");GraphUtil.eachNode(this.graph,function(B){if(B.ignore){B.endPos=B.pos}})},plot:function(){GraphPlot.plot(this,this.controller)},compute:function(B){var C=B||["pos","startPos"];var A=GraphUtil.getNode(this.graph,this.root);A._depth=0;this.flagRoot(this.root);GraphUtil.computeLevels(this.graph,this.root,"ignore");this.computeAngularWidths();this.computePositions(C)},computePositions:function(H){var I=(typeof H=="array"||typeof H=="object")?H:[H];var D=this.graph,F=GraphUtil;var G=this.graph.getNode(this.root),E=this,A=Config;for(var C=0;C<I.length;C++){G[I[C]]=new Polar(0,0)}G.angleSpan={begin:0,end:2*Math.PI};G._rel=1;var B=(function(){var L=0;F.eachNode(D,function(M){L=(M._depth>L)?M._depth:L},"ignore");for(var K=0.51;K<=1;K+=0.01){var J=(function(M,N){return(1-Math.pow(M,N))/(1-M)})(K,L+1);if(J>=2){return K-0.01}}return 0.5})();F.eachBFS(this.graph,this.root,function(M){var K=M.angleSpan.end-M.angleSpan.begin;var N=M.angleSpan.begin;var L=(function(O){var P=0;F.eachSubnode(D,O,function(Q){P+=Q._treeAngularWidth},"ignore");return P})(M);var J=(function(S,O){for(var Q=1,R=0,P=O;Q<=S+1;Q++){R+=P;P*=O}return R})(M._depth,B);F.eachSubnode(D,M,function(R){if(!R._flag){R._rel=R._treeAngularWidth/L;var Q=R._rel*K;var P=N+Q/2;for(var O=0;O<I.length;O++){R[I[O]]=new Polar(P,J)}R.angleSpan={begin:N,end:N+Q};N+=Q}},"ignore")},"ignore")},setAngularWidthForNodes:function(){var C=Config.nodeRangeValues,A=Config.nodeRangeDiameters,D=Config.nodeRadius;var B=function(E){return(((A.max-A.min)/(C.max-C.min))*(E-C.min)+A.min)};GraphUtil.eachBFS(this.graph,this.root,function(H,F){var I=(Config.allowVariableNodeDiameters&&H.data&&H.data.length>0)?H.data[0].value:D;var G=B(I);var E=F;H._angularWidth=G/E;H._radius=G/2})},setSubtreesAngularWidth:function(){var A=this;GraphUtil.eachNode(this.graph,function(B){A.setSubtreeAngularWidth(B)})},setSubtreeAngularWidth:function(D){var C=this,B=D._angularWidth,A=0;GraphUtil.eachSubnode(this.graph,D,function(E){C.setSubtreeAngularWidth(E);A++});D._treeAngularWidth=Math.max(B,A)},computeAngularWidths:function(){this.setAngularWidthForNodes();this.setSubtreesAngularWidth()},onClick:function(A){Mouse.capturePosition(A);var B=Mouse.getPosition(this.canvas);this.move(B)},move:function(D){if(this.busy===false&&D.norm()<1){this.busy=true;var A=this.graph.getNode(this.root),C=this;this.controller.onBeforeCompute(A);var B=new Complex(D.x,D.y);if(B.norm()<1){GraphPlot.animate(this,$_.merge(this.controller,{modes:["moebius"],hideLabels:true,onComplete:function(){C.busy=false}}),B)}}},prepareCanvasEvents:function(){var A=this;this.canvas.canvas.onclick=function(B){A.onClick(B)}}};var Mouse={position:null,getPosition:function(C){var B=this.posx;var G=this.posy;var A=C.getPosition();var E=C.getSmallerSize();var D=C.getSize();var F={x:((B-A.x)-D.x/2)/(E/2),y:((G-A.y)-D.y/2)/(E/2)};this.position=new Complex(F.x,F.y);return this.position},capturePosition:function(B){var A=0;var C=0;if(!B){var B=window.event}if(B.pageX||B.pageY){A=B.pageX;C=B.pageY}else{if(B.clientX||B.clientY){A=B.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;C=B.clientY+document.body.scrollTop+document.documentElement.scrollTop}}this.posx=A;this.posy=C}};var Graph=function(){this.nodes={}};Graph.prototype={getNode:function(A){if(this.hasNode(A)){return this.nodes[A]}return false},getAdjacence:function(C,A){var B=[];if(this.hasNode(C)&&this.hasNode(A)&&this.nodes[C].adjacentTo({id:A})&&this.nodes[A].adjacentTo({id:C})){B.push(this.nodes[C].getAdjacency(A));B.push(this.nodes[A].getAdjacency(C));return B}return false},addNode:function(A){if(!this.nodes[A.id]){this.nodes[A.id]=new Graph.Node(A.id,A.name,A.data)}return this.nodes[A.id]},addAdjacence:function(D,C,B){var E=[];if(!this.hasNode(D.id)){this.addNode(D)}if(!this.hasNode(C.id)){this.addNode(C)}D=this.nodes[D.id];C=this.nodes[C.id];for(var A in this.nodes){if(this.nodes[A].id==D.id){if(!this.nodes[A].adjacentTo(C)){E.push(this.nodes[A].addAdjacency(C,B))}}if(this.nodes[A].id==C.id){if(!this.nodes[A].adjacentTo(D)){E.push(this.nodes[A].addAdjacency(D,B))}}}return E},removeNode:function(C){if(this.hasNode(C)){var B=this.nodes[C];for(var A=0 in B.adjacencies){var adj=B.adjacencies[A];this.removeAdjacence(C,adj.nodeTo.id)}delete this.nodes[C]}},removeAdjacence:function(E,D){if(this.hasNode(E)){this.nodes[E].removeAdjacency(D)}if(this.hasNode(D)){this.nodes[D].removeAdjacency(E)}},hasNode:function(D){return D in this.nodes}};Graph.Node=function(F,D,E){this.id=F;this.name=D;this.data=E;this.drawn=false;this.angleSpan={begin:0,end:0};this.pos=new Polar(0,0);this.startPos=new Polar(0,0);this.endPos=new Polar(0,0);this.alpha=1;this.startAlpha=1;this.endAlpha=1;this.adjacencies={}};Graph.Node.prototype={adjacentTo:function(D){return D.id in this.adjacencies},getAdjacency:function(D){return this.adjacencies[D]},addAdjacency:function(E,F){var D=new Graph.Adjacence(this,E,F);return this.adjacencies[E.id]=D},removeAdjacency:function(D){delete this.adjacencies[D]}};Graph.Adjacence=function(D,F,E){this.nodeFrom=D;this.nodeTo=F;this.data=E;this.alpha=1;this.startAlpha=1;this.endAlpha=1};var Trans={linear:function(D){return D},Quart:function(D){return Math.pow(D,4)},easeIn:function(D,E){return D(E)},easeOut:function(D,E){return 1-D(1-E)},easeInOut:function(D,E){return(E<=0.5)?D(2*E)/2:(2-D(2*(1-E)))/2}};var Animation={duration:Config.animationTime,fps:Config.fps,transition:function(D){return Trans.easeInOut(Trans.Quart,D)},controller:false,getTime:function(){var D=(Date.now)?Date.now():new Date().getTime();return D},step:function(){var D=this.getTime();if(D<this.time+this.duration){var E=this.transition((D-this.time)/this.duration);this.controller.compute(E)}else{this.timer=clearInterval(this.timer);this.controller.compute(1);this.controller.complete()}},start:function(){this.time=0;this.startTimer();return this},startTimer:function(){if(this.timer){return false}this.time=this.getTime()-this.time;this.timer=setInterval((function(){Animation.step()}),Math.round(1000/this.fps));return true}};
