CanvasShape.js revision 0fdefaa9ca017edfb76b736c825b34186f33045a
* <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> implementation of the <a href="Shape.html">`Shape`</a> class.
* `CanvasShape` is not intended to be used directly. Instead, use the <a href="Shape.html">`Shape`</a> class.
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities but has
* <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> capabilities, the <a href="Shape.html">`Shape`</a>
this._transforms = [];
init: function()
var host = this;
getXY: function()
this._updateNodePosition(x, y);
_getDefaultFill: function() {
_getDefaultStroke: function()
createNode: function()
this._miterlimit = null;
this._dashstyle = (dashstyle && Y.Lang.isArray(dashstyle) && dashstyle.length > 1) ? dashstyle : null;
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
set: function()
var host = this,
else if(color)
this._fillColor = null;
translate: function(x, y)
this._translateX += x;
this._translateY += y;
translateX: function(x)
this._translateX += x;
translateY: function(y)
this._translateY += y;
skew: function(x, y)
skewX: function(x)
skewY: function(y)
scale: function(x, y)
if(this.initialized)
this._updateTransform();
_updateTransform: function()
key,
for(; i < len; ++i)
if(key)
if(transform)
this._transforms = [];
_updateHandler: function()
this._draw();
this._updateTransform();
_draw: function()
this.clear();
this._paint();
_paint: function()
if(!this._methods)
methods = [],
args,
if(this._methods)
for(; i < len; ++i)
if(method)
if (this._fillType)
if (this._stroke) {
if(this._strokeWeight)
if(this._miterlimit)
this._drawingComplete = true;
this._clearAndUpdateCoords();
this._updateNodePosition();
clear: function() {
this._initProps();
if(this.node)
* Calculates the a new bounding box from the original corner coordinates (base on size and position) and the transform matrix.
getBounds: function()
right = x + w,
bottom = y + h,
tlx,
tly,
blx,
bly,
brx,
bry,
trx,
trY,
bounds = {},
return bounds;
* Returns the x coordinate for a bounding box's corner based on the corner's original x/y coordinates, rotation and transform origin of the rotation.
* Returns the y coordinate for a bounding box's corner based on the corner's original x/y coordinates, rotation and transform origin of the rotation.
destroy: function()
if(node)
if(context)
* An array of x, y values which indicates the transformOrigin in which to rotate the shape. Valid values range between 0 and 1 representing a
valueFn: function()
* <p>A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values:
* <p>Applying transforms through the transform attribute will reset the transform matrix and apply a new transform. The shape class also contains corresponding methods for each transform
* that will apply the transform to the current matrix. The below code illustrates how you might use the `transform` attribute to instantiate a recangle with a rotation of 45 degrees.</p>
transform: {
if(this.initialized)
this._updateTransform();
return val;
getter: function()
return this._transform;
node: {
readOnly: true,
getter: function()
return this.node;
id: {
valueFn: function()
return Y.guid();
if(node)
return val;
width: {
height: {
visible: {
value: true,
return val;
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
* <p>If a `linear` or `radial` is specified as the fill type. The following additional property is used:
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stop. The default value is 1. Note: No effect for IE 6 - 8</dd>
* <dt>rotation</dt><dd>Linear gradients flow left to right by default. The rotation property allows you to change the flow by rotation. (e.g. A rotation of 180 would make the gradient pain from right to left.)</dd>
* <p>The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
* <p>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
fill: {
var fill,
return fill;
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stroke. The default value is 1.</dd>
* <dt>dashstyle</dt>Indicates whether to draw a dashed stroke. When set to "none", a solid stroke is drawn. When set to an array, the first index indicates the
* <dt>miter limit</dt><dd>An integer specifying the miter limit of a miter linejoin. If you want to specify a linejoin of miter, you simply specify the limit as opposed to having
stroke: {
wt;
return val;
autoSize: {
value: false
graphic: {
readOnly: true,
getter: function()
return this._graphic;