RE = RegExp,
/**
* <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> implementation of the <a href="Drawing.html">`Drawing`</a> class.
* `CanvasDrawing` is not intended to be used directly. Instead, use the <a href="Drawing.html">`Drawing`</a> class.
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities but has
* <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> capabilities, the <a href="Drawing.html">`Drawing`</a>
* class will point to the `CanvasDrawing` class.
*
* @module graphics
* @class CanvasDrawing
* @constructor
*/
function CanvasDrawing()
{
}
/**
* Parses hex color string and alpha value to rgba
*
* @method _toRGBA
* @param {Object} val Color value to parse. Can be hex string, rgb or name.
* @param {Number} alpha Numeric value between 0 and 1 representing the alpha level.
* @private
*/
}
val = 'rgba(' + [
}
return val;
},
/**
* Converts color to rgb format
*
* @method _toRGB
* @param val Color value to convert.
* @private
*/
},
/**
* 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.
* @private
*/
setSize: function(w, h) {
if(this.get("autoSize"))
{
{
}
{
}
}
},
/**
* Tracks coordinates. Used to calculate the start point of dashed lines.
*
* @method _updateCoords
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @private
*/
_updateCoords: function(x, y)
{
},
/**
* Clears the coordinate arrays. Called at the end of a drawing operation.
*
* @method _clearAndUpdateCoords
* @private
*/
_clearAndUpdateCoords: function()
{
this._updateCoords(x, y);
},
/**
* Moves the shape's dom node.
*
* @method _updateNodePosition
* @private
*/
_updateNodePosition: function()
{
x = this.get("x"),
y = this.get("y");
},
/**
* Queues up a method to be executed when a shape redraws.
*
* @method _updateDrawingQueue
* @param {Array} val An array containing data that can be parsed into a method and arguments. The value at zero-index of the array is a string reference of
* the drawing method that will be called. All subsequent indices are argument for that method. For example, `lineTo(10, 100)` would be structured as:
* `["lineTo", 10, 100]`.
* @private
*/
_updateDrawingQueue: function(val)
{
},
/**
* 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 = 0,
len,
x,
y,
if(!this._lineToMethods)
{
this._lineToMethods = [];
}
}
for (; i < len; ++i)
{
if(args[i])
{
x = args[i][0];
y = args[i][1];
this._updateDrawingQueue(["lineTo", x, y]);
this._updateCoords(x, y);
}
}
this._drawingComplete = false;
return this;
},
/**
* 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) {
this._updateDrawingQueue(["moveTo", x, y]);
this._updateCoords(x, y);
this._drawingComplete = false;
return this;
},
/**
* 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 hiX,
hiY,
loX,
loY;
this._drawingComplete = false;
return this;
},
/**
* 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 hiX,
hiY,
loX,
loY,
this._drawingComplete = false;
return this;
},
/**
* Draws a circle. Used internally by `CanvasCircle` class.
*
* @method drawCircle
* @param {Number} x y-coordinate
* @param {Number} y x-coordinate
* @param {Number} r radius
* @protected
*/
drawCircle: function(x, y, radius) {
var startAngle = 0,
this._drawingComplete = false;
this._updateCoords(x, y);
return this;
},
/**
* Draws a diamond.
*
* @method drawDiamond
* @param {Number} x y-coordinate
* @param {Number} y x-coordinate
* @param {Number} width width
* @param {Number} height height
* @protected
*/
{
return this;
},
/**
* Draws an ellipse. Used internally by `CanvasEllipse` class.
*
* @method drawEllipse
* @param {Number} x x-coordinate
* @param {Number} y y-coordinate
* @param {Number} w width
* @param {Number} h height
* @protected
*/
drawEllipse: function(x, y, w, h) {
var l = 8,
angle = 0,
radius = w/2,
yRadius = h/2,
i = 0,
for(; i < l; i++)
{
}
this._updateCoords(x, y);
return this;
},
/**
* 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._drawingComplete = false;
this._updateDrawingQueue(["moveTo", x, y]);
this._updateDrawingQueue(["lineTo", x + w, y]);
this._updateDrawingQueue(["lineTo", x + w, y + h]);
this._updateDrawingQueue(["lineTo", x, y + h]);
this._updateDrawingQueue(["lineTo", x, y]);
return this;
},
/**
* 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._drawingComplete = false;
this._updateCoords(w, h);
return this;
},
/**
* 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;
this._drawingComplete = false;
// move to x,y position
this._updateDrawingQueue(["moveTo", x, y]);
// 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
// draw the curve in segments no larger than 45 degrees.
if(segs > 0)
{
// draw a line from the center to the start of the curve
// Loop for drawing curve segments
for(; i < segs; ++i)
{
}
// close the wedge by drawing a line to the center
this._updateDrawingQueue(["lineTo", x, y]);
}
return this;
},
/**
* Completes a drawing operation.
*
* @method end
*/
end: function() {
this._closePath();
return this;
},
/**
* Ends a fill and stroke
*
* @method closePath
*/
closePath: function()
{
this._updateDrawingQueue(["closePath"]);
this._updateDrawingQueue(["beginPath"]);
},
/**
* Clears the graphics object.
*
* @method clear
*/
/**
* Returns a linear gradient fill
*
* @method _getLinearGradient
* @return CanvasGradient
* @private
*/
_getLinearGradient: function() {
stop,
i = 0,
x = 0,
y = 0,
w = this.get("width"),
h = this.get("height"),
cx = x + w/2,
cy = y + h/2,
{
if(r < 180)
{
y1 = y;
y2 = y + h;
}
else
{
y1 = y + h;
y2 = y;
}
}
else
{
if(r > 90 && r < 270)
{
x1 = x + w;
x2 = x;
}
else
{
x1 = x;
x2 = x + w;
}
}
for(; i < len; ++i)
{
{
}
else
{
}
}
return gradient;
},
/**
* Returns a radial gradient fill
*
* @method _getRadialGradient
* @return CanvasGradient
* @private
*/
_getRadialGradient: function() {
r = fill.r,
stop,
i = 0,
x = 0,
y = 0,
w = this.get("width"),
h = this.get("height"),
xc = x + w/2;
yc = y + h/2;
x2 = x + w/2;
y2 = y + h/2;
r2 = w * r;
if(d >= r2)
{
//hack. gradient won't show if it is exactly on the edge of the arc
if(ratio === 1)
{
ratio = 1.01;
}
}
//If the gradient radius is greater than the circle's, adjusting the radius stretches the gradient properly.
//If the gradient radius is less than the circle's, adjusting the radius of the gradient will not work.
//Instead, adjust the color stops to reflect the smaller radius.
if(r >= 0.5)
{
stopMultiplier = 1;
}
else
{
stopMultiplier = r * 2;
}
for(; i < len; ++i)
{
{
}
else
{
}
offset *= stopMultiplier;
if(offset <= 1)
{
}
}
return gradient;
},
/**
* Clears all values
*
* @method _initProps
* @private
*/
_initProps: function() {
this._methods = [];
this._lineToMethods = [];
this._xcoords = [0];
this._ycoords = [0];
this._width = 0;
this._height = 0;
this._left = 0;
this._top = 0;
this._right = 0;
this._bottom = 0;
},
/**
* Indicates a drawing has completed.
*
* @property _drawingComplete
* @type Boolean
* @private
*/
_drawingComplete: false,
/**
* Creates canvas element
*
* @method _createGraphic
* @return HTMLCanvasElement
* @private
*/
_createGraphic: function(config) {
return graphic;
},
/**
* 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;
}
}
};