SVGDrawing.js revision cec703a844d9691646231634fe709f4ea41d278a
var SHAPE = "svgShape",
function SVGDrawing(){}
/**
* Set of drawing methods for SVG based classes.
*
* @module graphics
* @class SVGDrawing
* @constructor
*/
SVGDrawing.prototype = {
/**
* Indicates the type of shape
*
* @private
* @property _type
* @readOnly
* @type String
*/
_type: "path",
/**
* 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.
*
* @method drawWedge
* @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.
* @private
*/
{
var segs,
ax,
ay,
bx,
by,
cx,
cy,
i = 0,
if(this._pathType != "M")
{
this._pathType = "M";
currentArray = ["M"];
}
else
{
currentArray = this._getCurrentArray();
}
// 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
this._pathType = "L";
pathArrayLen++;
pathArrayLen++;
this._pathType = "Q";
for(; i < segs; ++i)
{
}
}
return this;
},
/**
* 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
{
currentArray = this._getCurrentArray();
}
for (i = 0; i < len; ++i) {
}
},
_getCurrentArray: function()
{
if(!currentArray)
{
currentArray = [];
}
return currentArray;
},
/**
* 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
{
currentArray = this._getCurrentArray();
}
this._trackSize(x, y);
},
/**
* Completes a drawing operation.
*
* @method end
*/
end: function()
{
this._closePath();
this._graphic.addToRedrawQueue(this);
},
/**
* Clears the path.
*
* @method clear
*/
clear: function()
{
this._left = 0;
this._right = 0;
this._top = 0;
this._bottom = 0;
this._pathArray = [];
this._path = "";
},
/**
* Draws the path.
*
* @method _closePath
* @private
*/
_closePath: function()
{
var pathArray,
len,
val,
val2,
i,
path = "",
if(this._pathArray)
{
{
switch(pathType)
{
case "L" :
case "M" :
case "Q" :
for(i = 2; i < len; ++i)
{
}
break;
case "C" :
for(i = 2; i < len; ++i)
{
val2 = segmentArray[i];
}
break;
}
}
{
path += 'z';
}
if(path)
{
}
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
}
},
/**
* 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;