SVGGraphic.js revision 4ef2f7e4cb7c7d255be077c47d542199f7bf8607
/**
* Graphic is a simple drawing api that allows for basic drawing operations.
*
* @class Graphic
* @constructor
*/
SVGGraphic = function(cfg) {
};
SVGGraphic.ATTRS = {
render: {},
/**
* Unique id for class instance.
*
* @attribute id
* @type String
*/
id: {
valueFn: function()
{
return Y.guid();
},
{
if(node)
{
}
return val;
}
},
/**
* Key value pairs in which a shape instance is associated with its id.
*
* @attribute shapes
* @type Object
* @readOnly
*/
shapes: {
readOnly: true,
getter: function()
{
return this._shapes;
}
},
/**
* Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
*
* @attribute contentBounds
* @type Object
* @readOnly
*/
readOnly: true,
getter: function()
{
return this._contentBounds;
}
},
/**
* The html element that represents to coordinate system of the Graphic instance.
*
* @attribute node
* @type HTMLElement
* @readOnly
*/
node: {
readOnly: true,
getter: function()
{
return this._node;
}
},
width: {
{
return val;
}
},
height: {
{
return val;
}
},
/**
* Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents.
* If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions.
*
* @attribute autoSize
* @type Boolean
* @default false
*/
autoSize: {
value: false
},
/**
* When overflow is set to true, by default, the viewBox will resize to greater values but not values. (for performance)
* When resizing the viewBox down is desirable, set the resizeDown value to true.
*
* @attribute resizeDown
* @type Boolean
*/
resizeDown: {
getter: function()
{
return this._resizeDown;
},
{
this._resizeDown = val;
this._redraw();
return val;
}
},
/**
* Indicates the x-coordinate for the instance.
*
* @attribute x
* @type Number
*/
x: {
getter: function()
{
return this._x;
},
{
if(this._node)
{
}
return val;
}
},
/**
* Indicates the y-coordinate for the instance.
*
* @attribute y
* @type Number
*/
y: {
getter: function()
{
return this._y;
},
{
if(this._node)
{
}
return val;
}
},
/**
* Indicates whether or not the instance will automatically redraw after a change is made to a shape.
* This property will get set to false when batching operations.
*
* @attribute autoDraw
* @type Boolean
* @default true
* @private
*/
autoDraw: {
value: true
},
visible: {
value: true,
{
this._toggleVisible(val);
return val;
}
},
/**
* Indicates the pointer-events setting for the svg:svg element.
*
* @attribute pointerEvents
* @type String
*/
value: "none"
}
};
/**
* @private
*/
_x: 0,
/**
* @private
*/
_y: 0,
/**
* Gets the current position of the graphic instance in page coordinates.
*
* @method getXY
* @return Array The XY position of the shape.
*/
getXY: function()
{
xy;
if(node)
{
}
return xy;
},
/**
* @private
* @property _resizeDown
* @type Boolean
*/
_resizeDown: false,
/**
* Initializes the class.
*
* @method initializer
* @private
*/
initializer: function() {
this._shapes = {};
this._contentBounds = {
left: 0,
top: 0,
right: 0,
bottom: 0
};
this._gradients = {};
this._contentNode = this._createGraphics();
if(render)
{
}
},
/**
* Adds the graphics node to the dom.
*
* @method render
* @param {HTMLElement} parentNode node in which to render the graphics node into.
*/
this.parentNode = parentNode;
this.set("width", w);
this.set("height", h);
this.parentNode = parentNode;
return this;
},
/**
* Removes all nodes.
*
* @method destroy
*/
destroy: function()
{
this.removeAllShapes();
this._removeChildren(this._node);
{
}
},
/**
* Generates a shape instance by type.
*
* @method getShape
* @param {String} type type of shape to generate.
* @param {Object} cfg attributes for the shape
* @return Shape
*/
{
return shape;
},
/**
* Adds a shape instance to the graphic instance.
*
* @method addShape
* @param {Shape} shape The shape instance to be added to the graphic.
*/
{
if(this.get("autoDraw"))
{
}
else
{
}
},
/**
* Removes a shape instance from from the graphic instance.
*
* @method removeShape
* @param {Shape|String}
*/
removeShape: function(shape)
{
{
{
}
}
{
}
if(this.get("autoDraw"))
{
this._redraw();
}
return shape;
},
/**
* Removes all shape instances from the dom.
*
* @method removeAllShapes
*/
removeAllShapes: function()
{
i;
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
}
}
this._shapes = {};
},
/**
* Removes all child nodes.
*
* @method _removeChildren
* @param {HTMLElement} node
* @private
*/
_removeChildren: function(node)
{
if(node.hasChildNodes())
{
var child;
while(node.firstChild)
{
this._removeChildren(child);
}
}
},
/**
* Clears the graphics object.
*
* @method clear
*/
clear: function() {
this.removeAllShapes();
},
/**
* Toggles visibility
*
* @method _toggleVisible
* @param {HTMLElement} node element to toggle
* @param {Boolean} val indicates visibilitye
* @private
*/
_toggleVisible: function(val)
{
var i,
if(shapes)
{
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
}
}
}
},
/**
* @private
*/
_shapeClass: {
},
/**
* Returns a shape based on the id of its dom node.
*
* @method getShapeById
* @param {String} id Dom id of the shape's node attribute.
* @return Shape
*/
getShapeById: function(id)
{
return shape;
},
/**
* Allows for creating multiple shapes in order to batch appending and redraw operations.
*
* @method batch
* @param {Function} method Method to execute.
*/
{
this.set("autoDraw", false);
method();
this._redraw();
},
_getDocFrag: function()
{
if(!this._frag)
{
}
return this._frag;
},
_redraw: function()
{
this._contentNode.setAttribute("viewBox", "" + box.left + " " + box.top + " " + box.width + " " + box.height + "");
if(this.get("autoSize"))
{
}
if(this._frag)
{
this._frag = null;
}
},
/**
* Adds a shape to the redraw queue and calculates the contentBounds.
*
* @method addToRedrawQueue
* @param shape {SVGShape}
*/
addToRedrawQueue: function(shape)
{
var shapeBox,
box;
if(!this.get("resizeDown"))
{
box = this._contentBounds;
this._contentBounds = box;
}
if(this.get("autoDraw"))
{
this._redraw();
}
},
_getUpdatedContentBounds: function()
{
var bounds,
i,
box = {
left: 0,
top: 0,
right: 0,
bottom: 0
};
for(i in queue)
{
if(queue.hasOwnProperty(i))
{
}
}
this._contentBounds = box;
return box;
},
/**
* Creates a contentNode element
*
* @method _createGraphics
* @private
*/
_createGraphics: function() {
return contentNode;
},
/**
* Creates a graphic node
*
* @method _createGraphicNode
* @param {String} type node type to create
* @param {String} pe specified pointer-events value
* @return HTMLElement
* @private
*/
{
v = pe || "none";
{
}
return node;
},
/**
* Returns a reference to a gradient definition based on an id and type.
*
* @method getGradientNode
* @key {String} id that references the gradient definition
* @type {String} description of the gradient type
* @return HTMLElement
*/
{
var gradients = this._gradients,
{
}
else
{
if(!this._defs)
{
}
{
}
}
return gradient;
}
});
Y.SVGGraphic = SVGGraphic;