graphics-svg-debug.js revision 45be085c4155ae7ef409ffa4d79457928742f18f
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * Set of drawing methods for SVG based classes.
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @module graphics
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @class SVGDrawing
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @constructor
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * Indicates the type of shape
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @property _type
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @readOnly
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @type String
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * Draws a bezier curve.
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * @method curveTo
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * @param {Number} cp1x x-coordinate for the first control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} cp1y y-coordinate for the first control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} cp2x x-coordinate for the second control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} cp2y y-coordinate for the second control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate for the end point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate for the end point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cp1x), Math.round(cp1y), Math.round(cp2x) , Math.round(cp2y), x, y]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws a quadratic bezier curve.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method quadraticCurveTo
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} cpx x-coordinate for the control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} cpy y-coordinate for the control point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate for the end point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate for the end point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cpx), Math.round(cpy), Math.round(x), Math.round(y)]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws a rectangle.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method drawRect
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} w width
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} h height
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp drawRect: function(x, y, w, h) {
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp this.moveTo(x, y);
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp this.lineTo(x + w, y);
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp this.lineTo(x + w, y + h);
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp this.lineTo(x, y + h);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.lineTo(x, y);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws a rectangle with rounded corners.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method drawRect
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} w width
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * @param {Number} h height
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} ew width of the ellipse used to draw the rounded corners
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} eh height of the ellipse used to draw the rounded corners
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.quadraticCurveTo(x + w, y + h, x + w, y + h - eh);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws a wedge.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate of the wedge's center point
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate of the wedge's center point
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} startAngle starting angle in degrees
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} arc sweep of the wedge. Negative values draw clockwise.
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * @param {Number} yRadius [optional] y radius for wedge.
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp drawWedge: function(x, y, startAngle, arc, radius, yRadius)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // limit sweep to reasonable numbers
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // First we calculate how many segments are needed
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // for a smooth arc.
c8497af565e3869417da55c16f0afc9fafb7d79aTripp // Now calculate the sweep of each segment.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // The math requires radians rather than degrees. To convert from degrees
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // use the formula (degrees/180)*Math.PI to get radians.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp // convert angle startAngle to radians
c8497af565e3869417da55c16f0afc9fafb7d79aTripp // draw a line from the center to the start of the curve
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ax = x + Math.cos(startAngle / 180 * Math.PI) * radius;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp ay = y + Math.sin(startAngle / 180 * Math.PI) * yRadius;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < segs; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp cx = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp cy = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * @method lineTo
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * @param {Number} point1 x-coordinate for the end point.
c8497af565e3869417da55c16f0afc9fafb7d79aTripp * @param {Number} point2 y-coordinate for the end point.
c8497af565e3869417da55c16f0afc9fafb7d79aTripp if (typeof point1 === 'string' || typeof point1 === 'number') {
c8497af565e3869417da55c16f0afc9fafb7d79aTripp var currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * Moves the current drawing position to specified x and y coordinates.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method moveTo
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @param {Number} x x-coordinate for the end point.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate for the end point.
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp moveTo: function(x, y) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([x, y]);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Completes a drawing operation.
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @method end
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp end: function()
8648721e29bb657dd5c5ff20f03e86fe50628ce6Tripp * Clears the path.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method clear
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp clear: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Draws the path.
4beb671b9f23325489cc74a7950f2b1f1420b5f3Tripp * @method _closePath
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;
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;
_translate: function(x, y)
skewX: function(x)
skewY: function(y)
matrix: function(a, b, c, d, e, f)
if(!this._transformArgs)
this._transformArgs = {};
if(this.initialized)
this._updateTransform();
_updateTransform: function()
key,
args,
val,
test,
if(this._transformArgs)
if(transform)
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
_updateHandler: function(e)
this._draw();
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()
* 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()
rotation: {
getter: function()
return this._rotation;
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;
translateX: {
getter: function()
return this._translateX;
return val;
translateY: {
getter: function()
return this._translateY;
return val;
gradientNode: {
return val;
autoDraw: {
getter: function()
node: {
readOnly: true,
getter: function()
return this.node;
graphic: {
readOnly: true,
getter: function()
return this._graphic;
translate: function(x, y)
this._translateX = x;
this._translateY = y;
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
getBounds: function()
bounds = {},
return bounds;
path: {
readOnly: true,
getter: function()
return this._path;
width: {
getter: function()
return val;
height: {
getter: function()
SVGRect = function()
_draw: function()
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
xRadius: {
getter: function()
if(val)
return val;
yRadius: {
getter: function()
if(val)
return val;
_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: {
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
* When overflow is set to true, by default, the contentBounds will resize to greater values but not to smaller values. (for performance)
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;