//>>built
define("dojox/gfx/canvas","./_base,dojo/_base/lang,dojo/_base/array,dojo/_base/declare,dojo/_base/window,dojo/dom-geometry,dojo/dom,./_base,./shape,./path,./arc,./matrix,./decompose".split(","),function(g,p,v,e,t,y,z,k,f,q,w,r){var d=g.canvas={},m=null,h=r.multiplyPoint,s=Math.PI,A=2*s,u=s/2,k=p.extend;d.Shape=e("dojox.gfx.canvas.Shape",f.Shape,{_render:function(b){b.save();this._renderTransform(b);this._renderClip(b);this._renderShape(b);this._renderFill(b,!0);this._renderStroke(b,!0);b.restore()},
_renderClip:function(b){this.canvasClip&&(this.canvasClip.render(b),b.clip())},_renderTransform:function(b){if("canvasTransform"in this){var a=this.canvasTransform;b.translate(a.dx,a.dy);b.rotate(a.angle2);b.scale(a.sx,a.sy);b.rotate(a.angle1)}},_renderShape:function(){},_renderFill:function(b,a){if("canvasFill"in this){var c=this.fillStyle;if("canvasFillImage"in this){var i=c.width,d=c.height,j=this.canvasFillImage.width,e=this.canvasFillImage.height,f=Math.min(i==j?1:i/j,d==e?1:d/e),g=(i-f*j)/2,
k=(d-f*e)/2;m.width=i;m.height=d;var h=m.getContext("2d");h.clearRect(0,0,i,d);h.drawImage(this.canvasFillImage,0,0,j,e,g,k,f*j,f*e);this.canvasFill=b.createPattern(m,"repeat");delete this.canvasFillImage}b.fillStyle=this.canvasFill;a&&("pattern"===c.type&&(0!==c.x||0!==c.y)&&b.translate(c.x,c.y),b.fill())}else b.fillStyle="rgba(0,0,0,0.0)"},_renderStroke:function(b,a){var c=this.strokeStyle;if(c)b.strokeStyle=c.color.toString(),b.lineWidth=c.width,b.lineCap=c.cap,"number"==typeof c.join?(b.lineJoin=
"miter",b.miterLimit=c.join):b.lineJoin=c.join,a&&b.stroke();else if(!a)b.strokeStyle="rgba(0,0,0,0.0)"},getEventSource:function(){return null},connect:function(){},disconnect:function(){},canvasClip:null,setClip:function(b){this.inherited(arguments);var a=b?"width"in b?"rect":"cx"in b?"ellipse":"points"in b?"polyline":"d"in b?"path":null:null;if(b&&!a)return this;this.canvasClip=b?B(a,b):null;this.surface.makeDirty();return this}});var B=function(b,a){switch(b){case "ellipse":return{canvasEllipse:x(a),
render:function(a){return d.Ellipse.prototype._renderShape.call(this,a)}};case "rect":return{shape:p.delegate(a,{r:0}),render:function(a){return d.Rect.prototype._renderShape.call(this,a)}};case "path":return{canvasPath:C(a),render:function(a){this.canvasPath._renderShape(a)}};case "polyline":return{canvasPolyline:a.points,render:function(a){return d.Polyline.prototype._renderShape.call(this,a)}}}return null},C=function(b){var a=new dojox.gfx.canvas.Path;a.canvasPath=[];a._setPath(b.d);return a},
n=function(b,a,c){var i=b.prototype[a];b.prototype[a]=c?function(){this.surface.makeDirty();i.apply(this,arguments);c.call(this);return this}:function(){this.surface.makeDirty();return i.apply(this,arguments)}};n(d.Shape,"setTransform",function(){this.matrix?this.canvasTransform=g.decompose(this.matrix):delete this.canvasTransform});n(d.Shape,"setFill",function(){var b=this.fillStyle,a;if(b){if("object"==typeof b&&"type"in b){var c=this.surface.rawNode.getContext("2d");switch(b.type){case "linear":case "radial":a=
"linear"==b.type?c.createLinearGradient(b.x1,b.y1,b.x2,b.y2):c.createRadialGradient(b.cx,b.cy,0,b.cx,b.cy,b.r);v.forEach(b.colors,function(b){a.addColorStop(b.offset,g.normalizeColor(b.color).toString())});break;case "pattern":m||(m=document.createElement("canvas")),c=new Image,this.surface.downloadImage(c,b.src),this.canvasFillImage=c}}else a=b.toString();this.canvasFill=a}else delete this.canvasFill});n(d.Shape,"setStroke");n(d.Shape,"setShape");d.Group=e("dojox.gfx.canvas.Group",d.Shape,{constructor:function(){f.Container._init.call(this)},
_render:function(b){b.save();this._renderTransform(b);this._renderClip(b);for(var a=0;a<this.children.length;++a)this.children[a]._render(b);b.restore()},destroy:function(){this.clear(!0);d.Shape.prototype.destroy.apply(this,arguments)}});d.Rect=e("dojox.gfx.canvas.Rect",[d.Shape,f.Rect],{_renderShape:function(b){var a=this.shape,c=Math.min(a.r,a.height/2,a.width/2),i=a.x,d=i+a.width,j=a.y,a=j+a.height,e=i+c,f=d-c,g=j+c,h=a-c;b.beginPath();b.moveTo(e,j);c?(b.arc(f,g,c,-u,0,!1),b.arc(f,h,c,0,u,!1),
b.arc(e,h,c,u,s,!1),b.arc(e,g,c,s,s+u,!1)):(b.lineTo(f,j),b.lineTo(d,h),b.lineTo(e,a),b.lineTo(i,g));b.closePath()}});var l=[];(function(){var b=w.curvePI4;l.push(b.s,b.c1,b.c2,b.e);for(var a=45;360>a;a+=45){var c=r.rotateg(a);l.push(h(c,b.c1),h(c,b.c2),h(c,b.e))}})();var x=function(b){var a,c,d=[],e=r.normalize([r.translate(b.cx,b.cy),r.scale(b.rx,b.ry)]),b=h(e,l[0]);d.push([b.x,b.y]);for(var f=1;f<l.length;f+=3)a=h(e,l[f]),c=h(e,l[f+1]),b=h(e,l[f+2]),d.push([a.x,a.y,c.x,c.y,b.x,b.y]);return d};
d.Ellipse=e("dojox.gfx.canvas.Ellipse",[d.Shape,f.Ellipse],{setShape:function(){this.inherited(arguments);this.canvasEllipse=x(this.shape);return this},_renderShape:function(b){var a=this.canvasEllipse;b.beginPath();b.moveTo.apply(b,a[0]);for(var c=1;c<a.length;++c)b.bezierCurveTo.apply(b,a[c]);b.closePath()}});d.Circle=e("dojox.gfx.canvas.Circle",[d.Shape,f.Circle],{_renderShape:function(b){var a=this.shape;b.beginPath();b.arc(a.cx,a.cy,a.r,0,A,1)}});d.Line=e("dojox.gfx.canvas.Line",[d.Shape,f.Line],
{_renderShape:function(b){var a=this.shape;b.beginPath();b.moveTo(a.x1,a.y1);b.lineTo(a.x2,a.y2)}});d.Polyline=e("dojox.gfx.canvas.Polyline",[d.Shape,f.Polyline],{setShape:function(){this.inherited(arguments);var b=this.shape.points,a=b[0],c,d;this.bbox=null;this._normalizePoints();if(b.length)if("number"==typeof a)a=b;else{a=[];for(d=0;d<b.length;++d)c=b[d],a.push(c.x,c.y)}else a=[];this.canvasPolyline=a;return this},_renderShape:function(b){var a=this.canvasPolyline;if(a.length){b.beginPath();b.moveTo(a[0],
a[1]);for(var c=2;c<a.length;c+=2)b.lineTo(a[c],a[c+1])}}});d.Image=e("dojox.gfx.canvas.Image",[d.Shape,f.Image],{setShape:function(){this.inherited(arguments);var b=new Image;this.surface.downloadImage(b,this.shape.src);this.canvasImage=b;return this},_renderShape:function(b){var a=this.shape;b.drawImage(this.canvasImage,a.x,a.y,a.width,a.height)}});d.Text=e("dojox.gfx.canvas.Text",[d.Shape,f.Text],{_setFont:function(){this.fontStyle?this.canvasFont=g.makeFontString(this.fontStyle):delete this.canvasFont},
getTextWidth:function(){var b=this.shape,a=0,c;if(b.text&&0<b.text.length){c=this.surface.rawNode.getContext("2d");c.save();this._renderTransform(c);this._renderFill(c,!1);this._renderStroke(c,!1);if(this.canvasFont)c.font=this.canvasFont;a=c.measureText(b.text).width;c.restore()}return a},_render:function(b){b.save();this._renderTransform(b);this._renderFill(b,!1);this._renderStroke(b,!1);this._renderShape(b);b.restore()},_renderShape:function(b){var a=this.shape;if(a.text&&0!=a.text.length){b.textAlign=
"middle"===a.align?"center":a.align;if(this.canvasFont)b.font=this.canvasFont;this.canvasFill&&b.fillText(a.text,a.x,a.y);this.strokeStyle&&(b.beginPath(),b.strokeText(a.text,a.x,a.y),b.closePath())}}});n(d.Text,"setFont");t.global.CanvasRenderingContext2D&&(t=t.doc.createElement("canvas").getContext("2d"))&&"function"!=typeof t.fillText&&d.Text.extend({getTextWidth:function(){return 0},_renderShape:function(){}});var D={M:"_moveToA",m:"_moveToR",L:"_lineToA",l:"_lineToR",H:"_hLineToA",h:"_hLineToR",
V:"_vLineToA",v:"_vLineToR",C:"_curveToA",c:"_curveToR",S:"_smoothCurveToA",s:"_smoothCurveToR",Q:"_qCurveToA",q:"_qCurveToR",T:"_qSmoothCurveToA",t:"_qSmoothCurveToR",A:"_arcTo",a:"_arcTo",Z:"_closePath",z:"_closePath"};d.Path=e("dojox.gfx.canvas.Path",[d.Shape,q.Path],{constructor:function(){this.lastControl={}},setShape:function(){this.canvasPath=[];return this.inherited(arguments)},_updateWithSegment:function(b){var a=p.clone(this.last);this[D[b.action]](this.canvasPath,b.action,b.args);this.last=
a;this.inherited(arguments)},_renderShape:function(b){var a=this.canvasPath;b.beginPath();for(var c=0;c<a.length;c+=2)b[a[c]].apply(b,a[c+1])},_moveToA:function(b,a,c){b.push("moveTo",[c[0],c[1]]);for(a=2;a<c.length;a+=2)b.push("lineTo",[c[a],c[a+1]]);this.last.x=c[c.length-2];this.last.y=c[c.length-1];this.lastControl={}},_moveToR:function(b,a,c){"x"in this.last?b.push("moveTo",[this.last.x+=c[0],this.last.y+=c[1]]):b.push("moveTo",[this.last.x=c[0],this.last.y=c[1]]);for(a=2;a<c.length;a+=2)b.push("lineTo",
[this.last.x+=c[a],this.last.y+=c[a+1]]);this.lastControl={}},_lineToA:function(b,a,c){for(a=0;a<c.length;a+=2)b.push("lineTo",[c[a],c[a+1]]);this.last.x=c[c.length-2];this.last.y=c[c.length-1];this.lastControl={}},_lineToR:function(b,a,c){for(a=0;a<c.length;a+=2)b.push("lineTo",[this.last.x+=c[a],this.last.y+=c[a+1]]);this.lastControl={}},_hLineToA:function(b,a,c){for(a=0;a<c.length;++a)b.push("lineTo",[c[a],this.last.y]);this.last.x=c[c.length-1];this.lastControl={}},_hLineToR:function(b,a,c){for(a=
0;a<c.length;++a)b.push("lineTo",[this.last.x+=c[a],this.last.y]);this.lastControl={}},_vLineToA:function(b,a,c){for(a=0;a<c.length;++a)b.push("lineTo",[this.last.x,c[a]]);this.last.y=c[c.length-1];this.lastControl={}},_vLineToR:function(b,a,c){for(a=0;a<c.length;++a)b.push("lineTo",[this.last.x,this.last.y+=c[a]]);this.lastControl={}},_curveToA:function(b,a,c){for(a=0;a<c.length;a+=6)b.push("bezierCurveTo",c.slice(a,a+6));this.last.x=c[c.length-2];this.last.y=c[c.length-1];this.lastControl.x=c[c.length-
4];this.lastControl.y=c[c.length-3];this.lastControl.type="C"},_curveToR:function(b,a,c){for(a=0;a<c.length;a+=6)b.push("bezierCurveTo",[this.last.x+c[a],this.last.y+c[a+1],this.lastControl.x=this.last.x+c[a+2],this.lastControl.y=this.last.y+c[a+3],this.last.x+c[a+4],this.last.y+c[a+5]]),this.last.x+=c[a+4],this.last.y+=c[a+5];this.lastControl.type="C"},_smoothCurveToA:function(b,a,c){for(a=0;a<c.length;a+=4){var d="C"==this.lastControl.type;b.push("bezierCurveTo",[d?2*this.last.x-this.lastControl.x:
this.last.x,d?2*this.last.y-this.lastControl.y:this.last.y,c[a],c[a+1],c[a+2],c[a+3]]);this.lastControl.x=c[a];this.lastControl.y=c[a+1];this.lastControl.type="C"}this.last.x=c[c.length-2];this.last.y=c[c.length-1]},_smoothCurveToR:function(b,a,c){for(a=0;a<c.length;a+=4){var d="C"==this.lastControl.type;b.push("bezierCurveTo",[d?2*this.last.x-this.lastControl.x:this.last.x,d?2*this.last.y-this.lastControl.y:this.last.y,this.last.x+c[a],this.last.y+c[a+1],this.last.x+c[a+2],this.last.y+c[a+3]]);this.lastControl.x=
this.last.x+c[a];this.lastControl.y=this.last.y+c[a+1];this.lastControl.type="C";this.last.x+=c[a+2];this.last.y+=c[a+3]}},_qCurveToA:function(b,a,c){for(a=0;a<c.length;a+=4)b.push("quadraticCurveTo",c.slice(a,a+4));this.last.x=c[c.length-2];this.last.y=c[c.length-1];this.lastControl.x=c[c.length-4];this.lastControl.y=c[c.length-3];this.lastControl.type="Q"},_qCurveToR:function(b,a,c){for(a=0;a<c.length;a+=4)b.push("quadraticCurveTo",[this.lastControl.x=this.last.x+c[a],this.lastControl.y=this.last.y+
c[a+1],this.last.x+c[a+2],this.last.y+c[a+3]]),this.last.x+=c[a+2],this.last.y+=c[a+3];this.lastControl.type="Q"},_qSmoothCurveToA:function(b,a,c){for(a=0;a<c.length;a+=2){var d="Q"==this.lastControl.type;b.push("quadraticCurveTo",[this.lastControl.x=d?2*this.last.x-this.lastControl.x:this.last.x,this.lastControl.y=d?2*this.last.y-this.lastControl.y:this.last.y,c[a],c[a+1]]);this.lastControl.type="Q"}this.last.x=c[c.length-2];this.last.y=c[c.length-1]},_qSmoothCurveToR:function(b,a,c){for(a=0;a<c.length;a+=
2){var d="Q"==this.lastControl.type;b.push("quadraticCurveTo",[this.lastControl.x=d?2*this.last.x-this.lastControl.x:this.last.x,this.lastControl.y=d?2*this.last.y-this.lastControl.y:this.last.y,this.last.x+c[a],this.last.y+c[a+1]]);this.lastControl.type="Q";this.last.x+=c[a];this.last.y+=c[a+1]}},_arcTo:function(b,a,c){for(var a="a"==a,d=0;d<c.length;d+=7){var e=c[d+5],f=c[d+6];a&&(e+=this.last.x,f+=this.last.y);var g=w.arcAsBezier(this.last,c[d],c[d+1],c[d+2],c[d+3]?1:0,c[d+4]?1:0,e,f);v.forEach(g,
function(a){b.push("bezierCurveTo",a)});this.last.x=e;this.last.y=f}this.lastControl={}},_closePath:function(b){b.push("closePath",[]);this.lastControl={}}});v.forEach("moveTo,lineTo,hLineTo,vLineTo,curveTo,smoothCurveTo,qCurveTo,qSmoothCurveTo,arcTo,closePath".split(","),function(b){n(d.Path,b)});d.TextPath=e("dojox.gfx.canvas.TextPath",[d.Shape,q.TextPath],{_renderShape:function(){},_setText:function(){},_setFont:function(){}});d.Surface=e("dojox.gfx.canvas.Surface",f.Surface,{constructor:function(){f.Container._init.call(this);
this.pendingImageCount=0;this.makeDirty()},destroy:function(){f.Container.clear.call(this,!0);this.inherited(arguments)},setDimensions:function(b,a){this.width=g.normalizedLength(b);this.height=g.normalizedLength(a);if(!this.rawNode)return this;var c=!1;if(this.rawNode.width!=this.width)this.rawNode.width=this.width,c=!0;if(this.rawNode.height!=this.height)this.rawNode.height=this.height,c=!0;c&&this.makeDirty();return this},getDimensions:function(){return this.rawNode?{width:this.rawNode.width,height:this.rawNode.height}:
null},_render:function(b){if(this.rawNode&&(b||!this.pendingImageCount))b=this.rawNode.getContext("2d"),b.clearRect(0,0,this.rawNode.width,this.rawNode.height),this.render(b),"pendingRender"in this&&(clearTimeout(this.pendingRender),delete this.pendingRender)},render:function(b){b.save();for(var a=0;a<this.children.length;++a)this.children[a]._render(b);b.restore()},makeDirty:function(){if(!this.pendingImagesCount&&!("pendingRender"in this))this.pendingRender=setTimeout(p.hitch(this,this._render),
0)},downloadImage:function(b,a){var c=p.hitch(this,this.onImageLoad);!this.pendingImageCount++&&"pendingRender"in this&&(clearTimeout(this.pendingRender),delete this.pendingRender);b.onload=c;b.onerror=c;b.onabort=c;b.src=a},onImageLoad:function(){--this.pendingImageCount||(this.onImagesLoaded(),this._render())},onImagesLoaded:function(){},getEventSource:function(){return null},connect:function(){},disconnect:function(){}});d.createSurface=function(b,a,c){if(!a&&!c)var e=y.position(b),a=a||e.w,c=
c||e.h;"number"==typeof a&&(a+="px");"number"==typeof c&&(c+="px");var e=new d.Surface,b=z.byId(b),f=b.ownerDocument.createElement("canvas");f.width=g.normalizedLength(a);f.height=g.normalizedLength(c);b.appendChild(f);e.rawNode=f;e._parent=b;return e.surface=e};var o=f.Container,e={add:function(b){this.surface.makeDirty();return o.add.apply(this,arguments)},remove:function(b,a){this.surface.makeDirty();return o.remove.apply(this,arguments)},clear:function(){this.surface.makeDirty();return o.clear.apply(this,
arguments)},getBoundingBox:o.getBoundingBox,_moveChildToFront:function(b){this.surface.makeDirty();return o._moveChildToFront.apply(this,arguments)},_moveChildToBack:function(b){this.surface.makeDirty();return o._moveChildToBack.apply(this,arguments)}},q={createObject:function(b,a){var c=new b;c.surface=this.surface;c.setShape(a);this.add(c);return c}};k(d.Group,e);k(d.Group,f.Creator);k(d.Group,q);k(d.Surface,e);k(d.Surface,f.Creator);k(d.Surface,q);d.fixTarget=function(){return!0};return d});