SVGDrawing.js revision a89ad754cce3cfc8aee71760e10217b54020360d
var SHAPE = "svgShape",
function SVGDrawing(){}
SVGDrawing.prototype = {
/**
* Draws a bezier curve.
*
* @method curveTo
* @param {Number} cp1x x-coordinate for the first control point.
* @param {Number} cp1y y-coordinate for the first control point.
* @param {Number} cp2x x-coordinate for the second control point.
* @param {Number} cp2y y-coordinate for the second control point.
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
var pathArrayLen,
hiX,
loX,
hiY,
loY;
if(this._pathType !== "C")
{
this._pathType = "C";
currentArray = ["C"];
}
else
{
if(!currentArray)
{
currentArray = [];
}
}
this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cp1x), Math.round(cp1y), Math.round(cp2x) , Math.round(cp2y), x, y]);
},
/**
* Draws a quadratic bezier curve.
*
* @method quadraticCurveTo
* @param {Number} cpx x-coordinate for the control point.
* @param {Number} cpy y-coordinate for the control point.
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
var pathArrayLen,
hiX,
loX,
hiY,
loY;
if(this._pathType !== "Q")
{
this._pathType = "Q";
currentArray = ["Q"];
}
else
{
if(!currentArray)
{
currentArray = [];
}
}
this._pathArray[pathArrayLen] = this._pathArray[pathArrayLen].concat([Math.round(cpx), Math.round(cpy), Math.round(x), Math.round(y)]);
},
/**
* Draws a rectangle.
*
* @method drawRect
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
*/
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);
},
/**
* Draws a rectangle with rounded corners.
*
* @method drawRect
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
* @param {Number} ew width of the ellipse used to draw the rounded corners
* @param {Number} eh height of the ellipse used to draw the rounded corners
*/
this.quadraticCurveTo(x, y + h, x + ew, y + h);
this.quadraticCurveTo(x + w, y + h, x + w, y + h - eh);
this.quadraticCurveTo(x + w, y, x + w - ew, y);
this.quadraticCurveTo(x, y, x, y + eh);
},
/**
* Draws a wedge.
*
* @param {Number} x x-coordinate of the wedge's center point
* @param {Number} y y-coordinate of the wedge's center point
* @param {Number} startAngle starting angle in degrees
* @param {Number} arc sweep of the wedge. Negative values draw clockwise.
* @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
* @param {Number} yRadius [optional] y radius for wedge.
*/
{
this._drawingComplete = false;
this.path = this._getWedgePath({x:x, y:y, startAngle:startAngle, arc:arc, radius:radius, yRadius:yRadius});
},
/**
* Generates a path string for a wedge shape
*
* @method _getWedgePath
* @param {Object} config attributes used to create the path
* @return String
* @private
*/
_getWedgePath: function(config)
{
var x = config.x,
y = config.y,
segs,
ax,
ay,
bx,
by,
cx,
cy,
i = 0,
// limit sweep to reasonable numbers
{
arc = 360;
}
// First we calculate how many segments are needed
// for a smooth arc.
// Now calculate the sweep of each segment.
// The math requires radians rather than degrees. To convert from degrees
// use the formula (degrees/180)*Math.PI to get radians.
// convert angle startAngle to radians
if(segs > 0)
{
// draw a line from the center to the start of the curve
path += " Q";
for(; i < segs; ++i)
{
}
}
return path;
},
/**
* Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
*
* @method lineTo
* @param {Number} point1 x-coordinate for the end point.
* @param {Number} point2 y-coordinate for the end point.
*/
i,
len,
this._pathArray = this._pathArray || [];
}
this._shapeType = "path";
if(this._pathType !== "L")
{
this._pathType = "L";
currentArray = ['L'];
}
else
{
if(!currentArray)
{
currentArray = [];
}
}
for (i = 0; i < len; ++i) {
}
},
/**
* Moves the current drawing position to specified x and y coordinates.
*
* @method moveTo
* @param {Number} x x-coordinate for the end point.
* @param {Number} y y-coordinate for the end point.
*/
moveTo: function(x, y) {
var pathArrayLen,
this._pathArray = this._pathArray || [];
if(this._pathType != "M")
{
this._pathType = "M";
currentArray = ["M"];
}
else
{
if(!currentArray)
{
currentArray = [];
}
}
this._trackSize(x, y);
},
/**
* Completes a drawing operation.
*
* @method end
*/
end: function() {
this._draw();
},
/**
* Sets the size of the graphics object.
*
* @method setSize
* @param w {Number} width to set for the instance.
* @param h {Number} height to set for the instance.
*/
setSize: function(w, h) {
var node;
if(this.get("autoSize"))
{
{
}
{
}
}
},
/**
* Updates the size of the graphics object
*
* @method _trackSize
* @param {Number} w width
* @param {Number} h height
* @private
*/
_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;
}
}
};
Y.SVGDrawing = SVGDrawing;