CanvasShape.js revision 2ebe57b26e070070dacbe6e2b3351d5cefaee874
/**
* Base class for creating shapes.
*
* @module graphics
* @class CanvasShape
* @constructor
*/
CanvasShape = function(cfg)
{
this._transforms = [];
};
/**
* Init method, invoked during construction.
* Calls `initializer` method.
*
* @method init
* @protected
*/
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
*
* @method _getDefaultFill
* @return Object
* @private
*/
_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
*
* @method _getDefaultStroke
* @return Object
* @private
*/
_getDefaultStroke: function()
{
return {
weight: 1,
dashstyle: "none",
color: "#000",
opacity: 1.0
};
},
/**
* Left edge of the path
*
* @property _left
* @type Number
* @private
*/
_left: 0,
/**
* Right edge of the path
*
* @property _right
* @type Number
* @private
*/
_right: 0,
/**
* Top edge of the path
*
* @property _top
* @type Number
* @private
*/
_top: 0,
/**
* Bottom edge of the path
*
* @property _bottom
* @type Number
* @private
*/
_bottom: 0,
/**
* Creates the dom node for the shape.
*
* @method createNode
* @return HTMLElement
* @private
*/
createNode: function()
{
},
/**
* Overrides default `on` method. Checks to see if its a dom interaction event. If so,
* return an event attached to the `node` element. If not, return the normal functionality.
*
* @method on
* @param {String} type event type
* @param {Object} callback function
* @private
*/
{
{
}
},
/**
* Adds a stroke to the shape node.
*
* @method _strokeChangeHandler
* @param {Object} stroke Properties of the `stroke` attribute.
* @private
*/
_setStrokeProps: function(stroke)
{
this._miterlimit = null;
this._dashstyle = (dashstyle && Y.Lang.isArray(dashstyle) && dashstyle.length > 1) ? dashstyle : null;
this._strokeWeight = weight;
{
this._stroke = 1;
}
else
{
this._stroke = 0;
}
}
else
{
this._strokeStyle = color;
}
{
}
else
{
{
this._linejoin = "miter";
}
}
},
/**
* Sets the value of an attribute.
*
* @method set
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
* be passed in to set multiple attributes at once.
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
* the name param.
*/
set: function()
{
var host = this,
if(host.initialized)
{
}
},
/**
* Adds a fill to the shape node.
*
* @method _setFillProps
* @param {Object} fill Properties of the `fill` attribute.
* @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 value to transate on the x-axis.
* @param {Number} y The value to translate on the y-axis.
*/
translate: function(x, y)
{
this._translateX += x;
this._translateY += y;
},
/**
* Performs a translate on the x-coordinate. When translating x and y coordinates,
* use the `translate` method.
*
* @method translateX
* @param {Number} y The value to translate.
*/
translateX: function(x)
{
this._translateX += x;
},
/**
* Performs a translate on the y-coordinate. When translating x and y coordinates,
* use the `translate` method.
*
* @method translateY
* @param {Number} y The value to translate.
*/
translateY: function(y)
{
this._translateY += y;
},
/**
* Applies a skew transformation.
*
* @method skew
* @param {Number} x The value to skew on the x-axis.
* @param {Number} y The value to skew on the y-axis.
*/
skew: function(x, y)
{
},
/**
* Applies a skew to the x-coordinate
*
* @method skewX
* @param {Number} x x-coordinate
*/
skewX: function(x)
{
},
/**
* Applies a skew to the y-coordinate
*
* @method skewY
* @param {Number} y y-coordinate
*/
skewY: function(y)
{
},
/**
* Applies a rotate transform.
*
* @method rotate
* @param {Number} deg The degree of the rotation.
*/
{
},
/**
* Applies a scale transform
*
* @method scale
* @param {Number} val
*/
scale: function(x, y)
{
},
/**
* Storage for `rotation` atribute.
*
* @property _rotation
* @type Number
* @private
*/
_rotation: 0,
/**
* Storage for the transform attribute.
*
* @property _transform
* @type String
* @private
*/
_transform: "",
/**
* Adds a transform to the shape.
*
* @method _addTransform
* @param {String} type The transform being applied.
* @param {Array} args The arguments for the transform.
* @private
*/
{
if(this.initialized)
{
this._updateTransform();
}
},
/**
* Applies all transforms.
*
* @method _updateTransform
* @private
*/
_updateTransform: function()
{
key,
i = 0,
{
for(; i < len; ++i)
{
if(key)
{
}
}
}
this._graphic.addToRedrawQueue(this);
if(transform)
{
}
this._transforms = [];
},
/**
* Updates `Shape` based on attribute changes.
*
* @method _updateHandler
* @private
*/
_updateHandler: function()
{
this._draw();
this._updateTransform();
},
/**
* Updates the shape.
*
* @method _draw
* @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
*/
{
},
/**
* Destroys the instance.
*
* @method destroy
*/
destroy: function()
{
if(node)
{
if(context)
{
}
{
}
}
}
}, Y.CanvasDrawing.prototype));
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].
*
* @config transformOrigin
* @type Array
*/
valueFn: function()
{
return [0.5, 0.5];
}
},
/**
* A css transform string.
*
* @config transform
* @type String
*
* @writeOnly
*/
transform: {
{
this._transform = val;
if(this.initialized)
{
this._updateTransform();
}
return val;
},
getter: function()
{
return this._transform;
}
},
/**
* Dom node for the shape
*
* @config node
* @type HTMLElement
* @readOnly
*/
node: {
readOnly: true,
getter: function()
{
return this.node;
}
},
/**
* Unique id for class instance.
*
* @config id
* @type String
*/
id: {
valueFn: function()
{
return Y.guid();
},
{
if(node)
{
}
return val;
}
},
/**
* Indicates the width of the shape
*
* @config width
* @type Number
*/
width: {
value: 0
},
/**
* Indicates the height of the shape
*
* @config height
* @type Number
*/
height: {
value: 0
},
/**
* Indicates the x position of shape.
*
* @config x
* @type Number
*/
x: {
value: 0
},
/**
* Indicates the y position of shape.
*
* @config y
* @type Number
*/
y: {
value: 0
},
/**
* Indicates whether the shape is visible.
*
* @config 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>
*
* @config 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>
*
* @config stroke
* @type Object
*/
stroke: {
valueFn: "_getDefaultStroke",
{
this._setStrokeProps(val);
return val;
}
},
/**
* Indicates whether or not the instance will size itself based on its contents.
*
* @config autoSize
* @type Boolean
*/
autoSize: {
value: false
},
/**
* Determines whether the instance will receive mouse events.
*
* @config pointerEvents
* @type string
*/
value: "visiblePainted"
},
/**
* Reference to the container Graphic.
*
* @config graphic
* @type Graphic
*/
graphic: {
readOnly: true,
getter: function()
{
return this._graphic;
}
}
};
Y.CanvasShape = CanvasShape;