/* YUI 3.17.2 (build 9c3c78e) Copyright 2014 Yahoo! Inc. All rights reserved. Licensed under the BSD License. http://yuilibrary.com/license/ */ YUI.add("graphics-canvas",function(e,t){function T(){}function N(){N.superclass.constructor.apply(this,arguments)}var n="canvas",r="shape",i=/[a-z][^a-z]*/ig,s=/[\-]?[0-9]*[0-9|\.][0-9]*/g,o=e.config.doc,u=e.Lang,a=e.AttributeLite,f,l,c,h,p,d,v=e.DOM,m=e.Color,g=parseInt,y=parseFloat,b=u.isNumber,w=RegExp,E=m.toRGB,S=m.toHex,x=e.ClassNameManager.getClassName;T.prototype={_pathSymbolToMethod:{M:"moveTo",m:"relativeMoveTo",L:"lineTo",l:"relativeLineTo",C:"curveTo",c:"relativeCurveTo",Q:"quadraticCurveTo",q:"relativeQuadraticCurveTo",z:"closePath",Z:"closePath"},_currentX:0,_currentY:0,_toRGBA:function(e,t){return t=t!==undefined?t:1,m.re_RGB.test(e)||(e=S(e)),m.re_hex.exec(e)&&(e="rgba("+[g(w.$1,16),g(w.$2,16),g(w.$3,16)].join(",")+","+t+")"),e},_toRGB:function(e){return E(e)},setSize:function(e,t){this.get("autoSize")&&(e>this.node.getAttribute("width")&&(this.node.style.width=e+"px",this.node.setAttribute("width",e)),t>this.node.getAttribute("height")&&(this.node.style.height=t+"px",this.node.setAttribute("height",t)))},_updateCoords:function(e,t){this._xcoords.push(e),this._ycoords.push(t),this._currentX=e,this._currentY=t},_clearAndUpdateCoords:function(){var e=this._xcoords.pop()||0,t=this._ycoords.pop()||0;this._updateCoords(e,t)},_updateNodePosition:function(){var e=this.get("node"),t=this.get("x"),n=this.get("y");e.style.position="absolute",e.style.left=t+this._left+"px",e.style.top=n+this._top+"px"},_updateDrawingQueue:function(e){this._methods.push(e)},lineTo:function(){return this._lineTo.apply(this,[e.Array(arguments),!1]),this},relativeLineTo:function(){return this._lineTo.apply(this,[e.Array(arguments),!0]),this},_lineTo:function(e,t){var n=e[0],r,i,s,o,u=this._stroke&&this._strokeWeight?this._strokeWeight:0,a=t?parseFloat(this._currentX):0,f=t?parseFloat(this._currentY):0;this._lineToMethods||(this._lineToMethods=[]),i=e.length-1;if(typeof n=="string"||typeof n=="number")for(r=0;r360&&(r=360),u=Math.ceil(Math.abs(r)/45),a=r/u,f=-(a/180)*Math.PI,l=n/180*Math.PI;if(u>0){h=e+Math.cos(n/180*Math.PI)*i,p=t+Math.sin(n/180*Math.PI)*s,this.lineTo(h,p);for(y=0;y=p/2?(d<180?(g=c,y=c+p):(g=c+p,y=c),v=b-(w-g)/T,m=b-(w-y)/T):(d>90&&d<270?(v=l+h,m=l):(v=l,m=l+h),g=(T*(b-v)-w)*-1,y=(T*(b-m)-w)*-1),f=this._context.createLinearGradient(v,g,m,y);for(u=0;u=S&&(A=k/S,A===1&&(A=1.01),N=(g-x)/A,C=(b-T)/A,N=N>0?Math.floor(N):Math.ceil(N),C=C>0?Math.floor(C):Math.ceil(C),g=x+N,b=T+C),r>=.5?(h=this._context.createRadialGradient(g,b,r,y,w,r*v),O=1):(h=this._context.createRadialGradient(g,b,r,y,w,v/2),O=r*2);for(l=0;lthis._right&&(this._right=e),ethis._bottom&&(this._bottom=t),this._width=this._right-this._left,this._height=this._bottom-this._top}},e.CanvasDrawing=T,f=function(){this._transforms=[],this.matrix=new e.Matrix,f.superclass.constructor.apply(this,arguments)},f.NAME="shape",e.extend(f,e.GraphicBase,e.mix({init:function(){this.initializer.apply(this,arguments)},initializer:function(e){var t=this,n=e.graphic,r=this.get("data");t._initProps(),t.createNode(),t._xcoords=[0],t._ycoords=[0],n&&this._setGraphic(n),r&&t._parsePathData(r),t._updateHandler()},_setGraphic:function(t){var n;t instanceof e.CanvasGraphic?this._graphic=t:(n=new e.CanvasGraphic({render:t}),n._appendShape(this),this._graphic=n)},addClass:function(t){var n=this.get("node");e.DOM.addClass(n,t)},removeClass:function(t){var n=this.get("node");e.DOM.removeClass(n,t)},getXY:function(){var e=this.get("graphic"),t=e.getXY(),n=this.get("x"),r=this.get("y");return[t[0]+n,t[1]+r]},setXY:function(e){var t=this.get("graphic"),n=t.getXY(),r=e[0]-n[0],i=e[1]-n[1];this._set("x",r),this._set("y",i),this._updateNodePosition(r,i)},contains:function(t){var n=t instanceof e.Node?t._node:t;return n===this.node},test:function(t){return e.Selector.test(this.node,t)},compareTo:function(e){var t=this.node;return t===e},_getDefaultFill:function(){return{type:"solid",opacity:1,cx:.5,cy:.5,fx:.5,fy:.5,r:.5}},_getDefaultStroke:function(){return{weight:1,dashstyle:"none",color:"#000",opacity:1}},_left:0,_right:0,_top:0,_bottom:0,createNode:function(){var t=this,i=e.config.doc.createElement("canvas"),s=t.get("id"),o=t._camelCaseConcat,u=t.name;t._context=i.getContext("2d"),i.setAttribute("overflow","visible"),i.style.overflow="visible",t.get("visible")||(i.style.visibility="hidden"),i.setAttribute("id",s),s="#"+s,t.node=i,t.addClass(x(r)+" "+x(o(n,r))+" "+x(u)+" "+x(o(n,u)))},on:function(t,n){return e.Node.DOM_EVENTS[t]?e.on(t,n,"#"+this.get("id")):e.on.apply(this,arguments)},_setStrokeProps:function(t){var n,r,i,s,o,u;t?(n=t.color,r=y(t.weight),i=y(t.opacity),s=t.linejoin||"round",o=t.linecap||"butt",u=t.dashstyle,this._miterlimit=null,this._dashstyle=u&&e.Lang.isArray(u)&&u.length>1?u:null,this._strokeWeight=r,b(r)&&r>0?this._stroke=1:this._stroke=0,b(i)?this._strokeStyle=this._toRGBA(n,i):this._strokeStyle=n,this._linecap=o,s==="round"||s==="bevel"?this._linejoin=s:(s=parseInt(s,10),b(s)&&(this._miterlimit=Math.max(s,1),this._linejoin="miter"))):this._stroke=0},set:function(){var e=this;a.prototype.set.apply(e,arguments),e.initialized&&e._updateHandler()},_setFillProps:function(e){var t=b,n,r,i;e?(n=e.color,i=e.type,i==="linear"||i==="radial"?this._fillType=i:n?(r=e.opacity,t(r)?(r=Math .max(0,Math.min(1,r)),n=this._toRGBA(n,r)):n=E(n),this._fillColor=n,this._fillType="solid"):this._fillColor=null):(this._fillType=null,this._fillColor=null)},translate:function(e,t){this._translateX+=e,this._translateY+=t,this._addTransform("translate",arguments)},translateX:function(e){this._translateX+=e,this._addTransform("translateX",arguments)},translateY:function(e){this._translateY+=e,this._addTransform("translateY",arguments)},skew:function(){this._addTransform("skew",arguments)},skewX:function(){this._addTransform("skewX",arguments)},skewY:function(){this._addTransform("skewY",arguments)},rotate:function(){this._addTransform("rotate",arguments)},scale:function(){this._addTransform("scale",arguments)},_transform:"",_addTransform:function(t,n){n=e.Array(n),this._transform=u.trim(this._transform+" "+t+"("+n.join(", ")+")"),n.unshift(t),this._transforms.push(n),this.initialized&&this._updateTransform()},_updateTransform:function(){var e=this.node,t,n,r=this.get("transformOrigin"),i=this.matrix,s,o=this._transforms.length;if(this._transforms&&this._transforms.length>0){for(s=0;s0&&(a=f.shift(),a&&(a==="closePath"?(r.closePath(),this._strokeAndFill(r)):a&&a==="lineTo"&&this._dashstyle?(f.unshift(this._xcoords[o]-this._left,this._ycoords[o]-this._top),this._drawDashedLine.apply(this,f)):r[a].apply(r,f)));this._strokeAndFill(r),this._drawingComplete=!0,this._clearAndUpdateCoords(),this._updateNodePosition(),this._methods=s}},_strokeAndFill:function(e){this._fillType&&(this._fillType==="linear"?e.fillStyle=this._getLinearGradient():this._fillType==="radial"?e.fillStyle=this._getRadialGradient():e.fillStyle=this._fillColor,e.closePath(),e.fill()),this._stroke&&(this._strokeWeight&&(e.lineWidth=this._strokeWeight),e.lineCap=this._linecap,e.lineJoin=this._linejoin,this._miterlimit&&(e.miterLimit=this._miterlimit),e.strokeStyle=this._strokeStyle,e.stroke())},_drawDashedLine:function(e,t,n,r){var i=this._context,s=this._dashstyle[0],o=this._dashstyle[1],u=s+o,a=n-e,f=r-t,l=Math.sqrt(Math.pow(a,2)+Math.pow(f,2)),c=Math.floor(Math.abs(l/u)),h=Math.atan2(f,a),p=e,d=t,v;a=Math.cos(h)*u,f=Math.sin(h)*u;for(v=0;vs?i.lineTo(p+Math.cos(h)*s,d+Math.sin(h)*s):l>0&&i.lineTo(p+Math.cos(h)*l,d+Math.sin(h)*l),i.moveTo(n,r)},getBounds:function(){var e=this._type,t=this.get("width"),n=this.get("height"),r=this.get("x"),i=this.get("y");return e==="path"&&(r+=this._left,i+=this._top,t=this._right-this._left,n=this._bottom-this._top),this._getContentRect(t,n,r,i)},_getContentRect:function(t,n,r,i){var s=this.get("transformOrigin"),o=s[0]*t,u=s[1]*n,a=this.matrix.getTransformArray(this.get("transform")),f=new e.Matrix,l,c=a.length,h,p,d;this._type==="path"&&(o+=r,u+=i),o=isNaN(o)?0:o,u=isNaN(u)?0:u,f.translate(o,u);for(l=0;l0)if(u.isString&&r[n])s=!0;else if(u.isObject(n))for(i in r)if(r.hasOwnProperty(i)&&n[i]){s=!0;break}s&&t._redraw()},_x:0,_y:0,getXY:function(){var t=this._node,n;return t&&(n=e.DOM.getXY(t)),n},initializer:function(){var e=this.get("render"),t=this.get("visible")?"visible":"hidden",n=this.get("width")||0,r=this.get("height")||0;this._shapes={},this._redrawQueue={},this._contentBounds={left:0,top:0,right:0,bottom:0},this._node=o.createElement("div"),this._node.style.position="absolute",this._node.style.visibility=t,this.set("width",n),this.set("height",r),e&&this.render(e)},render:function(t){var n=t||o.body,r=this._node,i,s;return t instanceof e.Node?n=t._node:e.Lang.isString(t)&&(n=e.Selector.query(t,o.body,!0)),i=this.get("width")||parseInt(e.DOM.getComputedStyle(n,"width"),10),s=this.get("height")||parseInt(e.DOM.getComputedStyle(n,"height"),10),n.appendChild(r),r.style.display="block",r.style.position="absolute",r.style.left=this.get("x")+"px",r.style.top=this.get("y")+"px",this.set("width",i),this.set("height",s),this.parentNode=n,this},destroy:function(){this.removeAllShapes(),this._node&&(this._removeChildren(this._node),this._node.parentNode&&this._node.parentNode.removeChild(this._node),this._node=null)},addShape:function(e){e.graphic=this,this.get("visible")||(e.visible=!1);var t=this._getShapeClass(e.type),n=new t(e);return this._appendShape(n),n},_appendShape:function(e){var t=e.node,n=this._frag||this._node;this.get("autoDraw")?n.appendChild(t):this._getDocFrag().appendChild(t)},removeShape:function(e){return e instanceof f||u.isString(e)&&(e=this._shapes[e]),e&&e instanceof f&&(e._destroy(),delete this._shapes[e.get("id")]),this.get("autoDraw")&&this._redraw(),e},removeAllShapes:function(){var e=this._shapes,t;for(t in e)e.hasOwnProperty(t)&&e[t].destroy();this._shapes={}},clear:function(){this.removeAllShapes()},_removeChildren:function(e){if(e&&e.hasChildNodes()){var t;while(e.firstChild)t=e.firstChild,this._removeChildren(t),e.removeChild(t)}},_toggleVisible:function(e){var t,n=this._shapes,r=e?"visible":"hidden";if(n)for(t in n)n.hasOwnProperty(t)&& n[t].set("visible",e);this._node&&(this._node.style.visibility=r)},_getShapeClass:function(e){var t=this._shapeClass[e];return t?t:e},_shapeClass:{circle:e.CanvasCircle,rect:e.CanvasRect,path:e.CanvasPath,ellipse:e.CanvasEllipse,pieslice:e.CanvasPieSlice},getShapeById:function(e){var t=this._shapes[e];return t},batch:function(e){var t=this.get("autoDraw");this.set("autoDraw",!1),e(),this.set("autoDraw",t)},_getDocFrag:function(){return this._frag||(this._frag=o.createDocumentFragment()),this._frag},_redraw:function(){var t=this.get("autoSize"),n=this.get("preserveAspectRatio"),r=this.get("resizeDown")?this._getUpdatedContentBounds():this._contentBounds,i,s,o,u,a,f,l=0,c=0,h,p=this.get("node");t&&(t==="sizeContentToGraphic"?(i=r.right-r.left,s=r.bottom-r.top,o=parseFloat(v.getComputedStyle(p,"width")),u=parseFloat(v.getComputedStyle(p,"height")),h=new e.Matrix,n==="none"?(a=o/i,f=u/s):i/s!==o/u&&(i*u/s>o?(a=f=o/i,c=this._calculateTranslate(n.slice(5).toLowerCase(),s*o/i,u)):(a=f=u/s,l=this._calculateTranslate(n.slice(1,4).toLowerCase(),i*u/s,o))),v.setStyle(p,"transformOrigin","0% 0%"),l-=r.left*a,c-=r.top*f,h.translate(l,c),h.scale(a,f),v.setStyle(p,"transform",h.toCSSText())):(this.set("width",r.right),this.set("height",r.bottom))),this._frag&&(this._node.appendChild(this._frag),this._frag=null)},_calculateTranslate:function(e,t,n){var r=n-t,i;switch(e){case"mid":i=r*.5;break;case"max":i=r;break;default:i=0}return i},addToRedrawQueue:function(e){var t,n;this._shapes[e.get("id")]=e,this.get("resizeDown")||(t=e.getBounds(),n=this._contentBounds,n.left=n.leftt.right?n.right:t.right,n.bottom=n.bottom>t.bottom?n.bottom:t.bottom,this._contentBounds=n),this.get("autoDraw")&&this._redraw()},_getUpdatedContentBounds:function(){var e,t,n,r=this._shapes,i={};for(t in r)r.hasOwnProperty(t)&&(n=r[t],e=n.getBounds(),i.left=u.isNumber(i.left)?Math.min(i.left,e.left):e.left,i.top=u.isNumber(i.top)?Math.min(i.top,e.top):e.top,i.right=u.isNumber(i.right)?Math.max(i.right,e.right):e.right,i.bottom=u.isNumber(i.bottom)?Math.max(i.bottom,e.bottom):e.bottom);return i.left=u.isNumber(i.left)?i.left:0,i.top=u.isNumber(i.top)?i.top:0,i.right=u.isNumber(i.right)?i.right:0,i.bottom=u.isNumber(i.bottom)?i.bottom:0,this._contentBounds=i,i},_toFront:function(t){var n=this.get("node");t instanceof e.CanvasShape&&(t=t.get("node")),n&&t&&n.appendChild(t)},_toBack:function(t){var n=this.get("node"),r;t instanceof e.CanvasShape&&(t=t.get("node")),n&&t&&(r=n.firstChild,r?n.insertBefore(t,r):n.appendChild(t))}}),e.CanvasGraphic=N},"3.17.2",{requires:["graphics","color-base"]});