-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot.min.js
executable file
·51 lines (51 loc) · 27 KB
/
dot.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var DotUtils=function(){};DotUtils.escapeContainer=null;DotUtils.escapeText=null;DotUtils.escapeHtml=function(){DotUtils.escapeContainer=document.createElement("div");DotUtils.escapeText=document.createTextNode("");DotUtils.escapeContainer.appendChild(DotUtils.escapeText);return realEscape=function(a){DotUtils.escapeText.data=a;return DotUtils.escapeContainer.innerHTML}}();DotUtils.setHtml=function(a,c){c=c.replace(/<script[^>]*>([\\S\\s]*?)<\/script>/img,"");a.innerHTML=c};
DotUtils.bind=function(a,c){return function(){return c.apply(a,Array.prototype.slice.call(arguments))}};
DotUtils.ajaxGet=function(a,c,b){var d=null;if(window.XMLHttpRequest)d=new window.XMLHttpRequest;else try{d=new ActiveXObject("MSXML2.XMLHTTP.3.0")}catch(e){d=null}null===d&&alert("Your browser does not support basic AJAX requests");if("undefined"!==typeof c&&null!==c){var f=!1;-1<a.indexOf("?")&&(idFirst=!1);for(p in c)f?(a+="?",f=!1):a+="&",a+=escape(p)+"="+escape(c[p])}try{d.open("GET",a,!0)}catch(g){d=new ActiveXObject("Microsoft.XMLHTTP"),d.open("GET",a,!0)}d.onreadystatechange=function(){4==
d.readyState&&(200==d.status?b(d.responseText):0==d.status&&(alert("It seems you have some cross-domain access issues. Dot.js does not support cross-domain loading (yet ?). I'll still try to load your data but the app might get unstable."),b(d.responseText)))};d.send()};DotUtils.extend=function(a,c){for(var b in c)a[b]=c[b];return a};
DotUtils.addEventHandler=function(a,c,b){a.addEventListener?("mousewheel"==c&&a.addEventListener("DOMMouseScroll",b,!1),a.addEventListener(c,b,!1)):a.attachEvent&&a.attachEvent("on"+c,b)};DotUtils.removeEventHandler=function(a,c,b){a.removeEventHandler?("mousewheel"==c&&a.removeEventHandler("DOMMouseScroll",b,!1),a.removeEventHandler(c,b,!1)):a.detachEvent&&a.detachEvent("on"+c,b)};
DotUtils.preventDefault=function(a){a.preventDefault&&a.preventDefault();a.stopPropagation&&a.stopPropagation();a.cancelBubble=!0;a.cancel=!0;a.returnValue=!0;return!1};
DotUtils.createClass=function(){function a(){this.initialize.apply(this,arguments)}var c=null,b=Array.prototype.slice.call(arguments);"function"===typeof b[0]&&(c=b.shift());if(a.superclass=c){var d=function(){};d.prototype=c.prototype;a.prototype=new d}for(c=0;c<b.length;c++)DotUtils.addMethods(a,b[c]);if(!a.prototype.initialize)a.prototype.initialize=DotUtils.emptyMethod;return a.prototype.constructor=a};DotUtils.emptyMethod=function(){};
DotUtils.addMethods=function(a,c){var b=a.superclass&&a.superclass.prototype,d=[],e;for(e in c)d.push(e);for(var f=0,g=d.length;f<g;f++){e=d[f];var h=c[e];if(b&&"function"===typeof h&&"$super"==DotUtils.argumentNames(h)[0])var i=h,h=function(a){return function(){return b[a].apply(this,arguments)}}(e),h=DotUtils.wrap(h,i);a.prototype[e]=h}return a};
DotUtils.argumentNames=function(a){a=a.toString().match(/^[\s\(]*function[^(]*\(([^\)]*)\)/)[1].replace(/\s+/g,"").split(",");return 1==a.length&&!a[0]?[]:a};DotUtils.wrap=function(a,c){return function(){return c.apply(this,[DotUtils.bind(this,a)].concat(Array.prototype.slice.call(arguments)))}};var Dot=DotUtils.createClass({maxXdotVersion:"1.2",colors:{fallback:{black:"000000",lightgrey:"d3d3d3",white:"ffffff"}},initialize:function(a,c,b){this._canvas=document.createElement("canvas");this._canvas.style.position="absolute";this._canvas.style.top="0px";this._canvas.style.left="0px";if(!Dot._canvasCounter)Dot._canvasCounter=0;this._canvas.id="dot_canvas_"+ ++Dot._canvasCounter;this._container=document.getElementById(a);this._container.style.position="relative";this._container.style.overflow=
"hidden";this._container.appendChild(this._canvas);if("undefined"!==typeof G_vmlCanvasManager)G_vmlCanvasManager.initElement(this._canvas),this._canvas=document.getElementById(this._canvas.id);this._ctxScreen=this._canvas.getContext("2d");this._isDirty=!0;this._scale=1;this._minimumScale=0.5;this._maximumScale=2;this._padding=8;this._screenHeight=this._screenWidth="auto";this._dashLength=6;this._dotSpacing=4;this._graphs=[];this._images={};this._numImagesFinished=this._numImages=0;this._imagePath=
"";this._graphLoaded=!1;this._allowMouseScrolling=!0;this._viewPos={x:0,y:0};this._mouseIsDown=!1;this._lastMousePos={x:0,y:0};c&&this.load(c,b);DotUtils.addEventHandler(this._container,"mousewheel",DotUtils.bind(this,this._handleMouseWheel));DotUtils.addEventHandler(document,"mousemove",DotUtils.bind(this,this._handleMouseMove));DotUtils.addEventHandler(this._container,"mousedown",DotUtils.bind(this,this._handleMouseDown));DotUtils.addEventHandler(document,"mouseup",DotUtils.bind(this,this._handleMouseUp))},
setScale:function(a){this._scale=+a;if(this._scale<this._minimumScale)this._scale=this._minimumScale;if(this._scale>this._maximumScale)this._scale=this._maximumScale;this._graphLoaded&&this._draw()},getScale:function(){return this._scale},setMinimumScale:function(a){a=+a;if(a>this._maximumScale)a=this._maximumScale;0>=a&&(a=0.001);this._minimumScale=a;this._scale<a&&this.setScale(a)},getMinimumScale:function(){return this._minimumScale},setMaximumScale:function(a){a=+a;if(a<this._minimumScale)a=this._minimumScale;
this._maximumScale=a;this._scale>this._maximumScale&&this.setScale(this._maximumScale)},getMaximumScale:function(){return this._maximumScale},setAllowMouseZooming:function(a){this._allowMouseScrolling=!!a},getAllowMouseZooming:function(){return this._allowMouseScrolling},setImagePath:function(a){this._imagePath=a},getImagePath:function(){return this._imagePath},setWidth:function(a){this._isValidCssSize(a)?(this._screenWidth=a,this._container.style.width=a):(this._screenWidth="auto",this._container.style.width=
(this._width+2*this._padding)*this._scale+"px")},getWidth:function(){return this._screenWidth},setHeight:function(a){this._isValidCssSize(a)?(this._screenHeight=a,this._container.style.height=a):(this._screenHeight="auto",this._container.style.height=(this._height+2*this._padding)*this._scale+"px")},getHeight:function(){return this._screenHeight},setXPos:function(a){0>a&&(a=0);this._viewPos.x=-a},getXPos:function(){return-this._viewPos.x},setYPos:function(a){0>a&&(a=0);this._viewPos.y=-a},getYPos:function(){return-this._viewPos.y},
load:function(a,c){document.getElementById("debug_output").innerHTML="";var b=DotUtils.bind(this,function(a){this.parse(a)});DotUtils.ajaxGet(a,c,b)},parse:function(a){this._viewPos.x=this._viewPos.y=0;this._graphs=[];this._height=this._width=0;this._bbEnlarge=this._maxHeight=this._maxWidth=!1;this._dpi=96;this._bgcolor={opacity:1};this._bgcolor.canvasColor=this._bgcolor.textColor="#ffffff";for(var a=a.split(/\r?\n/),c=0,b,d,e,f,g,h,i,j,m,l,k=[];c<a.length;)if(b=a[c++].replace(/^\s+/,""),""!=b&&"#"!=
b.substr(0,1)){for(;c<a.length&&";"!=(d=b.substr(b.length-1,b.length))&&"{"!=d&&"}"!=d;)"\\"==d&&(b=b.substr(0,b.length-1)),b+=a[c++];if(0==k.length){if(e=b.match(this._graphMatchRe))f=new DotGraph(e[3],this),k.unshift(f),k[0]._strict="undefined"!==typeof e[1],k[0]._type="graph"==e[2]?"undirected":"directed",k[0]._attrs.xdotversion="1.0",this._graphs.push(k[0])}else if(e=b.match(this._subgraphMatchRe))k.unshift(new DotGraph(e[1],this,f,k[0])),k[1]._subgraphs.push(k[0]);if(!e)if("}"==b){if(k.shift(),
0==k.length)break}else{if(e=b.match(this._nodeMatchRe))switch(h=e[2],i=e[5],l=k[0]._drawAttrs,g=!1,h){case "graph":m=k[0]._attrs;g=!0;break;case "node":m=k[0]._nodeAttrs;break;case "edge":m=k[0]._edgeAttrs;break;default:b=new DotNode(h,this,f,k[0]),m=b._attrs,l=b._drawAttrs,k[0]._nodes.push(b)}else if(e=b.match(this._edgeMatchRe))h=e[1],i=e[8],b=new DotEdge(h,this,f,k[0],e[2],e[5]),m=b._attrs,l=b._drawAttrs,k[0]._edges.push(b);if(e){do{if(0==i.length)break;if(e=i.match(this._attrMatchRe)){if(i=i.substr(e[0].length),
b=e[1],j=this._unescape(e[2]),/^_.*draw_$/.test(b)?l[b]=j:m[b]=j,g&&1==k.length)switch(b){case "bb":b=j.split(/,/);this._width=Number(b[2]);this._height=Number(b[3]);break;case "bgcolor":this._bgcolor=f.parseColor(j);break;case "dpi":this._dpi=j;break;case "size":(b=j.match(/^(\d+|\d*(?:\.\d+)),\s*(\d+|\d*(?:\.\d+))(!?)$/))?(this._maxWidth=72*Number(b[1]),this._maxHeight=72*Number(b[2]),this._bbEnlarge="!"==b[3]):debug("can't parse size");break;case "xdotversion":0>this._versionCompare(this.maxXdotVersion,
m.xdotversion)&&debug("unsupported xdotversion "+m.xdotversion+"; this script currently supports up to xdotversion "+this.maxXdotVersion)}}else debug("can't read attributes for entity "+h+" from "+i)}while(e)}}}this._isDirty=!0;this._draw();this._graphLoaded=!0},_draw:function(){var a=this._scale*this._dpi/72,c=Math.round((this._width+2*this._padding)*this._cacheScale),b=Math.round((this._height+2*this._padding)*this._cacheScale),d=Math.round(a*this._width+2*this._padding),a=Math.round(a*this._height+
2*this._padding);if("auto"===this._screenWidth)this._container.style.width=d+"px";if("auto"===this._screenHeight)this._container.style.height=a+"px";if(this._isDirty)this._canvas.width=c,this._canvas.height=b,this._ctxScreen.save(),this._ctxScreen.lineCap="round",this._ctxScreen.fillStyle=this._bgcolor.canvasColor,this._ctxScreen.fillRect(0,0,c,b),this._ctxScreen.translate(this._padding,this._padding),this._ctxScreen.scale(this._cacheScale,this._cacheScale),this._graphs[0]._draw(this._ctxScreen,this._cacheScale),
this._ctxScreen.restore(),this._isDirty=!1;this._canvas.style.width=d+"px";this._canvas.style.height=a+"px";this._canvas._dot_width=d;this._canvas._dot_height=a;this._canvas.style.top=this._viewPos.y+"px";this._canvas.style.left=this._viewPos.x+"px"},_drawPath:function(a,c,b,d){b&&(a.beginPath(),c.makePath(a),a.fill());if(a.fillStyle!=a.strokeStyle||!b){switch(d){case "dashed":a.beginPath();c.makeDashedPath(a,this._dashLength);break;case "dotted":var e=a.lineWidth;a.lineWidth*=2;a.beginPath();c.makeDottedPath(a,
this._dotSpacing);break;default:b||(a.beginPath(),c.makePath(a))}a.stroke();if(e)a.lineWidth=e}},_unescape:function(a){var c=a.match(/^"(.*)"$/);return c?c[1].replace(/\\"/g,'"'):a},_parseHexColor:function(a){if(a=a.match(/^#([0-9a-f]{2})\s*([0-9a-f]{2})\s*([0-9a-f]{2})\s*([0-9a-f]{2})?$/i)){var c,b="#"+a[1]+a[2]+a[3],d=1;a[4]?(d=parseInt(a[4],16)/255,c="rgba("+parseInt(a[1],16)+","+parseInt(a[2],16)+","+parseInt(a[3],16)+","+d+")"):c=b}return{canvasColor:c,textColor:b,opacity:d}},_hsvToRgbColor:function(a,
c,b){var d,e,f,g,h,i,a=360*a;d=Math.floor(a/60)%6;e=a/60-d;a=b*(1-c);f=b*(1-e*c);c=b*(1-(1-e)*c);switch(d){case 0:g=b;h=c;i=a;break;case 1:g=f;h=b;i=a;break;case 2:g=a;h=b;i=c;break;case 3:g=a;h=f;i=b;break;case 4:g=c;h=a;i=b;break;case 5:g=b,h=a,i=f}return"rgb("+Math.round(255*g)+","+Math.round(255*h)+","+Math.round(255*i)+")"},_versionCompare:function(a,c){for(var a=a.split("."),c=c.split("."),b,d;a.length||c.length;){b=a.length?a.shift():0;d=c.length?c.shift():0;if(b<d)return-1;if(b>d)return 1}return 0},
_handleMouseWheel:function(a){if(this._allowMouseScrolling){if(!a)a=window.event;var c=0;a.wheelDelta?(c=a.wheelDelta/120,window.opera&&(c=-c)):a.detail&&(c=-a.detail/3);c&&this.setScale(this.getScale()+c/10);return DotUtils.preventDefault(a)}},_handleMouseMove:function(a){if(this._mouseIsDown){"undefined"!==typeof event&&(a=event);var c={};c.x=a.pageX||a.clientX+document.body.scrollLeft;c.y=a.pageY||a.clientY+document.body.scrollTop;a=c.y-this._lastMousePos.y;this._viewPos.x+=c.x-this._lastMousePos.x;
this._viewPos.y+=a;if(0<this._viewPos.x)this._viewPos.x=0;if(0<this._viewPos.y)this._viewPos.y=0;var a=this._container.offsetWidth-this._canvas._dot_width,b=this._container.offsetHeight-this._canvas._dot_height;if(0<a)this._viewPos.x=0;else if(this._viewPos.x<a)this._viewPos.x=a;if(0<b)this._viewPos.y=0;else if(this._viewPos.y<b)this._viewPos.y=b;this._lastMousePos=c;this._draw()}},_handleMouseDown:function(a){this._mouseIsDown=!0;var c={};c.x=a.pageX||a.clientX+document.body.scrollLeft;c.y=a.pageY||
a.clientY+document.body.scrollTop;this._lastMousePos=c},_handleMouseUp:function(){this._mouseIsDown=!1},_isValidCssSize:function(a){return"string"===typeof a&&this._cssSize.test(a)},_idMatch:'([a-zA-Z\u0080-\uffff_][0-9a-zA-Z\u0080-\uffff_]*|-?(?:\\.\\d+|\\d+(?:\\.\\d*)?)|"(?:\\\\"|[^"])*"|<(?:<[^>]*>|[^<>]+?)+>)'});Dot.prototype._nodeIdMatch=Dot.prototype._idMatch+"(?::"+Dot.prototype._idMatch+")?(?::"+Dot.prototype._idMatch+")?";
Dot.prototype._graphMatchRe=RegExp("^(strict\\s+)?(graph|digraph)(?:\\s+"+Dot.prototype._idMatch+")?\\s*{$","i");Dot.prototype._subgraphMatchRe=RegExp("^(?:subgraph\\s+)?"+Dot.prototype._idMatch+"?\\s*{$","i");Dot.prototype._nodeMatchRe=RegExp("^("+Dot.prototype._nodeIdMatch+")\\s+\\[(.+)\\];$");Dot.prototype._edgeMatchRe=RegExp("^("+Dot.prototype._nodeIdMatch+"\\s*-[->]\\s*"+Dot.prototype._nodeIdMatch+")\\s+\\[(.+)\\];$");
Dot.prototype._attrMatchRe=RegExp("^"+Dot.prototype._idMatch+"="+Dot.prototype._idMatch+"(?:[,\\s]+|$)");Dot.prototype._cssSize=/^\d+(\.\d+)?(px|%)$/;Dot.prototype._cacheScale=2;var DotTokenizer=DotUtils.createClass({initialize:function(a){this._str=a},takeChars:function(a){a||(a=1);for(var c=[];a--;){var b=this._str.match(/^(\S+)\s*/);b?(this._str=this._str.substr(b[0].length),c.push(b[1])):c.push(!1)}return 1==c.length?c[0]:c},takeNumber:function(a){a||(a=1);if(1==a)return Number(this.takeChars());for(var c=this.takeChars(a);a--;)c[a]=Number(c[a]);return c},takeString:function(){var a=Number(this.takeChars()),c=0,b;if("-"!=this._str.charAt(0))return!1;for(;0<a;)++c,b=this._str.charCodeAt(c),
128>b?--a:a=2048>b?a-2:a-3;a=this._str.substr(1,c);this._str=this._str.substr(1+c).replace(/^\s+/,"");return a}});var DotEntity=DotUtils.createClass({initialize:function(a,c,b,d,e,f){this._defaultAttrHashName=a;this._name=c;this._dot=b;this._rootGraph=d;this._parentGraph=e;this._immediateGraph=f;this._attrs={};this._drawAttrs={}},_initBB:function(){var a=this.getAttr("pos").match(/([0-9.]+),([0-9.]+)/),c=Math.round(a[1]),a=Math.round(this._dot._height-a[2]);this._bbRect=new Rect(c,a,c,a)},getAttr:function(a,c){"undefined"===typeof escStrinng&&(c=!1);var b=this._attrs[a];if("undefined"===typeof b)for(var d=this._parentGraph;"undefined"!==
typeof d;)if(b=d[this._defaultAttrHashName][a],"undefined"===typeof b)d=d._parentGraph;else break;b&&c&&(b=b.replace(this._escStringMatchRe,function(a,b){switch(b){case "N":case "E":return this._name;case "T":return this._tailNode;case "H":return this._headNode;case "G":return this._immediateGraph._name;case "L":return this.getAttr("label",!0)}return a}.bind(this)));return b},_draw:function(a,c){var b,d,e,f=12;this._initBB();for(daKey in this._drawAttrs){var g=new DotTokenizer(this._drawAttrs[daKey]);
if(b=g.takeChars()){var h="solid";for(a.save();b;){switch(b){case "E":case "e":var i="E"==b,j=g.takeNumber();b=this._dot._height-g.takeNumber();d=g.takeNumber();var m=g.takeNumber(),j=new Ellipse(j,b,d,m);break;case "P":case "p":case "L":var i="P"==b,m="L"!=b,l=g.takeNumber();d=g.takeNumber(2*l);j=new Path;for(b=2;b<2*l;b+=2)j.addBezier([new Point(d[b-2],this._dot._height-d[b-1]),new Point(d[b],this._dot._height-d[b+1])]);m&&j.addBezier([new Point(d[2*l-2],this._dot._height-d[2*l-1]),new Point(d[0],
this._dot._height-d[1])]);break;case "B":case "b":i="b"==b;l=g.takeNumber();d=g.takeNumber(2*l);j=new Path;for(b=2;b<2*l;b+=6)j.addBezier([new Point(d[b-2],this._dot._height-d[b-1]),new Point(d[b],this._dot._height-d[b+1]),new Point(d[b+2],this._dot._height-d[b+3]),new Point(d[b+4],this._dot._height-d[b+5])]);break;case "I":b=g.takeNumber();d=this._dot._height-g.takeNumber();var m=g.takeNumber(),l=g.takeNumber(),k=g.takeString();this._dot._images[k]||(this._dot._images[k]=new DotImage(this._dot,k));
this._dot._images[k].draw(a,b,d-l,m,l);break;case "T":b=Math.round(g.takeNumber());d=Math.round(this._dot._height-g.takeNumber());m=g.takeNumber();Math.round(c*g.takeNumber());l=g.takeString();if(!/^\s*$/.test(l)){l=DotUtils.escapeHtml(l);do if(matches=l.match(/ ( +)/)){var n=" ";matches[1].length.times(function(){n+=" "});l=l.replace(/ +/,n)}while(matches);a.font="normal normal normal "+f+"px "+fontFamily;a.textAlign=-1==m?"left":1==m?"right":"center";a.fillStyle=e.textColor;a.fillText(l,b,
d)}break;case "C":case "c":b="C"==b;d=this._parseColor(g.takeString());b?a.fillStyle=d.canvasColor:(e=d,a.strokeStyle=d.canvasColor);break;case "F":f=g.takeNumber();fontFamily=g.takeString();switch(fontFamily){case "Times-Roman":fontFamily="Times New Roman";break;case "Courier":fontFamily="Courier New";break;case "Helvetica":fontFamily="Arial"}break;case "S":b=g.takeString();switch(b){case "solid":case "filled":break;case "dashed":case "dotted":h=b;break;case "bold":a.lineWidth=2;break;default:(matches=
b.match(/^setlinewidth\((.*)\)$/))?a.lineWidth=Number(matches[1]):debug("unknown style "+b)}break;default:debug("unknown token "+b);return}j&&(this._dot._drawPath(a,j,i,h),this._bbRect.expandToInclude(j.getBB()),j=void 0);b=g.takeChars()}a.restore()}}},_parseColor:function(a){var c={opacity:1};if(/^#(?:[0-9a-f]{2}\s*){3,4}$/i.test(a))return this._dot._parseHexColor(a);var b=a.match(/^(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)$/);if(b)return c.canvasColor=c.textColor=this._dot._hsvToRgbColor(b[1],
b[2],b[3]),c;var d=this.getAttr("colorscheme")||"X11",e=a;if(b=a.match(/^\/(.*)\/(.*)$/))b[1]&&(d=b[1]),e=b[2];else if(b=a.match(/^\/(.*)$/))d="X11",e=b[1];e=e.toLowerCase();b=d.toLowerCase();if(b=Dot.prototype.colors[b]){var f=b[e];if(f)return this._dot._parseHexColor("#"+f)}if(f=Dot.prototype.colors.fallback[e])return this._dot._parseHexColor("#"+f);b||debug("unknown color scheme "+d);debug("unknown color "+a+"; color scheme is "+d);c.canvasColor=c.textColor="#000000";return c}});var DotNode=DotUtils.createClass(DotEntity,{initialize:function($super,c,b,d,e){$super("_nodeAttrs",c,b,d,e,e)}});DotNode.prototype.escStringMatchRe=/\\([NGL])/g;var DotEdge=DotUtils.createClass(DotEntity,{initialize:function($super,c,b,d,e,f,g){$super("_edgeAttrs",c,b,d,e,e);this._tailNode=f;this._headNode=g}});DotEdge.prototype._escStringMatchRe=/\\([EGTHL])/g;var DotGraph=DotUtils.createClass(DotEntity,{initialize:function($super,c,b,d,e){$super("_attrs",c,b,d,e,this);this._nodeAttrs={};this._edgeAttrs={};this._nodes=[];this._edges=[];this._subgraphs=[]},_initBB:function(){var a=this.getAttr("bb").split(",");this._bbRect=new Rect(a[0],this._dot._height-a[1],a[2],this._dot._height-a[3])},_draw:function($super,c,b){$super(c,b);for(var d=[this._subgraphs,this._nodes,this._edges],e=0,f=d.length;e<f;++e)for(var g=d[e],h=0,i=g.length;h<i;++h)g[h]._draw(c,b)}});
DotGraph.prototype.escStringMatchRe=/\\([GL])/g;var DotImage=DotUtils.createClass({initialize:function(a,c){this._dot=a;++this._dot.numImages;this._finished=this._loaded=!1;this._img=new Image;this._img.onload=this._onLoad.bind(this);this._img.onerror=this._onFinish.bind(this);this._img.onabort=this._onFinish.bind(this);this._img.src=this._dot.imagePath+c},_onLoad:function(){this._loaded=!0;this.onFinish()},_onFinish:function(){this._finished=!0;++this._dot._numImagesFinished;this._dot._numImages==this._dot._numImagesFinished&&this._dot._draw(!0)},
_draw:function(a,c,b,d,e){this._finished&&(this._loaded?a.drawImage(this._img,c,b,d,e):(debug("can't load image "+this._img.src),this._drawBrokenImage(a,c,b,d,e)))},_drawBrokenImage:function(a,c,b,d,e){a.save();a.beginPath();(new Rect(c,b,c+d,b+d)).draw(a);a.moveTo(c,b);a.lineTo(c+d,b+d);a.moveTo(c+d,b);a.lineTo(c,b+e);a.strokeStyle="#f00";a.lineWidth=1;a.stroke();a.restore()}});var Point=DotUtils.createClass({initialize:function(a,c){this.x=a;this.y=c},offset:function(a,c){this.x+=a;this.y+=c},distanceFrom:function(a){var c=this.x-a.x,a=this.y-a.y;return Math.sqrt(c*c+a*a)},makePath:function(a){a.moveTo(this.x,this.y);a.lineTo(this.x+0.001,this.y)}});var Bezier=DotUtils.createClass({initialize:function(a){this.points=a;this.order=a.length},pathCommands:[null,function(a,c){this.lineTo(a+0.001,c)},function(a,c){this.lineTo(a,c)},function(a,c,b,d){this.quadraticCurveTo(a,c,b,d)},function(a,c,b,d,e,f){this.bezierCurveTo(a,c,b,d,e,f)}],reset:function(){var a=Bezier.prototype;this.controlPolygonLength=a.controlPolygonLength;this.chordLength=a.chordLength;this.triangle=a.triangle;this.chordPoints=a.chordPoints;this.coefficients=a.coefficients},offset:function(a,
c){for(var b=0,d=this.points.length;b<d;++b)this.points[b].offset(a,c);this.reset()},getBB:function(){var h;if(this.order){var a,c,b,d;c=this.points[0];a=b=c.x;h=d=c.y,c=h;var e=0;for(a=this.points.length;e<a;++e){var f=this.points[e];a=Math.min(a,f.x);c=Math.min(c,f.y);b=Math.max(b,f.x);d=Math.max(d,f.y)}var g=new Rect(a,c,b,d);return(this.getBB=function(){return g})()}},isPointInBB:function(a,c,b){"undefined"===typeof b&&(b=0);var d=this.getBB();0<b&&(d=DotUtils.extend({},d),d.inset(-b,-b));return!(a<
d.l||a>d.r||c<d.t||c>d.b)},isPointOnBezier:function(a,c,b){"undefined"===typeof b&&(b=0);if(!this.isPointInBB(a,c,b))return!1;for(var d=this.chordPoints(),e=d[0].p,f,g,h,i,j,m,l=1;l<d.length;++l){f=d[l].p;g=e.x;h=e.y;i=f.x;j=f.y;m=new Rect(g,h,i,j);if(m.isPointInBB(a,c,b)&&(g=Math.abs(g*j+i*c+a*h-i*h-a*j-g*c),e=e.distanceFrom(f),e=g/e,e<=b))return!0;e=f}return!1},controlPolygonLength:function(){for(var a=0,c=1;c<this.order;++c)a+=this.points[c-1].distanceFrom(this.points[c]);return(this.controlPolygonLength=
function(){return a})()},chordLength:function(){var a=this.points[0].distanceFrom(this.points[this.order-1]);return(this.chordLength=function(){return a})()},triangle:function(){for(var a=this.points,c=[a],b=1;b<this.order;++b){for(var d=[],e=0;e<this.order-b;++e){var f=a[e],g=a[e+1];d[e]=new Point((f.x+g.x)/2,(f.y+g.y)/2)}c.push(d);a=d}return(this.triangle=function(){return c})()},triangleAtT:function(a){for(var c=1-a,b=this.points,d=[b],e=1;e<this.order;++e){for(var f=[],g=0;g<this.order-e;++g){var h=
b[g],i=b[g+1];f[g]=new Point(h.x*c+i.x*a,h.y*c+i.y*a)}d.push(f);b=f}return d},split:function(a){"undefined"==typeof a&&(a=0.5);for(var a=0.5==a?this.triangle():this.triangleAtT(a),c=Array(this.order),b=Array(this.order),d=0;d<this.order;++d)c[d]=a[d][0],b[d]=a[this.order-1-d][d];return{left:new Bezier(c),right:new Bezier(b)}},mid:function(a,c){return this.split(c).left.split(a/c).right},chordPoints:function(){var a=[{tStart:0,tEnd:0,dt:0,p:this.points[0]}].concat(this._chordPoints(0,1));return(this.chordPoints=
function(){return a})()},_chordPoints:function(a,c){var b=c-a;if(this.controlPolygonLength()<=1.001*this.chordLength())return[{tStart:a,tEnd:c,dt:b,p:this.points[this.order-1]}];var b=a+b/2,d=this.split();return d.left._chordPoints(a,b).concat(d.right._chordPoints(b,c))},markedEvery:function(a,c){for(var b=c||a,d=this.chordPoints(),e=[],f=0,g,h,i=1;i<d.length;++i)if(h=d[i],h.length=h.p.distanceFrom(d[i-1].p),0==h.length)f+=h.dt;else{g=b/h.length*h.dt;for(h.remainingLength=h.length;h.remainingLength>=
b;)h.remainingLength-=b,f+=g,e.push(f),a!=b&&(b=a,g=b/h.length*h.dt);b-=h.remainingLength;f=h.tEnd}return{times:e,nextDistance:b}},coefficients:function(){function a(a){for(;1<a.length;){for(var b=Array(a.length-1),c=0;c<a.length-1;++c){var d=b,e=c,f=a[c],k=a[c+1];f.push(0);var n=Array(f.length);n[0]=f[0];for(var o=0;o<k.length;++o)n[o+1]=f[o+1]+k[o]-f[o];d[e]=n}a=b}return a[0]}for(var c=[],b=[],d=0,e;e=this.points[d++];)c.push([e.x]),b.push([e.y]);var f={xs:a(c),ys:a(b)};return(this.coefficients=
function(){return f})()},pointAtT:function(a){for(var c=this.coefficients(),b=c.xs,c=c.ys,d=b[b.length-1],e=c[c.length-1],f=b.length-1;0<=--f;)d=d*a+b[f],e=e*a+c[f];return new Point(d,e)},makePath:function(a,c){"undefined"==typeof c&&(c=!0);c&&a.moveTo(this.points[0].x,this.points[0].y);var b=this.pathCommands[this.order];if(b){for(var d=[],e=1==this.order?0:1;e<this.points.length;++e)d.push(this.points[e].x),d.push(this.points[e].y);b.apply(a,d)}},makeDashedPath:function(a,c,b,d){b||(b=c);"undefined"==
typeof d&&(d=!0);c=this.markedEvery(c,b);d&&c.times.unshift(0);(d=c.times.length%2)&&c.times.push(1);for(b=1;b<c.times.length;b+=2)this.mid(c.times[b-1],c.times[b]).makePath(a);return{firstDistance:c.nextDistance,drawFirst:d}},makeDottedPath:function(a,c,b){b||(b=c);var d=this.markedEvery(c,b);c==b&&d.times.unshift(0);c=0;for(b=d.times.length;c<b;++c)this.pointAtT(d.times[c]).makePath(a);return d.nextDistance}});var Path=DotUtils.createClass({initialize:function(a){this.segments=a||[]},setupSegments:function(){},addBezier:function(a){this.segments.push(a instanceof Array?new Bezier(a):a)},offset:function(a,c){0==this.segments.length&&this.setupSegments();for(var b=0,d=this.segments.length;b<d;++b)this.segments[b].offset(a,c)},getBB:function(){var k;0==this.segments.length&&this.setupSegments();var a,c,b,d;c=this.segments[0].points[0];a=b=c.x;k=d=c.y,c=k;for(var e=0,f=this.segments.length;e<f;++e)for(var g=
this.segments[e].points,h=0,i=g.length;h<i;++h){var j=g[h];a=Math.min(a,j.x);c=Math.min(c,j.y);b=Math.max(b,j.x);d=Math.max(d,j.y)}var m=new Rect(a,c,b,d);return(this.getBB=function(){return m})()},isPointInBB:function(a,c,b){"undefined"===typeof b&&(b=0);var d=this.getBB();0<b&&(d=DotUtils.extend({},d),d.inset(-b,-b));return!(a<d.l||a>d.r||c<d.t||c>d.b)},isPointOnPath:function(a,c,b){"undefined"===typeof b&&(b=0);if(!this.isPointInBB(a,c,b))return!1;for(var d=0,e=this.segments.length;d<e;++d)if(this.segments[d].isPointOnBezier(a,
c,b))throw $break;return!1},isPointInPath:function(){return!1},makePath:function(a){0==this.segments.length&&this.setupSegments();for(var c=!0,b=0,d=this.segments.length;b<d;++b)this.segments[b].makePath(a,c),c=!1},makeDashedPath:function(a,c,b,d){0==this.segments.length&&this.setupSegments();for(var b={drawFirst:"undefined"==typeof d?!0:d,firstDistance:b||c},d=0,e=this.segments.length;d<e;++d)b=this.segments[d].makeDashedPath(a,c,b.firstDistance,b.drawFirst)},makeDottedPath:function(a,c,b){0==this.segments.length&&
this.setupSegments();b||(b=c);for(var d=0,e=this.segments.length;d<e;++d)b=this.segments[d].makeDottedPath(a,c,b)}});var Polygon=DotUtils.createClass(Path,{initialize:function($super,c){this.points=c||[];$super()},setupSegments:function(){for(var a=0,c=this.points.length;a<c;++a){var b=a+1;c==b&&(b=0);this.addBezier([this.points[a],this.points[b]])}}});var Rect=DotUtils.createClass(Polygon,{initialize:function($super,c,b,d,e){this.l=c;this.t=b;this.r=d;this.b=e;$super()},inset:function(a,c){this.l+=a;this.t+=c;this.r-=a;this.b-=c;return this},expandToInclude:function(a){this.l=Math.min(this.l,a.l);this.t=Math.min(this.t,a.t);this.r=Math.max(this.r,a.r);this.b=Math.max(this.b,a.b)},getWidth:function(){return this.r-this.l},getHeight:function(){return this.b-this.t},setupSegments:function($super){var c=this.getWidth(),b=this.getHeight();this.points=
[new Point(this.l,this.t),new Point(this.l+c,this.t),new Point(this.l+c,this.t+b),new Point(this.l,this.t+b)];$super()}});var Ellipse=DotUtils.createClass(Path,{KAPPA:0.5522847498,initialize:function($super,c,b,d,e){this.cx=c;this.cy=b;this.rx=d;this.ry=e;$super()},setupSegments:function(){this.addBezier([new Point(this.cx,this.cy-this.ry),new Point(this.cx+this.KAPPA*this.rx,this.cy-this.ry),new Point(this.cx+this.rx,this.cy-this.KAPPA*this.ry),new Point(this.cx+this.rx,this.cy)]);this.addBezier([new Point(this.cx+this.rx,this.cy),new Point(this.cx+this.rx,this.cy+this.KAPPA*this.ry),new Point(this.cx+this.KAPPA*this.rx,
this.cy+this.ry),new Point(this.cx,this.cy+this.ry)]);this.addBezier([new Point(this.cx,this.cy+this.ry),new Point(this.cx-this.KAPPA*this.rx,this.cy+this.ry),new Point(this.cx-this.rx,this.cy+this.KAPPA*this.ry),new Point(this.cx-this.rx,this.cy)]);this.addBezier([new Point(this.cx-this.rx,this.cy),new Point(this.cx-this.rx,this.cy-this.KAPPA*this.ry),new Point(this.cx-this.KAPPA*this.rx,this.cy-this.ry),new Point(this.cx,this.cy-this.ry)])}});