graphics-svg.js revision c234453b8a758c5d363f1854275aa88c527163c7
c869993e79c1eafbec61a56bf6cea848fe754c71xyfunction SVGDrawing(){}
c869993e79c1eafbec61a56bf6cea848fe754c71xy * <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Drawing.html">`Drawing`</a> class.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * `SVGDrawing` is not intended to be used directly. Instead, use the <a href="Drawing.html">`Drawing`</a> class.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Drawing.html">`Drawing`</a>
c869993e79c1eafbec61a56bf6cea848fe754c71xy * class will point to the `SVGDrawing` class.
08a0f9b044f01fb540a861b94b63d77dd3d576eechenlu chen - Sun Microsystems - Beijing China * @module graphics
08a0f9b044f01fb540a861b94b63d77dd3d576eechenlu chen - Sun Microsystems - Beijing China * @class SVGDrawing
08a0f9b044f01fb540a861b94b63d77dd3d576eechenlu chen - Sun Microsystems - Beijing China * @constructor
08a0f9b044f01fb540a861b94b63d77dd3d576eechenlu chen - Sun Microsystems - Beijing ChinaSVGDrawing.prototype = {
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Indicates the type of shape
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @property _type
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @readOnly
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @type String
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Draws a bezier curve.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method curveTo
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} cp1x x-coordinate for the first control point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} cp1y y-coordinate for the first control point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} cp2x x-coordinate for the second control point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} cp2y y-coordinate for the second control point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} x x-coordinate for the end point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} y y-coordinate for the end point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cp1x), Math.round(cp1y), Math.round(cp2x) , Math.round(cp2y), x, y]);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Draws a quadratic bezier curve.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method quadraticCurveTo
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} cpx x-coordinate for the control point.
3f7e60a636ef887af87fadf9ab6289c672532dd9zhefeng xu - Sun Microsystems - Beijing China * @param {Number} cpy y-coordinate for the control point.
cf8dcc9bbabedca41ecfee13dec8172104e99968zhefeng xu - Sun Microsystems - Beijing China * @param {Number} x x-coordinate for the end point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} y y-coordinate for the end point.
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China quadraticCurveTo: function(cpx, cpy, x, y) {
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China if(this._pathType !== "Q")
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic else
c869993e79c1eafbec61a56bf6cea848fe754c71xy currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China currentArray = [];
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathArray.push(currentArray);
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China pathArrayLen = this._pathArray.length - 1;
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cpx), Math.round(cpy), Math.round(x), Math.round(y)]);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Draws a rectangle.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method drawRect
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} x x-coordinate
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} y y-coordinate
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} w width
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic * @param {Number} h height
c869993e79c1eafbec61a56bf6cea848fe754c71xy drawRect: function(x, y, w, h) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy this.moveTo(x, y);
c869993e79c1eafbec61a56bf6cea848fe754c71xy this.lineTo(x + w, y);
c869993e79c1eafbec61a56bf6cea848fe754c71xy this.lineTo(x + w, y + h);
c869993e79c1eafbec61a56bf6cea848fe754c71xy this.lineTo(x, y + h);
3f7e60a636ef887af87fadf9ab6289c672532dd9zhefeng xu - Sun Microsystems - Beijing China * Draws a rectangle with rounded corners.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method drawRect
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} x x-coordinate
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} y y-coordinate
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} w width
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic * @param {Number} h height
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} ew width of the ellipse used to draw the rounded corners
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} eh height of the ellipse used to draw the rounded corners
3f7e60a636ef887af87fadf9ab6289c672532dd9zhefeng xu - Sun Microsystems - Beijing China this.quadraticCurveTo(x + w, y, x + w - ew, y);
69b2d733deffed6bf9baf89d901afd9c81b484edGuoqing Zhu * Draws a wedge.
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method drawWedge
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo * @param {Number} x x-coordinate of the wedge's center point
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo * @param {Number} y y-coordinate of the wedge's center point
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} startAngle starting angle in degrees
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} arc sweep of the wedge. Negative values draw clockwise.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} yRadius [optional] y radius for wedge.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy drawWedge: function(x, y, startAngle, arc, radius, yRadius)
b8d0a37778010a5166d34bb0d192cf6b1b2f7becchenlu chen - Sun Microsystems - Beijing China diameter = radius * 2,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng // limit sweep to reasonable numbers
c869993e79c1eafbec61a56bf6cea848fe754c71xy // First we calculate how many segments are needed
c869993e79c1eafbec61a56bf6cea848fe754c71xy // for a smooth arc.
c869993e79c1eafbec61a56bf6cea848fe754c71xy // Now calculate the sweep of each segment.
c869993e79c1eafbec61a56bf6cea848fe754c71xy // The math requires radians rather than degrees. To convert from degrees
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic // use the formula (degrees/180)*Math.PI to get radians.
c869993e79c1eafbec61a56bf6cea848fe754c71xy // convert angle startAngle to radians
c869993e79c1eafbec61a56bf6cea848fe754c71xy // draw a line from the center to the start of the curve
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo this._pathArray[pathArrayLen].push(Math.round(ay));
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo for(; i < segs; ++i)
c869993e79c1eafbec61a56bf6cea848fe754c71xy cx = x + Math.cos(angleMid) * (radius / Math.cos(theta / 2));
c869993e79c1eafbec61a56bf6cea848fe754c71xy cy = y + Math.sin(angleMid) * (yRadius / Math.cos(theta / 2));
c869993e79c1eafbec61a56bf6cea848fe754c71xy return this;
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method lineTo
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} point1 x-coordinate for the end point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} point2 y-coordinate for the end point.
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (typeof point1 === 'string' || typeof point1 === 'number') {
c869993e79c1eafbec61a56bf6cea848fe754c71xy var currentArray = this._pathArray[Math.max(0, this._pathArray.length - 1)];
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Moves the current drawing position to specified x and y coordinates.
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China * @method moveTo
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China * @param {Number} x x-coordinate for the end point.
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China * @param {Number} y y-coordinate for the end point.
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China moveTo: function(x, y) {
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China var pathArrayLen,
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China currentArray;
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathArray = this._pathArray || [];
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China if(this._pathType != "M")
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathType = "M";
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China currentArray = ["M"];
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathArray.push(currentArray);
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China currentArray = this._getCurrentArray();
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China pathArrayLen = this._pathArray.length - 1;
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([x, y]);
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China this._trackSize(x, y);
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China * Completes a drawing operation.
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China * @method end
c869993e79c1eafbec61a56bf6cea848fe754c71xy end: function()
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Clears the path.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method clear
c869993e79c1eafbec61a56bf6cea848fe754c71xy clear: function()
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Draws the path.
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo * @method _closePath
c869993e79c1eafbec61a56bf6cea848fe754c71xy _closePath: function()
69b2d733deffed6bf9baf89d901afd9c81b484edGuoqing Zhu path += " " + pathType + (segmentArray[1] - left);
c869993e79c1eafbec61a56bf6cea848fe754c71xy case "L" :
c869993e79c1eafbec61a56bf6cea848fe754c71xy case "M" :
c869993e79c1eafbec61a56bf6cea848fe754c71xy case "Q" :
c869993e79c1eafbec61a56bf6cea848fe754c71xy case "C" :
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Updates the size of the graphics object
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method _trackSize
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} w width
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Number} h height
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy _trackSize: function(w, h) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (w > this._right) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy if(w < this._left)
c869993e79c1eafbec61a56bf6cea848fe754c71xy if (h < this._top)
d11274aa6f1c1462c11e04d3da70b7453f6f0ebdPaul Guo if (h > this._bottom)
c869993e79c1eafbec61a56bf6cea848fe754c71xy * <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Shape.html">`Shape`</a> class.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * `SVGShape` is not intended to be used directly. Instead, use the <a href="Shape.html">`Shape`</a> class.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Shape.html">`Shape`</a>
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * class will point to the `SVGShape` class.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * @module graphics
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * @class SVGShape
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * @constructor
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {Object} cfg (optional) Attribute configs
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Init method, invoked during construction.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Calls `initializer` method.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method init
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @protected
c869993e79c1eafbec61a56bf6cea848fe754c71xy init: function()
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China this.initializer.apply(this, arguments);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Initializes the shape
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method initializer
c869993e79c1eafbec61a56bf6cea848fe754c71xy var host = this;
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Add a class name to each node.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method addClass
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * @param {String} className the class name to add to the node's class attribute
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China var node = this.node;
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.className.baseVal = Y_LANG.trim([node.className.baseVal, className].join(' '));
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * Removes a class name from each node.
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * @method removeClass
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * @param {String} className the class name to remove from the node's class attribute
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China removeClass: function(className)
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China var node = this.node,
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China classString = node.className.baseVal;
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China classString = classString.replace(new RegExp(className + ' '), className).replace(new RegExp(className), '');
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.className.baseVal = classString;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * Gets the current position of the node in page coordinates.
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * @method getXY
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * @return Array The XY position of the shape.
c869993e79c1eafbec61a56bf6cea848fe754c71xy getXY: function()
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Set the position of the shape in page coordinates, regardless of how the node is positioned.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method setXY
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Array} Contains x & y values for new position (coordinates are page-based)
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method contains
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {SVGShape | HTMLElement} needle The possible node or descendent
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return Boolean Whether or not this shape is the needle or its ancestor.
80a11ad227f9c82cd6e7cf5c8913a37f00b7af0echenlu chen - Sun Microsystems - Beijing China return needle === Y.one(this.node);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Compares nodes to determine if they match.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Node instances can be compared to each other and/or HTMLElements.
cf8dcc9bbabedca41ecfee13dec8172104e99968zhefeng xu - Sun Microsystems - Beijing China * @method compareTo
cf8dcc9bbabedca41ecfee13dec8172104e99968zhefeng xu - Sun Microsystems - Beijing China * @param {HTMLElement | Node} refNode The reference node to compare to the node.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return {Boolean} True if the nodes match, false if they do not.
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * Test if the supplied node matches the supplied selector.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method test
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {String} selector The CSS selector to test against.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return Boolean Wheter or not the shape matches the selector.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Value function for fill attribute
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method _getDefaultFill
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return Object
c869993e79c1eafbec61a56bf6cea848fe754c71xy _getDefaultFill: function() {
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Value function for stroke attribute
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method _getDefaultStroke
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return Object
cf8dcc9bbabedca41ecfee13dec8172104e99968zhefeng xu - Sun Microsystems - Beijing China * Creates the dom node for the shape.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method createNode
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @return HTMLElement
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy createNode: function()
c869993e79c1eafbec61a56bf6cea848fe754c71xy var node = DOCUMENT.createElementNS("http://www.w3.org/2000/svg", "svg:" + this._type),
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic this.addClass("yui3-" + SHAPE + " yui3-" + this.name);
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic if(id)
6ca163a136944eea4423498926e09cef9889312cvitezslav batrla - Sun Microsystems - Prague Czech Republic {
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore Y.one(node).setStyle("visibility", "hidden");
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore * Overrides default `on` method. Checks to see if its a dom interaction event. If so,
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore * return an event attached to the `node` element. If not, return the normal functionality.
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore * @param {String} type event type
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore * @param {Object} callback function
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore return Y.one("#" + this.get("id")).on(type, fn);
13485e69b5429e6c7d27301fb3c0deee0e93768aGarrett D'Amore * Adds a stroke to the shape node.
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China * @method _strokeChangeHandler
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China _strokeChangeHandler: function(e)
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China var node = this.node,
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China stroke = this.get("stroke"),
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China strokeOpacity,
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China if(stroke && stroke.weight && stroke.weight > 0)
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China linejoin = stroke.linejoin || "round";
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China strokeOpacity = parseFloat(stroke.opacity);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China dashstyle = stroke.dashstyle || "none";
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China dash = Y_LANG.isArray(dashstyle) ? dashstyle.toString() : dashstyle;
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China stroke.color = stroke.color || "#000000";
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China stroke.weight = stroke.weight || 1;
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China stroke.opacity = Y_LANG.isNumber(strokeOpacity) ? strokeOpacity : 1;
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China stroke.linecap = stroke.linecap || "butt";
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-dasharray", dash);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke", stroke.color);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-linecap", stroke.linecap);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-width", stroke.weight);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-opacity", stroke.opacity);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China if(linejoin == "round" || linejoin == "bevel")
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-linejoin", linejoin);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China linejoin = parseInt(linejoin, 10);
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China if(Y_LANG.isNumber(linejoin))
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-miterlimit", Math.max(linejoin, 1));
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China node.setAttribute("stroke-linejoin", "miter");
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl * Adds a fill to the shape node.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method _fillChangeHandler
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
b8d0a37778010a5166d34bb0d192cf6b1b2f7becchenlu chen - Sun Microsystems - Beijing China var node = this.node,
b8d0a37778010a5166d34bb0d192cf6b1b2f7becchenlu chen - Sun Microsystems - Beijing China fill = this.get("fill"),
c869993e79c1eafbec61a56bf6cea848fe754c71xy node.setAttribute("fill", "url(#grad" + this.get("id") + ")");
c869993e79c1eafbec61a56bf6cea848fe754c71xy fillOpacity = Y_LANG.isNumber(fillOpacity) ? fillOpacity : 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Creates a gradient fill
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @method _setGradientFill
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @param {String} type gradient type
c869993e79c1eafbec61a56bf6cea848fe754c71xy * @private
c869993e79c1eafbec61a56bf6cea848fe754c71xy gradientNode = graphic.getGradientNode("grad" + this.get("id"), type),
7d46e7ad7bb3e7ef36bb4f0816ad4d6c2784f405zhefeng xu - Sun Microsystems - Beijing China stops = fill.stops,
7d46e7ad7bb3e7ef36bb4f0816ad4d6c2784f405zhefeng xu - Sun Microsystems - Beijing China w = this.get("width"),
7d46e7ad7bb3e7ef36bb4f0816ad4d6c2784f405zhefeng xu - Sun Microsystems - Beijing China h = this.get("height"),
7d46e7ad7bb3e7ef36bb4f0816ad4d6c2784f405zhefeng xu - Sun Microsystems - Beijing China rotation = fill.rotation,
3f7e60a636ef887af87fadf9ab6289c672532dd9zhefeng xu - Sun Microsystems - Beijing China radCon = Math.PI/180,
3f7e60a636ef887af87fadf9ab6289c672532dd9zhefeng xu - Sun Microsystems - Beijing China tanRadians = parseFloat(parseFloat(Math.tan(rotation * radCon)).toFixed(8)),
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China cx = fill.cx,
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China cy = fill.cy,
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China y1 = ((tanRadians * (cx - x1)) - cy) * -1;
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer gradientNode.setAttribute("spreadMethod", "pad");
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China gradientNode.setAttribute("width", w);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer gradientNode.setAttribute("x1", Math.round(100 * x1/w) + "%");
ac7f5757903d7806e03e59f71c10eec36e0deadechenlu chen - Sun Microsystems - Beijing China gradientNode.setAttribute("y1", Math.round(100 * y1/h) + "%");
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng gradientNode.setAttribute("x2", Math.round(100 * x2/w) + "%");
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng gradientNode.setAttribute("y2", Math.round(100 * y2/h) + "%");
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer stopNode.setAttribute("stop-opacity", opacity);
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Sets the value of an attribute.
* @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)
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:
* <dt>matrix</dt><dd>Specifies a 2D transformation matrix comprised of the specified six values.</dd>
* <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,
if(this.node)
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;