/*
  Copyright (c) 2010, Nicolas Garcia Belmonte
  All rights reserved

  > Redistribution and use in source and binary forms, with or without
  > modification, are permitted provided that the following conditions are met:
  >      * Redistributions of source code must retain the above copyright
  >        notice, this list of conditions and the following disclaimer.
  >      * Redistributions in binary form must reproduce the above copyright
  >        notice, this list of conditions and the following disclaimer in the
  >        documentation and/or other materials provided with the distribution.
  >      * Neither the name of the organization nor the
  >        names of its contributors may be used to endorse or promote products
  >        derived from this software without specific prior written permission.
  >
  >  THIS SOFTWARE IS PROVIDED BY NICOLAS GARCIA BELMONTE ``AS IS'' AND ANY
  >  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  >  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  >  DISCLAIMED. IN NO EVENT SHALL NICOLAS GARCIA BELMONTE BE LIABLE FOR ANY
  >  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  >  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  >  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  >  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  >  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  >  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
 (function(){window.$jit=function(a){a=a||window;for(var b in $jit)if($jit[b].$extend)a[b]=$jit[b]};$jit.version="2.0.0b";var h=function(a){return document.getElementById(a)};h.empty=function(){};h.extend=function(a,b){for(var d in b||{})a[d]=b[d];return a};h.lambda=function(a){return typeof a=="function"?a:function(){return a}};h.time=Date.now||function(){return+new Date};h.splat=function(a){var b=h.type(a);return b?b!="array"?[a]:a:[]};h.type=function(a){var b=h.type.s.call(a).match(/^\[object\s(.*)\]$/)[1].toLowerCase();
if(b!="object")return b;if(a&&a.$$family)return a.$$family;return a&&a.nodeName&&a.nodeType==1?"element":b};h.type.s=Object.prototype.toString;h.each=function(a,b){if(h.type(a)=="object")for(var d in a)b(a[d],d);else{d=0;for(var c=a.length;d<c;d++)b(a[d],d)}};h.indexOf=function(a,b){if(Array.indexOf)return a.indexOf(b);for(var d=0,c=a.length;d<c;d++)if(a[d]===b)return d;return-1};h.map=function(a,b){var d=[];h.each(a,function(c,e){d.push(b(c,e))});return d};h.reduce=function(a,b,d){var c=a.length;
if(c==0)return d;for(var e=arguments.length==3?d:a[--c];c--;)e=b(e,a[c]);return e};h.merge=function(){for(var a={},b=0,d=arguments.length;b<d;b++){var c=arguments[b];if(h.type(c)=="object")for(var e in c){var f=c[e],g=a[e];a[e]=g&&h.type(f)=="object"&&h.type(g)=="object"?h.merge(g,f):h.unlink(f)}}return a};h.unlink=function(a){var b;switch(h.type(a)){case "object":b={};for(var d in a)b[d]=h.unlink(a[d]);break;case "array":b=[];d=0;for(var c=a.length;d<c;d++)b[d]=h.unlink(a[d]);break;default:return a}return b};
h.zip=function(){if(arguments.length===0)return[];for(var a=0,b=[],d=arguments.length,c=arguments[0].length;a<c;a++){for(var e=0,f=[];e<d;e++)f.push(arguments[e][a]);b.push(f)}return b};h.rgbToHex=function(a,b){if(a.length<3)return null;if(a.length==4&&a[3]==0&&!b)return"transparent";for(var d=[],c=0;c<3;c++){var e=(a[c]-0).toString(16);d.push(e.length==1?"0"+e:e)}return b?d:"#"+d.join("")};h.hexToRgb=function(a){if(a.length!=7){a=a.match(/^#?(\w{1,2})(\w{1,2})(\w{1,2})$/);a.shift();if(a.length!=
3)return null;for(var b=[],d=0;d<3;d++){var c=a[d];if(c.length==1)c+=c;b.push(parseInt(c,16))}return b}else{a=parseInt(a.slice(1),16);return[a>>16,a>>8&255,a&255]}};h.destroy=function(a){h.clean(a);a.parentNode&&a.parentNode.removeChild(a);a.clearAttributes&&a.clearAttributes()};h.clean=function(a){a=a.childNodes;for(var b=0,d=a.length;b<d;b++)h.destroy(a[b])};h.addEvent=function(a,b,d){a.addEventListener?a.addEventListener(b,d,false):a.attachEvent("on"+b,d)};h.addEvents=function(a,b){for(var d in b)h.addEvent(a,
d,b[d])};h.hasClass=function(a,b){return(" "+a.className+" ").indexOf(" "+b+" ")>-1};h.addClass=function(a,b){if(!h.hasClass(a,b))a.className=a.className+" "+b};h.removeClass=function(a,b){a.className=a.className.replace(RegExp("(^|\\s)"+b+"(?:\\s|$)"),"$1")};h.getPos=function(a){var b=function(d){for(var c={x:0,y:0};d&&!/^(?:body|html)$/i.test(d.tagName);){c.x+=d.offsetLeft;c.y+=d.offsetTop;d=d.offsetParent}return c}(a);a=function(d){for(var c={x:0,y:0};d&&!/^(?:body|html)$/i.test(d.tagName);){c.x+=
d.scrollLeft;c.y+=d.scrollTop;d=d.parentNode}return c}(a);return{x:b.x-a.x,y:b.y-a.y}};h.event={get:function(a,b){b=b||window;return a||b.event},getWheel:function(a){return a.wheelDelta?a.wheelDelta/120:-(a.detail||0)/3},isRightClick:function(a){return a.which==3||a.button==2},getPos:function(a,b){b=b||window;a=a||b.event;var d=b.document;d=d.documentElement||d.body;if(a.touches&&a.touches.length)a=a.touches[0];return{x:a.pageX||a.clientX+d.scrollLeft,y:a.pageY||a.clientY+d.scrollTop}},stop:function(a){a.stopPropagation&&
a.stopPropagation();a.cancelBubble=true;if(a.preventDefault)a.preventDefault();else a.returnValue=false}};$jit.util=$jit.id=h;var o=function(a){a=a||{};var b=function(){for(var c in this)if(typeof this[c]!="function")this[c]=h.unlink(this[c]);this.constructor=b;if(o.prototyping)return this;c=this.initialize?this.initialize.apply(this,arguments):this;this.$$family="class";return c},d;for(d in o.Mutators)if(a[d]){a=o.Mutators[d](a,a[d]);delete a[d]}h.extend(b,this);b.constructor=o;b.prototype=a;return b};
o.Mutators={Implements:function(a,b){h.each(h.splat(b),function(d){o.prototyping=d;d=typeof d=="function"?new d:d;for(var c in d)c in a||(a[c]=d[c]);delete o.prototyping});return a}};h.extend(o,{inherit:function(a,b){for(var d in b){var c=b[d],e=a[d],f=h.type(c);if(e&&f=="function")c!=e&&o.override(a,d,c);else a[d]=f=="object"?h.merge(e,c):c}return a},override:function(a,b,d){var c=o.prototyping;if(c&&a[b]!=c[b])c=null;a[b]=function(){var e=this.parent;this.parent=c?c[b]:a[b];var f=d.apply(this,arguments);
this.parent=e;return f}}});o.prototype.implement=function(){var a=this.prototype;h.each(Array.prototype.slice.call(arguments||[]),function(b){o.inherit(a,b)});return this};$jit.Class=o;$jit.json={prune:function(a,b){this.each(a,function(d,c){if(c==b&&d.children){delete d.children;d.children=[]}})},getParent:function(a,b){if(a.id==b)return false;var d=a.children;if(d&&d.length>0)for(var c=0;c<d.length;c++)if(d[c].id==b)return a;else{var e=this.getParent(d[c],b);if(e)return e}return false},getSubtree:function(a,
b){if(a.id==b)return a;for(var d=0,c=a.children;d<c.length;d++){var e=this.getSubtree(c[d],b);if(e!=null)return e}return null},eachLevel:function(a,b,d,c){if(b<=d){c(a,b);if(a.children){var e=0;for(a=a.children;e<a.length;e++)this.eachLevel(a[e],b+1,d,c)}}},each:function(a,b){this.eachLevel(a,0,Number.MAX_VALUE,b)}};$jit.Trans={$extend:true,linear:function(a){return a}};var y=$jit.Trans;(function(){var a=function(b,d){d=h.splat(d);return h.extend(b,{easeIn:function(c){return b(c,d)},easeOut:function(c){return 1-
b(1-c,d)},easeInOut:function(c){return c<=0.5?b(2*c,d)/2:(2-b(2*(1-c),d))/2}})};h.each({Pow:function(b,d){return Math.pow(b,d[0]||6)},Expo:function(b){return Math.pow(2,8*(b-1))},Circ:function(b){return 1-Math.sin(Math.acos(b))},Sine:function(b){return 1-Math.sin((1-b)*Math.PI/2)},Back:function(b,d){d=d[0]||1.618;return Math.pow(b,2)*((d+1)*b-d)},Bounce:function(b){for(var d,c=0,e=1;;c+=e,e/=2)if(b>=(7-4*c)/11){d=e*e-Math.pow((11-6*c-11*b)/4,2);break}return d},Elastic:function(b,d){return Math.pow(2,
10*--b)*Math.cos(20*b*Math.PI*(d[0]||1)/3)}},function(b,d){y[d]=a(b)});h.each(["Quad","Cubic","Quart","Quint"],function(b,d){y[b]=a(function(c){return Math.pow(c,[d+2])})})})();var E=new o({initialize:function(a){this.setOptions(a)},setOptions:function(a){this.opt=h.merge({duration:2500,fps:40,transition:y.Quart.easeInOut,compute:h.empty,complete:h.empty,link:"ignore"},a||{});return this},step:function(){var a=h.time(),b=this.opt;if(a<this.time+b.duration){a=b.transition((a-this.time)/b.duration);
b.compute(a)}else{this.timer=clearInterval(this.timer);b.compute(1);b.complete()}},start:function(){if(!this.check())return this;this.time=0;this.startTimer();return this},startTimer:function(){var a=this,b=this.opt.fps;if(this.timer)return false;this.time=h.time()-this.time;this.timer=setInterval(function(){a.step()},Math.round(1E3/b));return true},pause:function(){this.stopTimer();return this},resume:function(){this.startTimer();return this},stopTimer:function(){if(!this.timer)return false;this.time=
h.time()-this.time;this.timer=clearInterval(this.timer);return true},check:function(){if(!this.timer)return true;if(this.opt.link=="cancel"){this.stopTimer();return true}return false}}),u=function(){for(var a=arguments,b=0,d=a.length,c={};b<d;b++){var e=u[a[b]];if(e.$extend)h.extend(c,e);else c[a[b]]=e}return c};u.Canvas={$extend:true,injectInto:"id",width:false,height:false,useCanvas:false,withLabels:true,background:false};u.Tree={$extend:true,orientation:"left",subtreeOffset:8,siblingOffset:5,indent:10,
multitree:false,align:"center"};u.Node={$extend:false,overridable:false,type:"circle",color:"#ccb",alpha:1,dim:3,height:20,width:90,autoHeight:false,autoWidth:false,lineWidth:1,transform:true,align:"center",angularWidth:1,span:1,CanvasStyles:{}};u.Edge={$extend:false,overridable:false,type:"line",color:"#ccb",lineWidth:1,dim:15,alpha:1,epsilon:7,CanvasStyles:{}};u.Fx={$extend:true,fps:40,duration:2500,transition:$jit.Trans.Quart.easeInOut,clearCanvas:true};u.Label={$extend:false,overridable:false,
type:"HTML",style:" ",size:10,family:"sans-serif",textAlign:"center",textBaseline:"alphabetic",color:"#fff"};u.Tips={$extend:false,enable:false,type:"auto",offsetX:20,offsetY:20,force:false,onShow:h.empty,onHide:h.empty};u.Navigation={$extend:false,enable:false,type:"auto",panning:false,zooming:false};u.NodeStyles={$extend:false,enable:false,type:"auto",stylesHover:false,stylesClick:false};u.Events={$extend:false,enable:false,enableForEdges:false,type:"auto",onClick:h.empty,onRightClick:h.empty,onMouseMove:h.empty,
onMouseEnter:h.empty,onMouseLeave:h.empty,onDragStart:h.empty,onDragMove:h.empty,onDragCancel:h.empty,onDragEnd:h.empty,onTouchStart:h.empty,onTouchMove:h.empty,onTouchEnd:h.empty,onMouseWheel:h.empty};u.Controller={$extend:true,onBeforeCompute:h.empty,onAfterCompute:h.empty,onCreateLabel:h.empty,onPlaceLabel:h.empty,onComplete:h.empty,onBeforePlotLine:h.empty,onAfterPlotLine:h.empty,onBeforePlotNode:h.empty,onAfterPlotNode:h.empty,request:false};var s={initialize:function(a,b){this.viz=b;this.canvas=
b.canvas;this.config=b.config[a];this.nodeTypes=b.fx.nodeTypes;var d=this.config.type;this.labelContainer=(this.dom=d=="auto"?b.config.Label.type!="Native":d!="Native")&&b.labels.getLabelContainer();this.isEnabled()&&this.initializePost()},initializePost:h.empty,setAsProperty:h.lambda(false),isEnabled:function(){return this.config.enable},isLabel:function(a,b){a=h.event.get(a,b);var d=this.labelContainer,c=a.target||a.srcElement;if(c&&c.parentNode==d)return c;return false}},A={onMouseUp:h.empty,onMouseDown:h.empty,
onMouseMove:h.empty,onMouseOver:h.empty,onMouseOut:h.empty,onMouseWheel:h.empty,onTouchStart:h.empty,onTouchMove:h.empty,onTouchEnd:h.empty,onTouchCancel:h.empty},H=new o({initialize:function(a){this.viz=a;this.canvas=a.canvas;this.edge=this.node=false;this.registeredObjects=[];this.attachEvents()},attachEvents:function(){var a=this.canvas.getElement(),b=this;a.oncontextmenu=h.lambda(false);h.addEvents(a,{mouseup:function(c,e){var f=h.event.get(c,e);b.handleEvent("MouseUp",c,e,b.makeEventObject(c,
e),h.event.isRightClick(f))},mousedown:function(c,e){var f=h.event.get(c,e);b.handleEvent("MouseDown",c,e,b.makeEventObject(c,e),h.event.isRightClick(f))},mousemove:function(c,e){b.handleEvent("MouseMove",c,e,b.makeEventObject(c,e))},mouseover:function(c,e){b.handleEvent("MouseOver",c,e,b.makeEventObject(c,e))},mouseout:function(c,e){b.handleEvent("MouseOut",c,e,b.makeEventObject(c,e))},touchstart:function(c,e){b.handleEvent("TouchStart",c,e,b.makeEventObject(c,e))},touchmove:function(c,e){b.handleEvent("TouchMove",
c,e,b.makeEventObject(c,e))},touchend:function(c,e){b.handleEvent("TouchEnd",c,e,b.makeEventObject(c,e))}});var d=function(c,e){var f=h.event.get(c,e);f=h.event.getWheel(f);b.handleEvent("MouseWheel",c,e,f)};!document.getBoxObjectFor&&window.mozInnerScreenX==null?h.addEvent(a,"mousewheel",d):a.addEventListener("DOMMouseScroll",d,false)},register:function(a){this.registeredObjects.push(a)},handleEvent:function(){for(var a=Array.prototype.slice.call(arguments),b=a.shift(),d=0,c=this.registeredObjects,
e=c.length;d<e;d++)c[d]["on"+b].apply(c[d],a)},makeEventObject:function(a,b){var d=this,c=this.viz.graph,e=this.viz.fx,f=e.nodeTypes,g=e.edgeTypes;return{pos:false,node:false,edge:false,contains:false,getNodeCalled:false,getEdgeCalled:false,getPos:function(){var i=d.viz.canvas,j=i.getSize(),k=i.getPos(),l=i.translateOffsetX,m=i.translateOffsetY,n=i.scaleOffsetX;i=i.scaleOffsetY;var q=h.event.getPos(a,b);return this.pos={x:(q.x-k.x-j.width/2-l)*1/n,y:(q.y-k.y-j.height/2-m)*1/i}},getNode:function(){if(this.getNodeCalled)return this.node;
this.getNodeCalled=true;for(var i in c.nodes){var j=c.nodes[i],k=j&&f[j.getData("type")];if(k=k&&k.contains&&k.contains.call(e,j,this.getPos())){this.contains=k;return d.node=this.node=j}}return d.node=this.node=false},getEdge:function(){if(this.getEdgeCalled)return this.edge;this.getEdgeCalled=true;var i={},j;for(j in c.edges){var k=c.edges[j];i[j]=true;for(var l in k)if(!(l in i)){var m=k[l],n=m&&g[m.getData("type")];if(n=n&&n.contains&&n.contains.call(e,m,this.getPos())){this.contains=n;return d.edge=
this.edge=m}}}return d.edge=this.edge=false},getContains:function(){if(this.getNodeCalled)return this.contains;this.getNode();return this.contains}}}}),x={initializeExtras:function(){var a=new H(this),b=this;h.each(["NodeStyles","Tips","Navigation","Events"],function(d){var c=new x.Classes[d](d,b);c.isEnabled()&&a.register(c);if(c.setAsProperty())b[d.toLowerCase()]=c})}};x.Classes={};x.Classes.Events=new o({Implements:[s,A],initializePost:function(){this.fx=this.viz.fx;this.ntypes=this.viz.fx.nodeTypes;
this.etypes=this.viz.fx.edgeTypes;this.moved=this.touchMoved=this.touched=this.pressed=this.hovered=false},setAsProperty:h.lambda(true),onMouseUp:function(a,b,d,c){a=h.event.get(a,b);this.moved||(c?this.config.onRightClick(this.hovered,d,a):this.config.onClick(this.pressed,d,a));if(this.pressed){this.moved?this.config.onDragEnd(this.pressed,d,a):this.config.onDragCancel(this.pressed,d,a);this.pressed=this.moved=false}},onMouseOut:function(a,b,d){var c=h.event.get(a,b),e;if(this.dom&&(e=this.isLabel(a,
b))){this.config.onMouseLeave(this.viz.graph.getNode(e.id),d,c);this.hovered=false}else{a=c.relatedTarget;for(b=this.canvas.getElement();a&&a.parentNode;){if(b==a.parentNode)return;a=a.parentNode}if(this.hovered){this.config.onMouseLeave(this.hovered,d,c);this.hovered=false}}},onMouseOver:function(a,b,d){var c=h.event.get(a,b),e;if(this.dom&&(e=this.isLabel(a,b))){this.hovered=this.viz.graph.getNode(e.id);this.config.onMouseEnter(this.hovered,d,c)}},onMouseMove:function(a,b,d){a=h.event.get(a,b);
if(this.pressed){this.moved=true;this.config.onDragMove(this.pressed,d,a)}else if(this.dom)this.config.onMouseMove(this.hovered,d,a);else{if(this.hovered){b=this.hovered;var c=b.nodeFrom?this.etypes[b.getData("type")]:this.ntypes[b.getData("type")];if(c&&c.contains&&c.contains.call(this.fx,b,d.getPos())){this.config.onMouseMove(b,d,a);return}else{this.config.onMouseLeave(b,d,a);this.hovered=false}}(this.hovered=d.getNode()||this.config.enableForEdges&&d.getEdge())?this.config.onMouseEnter(this.hovered,
d,a):this.config.onMouseMove(false,d,a)}},onMouseWheel:function(a,b,d){this.config.onMouseWheel(d,h.event.get(a,b))},onMouseDown:function(a,b,d){a=h.event.get(a,b);this.pressed=d.getNode()||this.config.enableForEdges&&d.getEdge();this.config.onDragStart(this.pressed,d,a)},onTouchStart:function(a,b,d){a=h.event.get(a,b);this.touched=d.getNode()||this.config.enableForEdges&&d.getEdge();this.config.onTouchStart(this.touched,d,a)},onTouchMove:function(a,b,d){a=h.event.get(a,b);if(this.touched){this.touchMoved=
true;this.config.onTouchMove(this.touched,d,a)}},onTouchEnd:function(a,b,d){a=h.event.get(a,b);if(this.touched){this.touchMoved?this.config.onTouchEnd(this.touched,d,a):this.config.onTouchCancel(this.touched,d,a);this.touched=this.touchMoved=false}}});x.Classes.Tips=new o({Implements:[s,A],initializePost:function(){if(document.body){var a=h("_tooltip")||document.createElement("div");a.id="_tooltip";a.className="tip";h.extend(a.style,{position:"absolute",display:"none",zIndex:13E3});document.body.appendChild(a);
this.tip=a;this.node=false}},setAsProperty:h.lambda(true),onMouseOut:function(a,b){if(this.dom&&this.isLabel(a,b))this.hide(true);else{for(var d=a.relatedTarget,c=this.canvas.getElement();d&&d.parentNode;){if(c==d.parentNode)return;d=d.parentNode}this.hide(false)}},onMouseOver:function(a,b){var d;if(this.dom&&(d=this.isLabel(a,b))){this.node=this.viz.graph.getNode(d.id);this.config.onShow(this.tip,this.node,d)}},onMouseMove:function(a,b,d){this.dom&&this.isLabel(a,b)&&this.setTooltipPosition(h.event.getPos(a,
b));if(!this.dom){var c=d.getNode();if(c){if(this.config.force||!this.node||this.node.id!=c.id){this.node=c;this.config.onShow(this.tip,c,d.getContains())}this.setTooltipPosition(h.event.getPos(a,b))}else this.hide(true)}},setTooltipPosition:function(a){var b=this.tip,d=b.style,c=this.config;d.display="";var e={height:document.body.clientHeight,width:document.body.clientWidth};b={width:b.offsetWidth,height:b.offsetHeight};var f=c.offsetX;c=c.offsetY;d.top=(a.y+c+b.height>e.height?a.y-b.height-c:a.y+
c)+"px";d.left=(a.x+b.width+f>e.width?a.x-b.width-f:a.x+f)+"px"},hide:function(a){this.tip.style.display="none";a&&this.config.onHide()}});x.Classes.NodeStyles=new o({Implements:[s,A],initializePost:function(){this.fx=this.viz.fx;this.types=this.viz.fx.nodeTypes;this.nStyles=this.config;this.nodeStylesOnHover=this.nStyles.stylesHover;this.nodeStylesOnClick=this.nStyles.stylesClick;this.hoveredNode=false;this.fx.nodeFxAnimation=new E;this.move=this.down=false},onMouseOut:function(a,b){this.down=this.move=
false;if(this.hoveredNode){this.dom&&this.isLabel(a,b)&&this.toggleStylesOnHover(this.hoveredNode,false);for(var d=a.relatedTarget,c=this.canvas.getElement();d&&d.parentNode;){if(c==d.parentNode)return;d=d.parentNode}this.toggleStylesOnHover(this.hoveredNode,false);this.hoveredNode=false}},onMouseOver:function(a,b){var d;if(this.dom&&(d=this.isLabel(a,b))){d=this.viz.graph.getNode(d.id);if(!d.selected){this.hoveredNode=d;this.toggleStylesOnHover(this.hoveredNode,true)}}},onMouseDown:function(a,b,
d,c){if(!c){var e;if(this.dom&&(e=this.isLabel(a,b)))this.down=this.viz.graph.getNode(e.id);else if(!this.dom)this.down=d.getNode();this.move=false}},onMouseUp:function(a,b,d,c){if(!c){this.move||this.onClick(d.getNode());this.down=this.move=false}},getRestoredStyles:function(a,b){var d={},c=this["nodeStylesOn"+b],e;for(e in c)d[e]=a.styles["$"+e];return d},toggleStylesOnHover:function(a,b){this.nodeStylesOnHover&&this.toggleStylesOn("Hover",a,b)},toggleStylesOnClick:function(a,b){this.nodeStylesOnClick&&
this.toggleStylesOn("Click",a,b)},toggleStylesOn:function(a,b,d){var c=this.viz;if(d){if(!b.styles)b.styles=h.merge(b.data,{});for(var e in this["nodeStylesOn"+a]){d="$"+e;d in b.styles||(b.styles[d]=b.getData(e))}c.fx.nodeFx(h.extend({elements:{id:b.id,properties:this["nodeStylesOn"+a]},transition:y.Quart.easeOut,duration:300,fps:40},this.config))}else{a=this.getRestoredStyles(b,a);c.fx.nodeFx(h.extend({elements:{id:b.id,properties:a},transition:y.Quart.easeOut,duration:300,fps:40},this.config))}},
onClick:function(a){if(a){var b=this.nodeStylesOnClick;if(b)if(a.selected){this.toggleStylesOnClick(a,false);delete a.selected}else{this.viz.graph.eachNode(function(d){if(d.selected){for(var c in b)d.setData(c,d.styles["$"+c],"end");delete d.selected}});this.toggleStylesOnClick(a,true);a.selected=true;delete a.hovered;this.hoveredNode=false}}},onMouseMove:function(a,b,d){if(this.down)this.move=true;if(!(this.dom&&this.isLabel(a,b))){var c=this.nodeStylesOnHover;if(c)if(!this.dom){if(this.hoveredNode)if((a=
this.types[this.hoveredNode.getData("type")])&&a.contains&&a.contains.call(this.fx,this.hoveredNode,d.getPos()))return;d=d.getNode();if(this.hoveredNode||d)if(!d.hovered)if(d&&!d.selected){this.fx.nodeFxAnimation.stopTimer();this.viz.graph.eachNode(function(e){if(e.hovered&&!e.selected){for(var f in c)e.setData(f,e.styles["$"+f],"end");delete e.hovered}});d.hovered=true;this.hoveredNode=d;this.toggleStylesOnHover(d,true)}else if(this.hoveredNode&&!this.hoveredNode.selected){this.fx.nodeFxAnimation.stopTimer();
this.toggleStylesOnHover(this.hoveredNode,false);delete this.hoveredNode.hovered;this.hoveredNode=false}}}}});x.Classes.Navigation=new o({Implements:[s,A],initializePost:function(){this.pressed=this.pos=false},onMouseWheel:function(a,b,d){if(this.config.zooming){h.event.stop(h.event.get(a,b));a=1+d*(this.config.zooming/1E3);this.canvas.scale(a,a)}},onMouseDown:function(a,b,d){if(this.config.panning)if(!(this.config.panning=="avoid nodes"&&d.getNode())){this.pressed=true;this.pos=d.getPos();a=this.canvas;
b=a.translateOffsetX;d=a.translateOffsetY;var c=a.scaleOffsetY;this.pos.x*=a.scaleOffsetX;this.pos.x+=b;this.pos.y*=c;this.pos.y+=d}},onMouseMove:function(a,b,d){if(this.config.panning)if(this.pressed)if(!(this.config.panning=="avoid nodes"&&d.getNode())){a=this.pos;d=d.getPos();var c=this.canvas,e=c.translateOffsetX,f=c.translateOffsetY;b=c.scaleOffsetX;c=c.scaleOffsetY;d.x*=b;d.y*=c;d.x+=e;d.y+=f;e=d.x-a.x;a=d.y-a.y;this.pos=d;this.canvas.translate(e*1/b,a*1/c)}},onMouseUp:function(){if(this.config.panning)this.pressed=
false}});var w;(function(){function a(c,e){var f=document.createElement(c),g;for(g in e)if(typeof e[g]=="object")h.extend(f[g],e[g]);else f[g]=e[g];if(c=="canvas"&&!d&&G_vmlCanvasManager)f=G_vmlCanvasManager.initElement(document.body.appendChild(f));return f}var b=typeof HTMLCanvasElement,d=b=="object"||b=="function";$jit.Canvas=w=new o({canvases:[],pos:false,element:false,labelContainer:false,translateOffsetX:0,translateOffsetY:0,scaleOffsetX:1,scaleOffsetY:1,initialize:function(c,e){this.viz=c;
this.opt=e;var f=h.type(e.injectInto)=="string"?e.injectInto:e.injectInto.id,g=f+"-label",i=h(f),j=e.width||i.offsetWidth,k=e.height||i.offsetHeight;this.id=f;var l={injectInto:f,width:j,height:k};this.element=a("div",{id:f+"-canvaswidget",style:{position:"relative",width:j+"px",height:k+"px"}});this.labelContainer=this.createLabelContainer(e.Label.type,g,l);this.canvases.push(new w.Base({config:h.extend({idSuffix:"-canvas"},l),plot:function(){c.fx.plot()},resize:function(){c.refresh()}}));if(f=e.background){l=
new w.Background[f.type](c,h.extend(f,l));this.canvases.push(new w.Base(l))}for(l=this.canvases.length;l--;){this.element.appendChild(this.canvases[l].canvas);l>0&&this.canvases[l].plot()}this.element.appendChild(this.labelContainer);i.appendChild(this.element);var m=null,n=this;h.addEvent(window,"scroll",function(){clearTimeout(m);m=setTimeout(function(){n.getPos(true)},500)})},getCtx:function(c){return this.canvases[c||0].getCtx()},getConfig:function(){return this.opt},getElement:function(){return this.element},
getSize:function(c){return this.canvases[c||0].getSize()},resize:function(c,e){this.getPos(true);this.translateOffsetX=this.translateOffsetY=0;this.scaleOffsetX=this.scaleOffsetY=1;for(var f=0,g=this.canvases.length;f<g;f++)this.canvases[f].resize(c,e);f=this.element.style;f.width=c+"px";f.height=e+"px";if(this.labelContainer)this.labelContainer.style.width=c+"px"},translate:function(c,e,f){this.translateOffsetX+=c*this.scaleOffsetX;this.translateOffsetY+=e*this.scaleOffsetY;for(var g=0,i=this.canvases.length;g<
i;g++)this.canvases[g].translate(c,e,f)},scale:function(c,e){var f=this.scaleOffsetX*c,g=this.scaleOffsetY*e,i=this.translateOffsetX*(c-1)/f,j=this.translateOffsetY*(e-1)/g;this.scaleOffsetX=f;this.scaleOffsetY=g;f=0;for(g=this.canvases.length;f<g;f++)this.canvases[f].scale(c,e,true);this.translate(i,j,false)},getPos:function(c){if(c||!this.pos)return this.pos=h.getPos(this.getElement());return this.pos},clear:function(c){this.canvases[c||0].clear()},path:function(c,e){var f=this.canvases[0].getCtx();
f.beginPath();e(f);f[c]();f.closePath()},createLabelContainer:function(c,e,f){if(c=="HTML"||c=="Native")return a("div",{id:e,style:{overflow:"visible",position:"absolute",top:0,left:0,width:f.width+"px",height:0}});else if(c=="SVG"){c=document.createElementNS("http://www.w3.org/2000/svg","svg:svg");c.setAttribute("width",f.width);c.setAttribute("height",f.height);var g=c.style;g.position="absolute";g.left=g.top="0px";g=document.createElementNS("http://www.w3.org/2000/svg","svg:g");g.setAttribute("width",
f.width);g.setAttribute("height",f.height);g.setAttribute("x",0);g.setAttribute("y",0);g.setAttribute("id",e);c.appendChild(g);return c}}});w.Base=new o({translateOffsetX:0,translateOffsetY:0,scaleOffsetX:1,scaleOffsetY:1,initialize:function(c){this.viz=c;this.opt=c.config;this.size=false;this.createCanvas();this.translateToCenter()},createCanvas:function(){var c=this.opt,e=c.width,f=c.height;this.canvas=a("canvas",{id:c.injectInto+c.idSuffix,width:e,height:f,style:{position:"absolute",top:0,left:0,
width:e+"px",height:f+"px"}})},getCtx:function(){if(!this.ctx)return this.ctx=this.canvas.getContext("2d");return this.ctx},getSize:function(){if(this.size)return this.size;var c=this.canvas;return this.size={width:c.width,height:c.height}},translateToCenter:function(c){var e=this.getSize(),f=c?e.width-c.width-this.translateOffsetX*2:e.width;height=c?e.height-c.height-this.translateOffsetY*2:e.height;e=this.getCtx();c&&e.scale(1/this.scaleOffsetX,1/this.scaleOffsetY);e.translate(f/2,height/2)},resize:function(c,
e){var f=this.getSize(),g=this.canvas,i=g.style;this.size=false;g.width=c;g.height=e;i.width=c+"px";i.height=e+"px";d?this.translateToCenter():this.translateToCenter(f);this.translateOffsetX=this.translateOffsetY=0;this.scaleOffsetX=this.scaleOffsetY=1;this.clear();this.viz.resize(c,e,this)},translate:function(c,e,f){var g=this.scaleOffsetY;this.translateOffsetX+=c*this.scaleOffsetX;this.translateOffsetY+=e*g;this.getCtx().translate(c,e);!f&&this.plot()},scale:function(c,e,f){this.scaleOffsetX*=c;
this.scaleOffsetY*=e;this.getCtx().scale(c,e);!f&&this.plot()},clear:function(){var c=this.getSize(),e=this.translateOffsetX,f=this.translateOffsetY,g=this.scaleOffsetX,i=this.scaleOffsetY;this.getCtx().clearRect((-c.width/2-e)*1/g,(-c.height/2-f)*1/i,c.width*1/g,c.height*1/i)},plot:function(){this.clear();this.viz.plot(this)}});w.Background={};w.Background.Circles=new o({initialize:function(c,e){this.viz=c;this.config=h.merge({idSuffix:"-bkcanvas",levelDistance:100,numberOfCircles:6,CanvasStyles:{},
offset:0},e)},resize:function(c,e,f){this.plot(f)},plot:function(c){c=c.getCtx();var e=this.config,f=e.CanvasStyles,g;for(g in f)c[g]=f[g];g=e.numberOfCircles;e=e.levelDistance;for(f=1;f<=g;f++){c.beginPath();c.arc(0,0,e*f,0,2*Math.PI,false);c.stroke();c.closePath()}}})})();var t=function(a,b){this.theta=a;this.rho=b};$jit.Polar=t;t.prototype={getc:function(a){return this.toComplex(a)},getp:function(){return this},set:function(a){a=a.getp();this.theta=a.theta;this.rho=a.rho},setc:function(a,b){this.rho=
Math.sqrt(a*a+b*b);this.theta=Math.atan2(b,a);if(this.theta<0)this.theta+=Math.PI*2},setp:function(a,b){this.theta=a;this.rho=b},clone:function(){return new t(this.theta,this.rho)},toComplex:function(a){var b=Math.cos(this.theta)*this.rho,d=Math.sin(this.theta)*this.rho;if(a)return{x:b,y:d};return new r(b,d)},add:function(a){return new t(this.theta+a.theta,this.rho+a.rho)},scale:function(a){return new t(this.theta,this.rho*a)},equals:function(a){return this.theta==a.theta&&this.rho==a.rho},$add:function(a){this.theta+=
a.theta;this.rho+=a.rho;return this},$madd:function(a){this.theta=(this.theta+a.theta)%(Math.PI*2);this.rho+=a.rho;return this},$scale:function(a){this.rho*=a;return this},interpolate:function(a,b){var d=Math.PI,c=d*2,e=function(j){return j<0?j%c+c:j%c},f=this.theta,g=a.theta,i=Math.abs(f-g);return{theta:i==d?f>g?e(g+(f-c-g)*b):e(g-c+(f-g)*b):i>=d?f>g?e(g+(f-c-g)*b):e(g-c+(f-(g-c))*b):e(g+(f-g)*b),rho:(this.rho-a.rho)*b+a.rho}}};t.KER=new t(0,0);var r=function(a,b){this.x=a;this.y=b};$jit.Complex=
r;r.prototype={getc:function(){return this},getp:function(a){return this.toPolar(a)},set:function(a){a=a.getc(true);this.x=a.x;this.y=a.y},setc:function(a,b){this.x=a;this.y=b},setp:function(a,b){this.x=Math.cos(a)*b;this.y=Math.sin(a)*b},clone:function(){return new r(this.x,this.y)},toPolar:function(a){var b=this.norm(),d=Math.atan2(this.y,this.x);if(d<0)d+=Math.PI*2;if(a)return{theta:d,rho:b};return new t(d,b)},norm:function(){return Math.sqrt(this.squaredNorm())},squaredNorm:function(){return this.x*
this.x+this.y*this.y},add:function(a){return new r(this.x+a.x,this.y+a.y)},prod:function(a){return new r(this.x*a.x-this.y*a.y,this.y*a.x+this.x*a.y)},conjugate:function(){return new r(this.x,-this.y)},scale:function(a){return new r(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(a){var b=this.x,d=this.y;this.x=b*a.x-d*a.y;this.y=d*a.x+b*a.y;return this},$conjugate:function(){this.y=-this.y;return this},$scale:function(a){this.x*=
a;this.y*=a;return this},$div:function(a){var b=this.x,d=this.y,c=a.squaredNorm();this.x=b*a.x+d*a.y;this.y=d*a.x-b*a.y;return this.$scale(1/c)}};r.KER=new r(0,0);$jit.Graph=new o({initialize:function(a,b,d,c){this.Node=b;this.Edge=d;this.Label=c;this.opt=h.merge({complex:false,Node:{}},a||{});this.nodes={};this.edges={};var e=this;this.nodeList={};for(var f in B)e.nodeList[f]=function(g){return function(){var i=Array.prototype.slice.call(arguments);e.eachNode(function(j){j[g].apply(j,i)})}}(f)},
getNode:function(a){if(this.hasNode(a))return this.nodes[a];return false},getByName:function(a){for(var b in this.nodes){var d=this.nodes[b];if(d.name==a)return d}return false},getAdjacence:function(a,b){if(a in this.edges)return this.edges[a][b];return false},addNode:function(a){if(!this.nodes[a.id]){var b=this.edges[a.id]={};this.nodes[a.id]=new p.Node(h.extend({id:a.id,name:a.name,data:h.merge(a.data||{},{}),adjacencies:b},this.opt.Node),this.opt.complex,this.Node,this.Edge,this.Label)}return this.nodes[a.id]},
addAdjacence:function(a,b,d){this.hasNode(a.id)||this.addNode(a);this.hasNode(b.id)||this.addNode(b);a=this.nodes[a.id];b=this.nodes[b.id];if(!a.adjacentTo(b)){var c=this.edges[a.id]=this.edges[a.id]||{},e=this.edges[b.id]=this.edges[b.id]||{};c[b.id]=e[a.id]=new p.Adjacence(a,b,d,this.Edge,this.Label);return c[b.id]}return this.edges[a.id][b.id]},removeNode:function(a){if(this.hasNode(a)){delete this.nodes[a];var b=this.edges[a],d;for(d in b)delete this.edges[d][a];delete this.edges[a]}},removeAdjacence:function(a,
b){delete this.edges[a][b];delete this.edges[b][a]},hasNode:function(a){return a in this.nodes},empty:function(){this.nodes={};this.edges={}}});var p=$jit.Graph,B;(function(){var a=function(c,e,f,g,i){var j;f=f||"current";c="$"+(c?c+"-":"");if(f=="current")j=this.data;else if(f=="start")j=this.startData;else if(f=="end")j=this.endData;c=c+e;if(g)return j[c];if(!this.Config.overridable)return i[e]||0;return c in j?j[c]:c in this.data?this.data[c]:i[e]||0},b=function(c,e,f,g){g=g||"current";c="$"+(c?
c+"-":"");var i;if(g=="current")i=this.data;else if(g=="start")i=this.startData;else if(g=="end")i=this.endData;i[c+e]=f},d=function(c,e){c="$"+(c?c+"-":"");var f=this;h.each(e,function(g){g=c+g;delete f.data[g];delete f.endData[g];delete f.startData[g]})};B={getData:function(c,e,f){return a.call(this,"",c,e,f,this.Config)},setData:function(c,e,f){b.call(this,"",c,e,f)},setDataset:function(c,e){c=h.splat(c);for(var f in e)for(var g=0,i=h.splat(e[f]),j=c.length;g<j;g++)this.setData(f,i[g],c[g])},removeData:function(){d.call(this,
"",Array.prototype.slice.call(arguments))},getCanvasStyle:function(c,e,f){return a.call(this,"canvas",c,e,f,this.Config.CanvasStyles)},setCanvasStyle:function(c,e,f){b.call(this,"canvas",c,e,f)},setCanvasStyles:function(c,e){c=h.splat(c);for(var f in e)for(var g=0,i=h.splat(e[f]),j=c.length;g<j;g++)this.setCanvasStyle(f,i[g],c[g])},removeCanvasStyle:function(){d.call(this,"canvas",Array.prototype.slice.call(arguments))},getLabelData:function(c,e,f){return a.call(this,"label",c,e,f,this.Label)},setLabelData:function(c,
e,f){b.call(this,"label",c,e,f)},setLabelDataset:function(c,e){c=h.splat(c);for(var f in e)for(var g=0,i=h.splat(e[f]),j=c.length;g<j;g++)this.setLabelData(f,i[g],c[g])},removeLabelData:function(){d.call(this,"label",Array.prototype.slice.call(arguments))}}})();p.Node=new o({initialize:function(a,b,d,c,e){b={id:"",name:"",data:{},startData:{},endData:{},adjacencies:{},selected:false,drawn:false,exist:false,angleSpan:{begin:0,end:0},pos:b&&new r(0,0)||new t(0,0),startPos:b&&new r(0,0)||new t(0,0),
endPos:b&&new r(0,0)||new t(0,0)};h.extend(this,h.extend(b,a));this.Config=this.Node=d;this.Edge=c;this.Label=e},adjacentTo:function(a){return a.id in this.adjacencies},getAdjacency:function(a){return this.adjacencies[a]},getPos:function(a){a=a||"current";if(a=="current")return this.pos;else if(a=="end")return this.endPos;else if(a=="start")return this.startPos},setPos:function(a,b){b=b||"current";var d;if(b=="current")d=this.pos;else if(b=="end")d=this.endPos;else if(b=="start")d=this.startPos;d.set(a)}});
p.Node.implement(B);p.Adjacence=new o({initialize:function(a,b,d,c,e){this.nodeFrom=a;this.nodeTo=b;this.data=d||{};this.startData={};this.endData={};this.Config=this.Edge=c;this.Label=e}});p.Adjacence.implement(B);p.Util={filter:function(a){if(!a||h.type(a)!="string")return function(){return true};var b=a.split(" ");return function(d){for(var c=0;c<b.length;c++)if(d[b[c]])return false;return true}},getNode:function(a,b){return a.nodes[b]},eachNode:function(a,b,d){d=this.filter(d);for(var c in a.nodes)d(a.nodes[c])&&
b(a.nodes[c])},eachAdjacency:function(a,b,d){var c=a.adjacencies;d=this.filter(d);for(var e in c){var f=c[e];if(d(f)){if(f.nodeFrom!=a){var g=f.nodeFrom;f.nodeFrom=f.nodeTo;f.nodeTo=g}b(f,e)}}},computeLevels:function(a,b,d,c){d=d||0;var e=this.filter(c);this.eachNode(a,function(i){i._flag=false;i._depth=-1},c);a=a.getNode(b);a._depth=d;for(var f=[a];f.length!=0;){var g=f.pop();g._flag=true;this.eachAdjacency(g,function(i){i=i.nodeTo;if(i._flag==false&&e(i)){if(i._depth<0)i._depth=g._depth+1+d;f.unshift(i)}},
c)}},eachBFS:function(a,b,d,c){var e=this.filter(c);this.clean(a);for(var f=[a.getNode(b)];f.length!=0;){a=f.pop();a._flag=true;d(a,a._depth);this.eachAdjacency(a,function(g){g=g.nodeTo;if(g._flag==false&&e(g)){g._flag=true;f.unshift(g)}},c)}},eachLevel:function(a,b,d,c,e){var f=a._depth,g=this.filter(e),i=this;d=d===false?Number.MAX_VALUE-f:d;(function j(k,l,m){var n=k._depth;n>=l&&n<=m&&g(k)&&c(k,n);n<m&&i.eachAdjacency(k,function(q){q=q.nodeTo;q._depth>n&&j(q,l,m)})})(a,b+f,d+f)},eachSubgraph:function(a,
b,d){this.eachLevel(a,0,false,b,d)},eachSubnode:function(a,b,d){this.eachLevel(a,1,1,b,d)},anySubnode:function(a,b,d){var c=false;b=b||h.lambda(true);var e=h.type(b)=="string"?function(f){return f[b]}:b;this.eachSubnode(a,function(f){if(e(f))c=true},d);return c},getSubnodes:function(a,b,d){var c=[];b=b||0;var e;if(h.type(b)=="array"){e=b[0];b=b[1]}else{e=b;b=Number.MAX_VALUE-a._depth}this.eachLevel(a,e,b,function(f){c.push(f)},d);return c},getParents:function(a){var b=[];this.eachAdjacency(a,function(d){d=
d.nodeTo;d._depth<a._depth&&b.push(d)});return b},isDescendantOf:function(a,b){if(a.id==b)return true;for(var d=this.getParents(a),c=false,e=0;!c&&e<d.length;e++)c=c||this.isDescendantOf(d[e],b);return c},clean:function(a){this.eachNode(a,function(b){b._flag=false})},getClosestNodeToOrigin:function(a,b,d){return this.getClosestNodeToPos(a,t.KER,b,d)},getClosestNodeToPos:function(a,b,d,c){var e=null;d=d||"current";b=b&&b.getc(true)||r.KER;var f=function(g,i){var j=g.x-i.x,k=g.y-i.y;return j*j+k*k};
this.eachNode(a,function(g){e=e==null||f(g.getPos(d).getc(true),b)<f(e.getPos(d).getc(true),b)?g:e},c);return e}};h.each(["getNode","eachNode","computeLevels","eachBFS","clean","getClosestNodeToPos","getClosestNodeToOrigin"],function(a){p.prototype[a]=function(){return p.Util[a].apply(p.Util,[this].concat(Array.prototype.slice.call(arguments)))}});h.each(["eachAdjacency","eachLevel","eachSubgraph","eachSubnode","anySubnode","getSubnodes","getParents","isDescendantOf"],function(a){p.Node.prototype[a]=
function(){return p.Util[a].apply(p.Util,[this].concat(Array.prototype.slice.call(arguments)))}});p.Op={options:{type:"nothing",duration:2E3,hideLabels:true,fps:30},initialize:function(a){this.viz=a},removeNode:function(a,b){var d=this.viz,c=h.merge(this.options,d.controller,b),e=h.splat(a),f,g,i;switch(c.type){case "nothing":for(f=0;f<e.length;f++)d.graph.removeNode(e[f]);break;case "replot":this.removeNode(e,{type:"nothing"});d.labels.clearLabels();d.refresh(true);break;case "fade:seq":case "fade":g=
this;for(f=0;f<e.length;f++){i=d.graph.getNode(e[f]);i.setData("alpha",0,"end")}d.fx.animate(h.merge(c,{modes:["node-property:alpha"],onComplete:function(){g.removeNode(e,{type:"nothing"});d.labels.clearLabels();d.reposition();d.fx.animate(h.merge(c,{modes:["linear"]}))}}));break;case "fade:con":g=this;for(f=0;f<e.length;f++){i=d.graph.getNode(e[f]);i.setData("alpha",0,"end");i.ignore=true}d.reposition();d.fx.animate(h.merge(c,{modes:["node-property:alpha","linear"],onComplete:function(){g.removeNode(e,
{type:"nothing"})}}));break;case "iter":g=this;d.fx.sequence({condition:function(){return e.length!=0},step:function(){g.removeNode(e.shift(),{type:"nothing"});d.labels.clearLabels()},onComplete:function(){c.onComplete()},duration:Math.ceil(c.duration/e.length)});break;default:this.doError()}},removeEdge:function(a,b){var d=this.viz,c=h.merge(this.options,d.controller,b),e=h.type(a[0])=="string"?[a]:a,f,g,i;switch(c.type){case "nothing":for(f=0;f<e.length;f++)d.graph.removeAdjacence(e[f][0],e[f][1]);
break;case "replot":this.removeEdge(e,{type:"nothing"});d.refresh(true);break;case "fade:seq":case "fade":g=this;for(f=0;f<e.length;f++)(i=d.graph.getAdjacence(e[f][0],e[f][1]))&&i.setData("alpha",0,"end");d.fx.animate(h.merge(c,{modes:["edge-property:alpha"],onComplete:function(){g.removeEdge(e,{type:"nothing"});d.reposition();d.fx.animate(h.merge(c,{modes:["linear"]}))}}));break;case "fade:con":g=this;for(f=0;f<e.length;f++)if(i=d.graph.getAdjacence(e[f][0],e[f][1])){i.setData("alpha",0,"end");
i.ignore=true}d.reposition();d.fx.animate(h.merge(c,{modes:["edge-property:alpha","linear"],onComplete:function(){g.removeEdge(e,{type:"nothing"})}}));break;case "iter":g=this;d.fx.sequence({condition:function(){return e.length!=0},step:function(){g.removeEdge(e.shift(),{type:"nothing"});d.labels.clearLabels()},onComplete:function(){c.onComplete()},duration:Math.ceil(c.duration/e.length)});break;default:this.doError()}},sum:function(a,b){var d=this.viz,c=h.merge(this.options,d.controller,b),e=d.root,
f;d.root=b.id||d.root;switch(c.type){case "nothing":f=d.construct(a);f.eachNode(function(i){i.eachAdjacency(function(j){d.graph.addAdjacence(j.nodeFrom,j.nodeTo,j.data)})});break;case "replot":d.refresh(true);this.sum(a,{type:"nothing"});d.refresh(true);break;case "fade:seq":case "fade":case "fade:con":that=this;f=d.construct(a);var g=!this.preprocessSum(f)?["node-property:alpha"]:["node-property:alpha","edge-property:alpha"];d.reposition();if(c.type!="fade:con")d.fx.animate(h.merge(c,{modes:["linear"],
onComplete:function(){d.fx.animate(h.merge(c,{modes:g,onComplete:function(){c.onComplete()}}))}}));else{d.graph.eachNode(function(i){if(i.id!=e&&i.pos.getp().equals(t.KER)){i.pos.set(i.endPos);i.startPos.set(i.endPos)}});d.fx.animate(h.merge(c,{modes:["linear"].concat(g)}))}break;default:this.doError()}},morph:function(a,b,d){var c=this.viz,e=h.merge(this.options,c.controller,b),f=c.root,g;c.root=b.id||c.root;switch(e.type){case "nothing":g=c.construct(a);g.eachNode(function(k){var l=c.graph.hasNode(k.id);
k.eachAdjacency(function(n){var q=!!c.graph.getAdjacence(n.nodeFrom.id,n.nodeTo.id);c.graph.addAdjacence(n.nodeFrom,n.nodeTo,n.data);if(q){q=c.graph.getAdjacence(n.nodeFrom.id,n.nodeTo.id);for(var v in n.data||{})q.data[v]=n.data[v]}});if(l){l=c.graph.getNode(k.id);for(var m in k.data||{})l.data[m]=k.data[m]}});c.graph.eachNode(function(k){k.eachAdjacency(function(l){g.getAdjacence(l.nodeFrom.id,l.nodeTo.id)||c.graph.removeAdjacence(l.nodeFrom.id,l.nodeTo.id)});g.hasNode(k.id)||c.graph.removeNode(k.id)});
break;case "replot":c.labels.clearLabels(true);this.morph(a,{type:"nothing"});c.refresh(true);c.refresh(true);break;case "fade:seq":case "fade":case "fade:con":that=this;g=c.construct(a);var i=d&&"node-property"in d&&h.map(h.splat(d["node-property"]),function(k){return"$"+k});c.graph.eachNode(function(k){var l=g.getNode(k.id);if(l){l=l.data;for(var m in l)if(i&&h.indexOf(i,m)>-1)k.endData[m]=l[m];else k.data[m]=l[m]}else{k.setData("alpha",1);k.setData("alpha",1,"start");k.setData("alpha",0,"end");
k.ignore=true}});c.graph.eachNode(function(k){k.ignore||k.eachAdjacency(function(l){if(!(l.nodeFrom.ignore||l.nodeTo.ignore)){var m=g.getNode(l.nodeFrom.id);l=g.getNode(l.nodeTo.id);if(!m.adjacentTo(l)){l=c.graph.getAdjacence(m.id,l.id);j=true;l.setData("alpha",1);l.setData("alpha",1,"start");l.setData("alpha",0,"end")}}})});var j=this.preprocessSum(g);a=!j?["node-property:alpha"]:["node-property:alpha","edge-property:alpha"];a[0]+=d&&"node-property"in d?":"+h.splat(d["node-property"]).join(":"):
"";a[1]=(a[1]||"edge-property:alpha")+(d&&"edge-property"in d?":"+h.splat(d["edge-property"]).join(":"):"");d&&"label-property"in d&&a.push("label-property:"+h.splat(d["label-property"]).join(":"));c.reposition();c.graph.eachNode(function(k){if(k.id!=f&&k.pos.getp().equals(t.KER)){k.pos.set(k.endPos);k.startPos.set(k.endPos)}});c.fx.animate(h.merge(e,{modes:["polar"].concat(a),onComplete:function(){c.graph.eachNode(function(k){k.ignore&&c.graph.removeNode(k.id)});c.graph.eachNode(function(k){k.eachAdjacency(function(l){l.ignore&&
c.graph.removeAdjacence(l.nodeFrom.id,l.nodeTo.id)})});e.onComplete()}}))}},contract:function(a,b){var d=this.viz;if(!(a.collapsed||!a.anySubnode(h.lambda(true)))){b=h.merge(this.options,d.config,b||{},{modes:["node-property:alpha:span","linear"]});a.collapsed=true;(function c(e){e.eachSubnode(function(f){f.ignore=true;f.setData("alpha",0,b.type=="animate"?"end":"current");c(f)})})(a);if(b.type=="animate"){d.compute("end");d.rotated&&d.rotate(d.rotated,"none",{property:"end"});(function c(e){e.eachSubnode(function(f){f.setPos(a.getPos("end"),
"end");c(f)})})(a);d.fx.animate(b)}else b.type=="replot"&&d.refresh()}},expand:function(a,b){if("collapsed"in a){var d=this.viz;b=h.merge(this.options,d.config,b||{},{modes:["node-property:alpha:span","linear"]});delete a.collapsed;(function c(e){e.eachSubnode(function(f){delete f.ignore;f.setData("alpha",1,b.type=="animate"?"end":"current");c(f)})})(a);if(b.type=="animate"){d.compute("end");d.rotated&&d.rotate(d.rotated,"none",{property:"end"});d.fx.animate(b)}else b.type=="replot"&&d.refresh()}},
preprocessSum:function(a){var b=this.viz;a.eachNode(function(c){if(!b.graph.hasNode(c.id)){b.graph.addNode(c);c=b.graph.getNode(c.id);c.setData("alpha",0);c.setData("alpha",0,"start");c.setData("alpha",1,"end")}});var d=false;a.eachNode(function(c){c.eachAdjacency(function(e){var f=b.graph.getNode(e.nodeFrom.id),g=b.graph.getNode(e.nodeTo.id);if(!f.adjacentTo(g)){e=b.graph.addAdjacence(f,g,e.data);if(f.startAlpha==f.endAlpha&&g.startAlpha==g.endAlpha){d=true;e.setData("alpha",0);e.setData("alpha",
0,"start");e.setData("alpha",1,"end")}}})});return d}};var C={none:{render:h.empty,contains:h.lambda(false)},circle:{render:function(a,b,d,c){c=c.getCtx();c.beginPath();c.arc(b.x,b.y,d,0,Math.PI*2,true);c.closePath();c[a]()},contains:function(a,b,d){var c=a.x-b.x;a=a.y-b.y;return c*c+a*a<=d*d}},ellipse:{render:function(a,b,d,c,e){e=e.getCtx();c/=2;d/=2;e.save();e.scale(d/c,c/d);e.beginPath();e.arc(b.x*(c/d),b.y*(d/c),c,0,Math.PI*2,true);e.closePath();e[a]();e.restore()},contains:function(a,b,d,c){d/=
2;c/=2;d=(d+c)/2;c=a.x-b.x;a=a.y-b.y;return c*c+a*a<=d*d}},square:{render:function(a,b,d,c){c.getCtx()[a+"Rect"](b.x-d,b.y-d,2*d,2*d)},contains:function(a,b,d){return Math.abs(b.x-a.x)<=d&&Math.abs(b.y-a.y)<=d}},rectangle:{render:function(a,b,d,c,e){e.getCtx()[a+"Rect"](b.x-d/2,b.y-c/2,d,c)},contains:function(a,b,d,c){return Math.abs(b.x-a.x)<=d/2&&Math.abs(b.y-a.y)<=c/2}},triangle:{render:function(a,b,d,c){c=c.getCtx();var e=b.x,f=b.y-d,g=e-d;b=b.y+d;d=e+d;c.beginPath();c.moveTo(e,f);c.lineTo(g,
b);c.lineTo(d,b);c.closePath();c[a]()},contains:function(a,b,d){return C.circle.contains(a,b,d)}},star:{render:function(a,b,d,c){c=c.getCtx();var e=Math.PI/5;c.save();c.translate(b.x,b.y);c.beginPath();c.moveTo(d,0);for(b=0;b<9;b++){c.rotate(e);b%2==0?c.lineTo(d/0.525731*0.200811,0):c.lineTo(d,0)}c.closePath();c[a]();c.restore()},contains:function(a,b,d){return C.circle.contains(a,b,d)}}},F={line:{render:function(a,b,d){d=d.getCtx();d.beginPath();d.moveTo(a.x,a.y);d.lineTo(b.x,b.y);d.stroke()},contains:function(a,
b,d,c){var e=Math.min,f=Math.max,g=e(a.x,b.x),i=f(a.x,b.x);e=e(a.y,b.y);f=f(a.y,b.y);if(d.x>=g&&d.x<=i&&d.y>=e&&d.y<=f){if(Math.abs(b.x-a.x)<=c)return true;return Math.abs((b.y-a.y)/(b.x-a.x)*(d.x-a.x)+a.y-d.y)<=c}return false}},arrow:{render:function(a,b,d,c,e){e=e.getCtx();if(c){c=a;a=b;b=c}c=new r(b.x-a.x,b.y-a.y);c.$scale(d/c.norm());d=new r(b.x-c.x,b.y-c.y);var f=new r(-c.y/2,c.x/2);c=d.add(f);d=d.$add(f.$scale(-1));e.beginPath();e.moveTo(a.x,a.y);e.lineTo(b.x,b.y);e.stroke();e.beginPath();e.moveTo(c.x,
c.y);e.lineTo(d.x,d.y);e.lineTo(b.x,b.y);e.closePath();e.fill()},contains:function(a,b,d,c){return F.line.contains(a,b,d,c)}},hyperline:{render:function(a,b,d,c){function e(g,i){return g<i?g+Math.PI>i?false:true:i+Math.PI>g?true:false}c=c.getCtx();var f=function(g,i){var j=g.x*i.y-g.y*i.x,k=g.squaredNorm(),l=i.squaredNorm();if(j==0)return{x:0,y:0,ratio:-1};var m=(g.y*l-i.y*k+g.y-i.y)/j;j=(i.x*k-g.x*l+i.x-g.x)/j;k=(m*m+j*j)/4-1;if(k<0)return{x:0,y:0,ratio:-1};k=Math.sqrt(k);return{x:-m/2,y:-j/2,ratio:k>
1E3?-1:k,a:m,b:j}}(a,b);if(f.a>1E3||f.b>1E3||f.ratio<0){c.beginPath();c.moveTo(a.x*d,a.y*d);c.lineTo(b.x*d,b.y*d)}else{b=Math.atan2(b.y-f.y,b.x-f.x);a=Math.atan2(a.y-f.y,a.x-f.x);e=e(b,a);c.beginPath();c.arc(f.x*d,f.y*d,f.ratio*d,b,a,e)}c.stroke()},contains:h.lambda(false)}};p.Plot={initialize:function(a,b){this.viz=a;this.config=a.config;this.node=a.config.Node;this.edge=a.config.Edge;this.animation=new E;this.nodeTypes=new b.Plot.NodeTypes;this.edgeTypes=new b.Plot.EdgeTypes;this.labels=a.labels},
nodeHelper:C,edgeHelper:F,Interpolator:{map:{border:"color",color:"color",width:"number",height:"number",dim:"number",alpha:"number",lineWidth:"number",angularWidth:"number",span:"number",valueArray:"array-number",dimArray:"array-number"},canvas:{globalAlpha:"number",fillStyle:"color",strokeStyle:"color",lineWidth:"number",shadowBlur:"number",shadowColor:"color",shadowOffsetX:"number",shadowOffsetY:"number",miterLimit:"number"},label:{size:"number",color:"color"},compute:function(a,b,d){return a+
(b-a)*d},moebius:function(a,b,d,c){b=c.scale(-d);if(b.norm()<1){d=b.x;c=b.y;var e=a.startPos.getc().moebiusTransformation(b);a.pos.setc(e.x,e.y);b.x=d;b.y=c}},linear:function(a,b,d){b=a.startPos.getc(true);var c=a.endPos.getc(true);a.pos.setc(this.compute(b.x,c.x,d),this.compute(b.y,c.y,d))},polar:function(a,b,d){b=a.startPos.getp(true);d=a.endPos.getp().interpolate(b,d);a.pos.setp(d.theta,d.rho)},number:function(a,b,d,c,e){var f=a[c](b,"start");c=a[c](b,"end");a[e](b,this.compute(f,c,d))},color:function(a,
b,d,c,e){var f=h.hexToRgb(a[c](b,"start"));c=h.hexToRgb(a[c](b,"end"));var g=this.compute;d=h.rgbToHex([parseInt(g(f[0],c[0],d)),parseInt(g(f[1],c[1],d)),parseInt(g(f[2],c[2],d))]);a[e](b,d)},"array-number":function(a,b,d,c,e){var f=a[c](b,"start");c=a[c](b,"end");for(var g=[],i=0,j=f.length;i<j;i++){var k=f[i],l=c[i];if(k.length){for(var m=0,n=k.length,q=[];m<n;m++)q.push(this.compute(k[m],l[m],d));g.push(q)}else g.push(this.compute(k,l,d))}a[e](b,g)},node:function(a,b,d,c,e,f){c=this[c];if(b)for(var g=
b.length,i=0;i<g;i++){var j=b[i];this[c[j]](a,j,d,e,f)}else for(j in c)this[c[j]](a,j,d,e,f)},edge:function(a,b,d,c,e,f){a=a.adjacencies;for(var g in a)this.node(a[g],b,d,c,e,f)},"node-property":function(a,b,d){this.node(a,b,d,"map","getData","setData")},"edge-property":function(a,b,d){this.edge(a,b,d,"map","getData","setData")},"label-property":function(a,b,d){this.node(a,b,d,"label","getLabelData","setLabelData")},"node-style":function(a,b,d){this.node(a,b,d,"canvas","getCanvasStyle","setCanvasStyle")},
"edge-style":function(a,b,d){this.edge(a,b,d,"canvas","getCanvasStyle","setCanvasStyle")}},sequence:function(a){var b=this;a=h.merge({condition:h.lambda(false),step:h.empty,onComplete:h.empty,duration:200},a||{});var d=setInterval(function(){if(a.condition())a.step();else{clearInterval(d);a.onComplete()}b.viz.refresh(true)},a.duration)},prepare:function(a){var b=this.viz.graph,d={"node-property":{getter:"getData",setter:"setData"},"edge-property":{getter:"getData",setter:"setData"},"node-style":{getter:"getCanvasStyle",
setter:"setCanvasStyle"},"edge-style":{getter:"getCanvasStyle",setter:"setCanvasStyle"}},c={};if(h.type(a)=="array")for(var e=0,f=a.length;e<f;e++){var g=a[e].split(":");c[g.shift()]=g}else for(e in a)if(e=="position")c[a.position]=[];else c[e]=h.splat(a[e]);b.eachNode(function(i){i.startPos.set(i.pos);h.each(["node-property","node-style"],function(j){if(j in c)for(var k=c[j],l=0,m=k.length;l<m;l++)i[d[j].setter](k[l],i[d[j].getter](k[l]),"start")});h.each(["edge-property","edge-style"],function(j){if(j in
c){var k=c[j];i.eachAdjacency(function(l){for(var m=0,n=k.length;m<n;m++)l[d[j].setter](k[m],l[d[j].getter](k[m]),"start")})}})});return c},animate:function(a,b){a=h.merge(this.viz.config,a||{});var d=this,c=this.viz.graph,e=this.Interpolator,f=a.type==="nodefx"?this.nodeFxAnimation:this.animation,g=this.prepare(a.modes);a.hideLabels&&this.labels.hideLabels(true);f.setOptions(h.merge(a,{$animating:false,compute:function(i){c.eachNode(function(j){for(var k in g)e[k](j,g[k],i,b)});d.plot(a,this.$animating,
i);this.$animating=true},complete:function(){a.hideLabels&&d.labels.hideLabels(false);d.plot(a);a.onComplete();a.onAfterCompute()}})).start()},nodeFx:function(a){var b=this.viz,d=b.graph,c=this.nodeFxAnimation,e=h.merge(this.viz.config,{elements:{id:false,properties:{}},reposition:false});a=h.merge(e,a||{},{onBeforeCompute:h.empty,onAfterCompute:h.empty});c.stopTimer();var f=a.elements.properties;if(a.elements.id){c=h.splat(a.elements.id);h.each(c,function(i){if(i=d.getNode(i))for(var j in f)i.setData(j,
f[j],"end")})}else d.eachNode(function(i){for(var j in f)i.setData(j,f[j],"end")});c=[];for(var g in f)c.push(g);g=["node-property:"+c.join(":")];if(a.reposition){g.push("linear");b.compute("end")}this.animate(h.merge(a,{modes:g,type:"nodefx"}))},plot:function(a,b){var d=this.viz,c=d.graph,e=d.canvas;d=d.root;var f=this,g=e.getCtx(),i=Math.min;a=a||this.viz.controller;a.clearCanvas&&e.clear();if(d=c.getNode(d)){var j=!!d.visited;c.eachNode(function(k){var l=k.getData("alpha");k.eachAdjacency(function(m){var n=
m.nodeTo;if(!!n.visited===j&&k.drawn&&n.drawn){!b&&a.onBeforePlotLine(m);g.save();g.globalAlpha=i(l,n.getData("alpha"),m.getData("alpha"));f.plotLine(m,e,b);g.restore();!b&&a.onAfterPlotLine(m)}});g.save();if(k.drawn){!b&&a.onBeforePlotNode(k);f.plotNode(k,e,b);!b&&a.onAfterPlotNode(k)}if(!f.labelsHidden&&a.withLabels)k.drawn&&l>=0.95?f.labels.plotLabel(e,k,a):f.labels.hideLabel(k,false);g.restore();k.visited=!j})}},plotTree:function(a,b,d){var c=this,e=this.viz.canvas,f=e.getCtx(),g=a.getData("alpha");
a.eachSubnode(function(i){if(b.plotSubtree(a,i)&&i.exist&&i.drawn){var j=a.getAdjacency(i.id);!d&&b.onBeforePlotLine(j);f.globalAlpha=Math.min(g,i.getData("alpha"));c.plotLine(j,e,d);!d&&b.onAfterPlotLine(j);c.plotTree(i,b,d)}});if(a.drawn){!d&&b.onBeforePlotNode(a);this.plotNode(a,e,d);!d&&b.onAfterPlotNode(a);!b.hideLabels&&b.withLabels&&g>=0.95?this.labels.plotLabel(e,a,b):this.labels.hideLabel(a,false)}else this.labels.hideLabel(a,true)},plotNode:function(a,b,d){var c=a.getData("type"),e=this.node.CanvasStyles;
if(c!="none"){var f=a.getData("lineWidth"),g=a.getData("color"),i=a.getData("alpha"),j=b.getCtx();j.lineWidth=f;j.fillStyle=j.strokeStyle=g;j.globalAlpha=i;for(var k in e)j[k]=a.getCanvasStyle(k);this.nodeTypes[c].render.call(this,a,b,d)}},plotLine:function(a,b,d){var c=a.getData("type"),e=this.edge.CanvasStyles;if(c!="none"){var f=a.getData("lineWidth"),g=a.getData("color"),i=b.getCtx();i.lineWidth=f;i.fillStyle=i.strokeStyle=g;for(var j in e)i[j]=a.getCanvasStyle(j);this.edgeTypes[c].render.call(this,
a,b,d)}}};p.Label={};p.Label.Native=new o({plotLabel:function(a,b,d){var c=a.getCtx();b.pos.getc(true);c.font=b.getLabelData("style")+" "+b.getLabelData("size")+"px "+b.getLabelData("family");c.textAlign=b.getLabelData("textAlign");c.fillStyle=c.strokeStyle=b.getLabelData("color");c.textBaseline=b.getLabelData("textBaseline");this.renderLabel(a,b,d)},renderLabel:function(a,b){var d=a.getCtx(),c=b.pos.getc(true);d.fillText(b.name,c.x,c.y+b.getData("height")/2)},hideLabel:h.empty,hideLabels:h.empty});
p.Label.DOM=new o({labelsHidden:false,labelContainer:false,labels:{},getLabelContainer:function(){return this.labelContainer?this.labelContainer:this.labelContainer=document.getElementById(this.viz.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(a){this.getLabelContainer().style.display=a?"none":"";this.labelsHidden=a},clearLabels:function(a){for(var b in this.labels)if(a||!this.viz.graph.hasNode(b)){this.disposeLabel(b);
delete this.labels[b]}},disposeLabel:function(a){(a=this.getLabel(a))&&a.parentNode&&a.parentNode.removeChild(a)},hideLabel:function(a,b){a=h.splat(a);var d=b?"":"none",c=this;h.each(a,function(e){if(e=c.getLabel(e.id))e.style.display=d})},fitsInCanvas:function(a,b){var d=b.getSize();if(a.x>=d.width||a.x<0||a.y>=d.height||a.y<0)return false;return true}});p.Label.HTML=new o({Implements:p.Label.DOM,plotLabel:function(a,b,d){a=b.id;var c=this.getLabel(a);if(!c&&!(c=document.getElementById(a))){c=document.createElement("div");
var e=this.getLabelContainer();c.id=a;c.className="node";c.style.position="absolute";d.onCreateLabel(c,b);e.appendChild(c);this.labels[b.id]=c}this.placeLabel(c,b,d)}});p.Label.SVG=new o({Implements:p.Label.DOM,plotLabel:function(a,b,d){a=b.id;var c=this.getLabel(a);if(!c&&!(c=document.getElementById(a))){c=document.createElementNS("http://www.w3.org/2000/svg","svg:text");var e=document.createElementNS("http://www.w3.org/2000/svg","svg:tspan");c.appendChild(e);e=this.getLabelContainer();c.setAttribute("id",
a);c.setAttribute("class","node");e.appendChild(c);d.onCreateLabel(c,b);this.labels[b.id]=c}this.placeLabel(c,b,d)}});s=$jit.Layouts={};s.TM={};s.TM.SliceAndDice=new o({compute:function(a){var b=this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root);this.controller.onBeforeCompute(b);var d=this.canvas.getSize(),c=this.config,e=d.width;d=d.height;this.graph.computeLevels(this.root,0,"ignore");b.getPos(a).setc(-e/2,-d/2);b.setData("width",e,a);b.setData("height",d+c.titleHeight,a);this.computePositions(b,
b,this.layout.orientation,a);this.controller.onAfterCompute(b)},computePositions:function(a,b,d,c){var e=0;a.eachSubnode(function(z){e+=z.getData("area",c)});var f=this.config,g=a.getData("width",c),i=a.getData("height",c)-f.titleHeight;a=a==b?1:b.getData("area",c)/e;var j,k,l,m,n;if(d=="h"){d="v";i=i;g=g*a;j="height";k="y";l="x";m=f.titleHeight;n=0}else{d="h";i=i*a;g=g;j="width";k="x";l="y";m=0;n=f.titleHeight}var q=b.getPos(c);b.setData("width",g,c);b.setData("height",i,c);var v=0,D=this;b.eachSubnode(function(z){var G=
z.getPos(c);G[k]=v+q[k]+m;G[l]=q[l]+n;D.computePositions(b,z,d,c);v+=z.getData(j,c)})}});s.TM.Area={compute:function(a){a=a||"current";var b=this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root);this.controller.onBeforeCompute(b);var d=this.config,c=this.canvas.getSize(),e=c.width;c=c.height;var f=d.offset,g=e-f;f=c-f;this.graph.computeLevels(this.root,0,"ignore");b.getPos(a).setc(-e/2,-c/2);b.setData("width",e,a);b.setData("height",c,a);this.computePositions(b,{top:-c/2+d.titleHeight,
left:-e/2,width:g,height:f-d.titleHeight},a);this.controller.onAfterCompute(b)},computeDim:function(a,b,d,c,e,f){if(a.length+b.length==1)this.layoutLast(a.length==1?a:b,d,c,f);else{if(a.length>=2&&b.length==0)b=[a.shift()];if(a.length==0)b.length>0&&this.layoutRow(b,d,c,f);else{var g=a[0];if(e(b,d)>=e([g].concat(b),d))this.computeDim(a.slice(1),b.concat([g]),d,c,e,f);else{b=this.layoutRow(b,d,c,f);this.computeDim(a,[],b.dim,b,e,f)}}}},worstAspectRatio:function(a,b){if(!a||a.length==0)return Number.MAX_VALUE;
for(var d=0,c=0,e=Number.MAX_VALUE,f=0,g=a.length;f<g;f++){var i=a[f]._area;d+=i;e=e<i?e:i;c=c>i?c:i}f=b*b;d=d*d;return Math.max(f*c/d,d/(f*e))},avgAspectRatio:function(a,b){if(!a||a.length==0)return Number.MAX_VALUE;for(var d=0,c=0,e=a.length;c<e;c++){var f=a[c]._area/b;d+=b>f?b/f:f/b}return d/e},layoutLast:function(a,b,d,c){a=a[0];a.getPos(c).setc(d.left,d.top);a.setData("width",d.width,c);a.setData("height",d.height,c)}};s.TM.Squarified=new o({Implements:s.TM.Area,computePositions:function(a,b,
d){var c=this.config;this.layout.orientation=b.width>=b.height?"h":"v";var e=a.getSubnodes([1,1],"ignore");if(e.length>0){this.processChildrenLayout(a,e,b,d);a=0;for(var f=e.length;a<f;a++){var g=e[a],i=c.offset;b=g.getData("height",d)-i-c.titleHeight;i=g.getData("width",d)-i;var j=g.getPos(d);b={width:i,height:b,top:j.y+c.titleHeight,left:j.x};this.computePositions(g,b,d)}}},processChildrenLayout:function(a,b,d,c){a=d.width*d.height;var e,f=b.length,g=0,i=[];for(e=0;e<f;e++){i[e]=parseFloat(b[e].getData("area",
c));g+=i[e]}for(e=0;e<f;e++)b[e]._area=a*i[e]/g;a=this.layout.horizontal()?d.height:d.width;b.sort(function(j,k){var l=k._area-j._area;return l?l:k.id==j.id?0:k.id<j.id?1:-1});e=[b[0]];this.squarify(b.slice(1),e,a,d,c)},squarify:function(a,b,d,c,e){this.computeDim(a,b,d,c,this.worstAspectRatio,e)},layoutRow:function(a,b,d,c){return this.layout.horizontal()?this.layoutV(a,b,d,c):this.layoutH(a,b,d,c)},layoutV:function(a,b,d,c){var e=0;h.each(a,function(l){e+=l._area});b=e/b;for(var f=0,g=0,i=a.length;g<
i;g++){var j=a[g]._area/b,k=a[g];k.getPos(c).setc(d.left,d.top+f);k.setData("width",b,c);k.setData("height",j,c);f+=j}a={height:d.height,width:d.width-b,top:d.top,left:d.left+b};a.dim=Math.min(a.width,a.height);a.dim!=a.height&&this.layout.change();return a},layoutH:function(a,b,d,c){var e=0;h.each(a,function(m){e+=m._area});for(var f=e/b,g=d.top,i=0,j=0,k=a.length;j<k;j++){var l=a[j];b=l._area/f;l.getPos(c).setc(d.left+i,g);l.setData("width",b,c);l.setData("height",f,c);i+=b}a={height:d.height-f,
width:d.width,top:d.top+f,left:d.left};a.dim=Math.min(a.width,a.height);a.dim!=a.width&&this.layout.change();return a}});s.TM.Strip=new o({Implements:s.TM.Area,computePositions:function(a,b,d){var c=a.getSubnodes([1,1],"ignore"),e=this.config;if(c.length>0){this.processChildrenLayout(a,c,b,d);a=0;for(var f=c.length;a<f;a++){var g=c[a],i=e.offset;b=g.getData("height",d)-i-e.titleHeight;i=g.getData("width",d)-i;var j=g.getPos(d);b={width:i,height:b,top:j.y+e.titleHeight,left:j.x};this.computePositions(g,
b,d)}}},processChildrenLayout:function(a,b,d,c){a=d.width*d.height;var e,f=b.length,g=0,i=[];for(e=0;e<f;e++){i[e]=+b[e].getData("area",c);g+=i[e]}for(e=0;e<f;e++)b[e]._area=a*i[e]/g;a=this.layout.horizontal()?d.width:d.height;e=[b[0]];this.stripify(b.slice(1),e,a,d,c)},stripify:function(a,b,d,c,e){this.computeDim(a,b,d,c,this.avgAspectRatio,e)},layoutRow:function(a,b,d,c){return this.layout.horizontal()?this.layoutH(a,b,d,c):this.layoutV(a,b,d,c)},layoutV:function(a,b,d,c){var e=0;h.each(a,function(m){e+=
m._area});for(var f=e/b,g=0,i=0,j=a.length;i<j;i++){var k=a[i],l=k._area/f;k.getPos(c).setc(d.left,d.top+(b-l-g));k.setData("width",f,c);k.setData("height",l,c);g+=l}return{height:d.height,width:d.width-f,top:d.top,left:d.left+f,dim:b}},layoutH:function(a,b,d,c){var e=0;h.each(a,function(n){e+=n._area});for(var f=e/b,g=d.height-f,i=0,j=0,k=a.length;j<k;j++){var l=a[j],m=l._area/f;l.getPos(c).setc(d.left+i,d.top+g);l.setData("width",m,c);l.setData("height",f,c);i+=m}return{height:d.height-f,width:d.width,
top:d.top,left:d.left,dim:b}}});s.Icicle=new o({compute:function(a){a=a||"current";var b=this.graph.getNode(this.root),d=this.config,c=this.canvas.getSize(),e=c.width;c=c.height;d=d.constrained?d.levelsToShow:Number.MAX_VALUE;this.controller.onBeforeCompute(b);p.Util.computeLevels(this.graph,b.id,0,"ignore");var f=0;p.Util.eachLevel(b,0,false,function(i,j){if(j>f)f=j});b=this.graph.getNode(this.clickedNode&&this.clickedNode.id||b.id);d=Math.min(f,d-1);var g=b._depth;this.layout.horizontal()?this.computeSubtree(b,
-e/2,-c/2,e/(d+1),c,g,d,a):this.computeSubtree(b,-e/2,-c/2,e,c/(d+1),g,d,a)},computeSubtree:function(a,b,d,c,e,f,g,i){a.getPos(i).setc(b,d);a.setData("width",c,i);a.setData("height",e,i);var j=0,k=p.Util.getSubnodes(a,[1,1]);if(k.length){h.each(k,function(n){j+=n.getData("dim")});for(var l=0,m=k.length;l<m;l++)if(this.layout.horizontal()){a=e*k[l].getData("dim")/j;this.computeSubtree(k[l],b+c,d,c,a,f,g,i);d+=a}else{a=c*k[l].getData("dim")/j;this.computeSubtree(k[l],b,d+e,a,e,f,g,i);b+=a}}}});$jit.Icicle=
new o({Implements:[{construct:function(a){var b=h.type(a)=="array",d=new p(this.graphOptions,this.config.Node,this.config.Edge,this.config.Label);b?function(c,e){for(var f=function(q){for(var v=0,D=e.length;v<D;v++)if(e[v].id==q)return e[v];return c.addNode({id:q,name:q})},g=0,i=e.length;g<i;g++){c.addNode(e[g]);var j=e[g].adjacencies;if(j)for(var k=0,l=j.length;k<l;k++){var m=j[k],n={};if(typeof j[k]!="string"){n=h.merge(m.data,{});m=m.nodeTo}c.addAdjacence(e[g],f(m),n)}}}(d,a):function(c,e){c.addNode(e);
if(e.children)for(var f=0,g=e.children;f<g.length;f++){c.addAdjacence(e,g[f]);arguments.callee(c,g[f])}}(d,a);return d},loadJSON:function(a,b){this.json=a;this.labels&&this.labels.clearLabels&&this.labels.clearLabels(true);this.graph=this.construct(a);this.root=h.type(a)!="array"?a.id:a[b?b:0].id},toJSON:function(a){a=a||"tree";if(a=="tree"){var b={};b=function c(e){var f={};f.id=e.id;f.name=e.name;f.data=e.data;var g=[];e.eachSubnode(function(i){g.push(c(i))});f.children=g;return f}(this.graph.getNode(this.root))}else{b=
[];var d=!!this.graph.getNode(this.root).visited;this.graph.eachNode(function(c){var e={};e.id=c.id;e.name=c.name;e.data=c.data;var f=[];c.eachAdjacency(function(g){var i=g.nodeTo;if(!!i.visited===d){var j={};j.nodeTo=i.id;j.data=g.data;f.push(j)}});e.adjacencies=f;b.push(e);c.visited=!d})}return b}},x,s.Icicle],layout:{orientation:"h",vertical:function(){return this.orientation=="v"},horizontal:function(){return this.orientation=="h"},change:function(){this.orientation=this.vertical()?"h":"v"}},
initialize:function(a){var b={animate:false,orientation:"h",offset:2,levelsToShow:Number.MAX_VALUE,constrained:false,Node:{type:"rectangle",overridable:true},Edge:{type:"none"},Label:{type:"Native"},duration:700,fps:45},d=u("Canvas","Node","Edge","Fx","Tips","NodeStyles","Events","Navigation","Controller","Label");this.controller=this.config=h.merge(d,b,a);this.layout.orientation=this.config.orientation;a=this.config;if(a.useCanvas){this.canvas=a.useCanvas;this.config.labelContainer=this.canvas.id+
"-label"}else{this.canvas=new w(this,a);this.config.labelContainer=(typeof a.injectInto=="string"?a.injectInto:a.injectInto.id)+"-label"}this.graphOptions={complex:true,Node:{selected:false,exist:true,drawn:true}};this.graph=new p(this.graphOptions,this.config.Node,this.config.Edge,this.config.Label);this.labels=new $jit.Icicle.Label[this.config.Label.type](this);this.fx=new $jit.Icicle.Plot(this,$jit.Icicle);this.op=new $jit.Icicle.Op(this);this.group=new $jit.Icicle.Group(this);this.clickedNode=
null;this.initializeExtras()},refresh:function(){if(this.config.Label.type!="Native"){var a=this;this.graph.eachNode(function(b){a.labels.hideLabel(b,false)})}this.compute();this.plot()},plot:function(){this.fx.plot(this.config)},enter:function(a){if(!this.busy){this.busy=true;var b=this,d=this.config,c={onComplete:function(){d.request&&b.compute();if(d.animate){b.graph.nodeList.setDataset(["current","end"],{alpha:[1,0]});p.Util.eachSubgraph(a,function(e){e.setData("alpha",1,"end")},"ignore");b.fx.animate({duration:500,
modes:["node-property:alpha"],onComplete:function(){b.clickedNode=a;b.compute("end");b.fx.animate({modes:["linear","node-property:width:height"],duration:1E3,onComplete:function(){b.busy=false;b.clickedNode=a}})}})}else{b.clickedNode=a;b.busy=false;b.refresh()}}};d.request?this.requestNodes(clickedNode,c):c.onComplete()}},out:function(){if(!this.busy){var a=this,b=p.Util,d=this.config,c=this.graph,e=b.getParents(c.getNode(this.clickedNode&&this.clickedNode.id||this.root))[0],f=this.clickedNode;this.busy=
true;this.events.hoveredNode=false;if(e){callback={onComplete:function(){a.clickedNode=e;if(d.request)a.requestNodes(e,{onComplete:function(){a.compute();a.plot();a.busy=false}});else{a.compute();a.plot();a.busy=false}}};if(d.animate){this.clickedNode=e;this.compute("end");this.clickedNode=f;this.fx.animate({modes:["linear","node-property:width:height"],duration:1E3,onComplete:function(){a.clickedNode=e;c.nodeList.setDataset(["current","end"],{alpha:[0,1]});b.eachSubgraph(f,function(g){g.setData("alpha",
1)},"ignore");a.fx.animate({duration:500,modes:["node-property:alpha"],onComplete:function(){callback.onComplete()}})}})}else callback.onComplete()}else this.busy=false}},requestNodes:function(a,b){var d=h.merge(this.controller,b),c=this.config.constrained?this.config.levelsToShow:Number.MAX_VALUE;if(d.request){var e=[],f=a._depth;p.Util.eachLevel(a,0,c,function(g){if(g.drawn&&!p.Util.anySubnode(g)){e.push(g);g._level=g._depth-f;if(this.config.constrained)g._level=c-g._level}});this.group.requestNodes(e,
d)}else d.onComplete()}});$jit.Icicle.Op=new o({Implements:p.Op});$jit.Icicle.Group=new o({initialize:function(a){this.viz=a;this.canvas=a.canvas;this.config=a.config},requestNodes:function(a,b){var d=0,c=a.length,e=this.viz;c==0&&b.onComplete();for(var f=0;f<c;f++)b.request(a[f].id,a[f]._level,{onComplete:function(g,i){if(i&&i.children){i.id=g;e.op.sum(i,{type:"nothing"})}if(++d==c){p.Util.computeLevels(e.graph,e.root,0);b.onComplete()}}})}});$jit.Icicle.Plot=new o({Implements:p.Plot,plot:function(a,
b){a=a||this.viz.controller;var d=this.viz,c=d.graph.getNode(d.clickedNode&&d.clickedNode.id||d.root),e=c._depth;d.canvas.clear();this.plotTree(c,h.merge(a,{withLabels:true,hideLabels:false,plotSubtree:function(f,g){return!d.config.constrained||g._depth-e<d.config.levelsToShow}}),b)}});$jit.Icicle.Label={};$jit.Icicle.Label.Native=new o({Implements:p.Label.Native,renderLabel:function(a,b){var d=a.getCtx(),c=b.getData("width"),e=b.getData("height"),f=b.getLabelData("size"),g=d.measureText(b.name);
if(!(e<f*1.5||c<g.width)){f=b.pos.getc(true);d.fillText(b.name,f.x+c/2,f.y+e/2)}}});$jit.Icicle.Label.SVG=new o({Implements:p.Label.SVG,initialize:function(a){this.viz=a},placeLabel:function(a,b,d){var c=b.pos.getc(true),e=this.viz.canvas.getSize();c={x:Math.round(c.x+e.width/2),y:Math.round(c.y+e.height/2)};a.setAttribute("x",c.x);a.setAttribute("y",c.y);d.onPlaceLabel(a,b)}});$jit.Icicle.Label.HTML=new o({Implements:p.Label.HTML,initialize:function(a){this.viz=a},placeLabel:function(a,b,d){var c=
b.pos.getc(true),e=this.viz.canvas.getSize();c={x:Math.round(c.x+e.width/2),y:Math.round(c.y+e.height/2)};e=a.style;e.left=c.x+"px";e.top=c.y+"px";e.display="";d.onPlaceLabel(a,b)}});$jit.Icicle.Plot.NodeTypes=new o({none:{render:h.empty},rectangle:{render:function(a,b){var d=this.viz.config,c=d.offset,e=a.getData("width"),f=a.getData("height"),g=a.getData("border"),i=a.pos.getc(true),j=i.x+c/2,k=i.y+c/2,l=b.getCtx();if(!(e-c<2||f-c<2)){if(d.cushion){d=a.getData("color");var m=l.createRadialGradient(j+
(e-c)/2,k+(f-c)/2,1,j+(e-c)/2,k+(f-c)/2,e<f?f:e),n=h.rgbToHex(h.map(h.hexToRgb(d),function(q){return q*0.3>>0}));m.addColorStop(0,d);m.addColorStop(1,n);l.fillStyle=m}if(g){l.strokeStyle=g;l.lineWidth=3}l.fillRect(j,k,Math.max(0,e-c),Math.max(0,f-c));g&&l.strokeRect(i.x,i.y,e,f)}},contains:function(a,b){if(this.viz.clickedNode&&!$jit.Graph.Util.isDescendantOf(a,this.viz.clickedNode.id))return false;var d=a.pos.getc(true),c=a.getData("width"),e=a.getData("height");return this.nodeHelper.rectangle.contains({x:d.x+
c/2,y:d.y+e/2},b,c,e)}}});$jit.Icicle.Plot.EdgeTypes=new o({none:h.empty})})();
