/*
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>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-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=(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(ae.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;fg?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=l&&n<=m&&g(k)&&c(k,n);nn&&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-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 gi?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=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;fi?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;cf?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;a0){this.processChildrenLayout(a,c,b,d);a=0;for(var f=c.length;af)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>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})})();