graphics-svg-debug.js revision 785617639f6223ecb4afb307de137e64e19db94e
47N/Afunction SVGDrawing(){}
47N/A * <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Drawing.html">`Drawing`</a> class.
47N/A * `SVGDrawing` is not intended to be used directly. Instead, use the <a href="Drawing.html">`Drawing`</a> class.
47N/A * If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Drawing.html">`Drawing`</a>
47N/A var pathArrayLen,
47N/A if(!currentArray)
47N/A currentArray = [];
47N/A this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cp1x), Math.round(cp1y), Math.round(cp2x) , Math.round(cp2y), x, y]);
47N/A var pathArrayLen,
47N/A if(!currentArray)
47N/A currentArray = [];
this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cpx), Math.round(cpy), Math.round(x), Math.round(y)]);
drawRect: function(x, y, w, h) {
this.moveTo(x, y);
this.lineTo(x + w, y);
this.lineTo(x + w, y + h);
this.lineTo(x, y + h);
this.lineTo(x, y);
* @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
var segs,
ax,
ay,
bx,
by,
cx,
cy,
pathArrayLen++;
pathArrayLen++;
for(; i < segs; ++i)
* Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
len,
_getCurrentArray: function()
if(!currentArray)
currentArray = [];
return currentArray;
moveTo: function(x, y) {
var pathArrayLen,
this._trackSize(x, y);
end: function()
this._closePath();
clear: function()
this._pathArray = [];
_closePath: function()
var pathArray,
len,
val,
val2,
if(this._pathArray)
switch(pathType)
if(path)
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
_trackSize: function(w, h) {
if (w > this._right) {
this._right = w;
if(w < this._left)
this._left = w;
if (h < this._top)
this._top = h;
if (h > this._bottom)
this._bottom = h;
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Shape.html">`Shape`</a> class.
* `SVGShape` is not intended to be used directly. Instead, use the <a href="Shape.html">`Shape`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Shape.html">`Shape`</a>
this._transforms = [];
init: function()
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 `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><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape` classes which are used on Android or IE 6 - 8.</p>
* <p>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
* <p><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape` classes which are used on Android or IE 6 - 8.</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;
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;
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Path.html">`Path`</a> class.
* `SVGPath` is not intended to be used directly. Instead, use the <a href="Path.html">`Path`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Path.html">`Path`</a>
path: {
readOnly: true,
getter: function()
return this._path;
width: {
getter: function()
return val;
height: {
getter: function()
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Rect.html">`Rect`</a> class.
* `SVGRect` is not intended to be used directly. Instead, use the <a href="Rect.html">`Rect`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Rect.html">`Rect`</a>
SVGRect = function()
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Ellipse.html">`Ellipse`</a> class.
* `SVGEllipse` is not intended to be used directly. Instead, use the <a href="Ellipse.html">`Ellipse`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Ellipse.html">`Ellipse`</a>
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
xRadius: {
getter: function()
if(val)
return val;
yRadius: {
getter: function()
if(val)
return val;
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Circle.html">`Circle`</a> class.
* `SVGCircle` is not intended to be used directly. Instead, use the <a href="Circle.html">`Circle`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Circle.html">`Circle`</a>
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
width: {
return val;
getter: function()
height: {
return val;
getter: function()
radius: {
SVGPieSlice = function()
_draw: function(e)
this.clear();
this.end();
cx: {
cy: {
startAngle: {
arc: {
radius: {
* <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Graphic.html">`Graphic`</a> class.
* `SVGGraphic` is not intended to be used directly. Instead, use the <a href="Graphic.html">`Graphic`</a> class.
* If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Graphic.html">`Graphic`</a>
* Whether or not to render the `Graphic` automatically after to a specified parent node after init. This can be a Node instance or a CSS selector string.
render: {},
id: {
valueFn: function()
return Y.guid();
if(node)
return val;
shapes: {
readOnly: true,
getter: function()
return this._shapes;
* Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
readOnly: true,
getter: function()
return this._contentBounds;
node: {
readOnly: true,
getter: function()
return this._node;
width: {
if(this._node)
return val;
height: {
if(this._node)
return val;
* Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents.
* If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions.
autoSize: {
value: false
resizeDown: {
getter: function()
return this._resizeDown;
this._redraw();
return val;
getter: function()
return this._x;
if(this._node)
return val;
getter: function()
return this._y;
if(this._node)
return val;
* Indicates whether or not the instance will automatically redraw after a change is made to a shape.
autoDraw: {
value: true
visible: {
value: true,
return val;
getXY: function()
xy;
if(node)
return xy;
_resizeDown: false,
initializer: function() {
this._shapes = {};
this._contentBounds = {
this._gradients = {};
if(render)
destroy: function()
this.removeAllShapes();
return shape;
this._redraw();
return shape;
removeAllShapes: function()
for(i in shapes)
this._shapes = {};
var child;
clear: function() {
this.removeAllShapes();
if(shapes)
for(i in shapes)
if(shape)
return shape;
return val;
_shapeClass: {
return shape;
method();
this._redraw();
_getDocFrag: function()
if(!this._frag)
return this._frag;
_redraw: function()
this._contentNode.setAttribute("viewBox", "" + box.left + " " + box.top + " " + box.width + " " + box.height + "");
if(this._frag)
this._frag = null;
var shapeBox,
box;
this._redraw();
_getUpdatedContentBounds: function()
var bounds,
box = {
for(i in queue)
return box;
_createGraphics: function() {
return contentNode;
return node;
if(!this._defs)
return gradient;