graphics-svg-debug.js revision 4228ce333e19cf320ab65129c52b05ded2c1cc2e
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcfunction SVGDrawing(){}
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Draws a bezier curve.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method curveTo
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} cp1x x-coordinate for the first control point.
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * @param {Number} cp1y y-coordinate for the first control point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} cp2x x-coordinate for the second control point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} cp2y y-coordinate for the second control point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} x x-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cp1x), Math.round(cp1y), Math.round(cp2x) , Math.round(cp2y), x, y]);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Draws a quadratic bezier curve.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method quadraticCurveTo
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} cpx x-coordinate for the control point.
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * @param {Number} cpy y-coordinate for the control point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} x x-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cpx), Math.round(cpy), Math.round(x), Math.round(y)]);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Draws a rectangle.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method drawRect
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} x x-coordinate
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} w width
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} h height
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc drawRect: function(x, y, w, h) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this.moveTo(x, y);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this.lineTo(x + w, y);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this.lineTo(x + w, y + h);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this.lineTo(x, y + h);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this.lineTo(x, y);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Draws a rectangle with rounded corners.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method drawRect
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} x x-coordinate
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} w width
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} h height
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} ew width of the ellipse used to draw the rounded corners
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} eh height of the ellipse used to draw the rounded corners
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Draws a wedge.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} x x-coordinate of the wedge's center point
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate of the wedge's center point
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} startAngle starting angle in degrees
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} arc sweep of the wedge. Negative values draw clockwise.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} yRadius [optional] y radius for wedge.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc drawWedge: function(x, y, startAngle, arc, radius, yRadius)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // limit sweep to reasonable numbers
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // First we calculate how many segments are needed
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // for a smooth arc.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // Now calculate the sweep of each segment.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // The math requires radians rather than degrees. To convert from degrees
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // use the formula (degrees/180)*Math.PI to get radians.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // convert angle startAngle to radians
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // draw a line from the center to the start of the curve
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang ax = x + Math.cos(startAngle / 180 * Math.PI) * radius;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc for(; i < segs; ++i)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc cx = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc cy = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc return this;
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * @method lineTo
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * @param {Number} point1 x-coordinate for the end point.
e2cf88ac9d753a00c17aa235f6afdc76574fe3a6Quaker Fang * @param {Number} point2 y-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (typeof point1 === 'string' || typeof point1 === 'number') {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc var currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Moves the current drawing position to specified x and y coordinates.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method moveTo
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @param {Number} x x-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} y y-coordinate for the end point.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc moveTo: function(x, y) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([x, y]);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc this._trackSize(x, y);
a399b7655a1d835aa8606c2b29e4e777baac8635zf * Completes a drawing operation.
a399b7655a1d835aa8606c2b29e4e777baac8635zf * @method end
a399b7655a1d835aa8606c2b29e4e777baac8635zf end: function() {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Updates the size of the graphics object
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method _trackSize
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} w width
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Number} h height
22eb7cb54d8a6bcf6fe2674cb4b1f0cf2d85cfb6gd * @private
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _trackSize: function(w, h) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (w > this._right) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if(w < this._left)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (h < this._top)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (h > this._bottom)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Base class for creating shapes.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @class SVGShape
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @private
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc init: function()
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Initializes the shape
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @private
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method _initialize
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc var host = this;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Add a class name to each node.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method addClass
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {String} className the class name to add to the node's class attribute
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc node.className.baseVal = Y_LANG.trim([node.className.baseVal, className].join(' '));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Removes a class name from each node.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method removeClass
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {String} className the class name to remove from the node's class attribute
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc classString = classString.replace(new RegExp(className + ' '), className).replace(new RegExp(className), '');
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Gets the current position of the node in page coordinates.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method getXY
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @return Array The XY position of the shape.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc getXY: function()
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Set the position of the shape in page coordinates, regardless of how the node is positioned.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method setXY
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {Array} Contains X & Y values for new position (coordinates are page-based)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @method contains
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @param {SVGShape | HTMLElement} needle The possible node or descendent
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * @return Boolean Whether or not this shape is the needle or its ancestor.
_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;
gradientNode.setAttribute("gradientTransform", "rotate(" + rotation + "," + (w/2) + ", " + (h/2) + ")");
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 = {};
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;
_draw: function()
var pathArray,
len,
val,
val2,
if(this._pathArray)
switch(pathType)
if(path)
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
translate: function(x, y)
this._translateX = x;
this._translateY = y;
_updateHandler: function()
end: function()
this._draw();
clear: function()
this._pathArray = [];
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()
_updateHandler: function(e)
this.clear();
this._draw();
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: {
return val;
height: {
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 viewBox will resize to greater values but not 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)
_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;