SVGShape.js revision c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4e
/**
* Base class for creating shapes.
*
* @class SVGShape
*/
{
};
/**
* @private
*/
init: function()
{
},
/**
* Initializes the shape
*
* @private
* @method _initialize
*/
initializer: function(cfg)
{
var host = this;
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)
{
classString = classString.replace(new RegExp(className + ' '), className).replace(new RegExp(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)
*/
{
},
/**
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
*
* @method contains
* @param {SVGShape | HTMLElement} needle The possible node or descendent
* @return Boolean Whether or not this shape is the needle or its ancestor.
*/
{
},
/**
* 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.
*/
},
/**
* 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.
*/
{
},
/**
* Value function for fill attribute
*
* @private
* @method _getDefaultFill
* @return Object
*/
_getDefaultFill: function() {
return {
type: "solid",
opacity: 1,
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
};
},
/**
* Creates the dom node for the shape.
*
* @private
* @return HTMLElement
*/
createNode: function()
{
if(id)
{
}
if(pointerEvents)
{
}
},
/**
* @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
*/
_strokeChangeHandler: function(e)
{
dash,
{
{
}
else
{
{
}
}
}
else
{
}
},
/**
* Adds a fill to the shape node.
*
* @method _fillChangeHandler
* @private
*/
_fillChangeHandler: function(e)
{
type;
if(fill)
{
{
this._setGradientFill(fill);
}
{
}
else
{
}
}
else
{
}
},
/**
* Returns a linear gradient fill
*
* @method _getLinearGradient
* @param {String} type gradient type
* @private
*/
_setGradientFill: function(fill) {
var offset,
w = this.get("width"),
h = this.get("height"),
i,
len,
def,
stop,
x1 = "0%",
x2 = "100%",
y1 = "50%",
y2 = "50%",
r = fill.r;
if(type == "linear")
{
gradientNode.setAttribute("gradientTransform", "rotate(" + rotation + "," + (w/2) + ", " + (h/2) + ")");
}
else
{
}
def = 0;
for(i = 0; i < len; ++i)
{
}
},
/**
* @private
*/
set: function()
{
var host = this;
if(host.initialized)
{
}
},
/**
* Applies translate transformation.
*
* @method translate
* @param {Number} x The x-coordinate
* @param {Number} y The y-coordinate
*/
translate: function(x, y)
{
this._translateX = x;
this._translateY = y;
},
/**
* 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
* @param {Number} x x-coordinate
*/
skewX: function(x)
{
},
/**
* Applies a skew to the x-coordinate
*
* @method skewX
* @param {Number} x x-coordinate
*/
skewY: function(y)
{
},
/**
* @private
*/
_rotation: 0,
/**
* Applies a rotation.
*
* @method rotate
* @param
*/
{
},
/**
* Applies a scale transform
*
* @method scale
* @param {Number} val
*/
{
},
/**
* Applies a matrix transformation
*
* @method matrix
*/
matrix: function(a, b, c, d, e, f)
{
},
/**
* @private
*/
{
if(!this._transformArgs)
{
this._transformArgs = {};
}
this._updateTransform();
},
/**
* @private
*/
_updateTransform: function()
{
key,
args,
val,
test,
if(this._transformArgs)
{
{
}
}
for(key in this._transformArgs)
{
{
{
{
}
else
{
}
}
else
{
}
}
}
this._graphic.addToRedrawQueue(this);
if(transform)
{
}
},
/**
* Updates the shape.
*
* @method _draw
* @private
*/
_draw: function()
{
this._fillChangeHandler();
this._strokeChangeHandler();
this._updateTransform();
},
/**
* Change event listener
*
* @private
* @method _updateHandler
*/
_updateHandler: function(e)
{
this._draw();
},
/**
* Storage for translateX
*
* @private
*/
_translateX: 0,
/**
* Storage for translateY
*
* @private
*/
_translateY: 0,
/**
* 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()
{
{
}
}
});
/**
* 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;
}
},
/**
* Unique id for class instance.
*
* @attribute id
* @type String
*/
id: {
valueFn: function()
{
return Y.guid();
},
{
if(node)
{
}
return val;
}
},
/**
* 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 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 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,
{
{
}
}
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",
{
}
},
/**
* 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
*/
valueFn: function()
{
var val = "visiblePainted",
if(node)
{
}
return val;
},
{
if(node)
{
}
return val;
}
},
/**
* Performs a translate on the x-coordinate. When translating x and y coordinates,
* use the <code>translate</code> method.
*
* @attribute translateX
* @type Number
*/
translateX: {
getter: function()
{
return this._translateX;
},
{
this._translateX = val;
return val;
}
},
/**
* Performs a translate on the y-coordinate. When translating x and y coordinates,
* use the <code>translate</code> method.
*
* @attribute translateX
* @type Number
*/
translateY: {
getter: function()
{
return this._translateY;
},
{
this._translateY = val;
return val;
}
},
/**
* The node used for gradient fills.
*
* @attribute gradientNode
* @type HTMLElement
*/
gradientNode: {
{
{
}
return val;
}
},
/**
* Indicates whether to automatically refresh.
*
* @attribute autoDraw
* @type Boolean
* @readOnly
*/
autoDraw: {
getter: function()
{
}
},
/**
* Dom node for the shape.
*
* @attribute node
* @type HTMLElement
* @readOnly
*/
node: {
readOnly: true,
getter: function()
{
return this.node;
}
},
/**
* Reference to the parent graphic instance
*
* @graphic
* @type SVGGraphic
* @readOnly
*/
graphic: {
readOnly: true,
getter: function()
{
return this._graphic;
}
}
};