CanvasShape.js revision 4ef2f7e4cb7c7d255be077c47d542199f7bf8607
/**
* Base class for creating shapes.
*
* @class CanvasShape
*/
CanvasShape = function(cfg)
{
};
/**
* @private
*/
init: function()
{
},
/**
* Initializes the shape
*
* @private
* @method _initialize
*/
initializer: function(cfg)
{
var host = this;
host._initProps();
host.createNode();
},
/**
* Add a class name to each node.
*
* @method addClass
* @param {String} className the class name to add to the node's class attribute
*/
{
},
/**
* Removes a class name from each node.
*
* @method removeClass
* @param {String} className the class name to remove from the node's class attribute
*/
removeClass: function(className)
{
},
/**
* Gets the current position of the node in page coordinates.
*
* @method getXY
* @return Array The XY position of the shape.
*/
getXY: function()
{
x = this.get("x"),
y = this.get("y");
},
/**
* Set the position of the shape in page coordinates, regardless of how the node is positioned.
*
* @method setXY
* @param {Array} Contains X & Y values for new position (coordinates are page-based)
*/
{
this._set("x", x);
this._set("y", y);
this._updateNodePosition(x, y);
},
/**
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
*
* @method contains
* @param {CanvasShape | HTMLElement} needle The possible node or descendent
* @return Boolean Whether or not this shape is the needle or its ancestor.
*/
{
},
/**
* Test if the supplied node matches the supplied selector.
*
* @method test
* @param {String} selector The CSS selector to test against.
* @return Boolean Wheter or not the shape matches the selector.
*/
{
//return Y.Selector.test(this.node, selector);
},
/**
* Compares nodes to determine if they match.
* @method compareTo
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
* @return {Boolean} True if the nodes match, false if they do not.
*/
},
/**
* Value function for fill attribute
*
* @private
* @method _getDefaultFill
* @return Object
*/
_getDefaultFill: function() {
return {
type: "solid",
cx: 0.5,
cy: 0.5,
fx: 0.5,
fy: 0.5,
r: 0.5
};
},
/**
* Value function for stroke attribute
*
* @private
* @method _getDefaultStroke
* @return Object
*/
_getDefaultStroke: function()
{
return {
weight: 1,
dashstyle: "none",
color: "#000",
opacity: 1.0
};
},
/**
* Left edge of the path
*
* @private
*/
_left: 0,
/**
* Right edge of the path
*
* @private
*/
_right: 0,
/**
* Top edge of the path
*
* @private
*/
_top: 0,
/**
* Bottom edge of the path
*
* @private
*/
_bottom: 0,
/**
* Creates the dom node for the shape.
*
* @private
* @return HTMLElement
*/
createNode: function()
{
},
/**
* @private
*/
isMouseEvent: function(type)
{
{
return true;
}
return false;
},
/**
* @private
*/
{
if(this.isMouseEvent(type))
{
}
},
/**
* @private
*/
{
if(this.isMouseEvent(type))
{
}
},
/**
* @private
*/
{
if(this.isMouseEvent(type))
{
}
},
/**
* Adds a stroke to the shape node.
*
* @method _strokeChangeHandler
* @private
*/
_setStrokeProps: function(stroke)
{
this._miterlimit = null;
this._dashstyle = (dashstyle && Y.Lang.isArray(dashstyle) && dashstyle.length > 1) ? dashstyle : null;
this._strokeWeight = weight;
if (weight)
{
this._stroke = 1;
}
else
{
this._stroke = 0;
}
if (opacity) {
}
else
{
this._strokeStyle = color;
}
{
}
else
{
{
this._linejoin = "miter";
}
}
},
/**
* @private
*/
set: function()
{
var host = this,
{
}
},
/**
* Adds a fill to the shape node.
*
* @method _fillChangeHandler
* @private
*/
_setFillProps: function(fill)
{
{
}
else if(color)
{
{
}
else
{
}
this._fillColor = color;
this._fillType = 'solid';
}
else
{
this._fillColor = null;
}
},
/**
* Applies translate transformation.
*
* @method translate
* @param {Number} x The x-coordinate
* @param {Number} y The y-coordinate
* @protected
*/
translate: function(x, y)
{
},
/**
* Applies a skew to the x-coordinate
*
* @method skewX:q
* @param {Number} x x-coordinate
*/
skewX: function(x)
{
},
/**
* Applies a skew to the x-coordinate
*
* @method skewX:q
* @param {Number} x x-coordinate
*/
skewY: function(y)
{
},
/**
* @private
*/
_rotation: 0,
/**
* Applies a rotation.
*
* @method rotate
* @param
*/
{
},
/**
* 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
* fraction of the shape's corresponding bounding box dimension. The default value is [0.5, 0.5].
*
* @attribute transformOrigin
* @type Array
*/
_transformOrigin: function(x, y)
{
},
/**
* Applies a scale transform
*
* @method scale
* @param {Number} val
*/
{
},
/**
* Applies a matrix transformation
*
* @method matrix
*/
matrix: function(a, b, c, d, e, f)
{
},
/**
* @private
*/
{
transform = node.style.MozTransform || node.style.webkitTransform || node.style.msTransform || node.style.OTransform,
{
{
}
else
{
}
}
else
{
}
this._graphic.addToRedrawQueue(this);
},
/**
* @private
*/
_updateHandler: function()
{
this._draw();
this._graphic.addToRedrawQueue(this);
},
/**
* @private
*/
_draw: function()
{
this.clear();
this._paint();
},
/**
* Completes a shape or drawing
*
* @method _paint
* @private
*/
_paint: function()
{
if(!this._methods)
{
return;
}
methods = [],
i = 0,
j,
args,
len = 0;
if(this._methods)
{
{
return;
}
for(; i < len; ++i)
{
for(j = 1; j < argsLen; ++j)
{
if(j % 2 === 0)
{
}
else
{
}
}
}
for(i = 0; i < len; ++i)
{
{
if(method)
{
{
}
else
{
}
}
}
}
if (this._fillType)
{
if(this._fillType == "linear")
{
}
else if(this._fillType == "radial")
{
}
else
{
}
}
if (this._stroke) {
if(this._strokeWeight)
{
}
if(this._miterlimit)
{
}
}
this._drawingComplete = true;
this._clearAndUpdateCoords();
this._updateNodePosition();
this._methods = cachedMethods;
}
},
/**
* Draws a dashed line between two points.
*
* @method _drawDashedLine
* @param {Number} xStart The x position of the start of the line
* @param {Number} yStart The y position of the start of the line
* @param {Number} xEnd The x position of the end of the line
* @param {Number} yEnd The y position of the end of the line
* @private
*/
{
i;
for(i = 0; i < segmentCount; ++i)
{
}
{
}
else if(delta > 0)
{
}
},
/**
* Clears the graphics object.
*
* @method clear
*/
clear: function() {
this._initProps();
if(this.node)
{
}
return this;
},
/**
* Returns the bounds for a shape.
*
* @method getBounds
* @return Object
*/
getBounds: function()
{
w = this.get("width"),
h = this.get("height"),
x = this.get("x"),
y = this.get("y"),
right = x + w,
bottom = y + h,
tlx,
tly,
blx,
bly,
brx,
bry,
trx,
trY,
wt = 0,
bounds = {},
{
}
if(rotation !== 0)
{
}
else
{
}
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.
*
* @method _getRotatedCornerX
* @param {Number} x original x-coordinate of corner
* @param {Number} y original y-coordinate of corner
* @param {Number} tox transform origin x-coordinate of rotation
* @param {Number} toy transform origin y-coordinate of rotation
* @param {Number} cosRadians cosine (in radians) of rotation
* @param {Number} sinRadians sin (in radians) or rotation
* @return Number
* @private
*/
{
},
/**
* 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.
*
* @method _getRotatedCornerY
* @param {Number} x original x-coordinate of corner
* @param {Number} y original y-coordinate of corner
* @param {Number} tox transform origin x-coordinate of rotation
* @param {Number} toy transform origin y-coordinate of rotation
* @param {Number} cosRadians cosine (in radians) of rotation
* @param {Number} sinRadians sin (in radians) or rotation
* @return Number
* @private
*/
{
},
destroy: function()
{
if(node)
{
if(context)
{
}
{
}
}
}
}));
CanvasShape.ATTRS = {
/**
* 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
* fraction of the shape's corresponding bounding box dimension. The default value is [0.5, 0.5].
*
* @attribute transformOrigin
* @type Array
*/
valueFn: function()
{
return [0.5, 0.5];
}
},
/**
* The rotation (in degrees) of the shape.
*
* @attribute rotation
* @type Number
*/
rotation: {
{
},
getter: function()
{
return this._rotation;
}
},
/**
* Dom node of the shape
*
* @attribute node
* @type HTMLElement
* @readOnly
*/
node: {
readOnly: true,
getter: function()
{
return this.node;
}
},
/**
* Unique id for class instance.
*
* @attribute id
* @type String
*/
id: {
valueFn: function()
{
return Y.guid();
},
{
if(node)
{
}
return val;
}
},
/**
* Indicates the width of the shape
*
* @attribute width
* @type Number
*/
width: {
value: 0
},
/**
* Indicates the height of the shape
*
* @attribute height
* @type Number
*/
height: {
value: 0
},
/**
* Indicates the x position of shape.
*
* @attribute x
* @type Number
*/
x: {
value: 0
},
/**
* Indicates the y position of shape.
*
* @attribute y
* @type Number
*/
y: {
value: 0
},
/**
* Indicates whether the shape is visible.
*
* @attribute visible
* @type Boolean
*/
visible: {
value: true,
return val;
}
},
/**
* Contains information about the fill of the shape.
* <dl>
* <dt>color</dt><dd>The color of the fill.</dd>
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
* <dt>type</dt><dd>Type of fill.
* <dl>
* <dt>solid</dt><dd>Solid single color fill. (default)</dd>
* <dt>linear</dt><dd>Linear gradient fill.</dd>
* <dt>radial</dt><dd>Radial gradient fill.</dd>
* </dl>
* </dd>
* </dl>
*
* <p>If a gradient (linear or radial) is specified as the fill type. The following properties are used:
* <dl>
* <dt>stops</dt><dd>An array of objects containing the following properties:
* <dl>
* <dt>color</dt><dd>The color of the stop.</dd>
* <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>
* <dt>offset</dt><dd>Number between 0 and 1 indicating where the color stop is positioned.</dd>
* </dl>
* </dd>
* <dt></dt><dd></dd>
* <dt></dt><dd></dd>
* <dt></dt><dd></dd>
* </dl>
* </p>
*
* @attribute fill
* @type Object
*/
fill: {
valueFn: "_getDefaultFill",
{
var fill,
{
{
}
}
this._setFillProps(fill);
return fill;
}
},
/**
* Contains information about the stroke of the shape.
* <dl>
* <dt>color</dt><dd>The color of the stroke.</dd>
* <dt>weight</dt><dd>Number that indicates the width of the stroke.</dd>
* <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
* length of the dash. The second index indicates the length of gap.
* </dl>
*
* @attribute stroke
* @type Object
*/
stroke: {
valueFn: "_getDefaultStroke",
{
this._setStrokeProps(val);
return val;
}
},
/**
* Indicates whether or not the instance will size itself based on its contents.
*
* @attribute autoSize
* @type Boolean
*/
autoSize: {
value: false
},
/**
* Determines whether the instance will receive mouse events.
*
* @attribute pointerEvents
* @type string
*/
value: "visiblePainted"
},
/**
* Reference to the container Graphic.
*
* @attribute graphic
* @type Graphic
*/
graphic: {
readOnly: true,
getter: function()
{
return this._graphic;
}
}
};
Y.CanvasShape = CanvasShape;