SVGShape.js revision 6a3585e2672045e8e28e6a45f279f80aef446959
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * Base class for creating shapes.
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * @module graphics
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * @class SVGShape
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * @constructor
21257820ee962f4f2275b39088c43fcfd76f7fdeAllen Rabinovich * @param {Object} cfg (optional) Attribute configs
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich SVGShape.superclass.constructor.apply(this, arguments);
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * Init method, invoked during construction.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * Calls `initializer` method.
e459c407a404c834e5f9759744d1a134d820d41bAllen Rabinovich * @method init
var host = this;
classString = classString.replace(new RegExp(className + ' '), className).replace(new RegExp(className), '');
getXY: function()
_getDefaultFill: function() {
_getDefaultStroke: function()
createNode: function()
if(id)
if(pointerEvents)
_strokeChangeHandler: function(e)
dash,
_fillChangeHandler: function(e)
type;
if(fill)
var offset,
len,
def,
stop,
r = fill.r;
y2 = h;
y1 = h;
x1 = w;
x2 = w;
* @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;
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,
tx,
ty,
if(isPath)
x += this._left;
y += this._top;
for(; i < len; ++i)
if(key)
if(isPath)
if(transform)
if(!isPath)
this._transforms = [];
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
_updateHandler: function(e)
this._draw();
* Calculates the a new bounding box from the original corner coordinates (base on size and position) and the transform matrix.
getBounds: function()
wt,
bounds = {},
a = matrix.a,
b = matrix.b,
c = matrix.c,
d = matrix.d,
//The svg path element does not have x and y coordinates. Shapes based on path use translate to "fake" x and y. As a
//result, these values will show up in the transform matrix and should not be used in any conversion formula.
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()
* 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;
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 gradient (linear or radial) is specified as the fill type. The following properties are 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 <= 8</dd>
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
stroke: {
autoSize: {
value: false
valueFn: function()
if(node)
return val;
if(node)
return val;
gradientNode: {
return val;
autoDraw: {
getter: function()
node: {
readOnly: true,
getter: function()
return this.node;
graphic: {
readOnly: true,
getter: function()
return this._graphic;