/* 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(w){w=w||window;for(var k in $jit){if($jit[k].$extend){w[k]=$jit[k];}}};$jit.version='2.0.0b';var $=function(d){return document.getElementById(d);};$.empty=function(){};function pad(number,length){var str=''+number;while(str.length127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);} else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}} return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;} else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}} return string;}};Array.prototype.sum=function(){return(!this.length)?0:this.slice(1).sum()+ ((typeof this[0]=='number')?this[0]:0);};function array_match(needle,haystack){var length=haystack.length;var indexValue=new Array();for(var i=0,count=0;i>16,hex>>8&0xff,hex&0xff];}};$.destroy=function(elem){$.clean(elem);if(elem.parentNode) elem.parentNode.removeChild(elem);if(elem.clearAttributes) elem.clearAttributes();};$.clean=function(elem){for(var ch=elem.childNodes,i=0,l=ch.length;i-1;};$.addClass=function(obj,klass){if(!$.hasClass(obj,klass)) obj.className=(obj.className+" "+klass);};$.removeClass=function(obj,klass){obj.className=obj.className.replace(new RegExp('(^|\\s)'+klass+'(?:\\s|$)'),'$1');};$.getPos=function(elem){var offset=getOffsets(elem);var scroll=getScrolls(elem);return{x:offset.x-scroll.x,y:offset.y-scroll.y};function getOffsets(elem){var position={x:0,y:0};while(elem&&!isBody(elem)){position.x+=elem.offsetLeft;position.y+=elem.offsetTop;elem=elem.offsetParent;} return position;} function getScrolls(elem){var position={x:0,y:0};while(elem&&!isBody(elem)){position.x+=elem.scrollLeft;position.y+=elem.scrollTop;elem=elem.parentNode;} return position;} function isBody(element){return(/^(?:body|html)$/i).test(element.tagName);}};$.event={get:function(e,win){win=win||window;return e||win.event;},getWheel:function(e){return e.wheelDelta?e.wheelDelta/120:-(e.detail||0)/3;},isRightClick:function(e){return(e.which==3||e.button==2);},getPos:function(e,win){win=win||window;e=e||win.event;var doc=win.document;doc=doc.documentElement||doc.body;if(e.touches&&e.touches.length){e=e.touches[0];} var page={x:e.pageX||(e.clientX+doc.scrollLeft),y:e.pageY||(e.clientY+doc.scrollTop)};return page;},stop:function(e){if(e.stopPropagation)e.stopPropagation();e.cancelBubble=true;if(e.preventDefault)e.preventDefault();else e.returnValue=false;}};$jit.util=$jit.id=$;var Class=function(properties){properties=properties||{};var klass=function(){for(var key in this){if(typeof this[key]!='function') this[key]=$.unlink(this[key]);} this.constructor=klass;if(Class.prototyping) return this;var instance=this.initialize?this.initialize.apply(this,arguments):this;this.$$family='class';return instance;};for(var mutator in Class.Mutators){if(!properties[mutator]) continue;properties=Class.Mutators[mutator](properties,properties[mutator]);delete properties[mutator];} $.extend(klass,this);klass.constructor=Class;klass.prototype=properties;return klass;};Class.Mutators={Implements:function(self,klasses){$.each($.splat(klasses),function(klass){Class.prototyping=klass;var instance=(typeof klass=='function')?new klass:klass;for(var prop in instance){if(!(prop in self)){self[prop]=instance[prop];}} delete Class.prototyping;});return self;}};$.extend(Class,{inherit:function(object,properties){for(var key in properties){var override=properties[key];var previous=object[key];var type=$.type(override);if(previous&&type=='function'){if(override!=previous){Class.override(object,key,override);}}else if(type=='object'){object[key]=$.merge(previous,override);}else{object[key]=override;}} return object;},override:function(object,name,method){var parent=Class.prototyping;if(parent&&object[name]!=parent[name]) parent=null;var override=function(){var previous=this.parent;this.parent=parent?parent[name]:object[name];var value=method.apply(this,arguments);this.parent=previous;return value;};object[name]=override;}});Class.prototype.implement=function(){var proto=this.prototype;$.each(Array.prototype.slice.call(arguments||[]),function(properties){Class.inherit(proto,properties);});return this;};$jit.Class=Class;$jit.json={prune:function(tree,maxLevel){this.each(tree,function(elem,i){if(i==maxLevel&&elem.children){delete elem.children;elem.children=[];}});},getParent:function(tree,id){if(tree.id==id) return false;var ch=tree.children;if(ch&&ch.length>0){for(var i=0;i=(7-4*a)/11){value=b*b-Math.pow((11-6*a-11*p)/4,2);break;}} return value;},Elastic:function(p,x){return Math.pow(2,10*--p)*Math.cos(20*p*Math.PI*(x[0]||1)/3);}};$.each(transitions,function(val,key){Trans[key]=makeTrans(val);});$.each(['Quad','Cubic','Quart','Quint'],function(elem,i){Trans[elem]=makeTrans(function(p){return Math.pow(p,[i+2]);});});})();var Animation=new Class({initialize:function(options){this.setOptions(options);},setOptions:function(options){var opt={duration:2500,fps:40,transition:Trans.Quart.easeInOut,compute:$.empty,complete:$.empty,link:'ignore'};this.opt=$.merge(opt,options||{});return this;},step:function(){var time=$.time(),opt=this.opt;if(timewin.height)?(pos.y-obj.height-y):pos.y+y)+'px';style.left=((pos.x+obj.width+x>win.width)?(pos.x-obj.width-x):pos.x+x)+'px';},hide:function(triggerCallback){if(!SUGAR.util.isTouchScreen()){this.tip.style.display='none';} triggerCallback&&this.config.onHide();}});Extras.Classes.NodeStyles=new Class({Implements:[ExtrasInitializer,EventsInterface],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 Animation();this.down=false;this.move=false;},onMouseOut:function(e,win){this.down=this.move=false;if(!this.hoveredNode)return;if(this.dom&&this.isLabel(e,win)){this.toggleStylesOnHover(this.hoveredNode,false);} var rt=e.relatedTarget,canvasWidget=this.canvas.getElement();while(rt&&rt.parentNode){if(canvasWidget==rt.parentNode)return;rt=rt.parentNode;} this.toggleStylesOnHover(this.hoveredNode,false);this.hoveredNode=false;},onMouseOver:function(e,win){var label;if(this.dom&&(label=this.isLabel(e,win))){var node=this.viz.graph.getNode(label.id);if(node.selected)return;this.hoveredNode=node;this.toggleStylesOnHover(this.hoveredNode,true);}},onMouseDown:function(e,win,event,isRightClick){if(isRightClick)return;var label;if(this.dom&&(label=this.isLabel(e,win))){this.down=this.viz.graph.getNode(label.id);}else if(!this.dom){this.down=event.getNode();} this.move=false;},onMouseUp:function(e,win,event,isRightClick){if(isRightClick)return;if(!this.move){this.onClick(event.getNode());} this.down=this.move=false;},getRestoredStyles:function(node,type){var restoredStyles={},nStyles=this['nodeStylesOn'+type];for(var prop in nStyles){restoredStyles[prop]=node.styles['$'+prop];} return restoredStyles;},toggleStylesOnHover:function(node,set){if(this.nodeStylesOnHover){this.toggleStylesOn('Hover',node,set);}},toggleStylesOnClick:function(node,set){if(this.nodeStylesOnClick){this.toggleStylesOn('Click',node,set);}},toggleStylesOn:function(type,node,set){var viz=this.viz;var nStyles=this.nStyles;if(set){var that=this;if(!node.styles){node.styles=$.merge(node.data,{});} for(var s in this['nodeStylesOn'+type]){var $s='$'+s;if(!($s in node.styles)){node.styles[$s]=node.getData(s);}} viz.fx.nodeFx($.extend({'elements':{'id':node.id,'properties':that['nodeStylesOn'+type]},transition:Trans.Quart.easeOut,duration:300,fps:40},this.config));}else{var restoredStyles=this.getRestoredStyles(node,type);viz.fx.nodeFx($.extend({'elements':{'id':node.id,'properties':restoredStyles},transition:Trans.Quart.easeOut,duration:300,fps:40},this.config));}},onClick:function(node){if(!node)return;var nStyles=this.nodeStylesOnClick;if(!nStyles)return;if(node.selected){this.toggleStylesOnClick(node,false);delete node.selected;}else{this.viz.graph.eachNode(function(n){if(n.selected){for(var s in nStyles){n.setData(s,n.styles['$'+s],'end');} delete n.selected;}});this.toggleStylesOnClick(node,true);node.selected=true;delete node.hovered;this.hoveredNode=false;}},onMouseMove:function(e,win,event){if(this.down)this.move=true;if(this.dom&&this.isLabel(e,win))return;var nStyles=this.nodeStylesOnHover;if(!nStyles)return;if(!this.dom){if(this.hoveredNode){var geom=this.types[this.hoveredNode.getData('type')];var contains=geom&&geom.contains&&geom.contains.call(this.fx,this.hoveredNode,event.getPos());if(contains)return;} var node=event.getNode();if(!this.hoveredNode&&!node)return;if(node.hovered)return;if(node&&!node.selected){this.fx.nodeFxAnimation.stopTimer();this.viz.graph.eachNode(function(n){if(n.hovered&&!n.selected){for(var s in nStyles){n.setData(s,n.styles['$'+s],'end');} delete n.hovered;}});node.hovered=true;this.hoveredNode=node;this.toggleStylesOnHover(node,true);}else if(this.hoveredNode&&!this.hoveredNode.selected){this.fx.nodeFxAnimation.stopTimer();this.toggleStylesOnHover(this.hoveredNode,false);delete this.hoveredNode.hovered;this.hoveredNode=false;}}}});Extras.Classes.Navigation=new Class({Implements:[ExtrasInitializer,EventsInterface],initializePost:function(){this.pos=false;this.pressed=false;},onMouseWheel:function(e,win,scroll){if(!this.config.zooming)return;$.event.stop($.event.get(e,win));var val=this.config.zooming/1000,ans=1+scroll*val;this.canvas.scale(ans,ans);},onMouseDown:function(e,win,eventInfo){if(!this.config.panning)return;if(this.config.panning=='avoid nodes'&&eventInfo.getNode())return;this.pressed=true;this.pos=eventInfo.getPos();var canvas=this.canvas,ox=canvas.translateOffsetX,oy=canvas.translateOffsetY,sx=canvas.scaleOffsetX,sy=canvas.scaleOffsetY;this.pos.x*=sx;this.pos.x+=ox;this.pos.y*=sy;this.pos.y+=oy;},onMouseMove:function(e,win,eventInfo){if(!this.config.panning)return;if(!this.pressed)return;if(this.config.panning=='avoid nodes'&&eventInfo.getNode())return;var thispos=this.pos,currentPos=eventInfo.getPos(),canvas=this.canvas,ox=canvas.translateOffsetX,oy=canvas.translateOffsetY,sx=canvas.scaleOffsetX,sy=canvas.scaleOffsetY;currentPos.x*=sx;currentPos.y*=sy;currentPos.x+=ox;currentPos.y+=oy;var x=currentPos.x-thispos.x,y=currentPos.y-thispos.y;this.pos=currentPos;this.canvas.translate(x*1/sx,y*1/sy);},onMouseUp:function(e,win,eventInfo,isRightClick){if(!this.config.panning)return;this.pressed=false;}});var Canvas;(function(){var canvasType=typeof HTMLCanvasElement,supportsCanvas=(canvasType=='object'||canvasType=='function');function $E(tag,props){var elem=document.createElement(tag);for(var p in props){if(typeof props[p]=="object"){$.extend(elem[p],props[p]);}else{elem[p]=props[p];}} if(tag=="canvas"&&!supportsCanvas&&G_vmlCanvasManager){elem=G_vmlCanvasManager.initElement(elem);} return elem;} $jit.Canvas=Canvas=new Class({canvases:[],pos:false,element:false,labelContainer:false,translateOffsetX:0,translateOffsetY:0,scaleOffsetX:1,scaleOffsetY:1,initialize:function(viz,opt){this.viz=viz;this.opt=opt;var id=$.type(opt.injectInto)=='string'?opt.injectInto:opt.injectInto.id,idLabel=id+"-label",wrapper=$(id),width=opt.width||wrapper.offsetWidth,height=opt.height||wrapper.offsetHeight;this.id=id;var canvasOptions={injectInto:id,width:width,height:height};this.element=$E('div',{'id':id+'-canvaswidget','style':{'position':'relative','width':width+'px','height':height+'px'}});this.labelContainer=this.createLabelContainer(opt.Label.type,idLabel,canvasOptions);this.canvases.push(new Canvas.Base({config:$.extend({idSuffix:'-canvas'},canvasOptions),plot:function(base){viz.fx.plot();},resize:function(){viz.refresh();}}));var back=opt.background;if(back){var backCanvas=new Canvas.Background[back.type](viz,$.extend(back,canvasOptions));this.canvases.push(new Canvas.Base(backCanvas));} var len=this.canvases.length;while(len--){this.element.appendChild(this.canvases[len].canvas);if(len>0){this.canvases[len].plot();}} this.element.appendChild(this.labelContainer);wrapper.appendChild(this.element);var timer=null,that=this;$.addEvent(window,'scroll',function(){clearTimeout(timer);timer=setTimeout(function(){that.getPos(true);},500);});$.addEvent(window,'click',function(){clearTimeout(timer);timer=setTimeout(function(){that.getPos(true);},500);});sb=document.getElementById('sb'+id);$.addEvent(sb,'scroll',function(){clearTimeout(timer);timer=setTimeout(function(){that.getPos(true);},500);});},getCtx:function(i){return this.canvases[i||0].getCtx();},getConfig:function(){return this.opt;},getElement:function(){return this.element;},getSize:function(i){return this.canvases[i||0].getSize();},resize:function(width,height){this.getPos(true);this.translateOffsetX=this.translateOffsetY=0;this.scaleOffsetX=this.scaleOffsetY=1;for(var i=0,l=this.canvases.length;iet){sum=ch((et+((tt-pi2)-et)*delta));}else{sum=ch((et-pi2+(tt-(et))*delta));}}else if(diff>=pi){if(tt>et){sum=ch((et+((tt-pi2)-et)*delta));}else{sum=ch((et-pi2+(tt-(et-pi2))*delta));}}else{sum=ch((et+(tt-et)*delta));} var r=(this.rho-elem.rho)*delta+elem.rho;return{'theta':sum,'rho':r};}};var $P=function(a,b){return new Polar(a,b);};Polar.KER=$P(0,0);var Complex=function(x,y){this.x=x;this.y=y;};$jit.Complex=Complex;Complex.prototype={getc:function(){return this;},getp:function(simple){return this.toPolar(simple);},set:function(c){c=c.getc(true);this.x=c.x;this.y=c.y;},setc:function(x,y){this.x=x;this.y=y;},setp:function(theta,rho){this.x=Math.cos(theta)*rho;this.y=Math.sin(theta)*rho;},clone:function(){return new Complex(this.x,this.y);},toPolar:function(simple){var rho=this.norm();var atan=Math.atan2(this.y,this.x);if(atan<0)atan+=Math.PI*2;if(simple)return{'theta':atan,'rho':rho};return new Polar(atan,rho);},norm:function(){return Math.sqrt(this.squaredNorm());},squaredNorm:function(){return this.x*this.x+this.y*this.y;},add:function(pos){return new Complex(this.x+pos.x,this.y+pos.y);},prod:function(pos){return new Complex(this.x*pos.x-this.y*pos.y,this.y*pos.x+this.x*pos.y);},conjugate:function(){return new Complex(this.x,-this.y);},scale:function(factor){return new Complex(this.x*factor,this.y*factor);},equals:function(c){return this.x==c.x&&this.y==c.y;},$add:function(pos){this.x+=pos.x;this.y+=pos.y;return this;},$prod:function(pos){var x=this.x,y=this.y;this.x=x*pos.x-y*pos.y;this.y=y*pos.x+x*pos.y;return this;},$conjugate:function(){this.y=-this.y;return this;},$scale:function(factor){this.x*=factor;this.y*=factor;return this;},$div:function(pos){var x=this.x,y=this.y;var sq=pos.squaredNorm();this.x=x*pos.x+y*pos.y;this.y=y*pos.x-x*pos.y;return this.$scale(1/sq);}};var $C=function(a,b){return new Complex(a,b);};Complex.KER=$C(0,0);$jit.Graph=new Class({initialize:function(opt,Node,Edge,Label){var innerOptions={'complex':false,'Node':{}};this.Node=Node;this.Edge=Edge;this.Label=Label;this.opt=$.merge(innerOptions,opt||{});this.nodes={};this.edges={};var that=this;this.nodeList={};for(var p in Accessors){that.nodeList[p]=(function(p){return function(){var args=Array.prototype.slice.call(arguments);that.eachNode(function(n){n[p].apply(n,args);});};})(p);}},getNode:function(id){if(this.hasNode(id))return this.nodes[id];return false;},getByName:function(name){for(var id in this.nodes){var n=this.nodes[id];if(n.name==name)return n;} return false;},getAdjacence:function(id,id2){if(id in this.edges){return this.edges[id][id2];} return false;},addNode:function(obj){if(!this.nodes[obj.id]){var edges=this.edges[obj.id]={};this.nodes[obj.id]=new Graph.Node($.extend({'id':obj.id,'name':obj.name,'data':$.merge(obj.data||{},{}),'adjacencies':edges},this.opt.Node),this.opt.complex,this.Node,this.Edge,this.Label);} return this.nodes[obj.id];},addAdjacence:function(obj,obj2,data){if(!this.hasNode(obj.id)){this.addNode(obj);} if(!this.hasNode(obj2.id)){this.addNode(obj2);} obj=this.nodes[obj.id];obj2=this.nodes[obj2.id];if(!obj.adjacentTo(obj2)){var adjsObj=this.edges[obj.id]=this.edges[obj.id]||{};var adjsObj2=this.edges[obj2.id]=this.edges[obj2.id]||{};adjsObj[obj2.id]=adjsObj2[obj.id]=new Graph.Adjacence(obj,obj2,data,this.Edge,this.Label);return adjsObj[obj2.id];} return this.edges[obj.id][obj2.id];},removeNode:function(id){if(this.hasNode(id)){delete this.nodes[id];var adjs=this.edges[id];for(var to in adjs){delete this.edges[to][id];} delete this.edges[id];}},removeAdjacence:function(id1,id2){delete this.edges[id1][id2];delete this.edges[id2][id1];},hasNode:function(id){return id in this.nodes;},empty:function(){this.nodes={};this.edges={};}});var Graph=$jit.Graph;var Accessors;(function(){var getDataInternal=function(prefix,prop,type,force,prefixConfig){var data;type=type||'current';prefix="$"+(prefix?prefix+"-":"");if(type=='current'){data=this.data;}else if(type=='start'){data=this.startData;}else if(type=='end'){data=this.endData;} var dollar=prefix+prop;if(force){return data[dollar];} if(!this.Config.overridable) return prefixConfig[prop]||0;return(dollar in data)?data[dollar]:((dollar in this.data)?this.data[dollar]:(prefixConfig[prop]||0));} var setDataInternal=function(prefix,prop,value,type){type=type||'current';prefix='$'+(prefix?prefix+'-':'');var data;if(type=='current'){data=this.data;}else if(type=='start'){data=this.startData;}else if(type=='end'){data=this.endData;} data[prefix+prop]=value;} var removeDataInternal=function(prefix,properties){prefix='$'+(prefix?prefix+'-':'');var that=this;$.each(properties,function(prop){var pref=prefix+prop;delete that.data[pref];delete that.endData[pref];delete that.startData[pref];});} Accessors={getData:function(prop,type,force){return getDataInternal.call(this,"",prop,type,force,this.Config);},setData:function(prop,value,type){setDataInternal.call(this,"",prop,value,type);},setDataset:function(types,obj){types=$.splat(types);for(var attr in obj){for(var i=0,val=$.splat(obj[attr]),l=types.length;i=levelBegin&&d<=levelEnd&&filter(node))action(node,d);if(dd)loopLevel(n,levelBegin,levelEnd);});}})(node,levelBegin+d,levelEnd+d);},eachSubgraph:function(node,action,flags){this.eachLevel(node,0,false,action,flags);},eachSubnode:function(node,action,flags){this.eachLevel(node,1,1,action,flags);},anySubnode:function(node,cond,flags){var flag=false;cond=cond||$.lambda(true);var c=$.type(cond)=='string'?function(n){return n[cond];}:cond;this.eachSubnode(node,function(elem){if(c(elem))flag=true;},flags);return flag;},getSubnodes:function(node,level,flags){var ans=[],that=this;level=level||0;var levelStart,levelEnd;if($.type(level)=='array'){levelStart=level[0];levelEnd=level[1];}else{levelStart=level;levelEnd=Number.MAX_VALUE-node._depth;} this.eachLevel(node,levelStart,levelEnd,function(n){ans.push(n);},flags);return ans;},getParents:function(node){var ans=[];this.eachAdjacency(node,function(adj){var n=adj.nodeTo;if(n._depth-1)){elem.endData[prop]=graphNodeData[prop];}else{elem.data[prop]=graphNodeData[prop];}}}});viz.graph.eachNode(function(elem){if(elem.ignore)return;elem.eachAdjacency(function(adj){if(adj.nodeFrom.ignore||adj.nodeTo.ignore)return;var nodeFrom=graph.getNode(adj.nodeFrom.id);var nodeTo=graph.getNode(adj.nodeTo.id);if(!nodeFrom.adjacentTo(nodeTo)){var adj=viz.graph.getAdjacence(nodeFrom.id,nodeTo.id);fadeEdges=true;adj.setData('alpha',1);adj.setData('alpha',1,'start');adj.setData('alpha',0,'end');}});});var fadeEdges=this.preprocessSum(graph);var modes=!fadeEdges?['node-property:alpha']:['node-property:alpha','edge-property:alpha'];modes[0]=modes[0]+((extraModes&&('node-property'in extraModes))?(':'+$.splat(extraModes['node-property']).join(':')):'');modes[1]=(modes[1]||'edge-property:alpha')+((extraModes&&('edge-property'in extraModes))?(':'+$.splat(extraModes['edge-property']).join(':')):'');if(extraModes&&('label-property'in extraModes)){modes.push('label-property:'+$.splat(extraModes['label-property']).join(':'))} viz.reposition();viz.graph.eachNode(function(elem){if(elem.id!=root&&elem.pos.getp().equals(Polar.KER)){elem.pos.set(elem.endPos);elem.startPos.set(elem.endPos);}});viz.fx.animate($.merge(options,{modes:['polar'].concat(modes),onComplete:function(){viz.graph.eachNode(function(elem){if(elem.ignore)viz.graph.removeNode(elem.id);});viz.graph.eachNode(function(elem){elem.eachAdjacency(function(adj){if(adj.ignore)viz.graph.removeAdjacence(adj.nodeFrom.id,adj.nodeTo.id);});});options.onComplete();}}));break;default:;}},contract:function(node,opt){var viz=this.viz;if(node.collapsed||!node.anySubnode($.lambda(true)))return;opt=$.merge(this.options,viz.config,opt||{},{'modes':['node-property:alpha:span','linear']});node.collapsed=true;(function subn(n){n.eachSubnode(function(ch){ch.ignore=true;ch.setData('alpha',0,opt.type=='animate'?'end':'current');subn(ch);});})(node);if(opt.type=='animate'){viz.compute('end');if(viz.rotated){viz.rotate(viz.rotated,'none',{'property':'end'});} (function subn(n){n.eachSubnode(function(ch){ch.setPos(node.getPos('end'),'end');subn(ch);});})(node);viz.fx.animate(opt);}else if(opt.type=='replot'){viz.refresh();}},expand:function(node,opt){if(!('collapsed'in node))return;var viz=this.viz;opt=$.merge(this.options,viz.config,opt||{},{'modes':['node-property:alpha:span','linear']});delete node.collapsed;(function subn(n){n.eachSubnode(function(ch){delete ch.ignore;ch.setData('alpha',1,opt.type=='animate'?'end':'current');subn(ch);});})(node);if(opt.type=='animate'){viz.compute('end');if(viz.rotated){viz.rotate(viz.rotated,'none',{'property':'end'});} viz.fx.animate(opt);}else if(opt.type=='replot'){viz.refresh();}},preprocessSum:function(graph){var viz=this.viz;graph.eachNode(function(elem){if(!viz.graph.hasNode(elem.id)){viz.graph.addNode(elem);var n=viz.graph.getNode(elem.id);n.setData('alpha',0);n.setData('alpha',0,'start');n.setData('alpha',1,'end');}});var fadeEdges=false;graph.eachNode(function(elem){elem.eachAdjacency(function(adj){var nodeFrom=viz.graph.getNode(adj.nodeFrom.id);var nodeTo=viz.graph.getNode(adj.nodeTo.id);if(!nodeFrom.adjacentTo(nodeTo)){var adj=viz.graph.addAdjacence(nodeFrom,nodeTo,adj.data);if(nodeFrom.startAlpha==nodeFrom.endAlpha&&nodeTo.startAlpha==nodeTo.endAlpha){fadeEdges=true;adj.setData('alpha',0);adj.setData('alpha',0,'start');adj.setData('alpha',1,'end');}}});});return fadeEdges;}};var NodeHelper={'none':{'render':$.empty,'contains':$.lambda(false)},'circle':{'render':function(type,pos,radius,canvas){var ctx=canvas.getCtx();ctx.beginPath();ctx.arc(pos.x,pos.y,radius,0,Math.PI*2,true);ctx.closePath();ctx[type]();},'contains':function(npos,pos,radius){var diffx=npos.x-pos.x,diffy=npos.y-pos.y,diff=diffx*diffx+diffy*diffy;return diff<=radius*radius;}},'ellipse':{'render':function(type,pos,width,height,canvas){var ctx=canvas.getCtx();height/=2;width/=2;ctx.save();ctx.scale(width/height,height/width);ctx.beginPath();ctx.arc(pos.x*(height/width),pos.y*(width/height),height,0,Math.PI*2,true);ctx.closePath();ctx[type]();ctx.restore();},'contains':function(npos,pos,width,height){width/=2;height/=2;var dist=(width+height)/2,diffx=npos.x-pos.x,diffy=npos.y-pos.y,diff=diffx*diffx+diffy*diffy;return diff<=dist*dist;}},'square':{'render':function(type,pos,dim,canvas){canvas.getCtx()[type+"Rect"](pos.x-dim,pos.y-dim,2*dim,2*dim);},'contains':function(npos,pos,dim){return Math.abs(pos.x-npos.x)<=dim&&Math.abs(pos.y-npos.y)<=dim;}},'rectangle':{'render':function(type,pos,width,height,canvas){canvas.getCtx()[type+"Rect"](pos.x-width/2,pos.y-height/2,width,height);},'contains':function(npos,pos,width,height){return Math.abs(pos.x-npos.x)<=width/2&&Math.abs(pos.y-npos.y)<=height/2;}},'triangle':{'render':function(type,pos,dim,canvas){var ctx=canvas.getCtx(),c1x=pos.x,c1y=pos.y-dim,c2x=c1x-dim,c2y=pos.y+dim,c3x=c1x+dim,c3y=c2y;ctx.beginPath();ctx.moveTo(c1x,c1y);ctx.lineTo(c2x,c2y);ctx.lineTo(c3x,c3y);ctx.closePath();ctx[type]();},'contains':function(npos,pos,dim){return NodeHelper.circle.contains(npos,pos,dim);}},'star':{'render':function(type,pos,dim,canvas){var ctx=canvas.getCtx(),pi5=Math.PI/5;ctx.save();ctx.translate(pos.x,pos.y);ctx.beginPath();ctx.moveTo(dim,0);for(var i=0;i<9;i++){ctx.rotate(pi5);if(i%2==0){ctx.lineTo((dim/0.525731)*0.200811,0);}else{ctx.lineTo(dim,0);}} ctx.closePath();ctx[type]();ctx.restore();},'contains':function(npos,pos,dim){return NodeHelper.circle.contains(npos,pos,dim);}}};var EdgeHelper={'line':{'render':function(from,to,canvas){var ctx=canvas.getCtx();ctx.beginPath();ctx.moveTo(from.x,from.y);ctx.lineTo(to.x,to.y);ctx.stroke();},'contains':function(posFrom,posTo,pos,epsilon){var min=Math.min,max=Math.max,minPosX=min(posFrom.x,posTo.x),maxPosX=max(posFrom.x,posTo.x),minPosY=min(posFrom.y,posTo.y),maxPosY=max(posFrom.y,posTo.y);if(pos.x>=minPosX&&pos.x<=maxPosX&&pos.y>=minPosY&&pos.y<=maxPosY){if(Math.abs(posTo.x-posFrom.x)<=epsilon){return true;} var dist=(posTo.y-posFrom.y)/(posTo.x-posFrom.x)*(pos.x-posFrom.x)+posFrom.y;return Math.abs(dist-pos.y)<=epsilon;} return false;}},'arrow':{'render':function(from,to,dim,swap,canvas){var ctx=canvas.getCtx();if(swap){var tmp=from;from=to;to=tmp;} var vect=new Complex(to.x-from.x,to.y-from.y);vect.$scale(dim/vect.norm());var intermediatePoint=new Complex(to.x-vect.x,to.y-vect.y),normal=new Complex(-vect.y/2,vect.x/2),v1=intermediatePoint.add(normal),v2=intermediatePoint.$add(normal.$scale(-1));ctx.beginPath();ctx.moveTo(from.x,from.y);ctx.lineTo(to.x,to.y);ctx.stroke();ctx.beginPath();ctx.moveTo(v1.x,v1.y);ctx.lineTo(v2.x,v2.y);ctx.lineTo(to.x,to.y);ctx.closePath();ctx.fill();},'contains':function(posFrom,posTo,pos,epsilon){return EdgeHelper.line.contains(posFrom,posTo,pos,epsilon);}},'hyperline':{'render':function(from,to,r,canvas){var ctx=canvas.getCtx();var centerOfCircle=computeArcThroughTwoPoints(from,to);if(centerOfCircle.a>1000||centerOfCircle.b>1000||centerOfCircle.ratio<0){ctx.beginPath();ctx.moveTo(from.x*r,from.y*r);ctx.lineTo(to.x*r,to.y*r);ctx.stroke();}else{var angleBegin=Math.atan2(to.y-centerOfCircle.y,to.x -centerOfCircle.x);var angleEnd=Math.atan2(from.y-centerOfCircle.y,from.x -centerOfCircle.x);var sense=sense(angleBegin,angleEnd);ctx.beginPath();ctx.arc(centerOfCircle.x*r,centerOfCircle.y*r,centerOfCircle.ratio*r,angleBegin,angleEnd,sense);ctx.stroke();} function computeArcThroughTwoPoints(p1,p2){var aDen=(p1.x*p2.y-p1.y*p2.x),bDen=aDen;var sq1=p1.squaredNorm(),sq2=p2.squaredNorm();if(aDen==0) return{x:0,y:0,ratio:-1};var a=(p1.y*sq2-p2.y*sq1+p1.y-p2.y)/aDen;var b=(p2.x*sq1-p1.x*sq2+p2.x-p1.x)/bDen;var x=-a/2;var y=-b/2;var squaredRatio=(a*a+b*b)/4-1;if(squaredRatio<0) return{x:0,y:0,ratio:-1};var ratio=Math.sqrt(squaredRatio);var out={x:x,y:y,ratio:ratio>1000?-1:ratio,a:a,b:b};return out;} function sense(angleBegin,angleEnd){return(angleBeginangleEnd)?false:true):((angleEnd+Math.PI>angleBegin)?true:false);}},'contains':$.lambda(false)}};Graph.Plot={initialize:function(viz,klass){this.viz=viz;this.config=viz.config;this.node=viz.config.Node;this.edge=viz.config.Edge;this.animation=new Animation;this.nodeTypes=new klass.Plot.NodeTypes;this.edgeTypes=new klass.Plot.EdgeTypes;this.labels=viz.labels;},nodeHelper:NodeHelper,edgeHelper:EdgeHelper,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(from,to,delta){return from+(to-from)*delta;},'moebius':function(elem,props,delta,vector){var v=vector.scale(-delta);if(v.norm()<1){var x=v.x,y=v.y;var ans=elem.startPos.getc().moebiusTransformation(v);elem.pos.setc(ans.x,ans.y);v.x=x;v.y=y;}},'linear':function(elem,props,delta){var from=elem.startPos.getc(true);var to=elem.endPos.getc(true);elem.pos.setc(this.compute(from.x,to.x,delta),this.compute(from.y,to.y,delta));},'polar':function(elem,props,delta){var from=elem.startPos.getp(true);var to=elem.endPos.getp();var ans=to.interpolate(from,delta);elem.pos.setp(ans.theta,ans.rho);},'number':function(elem,prop,delta,getter,setter){var from=elem[getter](prop,'start');var to=elem[getter](prop,'end');elem[setter](prop,this.compute(from,to,delta));},'color':function(elem,prop,delta,getter,setter){var from=$.hexToRgb(elem[getter](prop,'start'));var to=$.hexToRgb(elem[getter](prop,'end'));var comp=this.compute;var val=$.rgbToHex([parseInt(comp(from[0],to[0],delta)),parseInt(comp(from[1],to[1],delta)),parseInt(comp(from[2],to[2],delta))]);elem[setter](prop,val);},'array-number':function(elem,prop,delta,getter,setter){var from=elem[getter](prop,'start'),to=elem[getter](prop,'end'),cur=[];for(var i=0,l=from.length;i=0.95){that.labels.plotLabel(canvas,node,opt);}else{that.labels.hideLabel(node,false);}} ctx.restore();node.visited=!T;});},plotTree:function(node,opt,animating){var that=this,viz=this.viz,canvas=viz.canvas,config=this.config,ctx=canvas.getCtx();var nodeAlpha=node.getData('alpha');node.eachSubnode(function(elem){if(opt.plotSubtree(node,elem)&&elem.exist&&elem.drawn){var adj=node.getAdjacency(elem.id);!animating&&opt.onBeforePlotLine(adj);ctx.globalAlpha=Math.min(nodeAlpha,elem.getData('alpha'));that.plotLine(adj,canvas,animating);!animating&&opt.onAfterPlotLine(adj);that.plotTree(elem,opt,animating);}});if(node.drawn){!animating&&opt.onBeforePlotNode(node);this.plotNode(node,canvas,animating);!animating&&opt.onAfterPlotNode(node);if(!opt.hideLabels&&opt.withLabels&&nodeAlpha>=0.95) this.labels.plotLabel(canvas,node,opt);else this.labels.hideLabel(node,false);}else{this.labels.hideLabel(node,true);}},plotNode:function(node,canvas,animating){var f=node.getData('type'),ctxObj=this.node.CanvasStyles;if(f!='none'){var width=node.getData('lineWidth'),color=node.getData('color'),alpha=node.getData('alpha'),ctx=canvas.getCtx();ctx.lineWidth=width;ctx.fillStyle=ctx.strokeStyle=color;ctx.globalAlpha=alpha;for(var s in ctxObj){ctx[s]=node.getCanvasStyle(s);} this.nodeTypes[f].render.call(this,node,canvas,animating);}},plotLine:function(adj,canvas,animating){var f=adj.getData('type'),ctxObj=this.edge.CanvasStyles;if(f!='none'){var width=adj.getData('lineWidth'),color=adj.getData('color'),ctx=canvas.getCtx();ctx.lineWidth=width;ctx.fillStyle=ctx.strokeStyle=color;for(var s in ctxObj){ctx[s]=adj.getCanvasStyle(s);} this.edgeTypes[f].render.call(this,adj,canvas,animating);}}};Graph.Label={};Graph.Label.Native=new Class({plotLabel:function(canvas,node,controller){var ctx=canvas.getCtx();var pos=node.pos.getc(true);ctx.font=node.getLabelData('style')+' '+node.getLabelData('size')+'px '+node.getLabelData('family');ctx.textAlign=node.getLabelData('textAlign');ctx.fillStyle=ctx.strokeStyle=node.getLabelData('color');ctx.textBaseline=node.getLabelData('textBaseline');this.renderLabel(canvas,node,controller);},renderLabel:function(canvas,node,controller){var ctx=canvas.getCtx();var pos=node.pos.getc(true);ctx.fillText(node.name,pos.x,pos.y+node.getData("height")/2);},hideLabel:$.empty,hideLabels:$.empty});Graph.Label.DOM=new Class({labelsHidden:false,labelContainer:false,labels:{},getLabelContainer:function(){return this.labelContainer?this.labelContainer:this.labelContainer=document.getElementById(this.viz.config.labelContainer);},getLabel:function(id){return(id in this.labels&&this.labels[id]!=null)?this.labels[id]:this.labels[id]=document.getElementById(id);},hideLabels:function(hide){var container=this.getLabelContainer();if(hide) container.style.display='none';else container.style.display='';this.labelsHidden=hide;},clearLabels:function(force){for(var id in this.labels){if(force||!this.viz.graph.hasNode(id)){this.disposeLabel(id);delete this.labels[id];}}},disposeLabel:function(id){var elem=this.getLabel(id);if(elem&&elem.parentNode){elem.parentNode.removeChild(elem);}},hideLabel:function(node,show){node=$.splat(node);var st=show?"":"none",lab,that=this;$.each(node,function(n){var lab=that.getLabel(n.id);if(lab){lab.style.display=st;}});},fitsInCanvas:function(pos,canvas){var size=canvas.getSize();if(pos.x>=size.width||pos.x<0||pos.y>=size.height||pos.y<0)return false;return true;}});Graph.Label.HTML=new Class({Implements:Graph.Label.DOM,plotLabel:function(canvas,node,controller){var id=node.id,tag=this.getLabel(id);if(!tag&&!(tag=document.getElementById(id))){tag=document.createElement('div');var container=this.getLabelContainer();tag.id=id;tag.className='node';tag.style.position='absolute';controller.onCreateLabel(tag,node);container.appendChild(tag);this.labels[node.id]=tag;} this.placeLabel(tag,node,controller);}});Graph.Label.SVG=new Class({Implements:Graph.Label.DOM,plotLabel:function(canvas,node,controller){var id=node.id,tag=this.getLabel(id);if(!tag&&!(tag=document.getElementById(id))){var ns='http://www.w3.org/2000/svg';tag=document.createElementNS(ns,'svg:text');var tspan=document.createElementNS(ns,'svg:tspan');tag.appendChild(tspan);var container=this.getLabelContainer();tag.setAttribute('id',id);tag.setAttribute('class','node');container.appendChild(tag);controller.onCreateLabel(tag,node);this.labels[node.id]=tag;} this.placeLabel(tag,node,controller);}});Graph.Geom=new Class({initialize:function(viz){this.viz=viz;this.config=viz.config;this.node=viz.config.Node;this.edge=viz.config.Edge;},translate:function(pos,prop){prop=$.splat(prop);this.viz.graph.eachNode(function(elem){$.each(prop,function(p){elem.getPos(p).$add(pos);});});},setRightLevelToShow:function(node,canvas,callback){var level=this.getRightLevelToShow(node,canvas),fx=this.viz.labels,opt=$.merge({execShow:true,execHide:true,onHide:$.empty,onShow:$.empty},callback||{});node.eachLevel(0,this.config.levelsToShow,function(n){var d=n._depth-node._depth;if(d>level){opt.onHide(n);if(opt.execHide){n.drawn=false;n.exist=false;fx.hideLabel(n,false);}}else{opt.onShow(n);if(opt.execShow){n.exist=true;}}});node.drawn=true;},getRightLevelToShow:function(node,canvas){var config=this.config;var level=config.levelsToShow;var constrained=config.constrained;if(!constrained)return level;while(!this.treeFitsInCanvas(node,canvas,level)&&level>1){level--;} return level;}});var Loader={construct:function(json){var isGraph=($.type(json)=='array');var ans=new Graph(this.graphOptions,this.config.Node,this.config.Edge,this.config.Label);if(!isGraph) (function(ans,json){ans.addNode(json);if(json.children){for(var i=0,ch=json.children;ioffsetHeight?offsetWidth:offsetHeight;n.setData('width',dim);n.setData('height',dim);n.setData('dim',dim);}}});},initializeLabel:function(opt){if(!this.label){this.label=document.createElement('div');document.body.appendChild(this.label);} this.setLabelStyles(opt);},setLabelStyles:function(opt){$.extend(this.label.style,{'visibility':'hidden','position':'absolute','width':'auto','height':'auto'});this.label.className='jit-autoadjust-label';}};Layouts.Tree=(function(){var slice=Array.prototype.slice;function getBoundaries(graph,config,level,orn,prop){var dim=config.Node;var multitree=config.multitree;if(dim.overridable){var w=-1,h=-1;graph.eachNode(function(n){if(n._depth==level&&(!multitree||('$orn'in n.data)&&n.data.$orn==orn)){var dw=n.getData('width',prop);var dh=n.getData('height',prop);w=(w0)?parents[0]:null;path(parents);};for(var i=0,ns=[node.id].concat(nodesInPath);i=b._depth);});for(var i=0;i0&&n.drawn){n.drawn=false;nds[node.id].push(n);}else if((!root||!orns)&&n.drawn){n.drawn=false;nds[node.id].push(n);}});node.drawn=true;} if(nodes.length>0)viz.fx.plot();for(i in nds){$.each(nds[i],function(n){n.drawn=true;});} for(i=0;ibaseHeight?size:baseHeight)+this.config.subtreeOffset;},getEdge:function(node,type,s){var $C=function(a,b){return function(){return node.pos.add(new Complex(a,b));};};var dim=this.node;var w=node.getData('width');var h=node.getData('height');if(type=='begin'){if(dim.align=="center"){return this.dispatch(s,$C(0,h/2),$C(-w/2,0),$C(0,-h/2),$C(w/2,0));}else if(dim.align=="left"){return this.dispatch(s,$C(0,h),$C(0,0),$C(0,0),$C(w,0));}else if(dim.align=="right"){return this.dispatch(s,$C(0,0),$C(-w,0),$C(0,-h),$C(0,0));}else throw"align: not implemented";}else if(type=='end'){if(dim.align=="center"){return this.dispatch(s,$C(0,-h/2),$C(w/2,0),$C(0,h/2),$C(-w/2,0));}else if(dim.align=="left"){return this.dispatch(s,$C(0,0),$C(w,0),$C(0,h),$C(0,0));}else if(dim.align=="right"){return this.dispatch(s,$C(0,-h),$C(0,0),$C(0,0),$C(-w,0));}else throw"align: not implemented";}},getScaledTreePosition:function(node,scale){var dim=this.node;var w=node.getData('width');var h=node.getData('height');var s=(this.config.multitree&&('$orn'in node.data)&&node.data.$orn)||this.config.orientation;var $C=function(a,b){return function(){return node.pos.add(new Complex(a,b)).$scale(1-scale);};};if(dim.align=="left"){return this.dispatch(s,$C(0,h),$C(0,0),$C(0,0),$C(w,0));}else if(dim.align=="center"){return this.dispatch(s,$C(0,h/2),$C(-w/2,0),$C(0,-h/2),$C(w/2,0));}else if(dim.align=="right"){return this.dispatch(s,$C(0,0),$C(-w,0),$C(0,-h),$C(0,0));}else throw"align: not implemented";},treeFitsInCanvas:function(node,canvas,level){var csize=canvas.getSize();var s=(this.config.multitree&&('$orn'in node.data)&&node.data.$orn)||this.config.orientation;var size=this.dispatch(s,csize.width,csize.height);var baseSize=this.getTreeBaseSize(node,level,function(level,node){return level===0||!node.anySubnode();});return(baseSize=0){node.drawn=false;var ctx=canvas.getCtx();var diff=viz.geom.getScaledTreePosition(node,scale);ctx.translate(diff.x,diff.y);ctx.scale(scale,scale);} this.plotTree(node,$.merge(opt,{'withLabels':true,'hideLabels':!!scale,'plotSubtree':function(n,ch){var root=config.multitree&&!('$orn'in node.data);var orns=root&&node.getData('orns');return!root||orns.indexOf(elem.getData('orn'))>-1;}}),animating);if(scale>=0)node.drawn=true;},getAlignedPos:function(pos,width,height){var nconfig=this.node;var square,orn;if(nconfig.align=="center"){square={x:pos.x-width/2,y:pos.y-height/2};}else if(nconfig.align=="left"){orn=this.config.orientation;if(orn=="bottom"||orn=="top"){square={x:pos.x-width/2,y:pos.y};}else{square={x:pos.x,y:pos.y-height/2};}}else if(nconfig.align=="right"){orn=this.config.orientation;if(orn=="bottom"||orn=="top"){square={x:pos.x-width/2,y:pos.y-height};}else{square={x:pos.x-width,y:pos.y-height/2};}}else throw"align: not implemented";return square;},getOrientation:function(adj){var config=this.config;var orn=config.orientation;if(config.multitree){var nodeFrom=adj.nodeFrom;var nodeTo=adj.nodeTo;orn=(('$orn'in nodeFrom.data)&&nodeFrom.data.$orn)||(('$orn'in nodeTo.data)&&nodeTo.data.$orn);} return orn;}});$jit.ST.Label={};$jit.ST.Label.Native=new Class({Implements:Graph.Label.Native,renderLabel:function(canvas,node,controller){var ctx=canvas.getCtx();var coord=node.pos.getc(true);ctx.fillText(node.name,coord.x,coord.y);}});$jit.ST.Label.DOM=new Class({Implements:Graph.Label.DOM,placeLabel:function(tag,node,controller){var pos=node.pos.getc(true),config=this.viz.config,dim=config.Node,canvas=this.viz.canvas,w=node.getData('width'),h=node.getData('height'),radius=canvas.getSize(),labelPos,orn;var ox=canvas.translateOffsetX,oy=canvas.translateOffsetY,sx=canvas.scaleOffsetX,sy=canvas.scaleOffsetY,posx=pos.x*sx+ox,posy=pos.y*sy+oy;if(dim.align=="center"){labelPos={x:Math.round(posx-w/2+radius.width/2),y:Math.round(posy-h/2+radius.height/2)};}else if(dim.align=="left"){orn=config.orientation;if(orn=="bottom"||orn=="top"){labelPos={x:Math.round(posx-w/2+radius.width/2),y:Math.round(posy+radius.height/2)};}else{labelPos={x:Math.round(posx+radius.width/2),y:Math.round(posy-h/2+radius.height/2)};}}else if(dim.align=="right"){orn=config.orientation;if(orn=="bottom"||orn=="top"){labelPos={x:Math.round(posx-w/2+radius.width/2),y:Math.round(posy-h+radius.height/2)};}else{labelPos={x:Math.round(posx-w+radius.width/2),y:Math.round(posy-h/2+radius.height/2)};}}else throw"align: not implemented";var style=tag.style;style.left=labelPos.x+'px';style.top=labelPos.y+'px';style.display=this.fitsInCanvas(labelPos,canvas)?'':'none';controller.onPlaceLabel(tag,node);}});$jit.ST.Label.SVG=new Class({Implements:[$jit.ST.Label.DOM,Graph.Label.SVG],initialize:function(viz){this.viz=viz;}});$jit.ST.Label.HTML=new Class({Implements:[$jit.ST.Label.DOM,Graph.Label.HTML],initialize:function(viz){this.viz=viz;}});$jit.ST.Plot.NodeTypes=new Class({'none':{'render':$.empty,'contains':$.lambda(false)},'circle':{'render':function(node,canvas){var dim=node.getData('dim'),pos=this.getAlignedPos(node.pos.getc(true),dim,dim),dim2=dim/2;this.nodeHelper.circle.render('fill',{x:pos.x+dim2,y:pos.y+dim2},dim2,canvas);},'contains':function(node,pos){var dim=node.getData('dim'),npos=this.getAlignedPos(node.pos.getc(true),dim,dim),dim2=dim/2;this.nodeHelper.circle.contains({x:npos.x+dim2,y:npos.y+dim2},dim2);}},'square':{'render':function(node,canvas){var dim=node.getData('dim'),dim2=dim/2,pos=this.getAlignedPos(node.pos.getc(true),dim,dim);this.nodeHelper.square.render('fill',{x:pos.x+dim2,y:pos.y+dim2},dim2,canvas);},'contains':function(node,pos){var dim=node.getData('dim'),npos=this.getAlignedPos(node.pos.getc(true),dim,dim),dim2=dim/2;this.nodeHelper.square.contains({x:npos.x+dim2,y:npos.y+dim2},dim2);}},'ellipse':{'render':function(node,canvas){var width=node.getData('width'),height=node.getData('height'),pos=this.getAlignedPos(node.pos.getc(true),width,height);this.nodeHelper.ellipse.render('fill',{x:pos.x+width/2,y:pos.y+height/2},width,height,canvas);},'contains':function(node,pos){var width=node.getData('width'),height=node.getData('height'),npos=this.getAlignedPos(node.pos.getc(true),width,height);this.nodeHelper.ellipse.contains({x:npos.x+width/2,y:npos.y+height/2},width,height,canvas);}},'rectangle':{'render':function(node,canvas){var width=node.getData('width'),height=node.getData('height'),pos=this.getAlignedPos(node.pos.getc(true),width,height);this.nodeHelper.rectangle.render('fill',{x:pos.x+width/2,y:pos.y+height/2},width,height,canvas);},'contains':function(node,pos){var width=node.getData('width'),height=node.getData('height'),npos=this.getAlignedPos(node.pos.getc(true),width,height);this.nodeHelper.rectangle.contains({x:npos.x+width/2,y:npos.y+height/2},width,height,canvas);}}});$jit.ST.Plot.EdgeTypes=new Class({'none':$.empty,'line':{'render':function(adj,canvas){var orn=this.getOrientation(adj),nodeFrom=adj.nodeFrom,nodeTo=adj.nodeTo,rel=nodeFrom._depth1&&direction[0]!=node.id);this.edgeHelper.arrow.render(from,to,dim,inv,canvas);},'contains':function(adj,pos){var orn=this.getOrientation(adj),nodeFrom=adj.nodeFrom,nodeTo=adj.nodeTo,rel=nodeFrom._depthx+dataPointMidPoint){return false;} for(var i=0,l=dimArray.length;i=x-dataPointMidPoint&&mpos.x<=x+dataPointMidPoint&&mpos.y>=y-dimi[0]-dataPointMidPoint&&mpos.y<=y-dimi[0]+dataPointMidPoint){var valArrayCur=node.getData('valArrayCur');var results=array_match(valArrayCur[i],valArrayCur);var matches=results[0];var indexValues=results[1];if(matches>1){var names=new Array(),values=new Array(),percentages=new Array(),linksArr=new Array();for(var j=0,il=indexValues.length;j0){acum+=valArray[i][0];leftAcum+=dimArray[i][0];}} aggregateStyle.top=(-font-config.labelOffset)+'px';labelStyle.top=(config.labelOffset+leftAcum)+'px';domElement.style.top=parseInt(domElement.style.top,10)-leftAcum+'px';domElement.style.height=wrapperStyle.height=leftAcum+'px';labels.aggregate.innerHTML=acum;}}});var size=st.canvas.getSize(),margin=config.Margin;st.config.offsetY=-size.height/2+margin.bottom +(config.showLabels&&(config.labelOffset+config.Label.size));st.config.offsetX=(margin.right-margin.left-config.labelOffset-config.Label.size)/2;this.st=st;this.canvas=this.st.canvas;},renderTitle:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,label=config.Label,title=config.Title;ctx=canvas.getCtx();ctx.fillStyle=title.color;ctx.textAlign='left';ctx.textBaseline='top';ctx.font=label.style+' bold '+' '+title.size+'px '+label.family;if(label.type=='Native'){ctx.fillText(title.text,-size.width/2+margin.left,-size.height/2+margin.top);}},renderTicks:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,ticks=config.Ticks,title=config.Title,subtitle=config.Subtitle,label=config.Label,maxValue=this.maxValue,maxTickValue=Math.ceil(maxValue*.1)*10;if(maxTickValue==maxValue){var length=maxTickValue.toString().length;maxTickValue=maxTickValue+parseInt(pad(1,length));} labelValue=0,labelIncrement=maxTickValue/ticks.segments,ctx=canvas.getCtx();ctx.strokeStyle=ticks.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textAlign='center';ctx.textBaseline='middle';idLabel=canvas.id+"-label";labelDim=100;container=document.getElementById(idLabel);var axis=(size.height/2)-(margin.bottom+config.labelOffset+label.size+(subtitle.text?subtitle.size+subtitle.offset:0)),htmlOrigin=size.height-(margin.bottom+config.labelOffset+label.size+(subtitle.text?subtitle.size+subtitle.offset:0)),grid=-size.height+(margin.bottom+config.labelOffset+label.size+margin.top+(title.text?title.size+title.offset:0)+(subtitle.text?subtitle.size+subtitle.offset:0)),segmentLength=grid/ticks.segments;ctx.fillStyle=ticks.color;ctx.fillRect(-(size.width/2)+margin.left+config.labelOffset+label.size-1,-(size.height/2)+margin.top+(title.text?title.size+title.offset:0),1,size.height-margin.top-margin.bottom-label.size-config.labelOffset-(title.text?title.size+title.offset:0)-(subtitle.text?subtitle.size+subtitle.offset:0));while(axis>=grid){ctx.save();ctx.translate(-(size.width/2)+margin.left,Math.round(axis));ctx.rotate(Math.PI/2);ctx.fillStyle=label.color;if(config.showLabels){if(label.type=='Native'){ctx.fillText(labelValue,0,0);}else{labelDiv=document.createElement('div');labelDiv.innerHTML=labelValue;labelDiv.className="rotatedLabel";labelDiv.style.top=(htmlOrigin-(labelDim/2))+"px";labelDiv.style.left=margin.left+"px";labelDiv.style.width=labelDim+"px";labelDiv.style.height=labelDim+"px";labelDiv.style.textAlign="center";labelDiv.style.verticalAlign="middle";labelDiv.style.position="absolute";container.appendChild(labelDiv);}} ctx.restore();ctx.fillStyle=ticks.color;ctx.fillRect(-(size.width/2)+margin.left+config.labelOffset+label.size,Math.round(axis),size.width-margin.right-margin.left-config.labelOffset-label.size,1);htmlOrigin+=segmentLength;axis+=segmentLength;labelValue+=labelIncrement;}},renderBackground:function(){var canvas=this.canvas,config=this.config,backgroundColor=config.backgroundColor,size=canvas.getSize(),ctx=canvas.getCtx();ctx.fillStyle=backgroundColor;ctx.fillRect(-size.width/2,-size.height/2,size.width,size.height);},loadJSON:function(json){var prefix=$.time(),ch=[],st=this.st,name=$.splat(json.label),color=$.splat(json.color||this.colors),config=this.config,ticks=config.Ticks,renderBackground=config.renderBackground,gradient=!!config.type.split(":")[1],animate=config.animate,title=config.Title,groupTotalValue=0;var valArrayAll=new Array();for(var i=0,values=json.values,l=values.length;i-1)?d:[0,0];}),'end');});this.st.fx.animate({modes:['node-property:dimArray'],duration:1500,onComplete:function(){that.busy=false;}});},restore:function(){if(this.busy)return;this.busy=true;if(this.config.Tips.enable)this.st.tips.hide();this.select(false,false,false);this.normalizeDims();var that=this;this.st.fx.animate({modes:['node-property:height:dimArray'],duration:1500,onComplete:function(){that.busy=false;}});},select:function(id,name,index){if(!this.config.selectOnHover)return;var s=this.selected;if(s.id!=id||s.name!=name||s.index!=index){s.id=id;s.name=name;s.index=index;this.st.graph.eachNode(function(n){n.setData('border',false);});if(id){var n=this.st.graph.getNode(id);n.setData('border',s);var link=index===0?'prev':'next';link=n.getData(link);if(link){n=this.st.graph.getByName(link);if(n){n.setData('border',{name:name,index:1-index});}}} this.st.plot();}},getLegend:function(){var legend=new Array();var name=new Array();var color=new Array();var n;this.st.graph.getNode(this.st.root).eachAdjacency(function(adj){n=adj.nodeTo;});var colors=n.getData('colorArray'),len=colors.length;$.each(n.getData('stringArray'),function(s,i){color[i]=colors[i%len];name[i]=s;});legend['name']=name;legend['color']=color;return legend;},normalizeDims:function(){var root=this.st.graph.getNode(this.st.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.maxValue||1,size=this.st.canvas.getSize(),config=this.config,margin=config.Margin,labelOffset=config.labelOffset+config.Label.size,fixedDim=(size.width-(margin.left+margin.right+labelOffset))/(l-1),animate=config.animate,ticks=config.Ticks,height=size.height-(margin.top+margin.bottom)-(config.showAggregates&&labelOffset) -(config.showLabels&&labelOffset);var maxTickValue=Math.ceil(maxValue*.1)*10;if(maxTickValue==maxValue){var length=maxTickValue.toString().length;maxTickValue=maxTickValue+parseInt(pad(1,length));} this.st.graph.eachNode(function(n){var acumLeft=0,acumRight=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acumLeft+=+v[0];acumRight+=+v[1];animateValue.push([0,0]);});var acum=acumRight>acumLeft?acumRight:acumLeft;n.setData('width',fixedDim);if(animate){n.setData('height',acum*height/maxValue,'end');n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return[n[0]*height/maxValue,n[1]*height/maxValue];}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{if(ticks.enable){n.setData('height',acum*height/maxValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return[n[0]*height/maxTickValue,n[1]*height/maxTickValue];}));}else{n.setData('height',acum*height/maxValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return[n[0]*height/maxValue,n[1]*height/maxValue];}));}}});}});$jit.ST.Plot.NodeTypes.implement({'areachart-stacked':{'render':function(node,canvas){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,stringArray=node.getData('stringArray'),dimArray=node.getData('dimArray'),valArray=node.getData('valueArray'),valLeft=$.reduce(valArray,function(x,y){return x+y[0];},0),valRight=$.reduce(valArray,function(x,y){return x+y[1];},0),colorArray=node.getData('colorArray'),colorLength=colorArray.length,config=node.getData('config'),gradient=node.getData('gradient'),showLabels=config.showLabels,aggregates=config.showAggregates,label=config.Label,prev=node.getData('prev');var ctx=canvas.getCtx(),border=node.getData('border');if(colorArray&&dimArray&&stringArray){for(var i=0,l=dimArray.length,acumLeft=0,acumRight=0,valAcum=0;i0||dimArray[i][1]>0)){var h1=acumLeft+dimArray[i][0],h2=acumRight+dimArray[i][1],alpha=Math.atan((h2-h1)/width),delta=55;var linear=ctx.createLinearGradient(x+width/2,y-(h1+h2)/2,x+width/2+delta*Math.sin(alpha),y-(h1+h2)/2+delta*Math.cos(alpha));var color=$.rgbToHex($.map($.hexToRgb(colorArray[i%colorLength].slice(1)),function(v){return(v*0.85)>>0;}));linear.addColorStop(0,colorArray[i%colorLength]);linear.addColorStop(1,color);ctx.fillStyle=linear;} ctx.beginPath();ctx.moveTo(x,y-acumLeft);ctx.lineTo(x+width,y-acumRight);ctx.lineTo(x+width,y-acumRight-dimArray[i][1]);ctx.lineTo(x,y-acumLeft-dimArray[i][0]);ctx.lineTo(x,y-acumLeft);ctx.fill();ctx.restore();if(border){var strong=border.name==stringArray[i];var perc=strong?0.7:0.8;var color=$.rgbToHex($.map($.hexToRgb(colorArray[i%colorLength].slice(1)),function(v){return(v*perc)>>0;}));ctx.strokeStyle=color;ctx.lineWidth=strong?4:1;ctx.save();ctx.beginPath();if(border.index===0){ctx.moveTo(x,y-acumLeft);ctx.lineTo(x,y-acumLeft-dimArray[i][0]);}else{ctx.moveTo(x+width,y-acumRight);ctx.lineTo(x+width,y-acumRight-dimArray[i][1]);} ctx.stroke();ctx.restore();} acumLeft+=(dimArray[i][0]||0);acumRight+=(dimArray[i][1]||0);if(dimArray[i][0]>0) valAcum+=(valArray[i][0]||0);} if(prev&&label.type=='Native'){ctx.save();ctx.beginPath();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textAlign='center';ctx.textBaseline='middle';if(aggregates(node.name,valLeft,valRight,node)){ctx.fillText(valAcum,x,y-acumLeft-config.labelOffset-label.size/2,width);} if(showLabels(node.name,valLeft,valRight,node)){ctx.fillText(node.name,x,y+label.size/2+config.labelOffset);} ctx.restore();}}},'contains':function(node,mpos){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),rx=mpos.x-x;if(mpos.xx+width||mpos.y>y||mpos.y=intersec){var index=+(rx>width/2);return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i][index],'index':index};}} return false;}}});$jit.AreaChart=new Class({st:null,colors:["#416D9C","#70A35E","#EBB056","#C74243","#83548B","#909291","#557EAA"],selected:{},busy:false,initialize:function(opt){this.controller=this.config=$.merge(Options("Canvas","Margin","Label","AreaChart"),{Label:{type:'Native'}},opt);var showLabels=this.config.showLabels,typeLabels=$.type(showLabels),showAggregates=this.config.showAggregates,typeAggregates=$.type(showAggregates);this.config.showLabels=typeLabels=='function'?showLabels:$.lambda(showLabels);this.config.showAggregates=typeAggregates=='function'?showAggregates:$.lambda(showAggregates);this.initializeViz();},initializeViz:function(){var config=this.config,that=this,nodeType=config.type.split(":")[0],nodeLabels={};var st=new $jit.ST({injectInto:config.injectInto,orientation:"bottom",levelDistance:0,siblingOffset:0,subtreeOffset:0,withLabels:config.Label.type!='Native',useCanvas:config.useCanvas,Label:{type:config.Label.type},Node:{overridable:true,type:'areachart-'+nodeType,align:'left',width:1,height:1},Edge:{type:'none'},Tips:{enable:config.Tips.enable,type:'Native',force:true,onShow:function(tip,node,contains){var elem=contains;config.Tips.onShow(tip,elem,node);}},Events:{enable:true,type:'Native',onClick:function(node,eventInfo,evt){if(!config.filterOnClick&&!config.Events.enable)return;var elem=eventInfo.getContains();if(elem)config.filterOnClick&&that.filter(elem.name);config.Events.enable&&config.Events.onClick(elem,eventInfo,evt);},onRightClick:function(node,eventInfo,evt){if(!config.restoreOnRightClick)return;that.restore();},onMouseMove:function(node,eventInfo,evt){if(!config.selectOnHover)return;if(node){var elem=eventInfo.getContains();that.select(node.id,elem.name,elem.index);}else{that.select(false,false,false);}}},onCreateLabel:function(domElement,node){var labelConf=config.Label,valueArray=node.getData('valueArray'),acumLeft=$.reduce(valueArray,function(x,y){return x+y[0];},0),acumRight=$.reduce(valueArray,function(x,y){return x+y[1];},0);if(node.getData('prev')){var nlbs={wrapper:document.createElement('div'),aggregate:document.createElement('div'),label:document.createElement('div')};var wrapper=nlbs.wrapper,label=nlbs.label,aggregate=nlbs.aggregate,wrapperStyle=wrapper.style,labelStyle=label.style,aggregateStyle=aggregate.style;nodeLabels[node.id]=nlbs;wrapper.appendChild(label);wrapper.appendChild(aggregate);if(!config.showLabels(node.name,acumLeft,acumRight,node)){label.style.display='none';} if(!config.showAggregates(node.name,acumLeft,acumRight,node)){aggregate.style.display='none';} wrapperStyle.position='relative';wrapperStyle.overflow='visible';wrapperStyle.fontSize=labelConf.size+'px';wrapperStyle.fontFamily=labelConf.family;wrapperStyle.color=labelConf.color;wrapperStyle.textAlign='center';aggregateStyle.position=labelStyle.position='absolute';domElement.style.width=node.getData('width')+'px';domElement.style.height=node.getData('height')+'px';label.innerHTML=node.name;domElement.appendChild(wrapper);}},onPlaceLabel:function(domElement,node){if(!node.getData('prev'))return;var labels=nodeLabels[node.id],wrapperStyle=labels.wrapper.style,labelStyle=labels.label.style,aggregateStyle=labels.aggregate.style,width=node.getData('width'),height=node.getData('height'),dimArray=node.getData('dimArray'),valArray=node.getData('valueArray'),acumLeft=$.reduce(valArray,function(x,y){return x+y[0];},0),acumRight=$.reduce(valArray,function(x,y){return x+y[1];},0),font=parseInt(wrapperStyle.fontSize,10),domStyle=domElement.style;if(dimArray&&valArray){if(config.showLabels(node.name,acumLeft,acumRight,node)){labelStyle.display='';}else{labelStyle.display='none';} if(config.showAggregates(node.name,acumLeft,acumRight,node)){aggregateStyle.display='';}else{aggregateStyle.display='none';} wrapperStyle.width=aggregateStyle.width=labelStyle.width=domElement.style.width=width+'px';aggregateStyle.left=labelStyle.left=-width/2+'px';for(var i=0,l=valArray.length,acum=0,leftAcum=0;i0){acum+=valArray[i][0];leftAcum+=dimArray[i][0];}} aggregateStyle.top=(-font-config.labelOffset)+'px';labelStyle.top=(config.labelOffset+leftAcum)+'px';domElement.style.top=parseInt(domElement.style.top,10)-leftAcum+'px';domElement.style.height=wrapperStyle.height=leftAcum+'px';labels.aggregate.innerHTML=acum;}}});var size=st.canvas.getSize(),margin=config.Margin;st.config.offsetY=-size.height/2+margin.bottom +(config.showLabels&&(config.labelOffset+config.Label.size));st.config.offsetX=(margin.right-margin.left)/2;this.st=st;this.canvas=this.st.canvas;},loadJSON:function(json){var prefix=$.time(),ch=[],st=this.st,name=$.splat(json.label),color=$.splat(json.color||this.colors),config=this.config,gradient=!!config.type.split(":")[1],animate=config.animate;for(var i=0,values=json.values,l=values.length;i-1)?d:[0,0];}),'end');});this.st.fx.animate({modes:['node-property:dimArray'],duration:1500,onComplete:function(){that.busy=false;}});},restore:function(){if(this.busy)return;this.busy=true;if(this.config.Tips.enable)this.st.tips.hide();this.select(false,false,false);this.normalizeDims();var that=this;this.st.fx.animate({modes:['node-property:height:dimArray'],duration:1500,onComplete:function(){that.busy=false;}});},select:function(id,name,index){if(!this.config.selectOnHover)return;var s=this.selected;if(s.id!=id||s.name!=name||s.index!=index){s.id=id;s.name=name;s.index=index;this.st.graph.eachNode(function(n){n.setData('border',false);});if(id){var n=this.st.graph.getNode(id);n.setData('border',s);var link=index===0?'prev':'next';link=n.getData(link);if(link){n=this.st.graph.getByName(link);if(n){n.setData('border',{name:name,index:1-index});}}} this.st.plot();}},getLegend:function(){var legend={};var n;this.st.graph.getNode(this.st.root).eachAdjacency(function(adj){n=adj.nodeTo;});var colors=n.getData('colorArray'),len=colors.length;$.each(n.getData('stringArray'),function(s,i){legend[s]=colors[i%len];});return legend;},getMaxValue:function(){var maxValue=0;this.st.graph.eachNode(function(n){var valArray=n.getData('valueArray'),acumLeft=0,acumRight=0;$.each(valArray,function(v){acumLeft+=+v[0];acumRight+=+v[1];});var acum=acumRight>acumLeft?acumRight:acumLeft;maxValue=maxValue>acum?maxValue:acum;});return maxValue;},normalizeDims:function(){var root=this.st.graph.getNode(this.st.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.getMaxValue()||1,size=this.st.canvas.getSize(),config=this.config,margin=config.Margin,labelOffset=config.labelOffset+config.Label.size,fixedDim=(size.width-(margin.left+margin.right))/l,animate=config.animate,height=size.height-(margin.top+margin.bottom)-(config.showAggregates&&labelOffset) -(config.showLabels&&labelOffset);this.st.graph.eachNode(function(n){var acumLeft=0,acumRight=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acumLeft+=+v[0];acumRight+=+v[1];animateValue.push([0,0]);});var acum=acumRight>acumLeft?acumRight:acumLeft;n.setData('width',fixedDim);if(animate){n.setData('height',acum*height/maxValue,'end');n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return[n[0]*height/maxValue,n[1]*height/maxValue];}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{n.setData('height',acum*height/maxValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return[n[0]*height/maxValue,n[1]*height/maxValue];}));}});}});Options.BarChart={$extend:true,animate:true,type:'stacked',labelOffset:3,barsOffset:0,nodeCount:0,hoveredColor:'#9fd4ff',background:false,renderBackground:false,orientation:'horizontal',showAggregates:true,showLabels:true,Ticks:{enable:false,segments:4,color:'#000000'},Tips:{enable:false,onShow:$.empty,onHide:$.empty},Events:{enable:false,onClick:$.empty}};$jit.ST.Plot.NodeTypes.implement({'barchart-stacked':{'render':function(node,canvas){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),stringArray=node.getData('stringArray'),linkArray=node.getData('linkArray'),gvl=node.getData('gvl'),colorArray=node.getData('colorArray'),colorLength=colorArray.length,nodeCount=node.getData('nodeCount');var ctx=canvas.getCtx(),canvasSize=canvas.getSize(),opt={},border=node.getData('border'),gradient=node.getData('gradient'),config=node.getData('config'),horz=config.orientation=='horizontal',aggregates=config.showAggregates,showLabels=config.showLabels,label=config.Label,margin=config.Margin;if(colorArray&&dimArray&&stringArray){for(var i=0,l=dimArray.length,acum=0,valAcum=0;i>0;}));linear.addColorStop(0,color);linear.addColorStop(0.3,colorArray[i%colorLength]);linear.addColorStop(0.7,colorArray[i%colorLength]);linear.addColorStop(1,color);ctx.fillStyle=linear;} if(horz){ctx.fillRect(x+acum,y,dimArray[i],height);}else{ctx.fillRect(x,y-acum-dimArray[i],width,dimArray[i]);} if(border&&border.name==stringArray[i]){opt.acum=acum;opt.dimValue=dimArray[i];} acum+=(dimArray[i]||0);valAcum+=(valueArray[i]||0);} if(border){ctx.save();ctx.lineWidth=2;ctx.strokeStyle=border.color;if(horz){ctx.strokeRect(x+opt.acum+1,y+1,opt.dimValue-2,height-2);}else{ctx.strokeRect(x+1,y-opt.acum-opt.dimValue+1,width-2,opt.dimValue-2);} ctx.restore();} if(label.type=='Native'){ctx.save();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textBaseline='middle';if(gvl){acumValueLabel=gvl;}else{acumValueLabel=valAcum;} if(aggregates(node.name,valAcum)){if(!horz){ctx.textAlign='center';ctx.font=label.style+' '+label.size+'px '+label.family;ctx.save();gridHeight=canvasSize.height-(margin.top+margin.bottom+(config.Title.text?config.Title.size+config.Title.offset:0)+ (config.Subtitle.text?config.Subtitle.size+config.Subtitle.offset:0)+ (label?label.size+config.labelOffset:0));mtxt=ctx.measureText(acumValueLabel);boxWidth=mtxt.width+10;inset=10;boxHeight=label.size+6;if(boxHeight+acum+config.labelOffset>gridHeight){bottomPadding=acum-config.labelOffset-boxHeight;}else{bottomPadding=acum+config.labelOffset+inset;} ctx.translate(x+width/2-(mtxt.width/2),y-bottomPadding);cornerRadius=4;boxX=-inset/2;boxY=-boxHeight/2;ctx.rotate(0*Math.PI/180);ctx.fillStyle="rgba(255,255,255,.8)";if(boxHeight+acum+config.labelOffset>gridHeight){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=ctx.strokeStyle=label.color;ctx.fillText(acumValueLabel,mtxt.width/2,0);ctx.restore();}} if(showLabels(node.name,valAcum,node)){if(horz){ctx.font=label.style+' '+label.size+'px '+label.family;inset=10;gridWidth=canvasSize.width-(config.Margin.left+config.Margin.right);mtxt=ctx.measureText(node.name+": "+acumValueLabel);boxWidth=mtxt.width+10;inset=10;if(acum+boxWidth+config.labelOffset+inset>gridWidth){leftPadding=acum-config.labelOffset-boxWidth-inset;}else{leftPadding=acum+config.labelOffset;} ctx.textAlign='left';ctx.translate(x+inset+leftPadding,y+height/2);boxHeight=label.size+6;boxX=-inset/2;boxY=-boxHeight/2;ctx.fillStyle="rgba(255,255,255,.8)";cornerRadius=4;if(acum+boxWidth+config.labelOffset+inset>gridWidth){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=label.color;ctx.rotate(0*Math.PI/180);ctx.fillText(node.name+": "+acumValueLabel,0,0);}else{if(nodeCount>8){ctx.textAlign='left';ctx.translate(x+width/2,y+label.size/2+config.labelOffset);ctx.rotate(45*Math.PI/180);ctx.fillText(node.name,0,0);}else{ctx.textAlign='center';ctx.fillText(node.name,x+width/2,y+label.size/2+config.labelOffset);}}} ctx.restore();}}},'contains':function(node,mpos){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),config=node.getData('config'),rx=mpos.x-x,horz=config.orientation=='horizontal';if(horz){if(mpos.xx+width||mpos.y>y+height||mpos.yx+width||mpos.y>y||mpos.y=intersec){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'percentage':((node.getData('valueArray')[i]/node.getData('barTotalValue'))*100).toFixed(1),'link':url,'label':node.name};}}} return false;}},'barchart-grouped':{'render':function(node,canvas){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),valuelabelArray=node.getData('valuelabelArray'),linkArray=node.getData('linkArray'),valueLength=valueArray.length,colorArray=node.getData('colorArray'),colorLength=colorArray.length,stringArray=node.getData('stringArray');var ctx=canvas.getCtx(),canvasSize=canvas.getSize(),opt={},border=node.getData('border'),gradient=node.getData('gradient'),config=node.getData('config'),horz=config.orientation=='horizontal',aggregates=config.showAggregates,showLabels=config.showLabels,label=config.Label,shadow=config.shadow,margin=config.Margin,fixedDim=(horz?height:width)/valueLength;maxValue=Math.max.apply(null,dimArray);ctx.fillStyle="rgba(0,0,0,.2)";if(colorArray&&dimArray&&stringArray&&shadow.enable){shadowThickness=shadow.size;for(var i=0,l=valueLength,acum=0,valAcum=0;idimArray[i]){ctx.fillRect((x-shadowThickness)+fixedDim*i,y-dimArray[i]-shadowThickness,fixedDim,dimArray[i]+shadowThickness);}else if(nextBar&&nextBar0&&idimArray[i]){ctx.fillRect((x-((prevBar>0;}));linear.addColorStop(0,color);linear.addColorStop(0.3,colorArray[i%colorLength]);linear.addColorStop(0.7,colorArray[i%colorLength]);linear.addColorStop(1,color);ctx.fillStyle=linear;} if(horz){ctx.fillRect(x,y+fixedDim*i,dimArray[i],fixedDim);}else{ctx.fillRect(x+fixedDim*i,y-dimArray[i],fixedDim,dimArray[i]);} if(border&&border.name==stringArray[i]){opt.acum=fixedDim*i;opt.dimValue=dimArray[i];} acum+=(dimArray[i]||0);valAcum+=(valueArray[i]||0);ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;inset=10;if(aggregates(node.name,valAcum)&&label.type=='Native'){if(valuelabelArray[i]){acumValueLabel=valuelabelArray[i];}else{acumValueLabel=valueArray[i];} if(horz){ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textAlign='left';ctx.textBaseline='top';ctx.fillStyle="rgba(255,255,255,.8)";gridWidth=canvasSize.width-(margin.left+margin.right+config.labeloffset+label.size);mtxt=ctx.measureText(acumValueLabel);boxWidth=mtxt.width+10;if(boxWidth+dimArray[i]+config.labelOffset>gridWidth){leftPadding=dimArray[i]-config.labelOffset-boxWidth-inset;}else{leftPadding=dimArray[i]+config.labelOffset+inset;} boxHeight=label.size+6;boxX=x+leftPadding;boxY=y+i*fixedDim+(fixedDim/2)-boxHeight/2;cornerRadius=4;if(boxWidth+dimArray[i]+config.labelOffset>gridWidth){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=ctx.strokeStyle=label.color;ctx.fillText(acumValueLabel,x+inset/2+leftPadding,y+i*fixedDim+(fixedDim/2)-(label.size/2));}else{ctx.font=label.style+' '+label.size+'px '+label.family;ctx.save();ctx.textAlign='center';gridHeight=canvasSize.height-(margin.top+margin.bottom+(config.Title.text?config.Title.size+config.Title.offset:0)+ (config.Subtitle.text?config.Subtitle.size+config.Subtitle.offset:0)+ (label?label.size+config.labelOffset:0));mtxt=ctx.measureText(acumValueLabel);boxWidth=mtxt.width+10;boxHeight=label.size+6;if(boxHeight+dimArray[i]+config.labelOffset>gridHeight){bottomPadding=dimArray[i]-config.labelOffset-boxHeight-inset;}else{bottomPadding=dimArray[i]+config.labelOffset+inset;} ctx.translate(x+(i*fixedDim)+(fixedDim/2),y-bottomPadding);boxX=-boxWidth/2;boxY=-boxHeight/2;ctx.fillStyle="rgba(255,255,255,.8)";cornerRadius=4;if(boxHeight+dimArray[i]+config.labelOffset>gridHeight){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=ctx.strokeStyle=label.color;ctx.fillText(acumValueLabel,0,0);ctx.restore();}}} if(border){ctx.save();ctx.lineWidth=2;ctx.strokeStyle=border.color;if(horz){ctx.strokeRect(x+1,y+opt.acum+1,opt.dimValue-2,fixedDim-2);}else{ctx.strokeRect(x+opt.acum+1,y-opt.dimValue+1,fixedDim-2,opt.dimValue-2);} ctx.restore();} if(label.type=='Native'){ctx.save();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textBaseline='middle';if(showLabels(node.name,valAcum,node)){if(horz){ctx.textAlign='center';ctx.translate(x-config.labelOffset-label.size/2,y+height/2);ctx.rotate(Math.PI/2);ctx.fillText(node.name,0,0);}else{ctx.textAlign='center';ctx.fillText(node.name,x+width/2,y+label.size/2+config.labelOffset);}} ctx.restore();}}},'contains':function(node,mpos){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),len=dimArray.length,config=node.getData('config'),rx=mpos.x-x,horz=config.orientation=='horizontal',fixedDim=(horz?height:width)/len;if(horz){if(mpos.xx+width||mpos.y>y+height||mpos.yx+width||mpos.y>y||mpos.y=limit&&mpos.y<=limit+fixedDim){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'title':node.getData('titleArray')[i],'percentage':((node.getData('valueArray')[i]/node.getData('barTotalValue'))*100).toFixed(1),'link':url,'label':node.name};}}else{var limit=x+fixedDim*i;if(mpos.x>=limit&&mpos.x<=limit+fixedDim&&mpos.y>=y-dimi){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'title':node.getData('titleArray')[i],'percentage':((node.getData('valueArray')[i]/node.getData('barTotalValue'))*100).toFixed(1),'link':url,'label':node.name};}}} return false;}},'barchart-basic':{'render':function(node,canvas){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),valuelabelArray=node.getData('valuelabelArray'),linkArray=node.getData('linkArray'),valueLength=valueArray.length,colorArray=node.getData('colorMono'),colorLength=colorArray.length,stringArray=node.getData('stringArray');var ctx=canvas.getCtx(),canvasSize=canvas.getSize(),opt={},border=node.getData('border'),gradient=node.getData('gradient'),config=node.getData('config'),horz=config.orientation=='horizontal',aggregates=config.showAggregates,showLabels=config.showLabels,label=config.Label,fixedDim=(horz?height:width)/valueLength,margin=config.Margin;if(colorArray&&dimArray&&stringArray){for(var i=0,l=valueLength,acum=0,valAcum=0;i>0;}));linear.addColorStop(0,color);linear.addColorStop(0.3,colorArray[i%colorLength]);linear.addColorStop(0.7,colorArray[i%colorLength]);linear.addColorStop(1,color);ctx.fillStyle=linear;} if(horz){ctx.fillRect(x,y+fixedDim*i,dimArray[i],fixedDim);}else{ctx.fillRect(x+fixedDim*i,y-dimArray[i],fixedDim,dimArray[i]);} if(border&&border.name==stringArray[i]){opt.acum=fixedDim*i;opt.dimValue=dimArray[i];} acum+=(dimArray[i]||0);valAcum+=(valueArray[i]||0);if(label.type=='Native'){ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;if(aggregates(node.name,valAcum)){if(valuelabelArray[i]){acumValueLabel=valuelabelArray[i];}else{acumValueLabel=valueArray[i];} if(!horz){ctx.textAlign='center';ctx.font=label.style+' '+label.size+'px '+label.family;ctx.save();gridHeight=canvasSize.height-(margin.top+margin.bottom+(config.Title.text?config.Title.size+config.Title.offset:0)+ (config.Subtitle.text?config.Subtitle.size+config.Subtitle.offset:0)+ (label?label.size+config.labelOffset:0));mtxt=ctx.measureText(acumValueLabel);boxWidth=mtxt.width+10;inset=10;boxHeight=label.size+6;if(boxHeight+dimArray[i]+config.labelOffset>gridHeight){bottomPadding=dimArray[i]-config.labelOffset-inset;}else{bottomPadding=dimArray[i]+config.labelOffset+inset;} ctx.translate(x+width/2-(mtxt.width/2),y-bottomPadding);cornerRadius=4;boxX=-inset/2;boxY=-boxHeight/2;ctx.fillStyle="rgba(255,255,255,.6)";if(boxHeight+dimArray[i]+config.labelOffset>gridHeight){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=ctx.strokeStyle=label.color;ctx.fillText(acumValueLabel,mtxt.width/2,0);ctx.restore();}}}} if(border){ctx.save();ctx.lineWidth=2;ctx.strokeStyle=border.color;if(horz){ctx.strokeRect(x+1,y+opt.acum+1,opt.dimValue-2,fixedDim-2);}else{ctx.strokeRect(x+opt.acum+1,y-opt.dimValue+1,fixedDim-2,opt.dimValue-2);} ctx.restore();} if(label.type=='Native'){ctx.save();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textBaseline='middle';if(showLabels(node.name,valAcum,node)){if(horz){gridWidth=canvasSize.width-(config.Margin.left+config.Margin.right);mtxt=ctx.measureText(node.name+": "+valAcum);boxWidth=mtxt.width+10;inset=10;if(acum+boxWidth+config.labelOffset+inset>gridWidth){leftPadding=acum-config.labelOffset-boxWidth-inset;}else{leftPadding=acum+config.labelOffset;} ctx.textAlign='left';ctx.translate(x+inset+leftPadding,y+height/2);boxHeight=label.size+6;boxX=-inset/2;boxY=-boxHeight/2;ctx.fillStyle="rgba(255,255,255,.8)";cornerRadius=4;if(acum+boxWidth+config.labelOffset+inset>gridWidth){$.roundedRect(ctx,boxX,boxY,boxWidth,boxHeight,cornerRadius,"fill");} ctx.fillStyle=label.color;ctx.fillText(node.name+": "+valAcum,0,0);}else{if(stringArray.length>8){ctx.textAlign='left';ctx.translate(x+width/2,y+label.size/2+config.labelOffset);ctx.rotate(45*Math.PI/180);ctx.fillText(node.name,0,0);}else{ctx.textAlign='center';ctx.fillText(node.name,x+width/2,y+label.size/2+config.labelOffset);}}} ctx.restore();}}},'contains':function(node,mpos){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),config=node.getData('config'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),len=dimArray.length,rx=mpos.x-x,horz=config.orientation=='horizontal',fixedDim=(horz?height:width)/len;if(horz){if(mpos.xx+width||mpos.y>y+height||mpos.yx+width||mpos.y>y||mpos.y=limit&&mpos.y<=limit+fixedDim){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'percentage':((node.getData('valueArray')[i]/node.getData('groupTotalValue'))*100).toFixed(1),'link':url,'label':node.name};}}else{var limit=x+fixedDim*i;if(mpos.x>=limit&&mpos.x<=limit+fixedDim&&mpos.y>=y-dimi){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'percentage':((node.getData('valueArray')[i]/node.getData('groupTotalValue'))*100).toFixed(1),'link':url,'label':node.name};}}} return false;}}});$jit.BarChart=new Class({st:null,colors:["#004b9c","#9c0079","#9c0033","#28009c","#9c0000","#7d009c","#001a9c","#00809c","#009c80","#009c42","#009c07","#469c00","#799c00","#9c9600","#9c5c00"],selected:{},busy:false,initialize:function(opt){this.controller=this.config=$.merge(Options("Canvas","Margin","Label","BarChart"),{Label:{type:'Native'}},opt);var showLabels=this.config.showLabels,typeLabels=$.type(showLabels),showAggregates=this.config.showAggregates,typeAggregates=$.type(showAggregates);this.config.showLabels=typeLabels=='function'?showLabels:$.lambda(showLabels);this.config.showAggregates=typeAggregates=='function'?showAggregates:$.lambda(showAggregates);Options.Fx.clearCanvas=false;this.initializeViz();},initializeViz:function(){var config=this.config,that=this;var nodeType=config.type.split(":")[0],horz=config.orientation=='horizontal',nodeLabels={};var st=new $jit.ST({injectInto:config.injectInto,orientation:horz?'left':'bottom',background:config.background,renderBackground:config.renderBackground,backgroundColor:config.backgroundColor,colorStop1:config.colorStop1,colorStop2:config.colorStop2,levelDistance:0,nodeCount:config.nodeCount,siblingOffset:config.barsOffset,subtreeOffset:0,withLabels:config.Label.type!='Native',useCanvas:config.useCanvas,Label:{type:config.Label.type},Node:{overridable:true,type:'barchart-'+nodeType,align:'left',width:1,height:1},Edge:{type:'none'},Tips:{enable:config.Tips.enable,type:'Native',force:true,onShow:function(tip,node,contains){var elem=contains;config.Tips.onShow(tip,elem,node);if(elem.link!='undefined'&&elem.link!=''){document.body.style.cursor='pointer';}},onHide:function(call){document.body.style.cursor='default';}},Events:{enable:true,type:'Native',onClick:function(node,eventInfo,evt){if(!config.Events.enable)return;var elem=eventInfo.getContains();config.Events.onClick(elem,eventInfo,evt);},onMouseMove:function(node,eventInfo,evt){if(!config.hoveredColor)return;if(node){var elem=eventInfo.getContains();that.select(node.id,elem.name,elem.index);}else{that.select(false,false,false);}}},onCreateLabel:function(domElement,node){var labelConf=config.Label,valueArray=node.getData('valueArray'),acum=$.reduce(valueArray,function(x,y){return x+y;},0),grouped=config.type.split(':')[0]=='grouped',horz=config.orientation=='horizontal';var nlbs={wrapper:document.createElement('div'),aggregate:document.createElement('div'),label:document.createElement('div')};var wrapper=nlbs.wrapper,label=nlbs.label,aggregate=nlbs.aggregate,wrapperStyle=wrapper.style,labelStyle=label.style,aggregateStyle=aggregate.style;nodeLabels[node.id]=nlbs;wrapper.appendChild(label);wrapper.appendChild(aggregate);if(!config.showLabels(node.name,acum,node)){labelStyle.display='none';} if(!config.showAggregates(node.name,acum,node)){aggregateStyle.display='none';} wrapperStyle.position='relative';wrapperStyle.overflow='visible';wrapperStyle.fontSize=labelConf.size+'px';wrapperStyle.fontFamily=labelConf.family;wrapperStyle.color=labelConf.color;wrapperStyle.textAlign='center';aggregateStyle.position=labelStyle.position='absolute';domElement.style.width=node.getData('width')+'px';domElement.style.height=node.getData('height')+'px';aggregateStyle.left="0px";labelStyle.left=config.labelOffset+'px';labelStyle.whiteSpace="nowrap";label.innerHTML=node.name;domElement.appendChild(wrapper);},onPlaceLabel:function(domElement,node){if(!nodeLabels[node.id])return;var labels=nodeLabels[node.id],wrapperStyle=labels.wrapper.style,labelStyle=labels.label.style,aggregateStyle=labels.aggregate.style,grouped=config.type.split(':')[0]=='grouped',horz=config.orientation=='horizontal',dimArray=node.getData('dimArray'),valArray=node.getData('valueArray'),nodeCount=node.getData('nodeCount'),valueLength=valArray.length;valuelabelArray=node.getData('valuelabelArray'),stringArray=node.getData('stringArray'),width=(grouped&&horz)?Math.max.apply(null,dimArray):node.getData('width'),height=(grouped&&!horz)?Math.max.apply(null,dimArray):node.getData('height'),font=parseInt(wrapperStyle.fontSize,10),domStyle=domElement.style,fixedDim=(horz?height:width)/valueLength;if(dimArray&&valArray){wrapperStyle.width=aggregateStyle.width=labelStyle.width=domElement.style.width=width+'px';aggregateStyle.width=width-config.labelOffset+"px";for(var i=0,l=valArray.length,acum=0;i0){acum+=valArray[i];}} if(config.showLabels(node.name,acum,node)){labelStyle.display='';}else{labelStyle.display='none';} if(config.showAggregates(node.name,acum,node)){aggregateStyle.display='';}else{aggregateStyle.display='none';} if(config.orientation=='horizontal'){aggregateStyle.textAlign='right';labelStyle.textAlign='left';labelStyle.textIndex=aggregateStyle.textIndent=config.labelOffset+'px';aggregateStyle.top=labelStyle.top=(height-font)/2+'px';domElement.style.height=wrapperStyle.height=height+'px';}else{aggregateStyle.top=(-font-config.labelOffset)+'px';labelStyle.top=(config.labelOffset+height)+'px';domElement.style.top=parseInt(domElement.style.top,10)-height+'px';domElement.style.height=wrapperStyle.height=height+'px';if(stringArray.length>8){labels.label.className="rotatedLabelReverse";labelStyle.textAlign="left";labelStyle.top=config.labelOffset+height+width/2+"px";}} if(horz){labels.label.innerHTML=labels.label.innerHTML+": "+acum;labels.aggregate.innerHTML="";}else{if(grouped){maxValue=Math.max.apply(null,dimArray);for(var i=0,l=valArray.length,acum=0,valAcum=0;i40)?40:fixedDim;whiteSpace=size.width-(marginWidth+(fixedDim*l));if(!horz&&typeof FlashCanvas!="undefined"&&size.width<250) location.reload();if(!grouped&&!horz){st.config.siblingOffset=whiteSpace/(l+1);} if(horz){st.config.offsetX=size.width/2-margin.left-(grouped&&config.Label?config.labelOffset+config.Label.size:0);if(config.Ticks.enable){st.config.offsetY=((margin.bottom+config.Label.size+config.labelOffset+(subtitle.text?subtitle.size+subtitle.offset:0))-(margin.top+(title.text?title.size+title.offset:0)))/2;}else{st.config.offsetY=(margin.bottom-margin.top-(title.text?title.size+title.offset:0)-(subtitle.text?subtitle.size+subtitle.offset:0))/2;}}else{st.config.offsetY=-size.height/2+margin.bottom +(config.showLabels&&(config.labelOffset+config.Label.size))+(subtitle.text?subtitle.size+subtitle.offset:0);if(config.Ticks.enable){st.config.offsetX=((margin.right-config.Label.size-config.labelOffset)-margin.left)/2;}else{st.config.offsetX=(margin.right-margin.left)/2;}} this.st=st;this.canvas=this.st.canvas;},renderTitle:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,label=config.Label,title=config.Title;ctx=canvas.getCtx();ctx.fillStyle=title.color;ctx.textAlign='left';ctx.font=label.style+' bold '+' '+title.size+'px '+label.family;if(label.type=='Native'){ctx.fillText(title.text,-size.width/2+margin.left,-size.height/2+margin.top);}},renderSubtitle:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,label=config.Label,subtitle=config.Subtitle,nodeCount=config.nodeCount,horz=config.orientation=='horizontal'?true:false,ctx=canvas.getCtx();ctx.fillStyle=title.color;ctx.textAlign='left';ctx.font=label.style+' '+subtitle.size+'px '+label.family;if(label.type=='Native'){ctx.fillText(subtitle.text,-size.width/2+margin.left,size.height/2-(!horz&&nodeCount>8?20:margin.bottom)-subtitle.size);}},renderScrollNote:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,label=config.Label,note=config.ScrollNote;ctx=canvas.getCtx();ctx.fillStyle=title.color;title=config.Title;ctx.textAlign='center';ctx.font=label.style+' bold '+' '+note.size+'px '+label.family;if(label.type=='Native'){ctx.fillText(note.text,0,-size.height/2+margin.top+title.size);}},renderTicks:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,ticks=config.Ticks,title=config.Title,subtitle=config.Subtitle,label=config.Label,shadow=config.shadow;horz=config.orientation=='horizontal',maxValue=this.getMaxValue(),maxTickValue=Math.ceil(maxValue*.1)*10;if(maxTickValue==maxValue){var length=maxTickValue.toString().length;maxTickValue=maxTickValue+parseInt(pad(1,length));} grouped=config.type.split(':')[0]=='grouped',labelValue=0,labelIncrement=maxTickValue/ticks.segments,ctx=canvas.getCtx();ctx.strokeStyle=ticks.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textAlign='center';ctx.textBaseline='middle';idLabel=canvas.id+"-label";labelDim=100;container=document.getElementById(idLabel);if(horz){var axis=-(size.width/2)+margin.left+(grouped&&config.Label?config.labelOffset+label.size:0),grid=size.width-(margin.left+margin.right+(grouped&&config.Label?config.labelOffset+label.size:0)),segmentLength=grid/ticks.segments;ctx.fillStyle=ticks.color;ctx.fillRect(axis,(size.height/2)-margin.bottom-config.labelOffset-label.size-(subtitle.text?subtitle.size+subtitle.offset:0)+(shadow.enable?shadow.size:0),size.width-margin.left-margin.right-(grouped&&config.Label?config.labelOffset+label.size:0),1);while(axis<=grid){ctx.fillStyle=ticks.color;lineHeight=size.height-margin.bottom-margin.top-config.labelOffset-label.size-(title.text?title.size+title.offset:0)-(subtitle.text?subtitle.size+subtitle.offset:0);ctx.fillRect(Math.round(axis),-(size.height/2)+margin.top+(title.text?title.size+title.offset:0)-(shadow.enable?shadow.size:0),1,lineHeight+(shadow.enable?shadow.size*2:0));ctx.fillStyle=label.color;if(label.type=='Native'&&config.showLabels){ctx.fillText(labelValue,Math.round(axis),-(size.height/2)+margin.top+(title.text?title.size+title.offset:0)+config.labelOffset+lineHeight+label.size);} axis+=segmentLength;labelValue+=labelIncrement;}}else{var axis=(size.height/2)-(margin.bottom+config.labelOffset+label.size+(subtitle.text?subtitle.size+subtitle.offset:0)),htmlOrigin=size.height-(margin.bottom+config.labelOffset+label.size+(subtitle.text?subtitle.size+subtitle.offset:0)),grid=-size.height+(margin.bottom+config.labelOffset+label.size+margin.top+(title.text?title.size+title.offset:0)+(subtitle.text?subtitle.size+subtitle.offset:0)),segmentLength=grid/ticks.segments;ctx.fillStyle=ticks.color;ctx.fillRect(-(size.width/2)+margin.left+config.labelOffset+label.size-1,-(size.height/2)+margin.top+(title.text?title.size+title.offset:0),1,size.height-margin.top-margin.bottom-label.size-config.labelOffset-(title.text?title.size+title.offset:0)-(subtitle.text?subtitle.size+subtitle.offset:0));while(axis>=grid){ctx.save();ctx.translate(-(size.width/2)+margin.left,Math.round(axis));ctx.rotate(0*Math.PI/180);ctx.fillStyle=label.color;if(config.showLabels){if(label.type=='Native'){ctx.fillText(labelValue,0,0);}else{labelDiv=document.createElement('div');labelDiv.innerHTML=labelValue;labelDiv.className="rotatedLabel";labelDiv.style.top=(htmlOrigin-(labelDim/2))+"px";labelDiv.style.left=margin.left+"px";labelDiv.style.width=labelDim+"px";labelDiv.style.height=labelDim+"px";labelDiv.style.textAlign="center";labelDiv.style.verticalAlign="middle";labelDiv.style.position="absolute";container.appendChild(labelDiv);}} ctx.restore();ctx.fillStyle=ticks.color;ctx.fillRect(-(size.width/2)+margin.left+config.labelOffset+label.size,Math.round(axis),size.width-margin.right-margin.left-config.labelOffset-label.size,1);htmlOrigin+=segmentLength;axis+=segmentLength;labelValue+=labelIncrement;}}},renderBackground:function(){var canvas=this.canvas,config=this.config,backgroundColor=config.backgroundColor,size=canvas.getSize(),ctx=canvas.getCtx();ctx.fillStyle=backgroundColor;ctx.fillRect(-size.width/2,-size.height/2,size.width,size.height);},loadJSON:function(json){if(this.busy)return;this.busy=true;var prefix=$.time(),ch=[],st=this.st,name=$.splat(json.label),color=$.splat(json.color||this.colors),config=this.config,gradient=!!config.type.split(":")[1],renderBackground=config.renderBackground,animate=config.animate,ticks=config.Ticks,title=config.Title,note=config.ScrollNote,subtitle=config.Subtitle,horz=config.orientation=='horizontal',that=this,colorLength=color.length,nameLength=name.length;groupTotalValue=0;for(var i=0,values=json.values,l=values.length;iacum?maxValue:acum;});return maxValue;},setBarType:function(type){this.config.type=type;this.st.config.Node.type='barchart-'+type.split(':')[0];},normalizeDims:function(){var root=this.st.graph.getNode(this.st.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.getMaxValue()||1,size=this.st.canvas.getSize(),config=this.config,margin=config.Margin,ticks=config.Ticks,title=config.Title,subtitle=config.Subtitle,grouped=config.type.split(':')[0]=='grouped',marginWidth=margin.left+margin.right+(config.Label&&grouped?config.Label.size+config.labelOffset:0),marginHeight=(title.text?title.size+title.offset:0)+(subtitle.text?subtitle.size+subtitle.offset:0)+margin.top+margin.bottom,horz=config.orientation=='horizontal',fixedDim=(size[horz?'height':'width']-(horz?marginHeight:marginWidth)-(ticks.enable?config.Label.size+config.labelOffset:0)-(l-1)*config.barsOffset)/l,animate=config.animate,height=size[horz?'width':'height']-(horz?marginWidth:marginHeight) -((config.showLabels&&!horz)?(config.Label.size+config.labelOffset):0),dim1=horz?'height':'width',dim2=horz?'width':'height',basic=config.type.split(':')[0]=='basic';var maxTickValue=Math.ceil(maxValue*.1)*10;if(maxTickValue==maxValue){var length=maxTickValue.toString().length;maxTickValue=maxTickValue+parseInt(pad(1,length));} fixedDim=fixedDim>40?40:fixedDim;this.st.graph.eachNode(function(n){var acum=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acum+=+v;animateValue.push(0);});if(grouped){fixedDim=animateValue.length*40;} n.setData(dim1,fixedDim);if(animate){n.setData(dim2,acum*height/maxValue,'end');n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return n*height/maxValue;}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{if(ticks.enable){n.setData(dim2,acum*height/maxTickValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return n*height/maxTickValue;}));}else{n.setData(dim2,acum*height/maxValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return n*height/maxValue;}));}}});}});Options.FunnelChart={$extend:true,animate:true,type:'stacked',labelOffset:3,barsOffset:0,hoveredColor:'#9fd4ff',orientation:'vertical',showAggregates:true,showLabels:true,Tips:{enable:false,onShow:$.empty,onHide:$.empty},Events:{enable:false,onClick:$.empty}};$jit.ST.Plot.NodeTypes.implement({'funnelchart-basic':{'render':function(node,canvas){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),valuelabelArray=node.getData('valuelabelArray'),linkArray=node.getData('linkArray'),colorArray=node.getData('colorArray'),colorLength=colorArray.length,stringArray=node.getData('stringArray');var ctx=canvas.getCtx(),opt={},border=node.getData('border'),gradient=node.getData('gradient'),config=node.getData('config'),horz=config.orientation=='horizontal',aggregates=config.showAggregates,showLabels=config.showLabels,label=config.Label,size=canvas.getSize(),labelOffset=config.labelOffset+10;minWidth=width*.25;ratio=.65;if(colorArray&&dimArray&&stringArray){for(var i=0,l=dimArray.length,acum=0,valAcum=0;i0)?dimArray[i-1]:100;var labelOffsetHeight=(previousElementHeight0)?((dimArray[i]>label.size)?(dimArray[i]/2)-(label.size/2):label.size):0;var topWidth=minWidth+((acum+dimArray[i])*ratio);var bottomWidth=minWidth+((acum)*ratio);var bottomWidthLabel=minWidth+((acum+labelOffsetHeight)*ratio);var labelOffsetRight=(previousElementHeight0)?((i%2!=0&&dimArray[i]0)?((i%2!=0&&dimArray[i]0)?dimArray[i-1]:100;var labelOffsetHeight=(previousElementHeight0)?((dimArray[i]>label.size)?(dimArray[i]/2)-(label.size/2):label.size):0;var labelOffsetRight=(previousElementHeight0)?((i%2!=0&&dimArray[i]0)?((i%2!=0&&dimArray[i]>0;});linear.addColorStop(0,'rgba('+color+',1)');linear.addColorStop(0.5,'rgba('+colorRgb+',1)');linear.addColorStop(1,'rgba('+color+',1)');ctx.fillStyle=linear;} ctx.beginPath();ctx.moveTo(-topWidth/2,y-acum-dimArray[i]);ctx.lineTo(topWidth/2,y-acum-dimArray[i]);ctx.lineTo(bottomWidth/2,y-acum);ctx.lineTo(-bottomWidth/2,y-acum);ctx.closePath();ctx.fill();if(border&&border.name==stringArray[i]){opt.acum=acum;opt.dimValue=dimArray[i];} if(border){ctx.save();ctx.lineWidth=2;ctx.strokeStyle=border.color;ctx.restore();} if(label.type=='Native'){ctx.save();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textBaseline='middle';acumValueLabel=valAcum;if(showLabels(node.name,valAcum,node)){ctx.textAlign='left';ctx.fillText(stringArray[i],(bottomWidthLabel/2)+labelOffset+labelOffsetRight,y-acum-labelOffsetHeight-label.size/2);ctx.textAlign='right';ctx.fillText(valuelabelArray[i],(-bottomWidthLabel/2)-labelOffset-labelOffsetLeft,y-acum-labelOffsetHeight-label.size/2);} ctx.restore();} acum+=(dimArray[i]||0);valAcum+=(valueArray[i]||0);}}},'contains':function(node,mpos){var pos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height'),algnPos=this.getAlignedPos(pos,width,height),x=algnPos.x,y=algnPos.y,dimArray=node.getData('dimArray'),config=node.getData('config'),st=node.getData('st'),rx=mpos.x-x,horz=config.orientation=='horizontal',minWidth=width*.25;ratio=.65,canvas=node.getData('canvas'),size=canvas.getSize(),offsetY=st.config.offsetY;if(mpos.y>y||mpos.yboundRight){return false;} for(var i=0,l=dimArray.length,acum=(horz?x:y);i=intersec){return{'name':node.getData('stringArray')[i],'color':node.getData('colorArray')[i],'value':node.getData('valueArray')[i],'percentage':node.getData('percentageArray')[i],'valuelabel':node.getData('valuelabelArray')[i],'link':url,'label':node.name};}} return false;}}});$jit.FunnelChart=new Class({st:null,colors:["#004b9c","#9c0079","#9c0033","#28009c","#9c0000","#7d009c","#001a9c","#00809c","#009c80","#009c42","#009c07","#469c00","#799c00","#9c9600","#9c5c00"],selected:{},busy:false,initialize:function(opt){this.controller=this.config=$.merge(Options("Canvas","Margin","Label","BarChart"),{Label:{type:'Native'}},opt);var showLabels=this.config.showLabels,typeLabels=$.type(showLabels),showAggregates=this.config.showAggregates,typeAggregates=$.type(showAggregates);this.config.showLabels=typeLabels=='function'?showLabels:$.lambda(showLabels);this.config.showAggregates=typeAggregates=='function'?showAggregates:$.lambda(showAggregates);Options.Fx.clearCanvas=false;this.initializeViz();},initializeViz:function(){var config=this.config,that=this;var nodeType=config.type.split(":")[0],horz=config.orientation=='horizontal',nodeLabels={};var st=new $jit.ST({injectInto:config.injectInto,orientation:horz?'left':'bottom',levelDistance:0,background:config.background,renderBackground:config.renderBackground,backgroundColor:config.backgroundColor,colorStop1:config.colorStop1,colorStop2:config.colorStop2,siblingOffset:config.segmentOffset,subtreeOffset:0,withLabels:config.Label.type!='Native',useCanvas:config.useCanvas,Label:{type:config.Label.type},Node:{overridable:true,type:'funnelchart-'+nodeType,align:'left',width:1,height:1},Edge:{type:'none'},Tips:{enable:config.Tips.enable,type:'Native',force:true,onShow:function(tip,node,contains){var elem=contains;config.Tips.onShow(tip,elem,node);if(elem.link!='undefined'&&elem.link!=''){document.body.style.cursor='pointer';}},onHide:function(call){document.body.style.cursor='default';}},Events:{enable:true,type:'Native',onClick:function(node,eventInfo,evt){if(!config.Events.enable)return;var elem=eventInfo.getContains();config.Events.onClick(elem,eventInfo,evt);},onMouseMove:function(node,eventInfo,evt){if(!config.hoveredColor)return;if(node){var elem=eventInfo.getContains();that.select(node.id,elem.name,elem.index);}else{that.select(false,false,false);}}},onCreateLabel:function(domElement,node){var labelConf=config.Label,valueArray=node.getData('valueArray'),idArray=node.getData('idArray'),valuelabelArray=node.getData('valuelabelArray'),stringArray=node.getData('stringArray');size=st.canvas.getSize() prefix=$.time();for(var i=0,l=valueArray.length;iacum?maxValue:acum;});return maxValue;},setBarType:function(type){this.config.type=type;this.st.config.Node.type='funnelchart-'+type.split(':')[0];},normalizeDims:function(){var root=this.st.graph.getNode(this.st.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.getMaxValue()||1,size=this.st.canvas.getSize(),config=this.config,margin=config.Margin,title=config.Title,subtitle=config.Subtitle,marginWidth=margin.left+margin.right,marginHeight=(title.text?title.size+title.offset:0)+(subtitle.text?subtitle.size+subtitle.offset:0)+margin.top+margin.bottom,horz=config.orientation=='horizontal',animate=config.animate,height=size[horz?'width':'height']-(horz?marginWidth:marginHeight) -(config.showLabels&&(config.Label.size+config.labelOffset)),dim1=horz?'height':'width',dim2=horz?'width':'height';minWidth=size.width/8;this.st.graph.eachNode(function(n){var acum=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acum+=+v;animateValue.push(0);});n.setData(dim1,minWidth);if(animate){n.setData(dim2,acum*height/maxValue,'end');n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return n*height/maxValue;}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{n.setData(dim2,acum*height/maxValue);n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return n*height/maxValue;}));}});}});Options.PieChart={$extend:true,animate:true,offset:25,sliceOffset:0,labelOffset:3,type:'stacked',labelType:'name',hoveredColor:'#9fd4ff',Events:{enable:false,onClick:$.empty},Tips:{enable:false,onShow:$.empty,onHide:$.empty},showLabels:true,resizeLabels:false,updateHeights:false};Layouts.Radial=new Class({compute:function(property){var prop=$.splat(property||['current','start','end']);NodeDim.compute(this.graph,prop,this.config);this.graph.computeLevels(this.root,0,"ignore");var lengthFunc=this.createLevelDistanceFunc();this.computeAngularWidths(prop);this.computePositions(prop,lengthFunc);},computePositions:function(property,getLength){var propArray=property;var graph=this.graph;var root=graph.getNode(this.root);var parent=this.parent;var config=this.config;for(var i=0,l=propArray.length;imaxDim[pi]?dim:maxDim[pi]):dim;} subnodes.push(sib);},"ignore");if(parent&&parent.id==elem.id&&subnodes.length>0&&subnodes[0].dist){subnodes.sort(function(a,b){return(a.dist>=b.dist)-(a.dist<=b.dist);});} for(var k=0,ls=subnodes.length;kpi/2&&p.theta<3*pi/2);var thetap=cond?p.theta+pi:p.theta;if(cond){x-=Math.abs(Math.cos(p.theta)*measure.width);y+=Math.sin(p.theta)*measure.width;}else if(node.id==this.viz.root){x-=measure.width/2;}} ctx.save();ctx.translate(x,y);ctx.rotate(thetap);ctx.fillText(node.name,0,0);ctx.restore();}});Sunburst.Label.SVG=new Class({Implements:Graph.Label.SVG,initialize:function(viz){this.viz=viz;},placeLabel:function(tag,node,controller){var pos=node.pos.getc(true),viz=this.viz,canvas=this.viz.canvas;var radius=canvas.getSize();var labelPos={x:Math.round(pos.x+radius.width/2),y:Math.round(pos.y+radius.height/2)};tag.setAttribute('x',labelPos.x);tag.setAttribute('y',labelPos.y);var bb=tag.getBBox();if(bb){var x=tag.getAttribute('x');var y=tag.getAttribute('y');var p=node.pos.getp(true);var pi=Math.PI;var cond=(p.theta>pi/2&&p.theta<3*pi/2);if(cond){tag.setAttribute('x',x-bb.width);tag.setAttribute('y',y-bb.height);}else if(node.id==viz.root){tag.setAttribute('x',x-bb.width/2);} var thetap=cond?p.theta+pi:p.theta;if(node._depth) tag.setAttribute('transform','rotate('+thetap*360/(2*pi)+' '+x +' '+y+')');} controller.onPlaceLabel(tag,node);}});Sunburst.Label.HTML=new Class({Implements:Graph.Label.HTML,initialize:function(viz){this.viz=viz;},placeLabel:function(tag,node,controller){var pos=node.pos.clone(),canvas=this.viz.canvas,height=node.getData('height'),ldist=((height||node._depth==0)?height:this.viz.config.levelDistance)/2,radius=canvas.getSize();pos.rho+=ldist;pos=pos.getc(true);var labelPos={x:Math.round(pos.x+radius.width/2),y:Math.round(pos.y+radius.height/2)};var style=tag.style;style.left=labelPos.x+'px';style.top=labelPos.y+'px';style.display=this.fitsInCanvas(labelPos,canvas)?'':'none';controller.onPlaceLabel(tag,node);}});Sunburst.Plot.NodeTypes=new Class({'none':{'render':$.empty,'contains':$.lambda(false),'anglecontains':function(node,pos){var span=node.getData('span')/2,theta=node.pos.theta;var begin=theta-span,end=theta+span;if(begin<0) begin+=Math.PI*2;var atan=Math.atan2(pos.y,pos.x);if(atan<0) atan+=Math.PI*2;if(begin>end){return(atan>begin&&atan<=Math.PI*2)||atanbegin&&atanend){return(atan>begin&&atan<=Math.PI*2)||atanbegin&&atan=ld*d)&&(rho<=(ld*d+ldist));} return false;}},'gradient-multipie':{'render':function(node,canvas){var ctx=canvas.getCtx();var height=node.getData('height');var ldist=height?height:this.config.levelDistance;var radialGradient=ctx.createRadialGradient(0,0,node.getPos().rho,0,0,node.getPos().rho+ldist);var colorArray=$.hexToRgb(node.getData('color')),ans=[];$.each(colorArray,function(i){ans.push(parseInt(i*0.5,10));});var endColor=$.rgbToHex(ans);radialGradient.addColorStop(0,endColor);radialGradient.addColorStop(1,node.getData('color'));ctx.fillStyle=radialGradient;this.nodeTypes['multipie'].render.call(this,node,canvas);},'contains':function(node,pos){return this.nodeTypes['multipie'].contains.call(this,node,pos);}},'gradient-pie':{'render':function(node,canvas){var ctx=canvas.getCtx();var radialGradient=ctx.createRadialGradient(0,0,0,0,0,node.getPos().rho);var colorArray=$.hexToRgb(node.getData('color')),ans=[];$.each(colorArray,function(i){ans.push(parseInt(i*0.5,10));});var endColor=$.rgbToHex(ans);radialGradient.addColorStop(1,endColor);radialGradient.addColorStop(0,node.getData('color'));ctx.fillStyle=radialGradient;this.nodeTypes['pie'].render.call(this,node,canvas);},'contains':function(node,pos){return this.nodeTypes['pie'].contains.call(this,node,pos);}}});Sunburst.Plot.EdgeTypes=new Class({'none':$.empty,'line':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true);this.edgeHelper.line.render(from,to,canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true);return this.edgeHelper.line.contains(from,to,pos,this.edge.epsilon);}},'arrow':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true),dim=adj.getData('dim'),direction=adj.data.$direction,inv=(direction&&direction.length>1&&direction[0]!=adj.nodeFrom.id);this.edgeHelper.arrow.render(from,to,dim,inv,canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true);return this.edgeHelper.arrow.contains(from,to,pos,this.edge.epsilon);}},'hyperline':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(),to=adj.nodeTo.pos.getc(),dim=Math.max(from.norm(),to.norm());this.edgeHelper.hyperline.render(from.$scale(1/dim),to.$scale(1/dim),dim,canvas);},'contains':$.lambda(false)}});})($jit.Sunburst);$jit.Sunburst.Plot.NodeTypes.implement({'piechart-stacked':{'render':function(node,canvas){var pos=node.pos.getp(true),dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),colorArray=node.getData('colorArray'),colorLength=colorArray.length,stringArray=node.getData('stringArray'),span=node.getData('span')/2,theta=node.pos.theta,begin=theta-span,end=theta+span,polar=new Polar;var ctx=canvas.getCtx(),opt={},gradient=node.getData('gradient'),border=node.getData('border'),config=node.getData('config'),showLabels=config.showLabels,resizeLabels=config.resizeLabels,label=config.Label;var xpos=config.sliceOffset*Math.cos((begin+end)/2);var ypos=config.sliceOffset*Math.sin((begin+end)/2);if(colorArray&&dimArray&&stringArray){for(var i=0,l=dimArray.length,acum=0,valAcum=0;i>0;}),endColor=$.rgbToHex(ans);radialGradient.addColorStop(0,colori);radialGradient.addColorStop(0.5,colori);radialGradient.addColorStop(1,endColor);ctx.fillStyle=radialGradient;} polar.rho=acum+config.sliceOffset;polar.theta=begin;var p1coord=polar.getc(true);polar.theta=end;var p2coord=polar.getc(true);polar.rho+=dimi;var p3coord=polar.getc(true);polar.theta=begin;var p4coord=polar.getc(true);ctx.beginPath();ctx.arc(xpos,ypos,acum+.01,begin,end,false);ctx.arc(xpos,ypos,acum+dimi+.01,end,begin,true);ctx.fill();if(border&&border.name==stringArray[i]){opt.acum=acum;opt.dimValue=dimArray[i];opt.begin=begin;opt.end=end;} acum+=(dimi||0);valAcum+=(valueArray[i]||0);} if(border){ctx.save();ctx.globalCompositeOperation="source-over";ctx.lineWidth=2;ctx.strokeStyle=border.color;var s=begin>0;fontSize=fontSize<+resizeLabels?+resizeLabels:fontSize;ctx.font=label.style+' '+fontSize+'px '+label.family;ctx.textBaseline='middle';ctx.textAlign='center';polar.rho=acum+config.labelOffset+config.sliceOffset;polar.theta=node.pos.theta;var cart=polar.getc(true);ctx.fillText(node.name,cart.x,cart.y);ctx.restore();}}},'contains':function(node,pos){if(this.nodeTypes['none'].anglecontains.call(this,node,pos)){var rho=Math.sqrt(pos.x*pos.x+pos.y*pos.y);var ld=this.config.levelDistance,d=node._depth;var config=node.getData('config');if(rho<=ld*d+config.sliceOffset){var dimArray=node.getData('dimArray');for(var i=0,l=dimArray.length,acum=config.sliceOffset;i=acum&&rho<=acum+dimi){return{name:node.getData('stringArray')[i],color:node.getData('colorArray')[i],value:node.getData('valueArray')[i],label:node.name};} acum+=dimi;}} return false;} return false;}},'piechart-basic':{'render':function(node,canvas){var pos=node.pos.getp(true),dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),colorArray=node.getData('colorMono'),colorLength=colorArray.length,stringArray=node.getData('stringArray'),percentage=node.getData('percentage'),iteration=node.getData('iteration'),span=node.getData('span')/2,theta=node.pos.theta,begin=theta-span,end=theta+span,polar=new Polar;var ctx=canvas.getCtx(),opt={},gradient=node.getData('gradient'),border=node.getData('border'),config=node.getData('config'),renderSubtitle=node.getData('renderSubtitle'),renderBackground=config.renderBackground,showLabels=config.showLabels,resizeLabels=config.resizeLabels,label=config.Label;var xpos=config.sliceOffset*Math.cos((begin+end)/2);var ypos=config.sliceOffset*Math.sin((begin+end)/2);if(iteration==0&&typeof FlashCanvas!="undefined"&&renderBackground){backgroundColor=config.backgroundColor,size=canvas.getSize();ctx.save();ctx.fillStyle=backgroundColor;ctx.fillRect(-size.width/2,-size.height/2,size.width,size.height);var margin=config.Margin,title=config.Title,subtitle=config.Subtitle;ctx.fillStyle=title.color;ctx.textAlign='left';if(title.text!=""){ctx.font=label.style+' bold '+' '+title.size+'px '+label.family;ctx.moveTo(0,0);if(label.type=='Native'){ctx.fillText(title.text,-size.width/2+margin.left,-size.height/2+margin.top);}} if(subtitle.text!=""){ctx.font=label.style+' '+subtitle.size+'px '+label.family;if(label.type=='Native'){ctx.fillText(subtitle.text,-size.width/2+margin.left,size.height/2-margin.bottom);}} ctx.restore();} if(colorArray&&dimArray&&stringArray){for(var i=0,l=dimArray.length,acum=0,valAcum=0;i>0;}),endColor2=$.map(colorRgb,function(i){return(i*0.7)>>0;});radialGradient.addColorStop(0,'rgba('+colorRgb+',1)');radialGradient.addColorStop(.7,'rgba('+colorRgb+',1)');radialGradient.addColorStop(.98,'rgba('+endColor+',1)');radialGradient.addColorStop(1,'rgba('+endColor2+',1)');ctx.fillStyle=radialGradient;}} ctx.beginPath();ctx.arc(xpos,ypos,acum+.01,begin,end,false);ctx.arc(xpos,ypos,acum+dimi+.01,end,begin,true);ctx.fill();if(border&&border.name==stringArray[i]){opt.acum=acum;opt.dimValue=dimArray[i];opt.begin=begin;opt.end=end;opt.sliceValue=valueArray[i];} acum+=(dimi||0);valAcum+=(valueArray[i]||0);} if(border){ctx.save();ctx.globalCompositeOperation="source-over";ctx.lineWidth=2;ctx.strokeStyle=border.color;var s=begin>0;fontSize=fontSize<+resizeLabels?+resizeLabels:fontSize;ctx.font=label.style+' '+fontSize+'px '+label.family;ctx.textBaseline='middle';ctx.textAlign='center';pi=Math.PI;angle=theta*360/(2*pi);polar.rho=acum+config.labelOffset+config.sliceOffset;polar.theta=node.pos.theta;var cart=polar.getc(true);if(((angle>=225&&angle<=315)||(angle<=135&&angle>=45))&&percentage<=5){}else{if(config.labelType=='name'){ctx.fillText(node.name,cart.x,cart.y);}else{ctx.fillText(node.data.valuelabel,cart.x,cart.y);}} ctx.restore();}}},'contains':function(node,pos){if(this.nodeTypes['none'].anglecontains.call(this,node,pos)){var rho=Math.sqrt(pos.x*pos.x+pos.y*pos.y);var ld=this.config.levelDistance,d=node._depth;var config=node.getData('config');if(rho<=ld*d+config.sliceOffset){var dimArray=node.getData('dimArray');for(var i=0,l=dimArray.length,acum=config.sliceOffset;i=acum&&rho<=acum+dimi){var url=Url.decode(node.getData('linkArray')[i]);return{name:node.getData('stringArray')[i],link:url,color:node.getData('colorArray')[i],value:node.getData('valueArray')[i],percentage:node.getData('percentage'),valuelabel:node.getData('valuelabelsArray')[i],label:node.name};} acum+=dimi;}} return false;} return false;}}});$jit.PieChart=new Class({sb:null,colors:["#416D9C","#70A35E","#EBB056","#C74243","#83548B","#909291","#557EAA"],selected:{},busy:false,initialize:function(opt){this.controller=this.config=$.merge(Options("Canvas","PieChart","Label"),{Label:{type:'Native'}},opt);this.initializeViz();},initializeViz:function(){var config=this.config,that=this;var nodeType=config.type.split(":")[0];var sb=new $jit.Sunburst({injectInto:config.injectInto,useCanvas:config.useCanvas,withLabels:config.Label.type!='Native',background:config.background,renderBackground:config.renderBackground,backgroundColor:config.backgroundColor,colorStop1:config.colorStop1,colorStop2:config.colorStop2,Label:{type:config.Label.type},Node:{overridable:true,type:'piechart-'+nodeType,width:1,height:1},Edge:{type:'none'},Tips:{enable:config.Tips.enable,type:'Native',force:true,onShow:function(tip,node,contains){var elem=contains;config.Tips.onShow(tip,elem,node);if(elem.link!='undefined'&&elem.link!=''){document.body.style.cursor='pointer';}},onHide:function(){document.body.style.cursor='default';}},Events:{enable:true,type:'Native',onClick:function(node,eventInfo,evt){if(!config.Events.enable)return;var elem=eventInfo.getContains();config.Events.onClick(elem,eventInfo,evt);},onMouseMove:function(node,eventInfo,evt){if(!config.hoveredColor)return;if(node){var elem=eventInfo.getContains();that.select(node.id,elem.name,elem.index);}else{that.select(false,false,false);}}},onCreateLabel:function(domElement,node){var labelConf=config.Label;if(config.showLabels){var style=domElement.style;style.fontSize=labelConf.size+'px';style.fontFamily=labelConf.family;style.color=labelConf.color;style.textAlign='center';if(config.labelType=='name'){domElement.innerHTML=node.name;}else{domElement.innerHTML=(node.data.valuelabel!=undefined)?node.data.valuelabel:"";} domElement.style.width='400px';}},onPlaceLabel:function(domElement,node){if(!config.showLabels)return;var pos=node.pos.getp(true),dimArray=node.getData('dimArray'),span=node.getData('span')/2,theta=node.pos.theta,begin=theta-span,end=theta+span,polar=new Polar;var showLabels=config.showLabels,resizeLabels=config.resizeLabels,label=config.Label;if(dimArray){for(var i=0,l=dimArray.length,acum=0;i>0;fontSize=fontSize<+resizeLabels?+resizeLabels:fontSize;domElement.style.fontSize=fontSize+'px';polar.rho=acum+config.labelOffset+config.sliceOffset;polar.theta=(begin+end)/2;var pos=polar.getc(true);var radius=that.canvas.getSize();var labelPos={x:Math.round(pos.x+radius.width/2),y:Math.round(pos.y+radius.height/2)};domElement.style.left=(labelPos.x-200)+'px';domElement.style.top=labelPos.y+'px';}}});var size=sb.canvas.getSize(),min=Math.min;sb.config.levelDistance=min(size.width,size.height)/2 -config.offset-config.sliceOffset;this.sb=sb;this.canvas=this.sb.canvas;this.canvas.getCtx().globalCompositeOperation='lighter';},renderBackground:function(){var canvas=this.canvas,config=this.config,backgroundColor=config.backgroundColor,size=canvas.getSize(),ctx=canvas.getCtx();ctx.globalCompositeOperation="destination-over";ctx.fillStyle=backgroundColor;ctx.fillRect(-size.width/2,-size.height/2,size.width,size.height);},renderTitle:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,radius=this.sb.config.levelDistance,title=config.Title,label=config.Label,subtitle=config.Subtitle;ctx=canvas.getCtx();ctx.fillStyle=title.color;ctx.textAlign='left';ctx.font=label.style+' bold '+' '+title.size+'px '+label.family;ctx.moveTo(0,0);if(label.type=='Native'){ctx.fillText(title.text,-size.width/2+margin.left,-size.height/2+margin.top);}},renderSubtitle:function(){var canvas=this.canvas,size=canvas.getSize(),config=this.config,margin=config.Margin,radius=this.sb.config.levelDistance,title=config.Title,label=config.Label,subtitle=config.Subtitle;ctx=canvas.getCtx();ctx.fillStyle=title.color;ctx.textAlign='left';ctx.font=label.style+' '+subtitle.size+'px '+label.family;ctx.moveTo(0,0);if(label.type=='Native'){ctx.fillText(subtitle.text,-size.width/2+margin.left,size.height/2-margin.bottom);}},loadJSON:function(json){var prefix=$.time(),ch=[],sb=this.sb,name=$.splat(json.label),nameLength=name.length,color=$.splat(json.color||this.colors),colorLength=color.length,config=this.config,renderBackground=config.renderBackground,title=config.Title,subtitle=config.Subtitle,gradient=!!config.type.split(":")[1],animate=config.animate,mono=nameLength==1;totalValue=0;for(var i=0,values=json.values,l=values.length;iacum?maxValue:acum;});return maxValue;},normalizeDims:function(){var root=this.sb.graph.getNode(this.sb.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.getMaxValue()||1,config=this.config,animate=config.animate,rho=this.sb.config.levelDistance;this.sb.graph.eachNode(function(n){var acum=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acum+=+v;animateValue.push(1);});var stat=(animateValue.length==1)&&!config.updateHeights;if(animate){n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return stat?rho:(n*rho/maxValue);}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return stat?rho:(n*rho/maxValue);}));} n.setData('normalizedDim',acum/maxValue);});}});Options.GaugeChart={$extend:true,animate:true,offset:25,sliceOffset:0,labelOffset:3,type:'stacked',labelType:'name',hoveredColor:'#9fd4ff',Events:{enable:false,onClick:$.empty},Tips:{enable:false,onShow:$.empty,onHide:$.empty},showLabels:true,resizeLabels:false,updateHeights:false};$jit.Sunburst.Plot.NodeTypes.implement({'gaugechart-basic':{'render':function(node,canvas){var pos=node.pos.getp(true),dimArray=node.getData('dimArray'),valueArray=node.getData('valueArray'),valuelabelsArray=node.getData('valuelabelsArray'),gaugeTarget=node.getData('gaugeTarget'),nodeIteration=node.getData('nodeIteration'),nodeLength=node.getData('nodeLength'),colorArray=node.getData('colorMono'),colorLength=colorArray.length,stringArray=node.getData('stringArray'),span=node.getData('span')/2,theta=node.pos.theta,begin=((theta-span)/2)+Math.PI,end=((theta+span)/2)+Math.PI,polar=new Polar;var ctx=canvas.getCtx(),opt={},gradient=node.getData('gradient'),border=node.getData('border'),config=node.getData('config'),showLabels=config.showLabels,resizeLabels=config.resizeLabels,label=config.Label;var xpos=Math.cos((begin+end)/2);var ypos=Math.sin((begin+end)/2);if(colorArray&&dimArray&&stringArray&&gaugeTarget!=0){for(var i=0,l=dimArray.length,acum=0,valAcum=0;i>0;}),endColor=$.rgbToHex(ans);radialGradient.addColorStop(0,'rgba('+colorRgb+',1)');radialGradient.addColorStop(0.1,'rgba('+colorRgb+',1)');radialGradient.addColorStop(0.85,'rgba('+colorRgb+',1)');radialGradient.addColorStop(1,'rgba('+ans+',1)');ctx.fillStyle=radialGradient;} polar.rho=acum;polar.theta=begin;var p1coord=polar.getc(true);polar.theta=end;var p2coord=polar.getc(true);polar.rho+=dimi;var p3coord=polar.getc(true);polar.theta=begin;var p4coord=polar.getc(true);ctx.beginPath();ctx.arc(xpos,(ypos+dimi/2),(acum+dimi+.01)*.8,begin,end,false);ctx.arc(xpos,(ypos+dimi/2),(acum+dimi+.01),end,begin,true);ctx.fill();acum+=(dimi||0);valAcum+=(valueArray[i]||0);} if(showLabels&&label.type=='Native'){ctx.save();ctx.fillStyle=ctx.strokeStyle=label.color;ctx.font=label.style+' '+label.size+'px '+label.family;ctx.textBaseline='bottom';ctx.textAlign='center';polar.rho=acum*.65;polar.theta=begin;var cart=polar.getc(true);if(nodeIteration==1){textY=cart.y-(label.size/2)+acum/2;}else{textY=cart.y+acum/2;} if(config.labelType=='name'){ctx.fillText(node.name,cart.x,textY);}else{ctx.fillText(valuelabelsArray[0],cart.x,textY);} if(nodeIteration==nodeLength){polar.theta=end;var cart=polar.getc(true);if(config.labelType=='name'){ctx.fillText(node.name,cart.x,cart.x,cart.y-(label.size/2)+acum/2);}else{ctx.fillText(valuelabelsArray[1],cart.x,cart.y-(label.size/2)+acum/2);}} ctx.restore();}}},'contains':function(node,pos){if(this.nodeTypes['none'].anglecontainsgauge.call(this,node,pos)){var config=node.getData('config');var ld=this.config.levelDistance,d=node._depth;var yOffset=pos.y-(ld/2);var xOffset=pos.x;var rho=Math.sqrt(xOffset*xOffset+yOffset*yOffset);if(rho<=parseInt(ld*d)){var dimArray=node.getData('dimArray');for(var i=0,l=dimArray.length,acum=config.sliceOffset;i=ld*.8&&rho<=acum+dimi){var url=Url.decode(node.getData('linkArray')[i]);return{name:node.getData('stringArray')[i],link:url,color:node.getData('colorArray')[i],value:node.getData('valueArray')[i],valuelabel:node.getData('valuelabelsArray')[0]+" - "+node.getData('valuelabelsArray')[1],label:node.name};} acum+=dimi;}} return false;} return false;}}});$jit.GaugeChart=new Class({sb:null,colors:["#416D9C","#70A35E","#EBB056","#C74243","#83548B","#909291","#557EAA"],selected:{},busy:false,initialize:function(opt){this.controller=this.config=$.merge(Options("Canvas","GaugeChart","Label"),{Label:{type:'Native'}},opt);this.initializeViz();},initializeViz:function(){var config=this.config,that=this;var nodeType=config.type.split(":")[0];var sb=new $jit.Sunburst({injectInto:config.injectInto,useCanvas:config.useCanvas,withLabels:config.Label.type!='Native',background:config.background,renderBackground:config.renderBackground,backgroundColor:config.backgroundColor,colorStop1:config.colorStop1,colorStop2:config.colorStop2,Label:{type:config.Label.type},Node:{overridable:true,type:'gaugechart-'+nodeType,width:1,height:1},Edge:{type:'none'},Tips:{enable:config.Tips.enable,type:'Native',force:true,onShow:function(tip,node,contains){var elem=contains;config.Tips.onShow(tip,elem,node);if(elem.link!='undefined'&&elem.link!=''){document.body.style.cursor='pointer';}},onHide:function(){document.body.style.cursor='default';}},Events:{enable:true,type:'Native',onClick:function(node,eventInfo,evt){if(!config.Events.enable)return;var elem=eventInfo.getContains();config.Events.onClick(elem,eventInfo,evt);}},onCreateLabel:function(domElement,node){var labelConf=config.Label;if(config.showLabels){var style=domElement.style;style.fontSize=labelConf.size+'px';style.fontFamily=labelConf.family;style.color=labelConf.color;style.textAlign='center';valuelabelsArray=node.getData('valuelabelsArray'),nodeIteration=node.getData('nodeIteration'),nodeLength=node.getData('nodeLength'),canvas=sb.canvas,prefix=$.time();if(config.labelType=='name'){domElement.innerHTML=node.name;}else{domElement.innerHTML=(valuelabelsArray[0]!=undefined)?valuelabelsArray[0]:"";} domElement.style.width='400px';if(nodeIteration==nodeLength&&nodeLength!=0){idLabel=canvas.id+"-label";container=document.getElementById(idLabel);finalLabel=document.createElement('div');finalLabelStyle=finalLabel.style;finalLabel.id=prefix+"finalLabel";finalLabelStyle.position="absolute";finalLabelStyle.width="400px";finalLabelStyle.left="0px";container.appendChild(finalLabel);if(config.labelType=='name'){finalLabel.innerHTML=node.name;}else{finalLabel.innerHTML=(valuelabelsArray[1]!=undefined)?valuelabelsArray[1]:"";}}}},onPlaceLabel:function(domElement,node){if(!config.showLabels)return;var pos=node.pos.getp(true),dimArray=node.getData('dimArray'),nodeIteration=node.getData('nodeIteration'),nodeLength=node.getData('nodeLength'),span=node.getData('span')/2,theta=node.pos.theta,begin=((theta-span)/2)+Math.PI,end=((theta+span)/2)+Math.PI,polar=new Polar;var showLabels=config.showLabels,resizeLabels=config.resizeLabels,label=config.Label,radiusOffset=sb.config.levelDistance;if(dimArray){for(var i=0,l=dimArray.length,acum=0;i>0;fontSize=fontSize<+resizeLabels?+resizeLabels:fontSize;domElement.style.fontSize=fontSize+'px';polar.rho=acum*.65;polar.theta=begin;var pos=polar.getc(true);var radius=that.canvas.getSize();var labelPos={x:Math.round(pos.x+radius.width/2),y:Math.round(pos.y+(radius.height/2)+radiusOffset/2)};domElement.style.left=(labelPos.x-200)+'px';domElement.style.top=labelPos.y+'px';if(nodeIteration==1){domElement.style.top=labelPos.y-label.size+'px';} if(nodeIteration==nodeLength&&nodeLength!=0){polar.theta=end;var final=polar.getc(true);var finalPos={x:Math.round(final.x+radius.width/2),y:Math.round(final.y+(radius.height/2)+radiusOffset/2)};finalLabel.style.left=(finalPos.x-200)+"px";finalLabel.style.top=finalPos.y-label.size+"px";}}}});this.sb=sb;this.canvas=this.sb.canvas;var size=sb.canvas.getSize(),min=Math.min;sb.config.levelDistance=min(size.width,size.height)/2 -config.offset-config.sliceOffset;},renderBackground:function(){var canvas=this.sb.canvas,config=this.config,style=config.gaugeStyle,ctx=canvas.getCtx(),size=canvas.getSize(),radius=this.sb.config.levelDistance,startAngle=(Math.PI/180)*1,endAngle=(Math.PI/180)*179;ctx.fillStyle=style.borderColor;ctx.beginPath();ctx.arc(0,radius/2,radius+4,startAngle,endAngle,true);ctx.fill();var radialGradient=ctx.createRadialGradient(0,radius/2,0,0,radius/2,radius);radialGradient.addColorStop(0,'#ffffff');radialGradient.addColorStop(0.3,style.backgroundColor);radialGradient.addColorStop(0.6,style.backgroundColor);radialGradient.addColorStop(1,'#FFFFFF');ctx.fillStyle=radialGradient;startAngle=(Math.PI/180)*0;endAngle=(Math.PI/180)*180;ctx.beginPath();ctx.arc(0,radius/2,radius,startAngle,endAngle,true);ctx.fill();},renderNeedle:function(gaugePosition,target){var canvas=this.sb.canvas,config=this.config,style=config.gaugeStyle,ctx=canvas.getCtx(),size=canvas.getSize(),radius=this.sb.config.levelDistance;gaugeCenter=(radius/2);startAngle=0;endAngle=(Math.PI/180)*180;ctx.fillStyle=style.needleColor;var segments=180/target;needleAngle=gaugePosition*segments;ctx.translate(0,gaugeCenter);ctx.save();ctx.rotate(needleAngle*Math.PI/180);ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(0,-4);ctx.lineTo(-radius*.9,-1);ctx.lineTo(-radius*.9,1);ctx.lineTo(0,4);ctx.lineTo(0,0);ctx.closePath();ctx.fill();ctx.restore();ctx.lineWidth=1;ctx.strokeStyle='#aa0000';ctx.save();ctx.rotate(needleAngle*Math.PI/180);ctx.beginPath();ctx.moveTo(0,0);ctx.lineTo(0,-4);ctx.lineTo(-radius*.8,-1);ctx.lineTo(-radius*.8,1);ctx.lineTo(0,4);ctx.lineTo(0,0);ctx.closePath();ctx.stroke();ctx.restore();ctx.fillStyle="#000000";ctx.lineWidth=style.borderSize;ctx.strokeStyle=style.borderColor;var radialGradient=ctx.createRadialGradient(0,style.borderSize,0,0,style.borderSize,radius*.2);radialGradient.addColorStop(0,'#666666');radialGradient.addColorStop(0.8,'#444444');radialGradient.addColorStop(1,'rgba(0,0,0,0)');ctx.fillStyle=radialGradient;ctx.translate(0,5);ctx.save();ctx.beginPath();ctx.arc(0,0,radius*.2,startAngle,endAngle,true);ctx.fill();ctx.restore();},renderTicks:function(values){var canvas=this.sb.canvas,config=this.config,style=config.gaugeStyle,ctx=canvas.getCtx(),size=canvas.getSize(),radius=this.sb.config.levelDistance,gaugeCenter=(radius/2);ctx.strokeStyle=style.borderColor;ctx.lineWidth=5;ctx.lineCap="round";for(var i=0,total=0,l=values.length;iacum?maxValue:acum;});return maxValue;},normalizeDims:function(){var root=this.sb.graph.getNode(this.sb.root),l=0;root.eachAdjacency(function(){l++;});var maxValue=this.getMaxValue()||1,config=this.config,animate=config.animate,rho=this.sb.config.levelDistance;this.sb.graph.eachNode(function(n){var acum=0,animateValue=[];$.each(n.getData('valueArray'),function(v){acum+=+v;animateValue.push(1);});var stat=(animateValue.length==1)&&!config.updateHeights;if(animate){n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return stat?rho:(n*rho/maxValue);}),'end');var dimArray=n.getData('dimArray');if(!dimArray){n.setData('dimArray',animateValue);}}else{n.setData('dimArray',$.map(n.getData('valueArray'),function(n){return stat?rho:(n*rho/maxValue);}));} n.setData('normalizedDim',acum/maxValue);});}});Layouts.TM={};Layouts.TM.SliceAndDice=new Class({compute:function(prop){var root=this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root);this.controller.onBeforeCompute(root);var size=this.canvas.getSize(),config=this.config,width=size.width,height=size.height;this.graph.computeLevels(this.root,0,"ignore");root.getPos(prop).setc(-width/2,-height/2);root.setData('width',width,prop);root.setData('height',height+config.titleHeight,prop);this.computePositions(root,root,this.layout.orientation,prop);this.controller.onAfterCompute(root);},computePositions:function(par,ch,orn,prop){var totalArea=0;par.eachSubnode(function(n){totalArea+=n.getData('area',prop);});var config=this.config,offst=config.offset,width=par.getData('width',prop),height=par.getData('height',prop)-config.titleHeight,fact=par==ch?1:(ch.getData('area',prop)/totalArea);var otherSize,size,dim,pos,pos2,posth,pos2th;var horizontal=(orn=="h");if(horizontal){orn='v';otherSize=height;size=width*fact;dim='height';pos='y';pos2='x';posth=config.titleHeight;pos2th=0;}else{orn='h';otherSize=height*fact;size=width;dim='width';pos='x';pos2='y';posth=0;pos2th=config.titleHeight;} var cpos=ch.getPos(prop);ch.setData('width',size,prop);ch.setData('height',otherSize,prop);var offsetSize=0,tm=this;ch.eachSubnode(function(n){var p=n.getPos(prop);p[pos]=offsetSize+cpos[pos]+posth;p[pos2]=cpos[pos2]+pos2th;tm.computePositions(ch,n,orn,prop);offsetSize+=n.getData(dim,prop);});}});Layouts.TM.Area={compute:function(prop){prop=prop||"current";var root=this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root);this.controller.onBeforeCompute(root);var config=this.config,size=this.canvas.getSize(),width=size.width,height=size.height,offst=config.offset,offwdth=width-offst,offhght=height-offst;this.graph.computeLevels(this.root,0,"ignore");root.getPos(prop).setc(-width/2,-height/2);root.setData('width',width,prop);root.setData('height',height,prop);var coord={'top':-height/2+config.titleHeight,'left':-width/2,'width':offwdth,'height':offhght-config.titleHeight};this.computePositions(root,coord,prop);this.controller.onAfterCompute(root);},computeDim:function(tail,initElem,w,coord,comp,prop){if(tail.length+initElem.length==1){var l=(tail.length==1)?tail:initElem;this.layoutLast(l,w,coord,prop);return;} if(tail.length>=2&&initElem.length==0){initElem=[tail.shift()];} if(tail.length==0){if(initElem.length>0)this.layoutRow(initElem,w,coord,prop);return;} var c=tail[0];if(comp(initElem,w)>=comp([c].concat(initElem),w)){this.computeDim(tail.slice(1),initElem.concat([c]),w,coord,comp,prop);}else{var newCoords=this.layoutRow(initElem,w,coord,prop);this.computeDim(tail,[],newCoords.dim,newCoords,comp,prop);}},worstAspectRatio:function(ch,w){if(!ch||ch.length==0)return Number.MAX_VALUE;var areaSum=0,maxArea=0,minArea=Number.MAX_VALUE;for(var i=0,l=ch.length;iarea?maxArea:area;} var sqw=w*w,sqAreaSum=areaSum*areaSum;return Math.max(sqw*maxArea/sqAreaSum,sqAreaSum/(sqw*minArea));},avgAspectRatio:function(ch,w){if(!ch||ch.length==0)return Number.MAX_VALUE;var arSum=0;for(var i=0,l=ch.length;ih?w/h:h/w;} return arSum/l;},layoutLast:function(ch,w,coord,prop){var child=ch[0];child.getPos(prop).setc(coord.left,coord.top);child.setData('width',coord.width,prop);child.setData('height',coord.height,prop);}};Layouts.TM.Squarified=new Class({Implements:Layouts.TM.Area,computePositions:function(node,coord,prop){var config=this.config;if(coord.width>=coord.height) this.layout.orientation='h';else this.layout.orientation='v';var ch=node.getSubnodes([1,1],"ignore");if(ch.length>0){this.processChildrenLayout(node,ch,coord,prop);for(var i=0,l=ch.length;i0){this.processChildrenLayout(node,ch,coord,prop);for(var i=0,l=ch.length;itreeDepth)treeDepth=d;});var startNode=this.graph.getNode(this.clickedNode&&this.clickedNode.id||root.id);var maxDepth=Math.min(treeDepth,levelsToShow-1);var initialDepth=startNode._depth;if(this.layout.horizontal()){this.computeSubtree(startNode,-width/2,-height/2,width/(maxDepth+1),height,initialDepth,maxDepth,posType);}else{this.computeSubtree(startNode,-width/2,-height/2,width,height/(maxDepth+1),initialDepth,maxDepth,posType);}},computeSubtree:function(root,x,y,width,height,initialDepth,maxDepth,posType){root.getPos(posType).setc(x,y);root.setData('width',width,posType);root.setData('height',height,posType);var nodeLength,prevNodeLength=0,totalDim=0;var children=Graph.Util.getSubnodes(root,[1,1]);if(!children.length) return;$.each(children,function(e){totalDim+=e.getData('dim');});for(var i=0,l=children.length;i>0;}));lg.addColorStop(0,color);lg.addColorStop(1,colorGrad);ctx.fillStyle=lg;} if(border){ctx.strokeStyle=border;ctx.lineWidth=3;} ctx.fillRect(posx,posy,Math.max(0,width-offset),Math.max(0,height-offset));border&&ctx.strokeRect(pos.x,pos.y,width,height);},'contains':function(node,pos){if(this.viz.clickedNode&&!$jit.Graph.Util.isDescendantOf(node,this.viz.clickedNode.id))return false;var npos=node.pos.getc(true),width=node.getData('width'),height=node.getData('height');return this.nodeHelper.rectangle.contains({x:npos.x+width/2,y:npos.y+height/2},pos,width,height);}}});$jit.Icicle.Plot.EdgeTypes=new Class({'none':$.empty});Layouts.ForceDirected=new Class({getOptions:function(random){var s=this.canvas.getSize();var w=s.width,h=s.height;var count=0;this.graph.eachNode(function(n){count++;});var k2=w*h/count,k=Math.sqrt(k2);var l=this.config.levelDistance;return{width:w,height:h,tstart:w*0.1,nodef:function(x){return k2/(x||1);},edgef:function(x){return k*(x-l);}};},compute:function(property,incremental){var prop=$.splat(property||['current','start','end']);var opt=this.getOptions();NodeDim.compute(this.graph,prop,this.config);this.graph.computeLevels(this.root,0,"ignore");this.graph.eachNode(function(n){$.each(prop,function(p){var pos=n.getPos(p);if(pos.equals(Complex.KER)){pos.x=opt.width/5*(Math.random()-0.5);pos.y=opt.height/5*(Math.random()-0.5);} n.disp={};$.each(prop,function(p){n.disp[p]=$C(0,0);});});});this.computePositions(prop,opt,incremental);},computePositions:function(property,opt,incremental){var times=this.config.iterations,i=0,that=this;if(incremental){(function iter(){for(var total=incremental.iter,j=0;j=times){incremental.onComplete();return;}} incremental.onStep(Math.round(i/(times-1)*100));setTimeout(iter,1);})();}else{for(;i1&&direction[0]!=adj.nodeFrom.id);this.edgeHelper.arrow.render(from,to,dim,inv,canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true);return this.edgeHelper.arrow.contains(from,to,pos,this.edge.epsilon);}}});})($jit.ForceDirected);$jit.TM={};var TM=$jit.TM;$jit.TM.$extend=true;TM.Base={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(controller){var config={orientation:"h",titleHeight:13,offset:2,levelsToShow:0,constrained:false,animate:false,Node:{type:'rectangle',overridable:true,width:3,height:3,color:'#444'},Label:{textAlign:'center',textBaseline:'top'},Edge:{type:'none'},duration:700,fps:45};this.controller=this.config=$.merge(Options("Canvas","Node","Edge","Fx","Controller","Tips","NodeStyles","Events","Navigation","Label"),config,controller);this.layout.orientation=this.config.orientation;var canvasConfig=this.config;if(canvasConfig.useCanvas){this.canvas=canvasConfig.useCanvas;this.config.labelContainer=this.canvas.id+'-label';}else{if(canvasConfig.background){canvasConfig.background=$.merge({type:'Circles'},canvasConfig.background);} this.canvas=new Canvas(this,canvasConfig);this.config.labelContainer=(typeof canvasConfig.injectInto=='string'?canvasConfig.injectInto:canvasConfig.injectInto.id)+'-label';} this.graphOptions={'complex':true,'Node':{'selected':false,'exist':true,'drawn':true}};this.graph=new Graph(this.graphOptions,this.config.Node,this.config.Edge);this.labels=new TM.Label[canvasConfig.Label.type](this);this.fx=new TM.Plot(this);this.op=new TM.Op(this);this.group=new TM.Group(this);this.geom=new TM.Geom(this);this.clickedNode=null;this.busy=false;this.initializeExtras();},refresh:function(){if(this.busy)return;this.busy=true;var that=this;if(this.config.animate){this.compute('end');this.config.levelsToShow>0&&this.geom.setRightLevelToShow(this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root));this.fx.animate($.merge(this.config,{modes:['linear','node-property:width:height'],onComplete:function(){that.busy=false;}}));}else{var labelType=this.config.Label.type;if(labelType!='Native'){var that=this;this.graph.eachNode(function(n){that.labels.hideLabel(n,false);});} this.busy=false;this.compute();this.config.levelsToShow>0&&this.geom.setRightLevelToShow(this.graph.getNode(this.clickedNode&&this.clickedNode.id||this.root));this.plot();}},plot:function(){this.fx.plot();},leaf:function(n){return n.getSubnodes([1,1],"ignore").length==0;},enter:function(n){if(this.busy)return;this.busy=true;var that=this,config=this.config,graph=this.graph,clickedNode=n,previousClickedNode=this.clickedNode;var callback={onComplete:function(){if(config.levelsToShow>0){that.geom.setRightLevelToShow(n);} if(config.levelsToShow>0||config.request)that.compute();if(config.animate){graph.nodeList.setData('alpha',0,'end');n.eachSubgraph(function(n){n.setData('alpha',1,'end');},"ignore");that.fx.animate({duration:500,modes:['node-property:alpha'],onComplete:function(){that.clickedNode=clickedNode;that.compute('end');that.clickedNode=previousClickedNode;that.fx.animate({modes:['linear','node-property:width:height'],duration:1000,onComplete:function(){that.busy=false;that.clickedNode=clickedNode;}});}});}else{that.busy=false;that.clickedNode=n;that.refresh();}}};if(config.request){this.requestNodes(clickedNode,callback);}else{callback.onComplete();}},out:function(){if(this.busy)return;this.busy=true;this.events.hoveredNode=false;var that=this,config=this.config,graph=this.graph,parents=graph.getNode(this.clickedNode&&this.clickedNode.id||this.root).getParents(),parent=parents[0],clickedNode=parent,previousClickedNode=this.clickedNode;if(!parent){this.busy=false;return;} callback={onComplete:function(){that.clickedNode=parent;if(config.request){that.requestNodes(parent,{onComplete:function(){that.compute();that.plot();that.busy=false;}});}else{that.compute();that.plot();that.busy=false;}}};if(config.levelsToShow>0) this.geom.setRightLevelToShow(parent);if(config.animate){this.clickedNode=clickedNode;this.compute('end');this.clickedNode=previousClickedNode;this.fx.animate({modes:['linear','node-property:width:height'],duration:1000,onComplete:function(){that.clickedNode=clickedNode;graph.eachNode(function(n){n.setDataset(['current','end'],{'alpha':[0,1]});},"ignore");previousClickedNode.eachSubgraph(function(node){node.setData('alpha',1);},"ignore");that.fx.animate({duration:500,modes:['node-property:alpha'],onComplete:function(){callback.onComplete();}});}});}else{callback.onComplete();}},requestNodes:function(node,onComplete){var handler=$.merge(this.controller,onComplete),lev=this.config.levelsToShow;if(handler.request){var leaves=[],d=node._depth;node.eachLevel(0,lev,function(n){var nodeLevel=lev-(n._depth-d);if(n.drawn&&!n.anySubnode()&&nodeLevel>0){leaves.push(n);n._level=nodeLevel;}});this.group.requestNodes(leaves,handler);}else{handler.onComplete();}}};TM.Op=new Class({Implements:Graph.Op,initialize:function(viz){this.viz=viz;}});TM.Geom=new Class({Implements:Graph.Geom,getRightLevelToShow:function(){return this.viz.config.levelsToShow;},setRightLevelToShow:function(node){var level=this.getRightLevelToShow(),fx=this.viz.labels;node.eachLevel(0,level+1,function(n){var d=n._depth-node._depth;if(d>level){n.drawn=false;n.exist=false;n.ignore=true;fx.hideLabel(n,false);}else{n.drawn=true;n.exist=true;delete n.ignore;}});node.drawn=true;delete node.ignore;}});TM.Group=new Class({initialize:function(viz){this.viz=viz;this.canvas=viz.canvas;this.config=viz.config;},requestNodes:function(nodes,controller){var counter=0,len=nodes.length,nodeSelected={};var complete=function(){controller.onComplete();};var viz=this.viz;if(len==0) complete();for(var i=0;i>0;}));lg.addColorStop(0,color);lg.addColorStop(1,colorGrad);ctx.fillStyle=lg;} ctx.fillRect(posx,posy,width-offst,height-offst);if(border){ctx.save();ctx.strokeStyle=border;ctx.strokeRect(posx,posy,width-offst,height-offst);ctx.restore();}}else if(titleHeight>0){ctx.fillRect(pos.x+offst/2,pos.y+offst/2,width-offst,titleHeight-offst);if(border){ctx.save();ctx.strokeStyle=border;ctx.strokeRect(pos.x+offst/2,pos.y+offst/2,width-offst,height-offst);ctx.restore();}}},'contains':function(node,pos){if(this.viz.clickedNode&&!node.isDescendantOf(this.viz.clickedNode.id)||node.ignore)return false;var npos=node.pos.getc(true),width=node.getData('width'),leaf=this.viz.leaf(node),height=leaf?node.getData('height'):this.config.titleHeight;return this.nodeHelper.rectangle.contains({x:npos.x+width/2,y:npos.y+height/2},pos,width,height);}}});TM.Plot.EdgeTypes=new Class({'none':$.empty});TM.SliceAndDice=new Class({Implements:[Loader,Extras,TM.Base,Layouts.TM.SliceAndDice]});TM.Squarified=new Class({Implements:[Loader,Extras,TM.Base,Layouts.TM.Squarified]});TM.Strip=new Class({Implements:[Loader,Extras,TM.Base,Layouts.TM.Strip]});$jit.RGraph=new Class({Implements:[Loader,Extras,Layouts.Radial],initialize:function(controller){var $RGraph=$jit.RGraph;var config={interpolation:'linear',levelDistance:100};this.controller=this.config=$.merge(Options("Canvas","Node","Edge","Fx","Controller","Tips","NodeStyles","Events","Navigation","Label"),config,controller);var canvasConfig=this.config;if(canvasConfig.useCanvas){this.canvas=canvasConfig.useCanvas;this.config.labelContainer=this.canvas.id+'-label';}else{if(canvasConfig.background){canvasConfig.background=$.merge({type:'Circles'},canvasConfig.background);} this.canvas=new Canvas(this,canvasConfig);this.config.labelContainer=(typeof canvasConfig.injectInto=='string'?canvasConfig.injectInto:canvasConfig.injectInto.id)+'-label';} this.graphOptions={'complex':false,'Node':{'selected':false,'exist':true,'drawn':true}};this.graph=new Graph(this.graphOptions,this.config.Node,this.config.Edge);this.labels=new $RGraph.Label[canvasConfig.Label.type](this);this.fx=new $RGraph.Plot(this,$RGraph);this.op=new $RGraph.Op(this);this.json=null;this.root=null;this.busy=false;this.parent=false;this.initializeExtras();},createLevelDistanceFunc:function(){var ld=this.config.levelDistance;return function(elem){return(elem._depth+1)*ld;};},refresh:function(){this.compute();this.plot();},reposition:function(){this.compute('end');},plot:function(){this.fx.plot();},getNodeAndParentAngle:function(id){var theta=false;var n=this.graph.getNode(id);var ps=n.getParents();var p=(ps.length>0)?ps[0]:false;if(p){var posParent=p.pos.getc(),posChild=n.pos.getc();var newPos=posParent.add(posChild.scale(-1));theta=Math.atan2(newPos.y,newPos.x);if(theta<0) theta+=2*Math.PI;} return{parent:p,theta:theta};},tagChildren:function(par,id){if(par.angleSpan){var adjs=[];par.eachAdjacency(function(elem){adjs.push(elem.nodeTo);},"ignore");var len=adjs.length;for(var i=0;i1&&direction[0]!=adj.nodeFrom.id);this.edgeHelper.arrow.render(from,to,dim,inv,canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true);return this.edgeHelper.arrow.contains(from,to,pos,this.edge.epsilon);}}});})($jit.RGraph);Complex.prototype.moebiusTransformation=function(c){var num=this.add(c);var den=c.$conjugate().$prod(this);den.x++;return num.$div(den);};Graph.Util.moebiusTransformation=function(graph,pos,prop,startPos,flags){this.eachNode(graph,function(elem){for(var i=0;i=2){return genDistFunc(i-0.01);}} return genDistFunc(0.75);},getRadius:function(){var rad=this.config.radius;if(rad!=="auto"){return rad;} var s=this.canvas.getSize();return Math.min(s.width,s.height)/2;},refresh:function(reposition){if(reposition){this.reposition();this.graph.eachNode(function(node){node.startPos.rho=node.pos.rho=node.endPos.rho;node.startPos.theta=node.pos.theta=node.endPos.theta;});}else{this.compute();} this.plot();},reposition:function(){this.compute('end');var vector=this.graph.getNode(this.root).pos.getc().scale(-1);Graph.Util.moebiusTransformation(this.graph,[vector],['end'],'end',"ignore");this.graph.eachNode(function(node){if(node.ignore){node.endPos.rho=node.pos.rho;node.endPos.theta=node.pos.theta;}});},plot:function(){this.fx.plot();},onClick:function(id,opt){var pos=this.graph.getNode(id).pos.getc(true);this.move(pos,opt);},move:function(pos,opt){var versor=$C(pos.x,pos.y);if(this.busy===false&&versor.norm()<1){this.busy=true;var root=this.graph.getClosestNodeToPos(versor),that=this;this.graph.computeLevels(root.id,0);this.controller.onBeforeCompute(root);opt=$.merge({onComplete:$.empty},opt||{});this.fx.animate($.merge({modes:['moebius'],hideLabels:true},opt,{onComplete:function(){that.busy=false;opt.onComplete();}}),versor);}}});$jit.Hypertree.$extend=true;(function(Hypertree){Hypertree.Op=new Class({Implements:Graph.Op});Hypertree.Plot=new Class({Implements:Graph.Plot});Hypertree.Label={};Hypertree.Label.Native=new Class({Implements:Graph.Label.Native,initialize:function(viz){this.viz=viz;},renderLabel:function(canvas,node,controller){var ctx=canvas.getCtx();var coord=node.pos.getc(true);var s=this.viz.getRadius();ctx.fillText(node.name,coord.x*s,coord.y*s);}});Hypertree.Label.SVG=new Class({Implements:Graph.Label.SVG,initialize:function(viz){this.viz=viz;},placeLabel:function(tag,node,controller){var pos=node.pos.getc(true),canvas=this.viz.canvas,ox=canvas.translateOffsetX,oy=canvas.translateOffsetY,sx=canvas.scaleOffsetX,sy=canvas.scaleOffsetY,radius=canvas.getSize(),r=this.viz.getRadius();var labelPos={x:Math.round((pos.x*sx)*r+ox+radius.width/2),y:Math.round((pos.y*sy)*r+oy+radius.height/2)};tag.setAttribute('x',labelPos.x);tag.setAttribute('y',labelPos.y);controller.onPlaceLabel(tag,node);}});Hypertree.Label.HTML=new Class({Implements:Graph.Label.HTML,initialize:function(viz){this.viz=viz;},placeLabel:function(tag,node,controller){var pos=node.pos.getc(true),canvas=this.viz.canvas,ox=canvas.translateOffsetX,oy=canvas.translateOffsetY,sx=canvas.scaleOffsetX,sy=canvas.scaleOffsetY,radius=canvas.getSize(),r=this.viz.getRadius();var labelPos={x:Math.round((pos.x*sx)*r+ox+radius.width/2),y:Math.round((pos.y*sy)*r+oy+radius.height/2)};var style=tag.style;style.left=labelPos.x+'px';style.top=labelPos.y+'px';style.display=this.fitsInCanvas(labelPos,canvas)?'':'none';controller.onPlaceLabel(tag,node);}});Hypertree.Plot.NodeTypes=new Class({'none':{'render':$.empty,'contains':$.lambda(false)},'circle':{'render':function(node,canvas){var nconfig=this.node,dim=node.getData('dim'),p=node.pos.getc();dim=nconfig.transform?dim*(1-p.squaredNorm()):dim;p.$scale(node.scale);if(dim>0.2){this.nodeHelper.circle.render('fill',p,dim,canvas);}},'contains':function(node,pos){var dim=node.getData('dim'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.circle.contains(npos,pos,dim);}},'ellipse':{'render':function(node,canvas){var pos=node.pos.getc().$scale(node.scale),width=node.getData('width'),height=node.getData('height');this.nodeHelper.ellipse.render('fill',pos,width,height,canvas);},'contains':function(node,pos){var width=node.getData('width'),height=node.getData('height'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.circle.contains(npos,pos,width,height);}},'square':{'render':function(node,canvas){var nconfig=this.node,dim=node.getData('dim'),p=node.pos.getc();dim=nconfig.transform?dim*(1-p.squaredNorm()):dim;p.$scale(node.scale);if(dim>0.2){this.nodeHelper.square.render('fill',p,dim,canvas);}},'contains':function(node,pos){var dim=node.getData('dim'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.square.contains(npos,pos,dim);}},'rectangle':{'render':function(node,canvas){var nconfig=this.node,width=node.getData('width'),height=node.getData('height'),pos=node.pos.getc();width=nconfig.transform?width*(1-pos.squaredNorm()):width;height=nconfig.transform?height*(1-pos.squaredNorm()):height;pos.$scale(node.scale);if(width>0.2&&height>0.2){this.nodeHelper.rectangle.render('fill',pos,width,height,canvas);}},'contains':function(node,pos){var width=node.getData('width'),height=node.getData('height'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.square.contains(npos,pos,width,height);}},'triangle':{'render':function(node,canvas){var nconfig=this.node,dim=node.getData('dim'),p=node.pos.getc();dim=nconfig.transform?dim*(1-p.squaredNorm()):dim;p.$scale(node.scale);if(dim>0.2){this.nodeHelper.triangle.render('fill',p,dim,canvas);}},'contains':function(node,pos){var dim=node.getData('dim'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.triangle.contains(npos,pos,dim);}},'star':{'render':function(node,canvas){var nconfig=this.node,dim=node.getData('dim'),p=node.pos.getc();dim=nconfig.transform?dim*(1-p.squaredNorm()):dim;p.$scale(node.scale);if(dim>0.2){this.nodeHelper.star.render('fill',p,dim,canvas);}},'contains':function(node,pos){var dim=node.getData('dim'),npos=node.pos.getc().$scale(node.scale);return this.nodeHelper.star.contains(npos,pos,dim);}}});Hypertree.Plot.EdgeTypes=new Class({'none':$.empty,'line':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true),r=adj.nodeFrom.scale;this.edgeHelper.line.render({x:from.x*r,y:from.y*r},{x:to.x*r,y:to.y*r},canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true),r=adj.nodeFrom.scale;this.edgeHelper.line.contains({x:from.x*r,y:from.y*r},{x:to.x*r,y:to.y*r},pos,this.edge.epsilon);}},'arrow':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true),r=adj.nodeFrom.scale,dim=adj.getData('dim'),direction=adj.data.$direction,inv=(direction&&direction.length>1&&direction[0]!=adj.nodeFrom.id);this.edgeHelper.arrow.render({x:from.x*r,y:from.y*r},{x:to.x*r,y:to.y*r},dim,inv,canvas);},'contains':function(adj,pos){var from=adj.nodeFrom.pos.getc(true),to=adj.nodeTo.pos.getc(true),r=adj.nodeFrom.scale;this.edgeHelper.arrow.contains({x:from.x*r,y:from.y*r},{x:to.x*r,y:to.y*r},pos,this.edge.epsilon);}},'hyperline':{'render':function(adj,canvas){var from=adj.nodeFrom.pos.getc(),to=adj.nodeTo.pos.getc(),dim=this.viz.getRadius();this.edgeHelper.hyperline.render(from,to,dim,canvas);},'contains':$.lambda(false)}});})($jit.Hypertree);})();