SVGGraphic.js revision e7c7565d9550eaa87043aef0df77125ada996dea
/**
* Graphic is a simple drawing api that allows for basic drawing operations.
*
* @class Graphic
* @constructor
*/
function SVGGraphic(config) {
}
SVGGraphic.prototype = {
/**
* Gets the current position of the node's parentNode in page coordinates.
*
* @method getXY
* @return Array The XY position of the shape.
*/
getXY: function()
{
if(parentNode)
{
}
return parentXY;
},
/**
* Indicates whether or not the instance will size itself based on its contents.
*
* @property autoSize
* @type Boolean
* @default true
*/
autoSize: true,
/**
* 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.
*
* @property autoDraw
* @type Boolean
* @default true
*/
autoDraw: true,
/**
* Initializes the class.
*
* @method initializer
* @private
*/
initializer: function(config) {
this._shapeInstances = {
ellipse: null,
circle: null,
path: null,
rect: null
};
this._shapes = {};
this._redrawQueue = {};
this._gradients = {};
this.group = this._createGraphics();
this.setSize(w, h);
{
}
},
/**
* Removes all nodes.
*
* @method destroy
*/
destroy: function()
{
this._removeChildren(this.node);
{
}
},
/**
* Removes all child nodes.
*
* @method _removeChildren
* @param {HTMLElement} node
* @private
*/
_removeChildren: function(node)
{
if(node.hasChildNodes())
{
var child;
while(node.firstChild)
{
this._removeChildren(child);
}
}
},
/**
* Shows and and hides a the graphic instance.
*
* @method toggleVisible
* @param val {Boolean} indicates whether the instance should be visible.
*/
toggleVisible: function(val)
{
},
/**
* Toggles visibility
*
* @method _toggleVisible
* @param {HTMLElement} node element to toggle
* @param {Boolean} val indicates visibilitye
* @private
*/
{
i = 0,
len;
if(children)
{
for(; i < len; ++i)
{
}
}
},
/**
* Clears the graphics object.
*
* @method clear
*/
clear: function() {
if(this._graphicsList)
{
{
}
}
},
/**
* 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.
*/
setSize: function(w, h) {
if(this.autoSize)
{
{
}
{
}
}
},
/**
* 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;
}
},
/**
* Adds the graphics node to the dom.
*
* @method render
* @param {HTMLElement} parentNode node in which to render the graphics node into.
*/
this.setSize(w, h);
this.parentNode = parentNode;
return this;
},
/**
* Creates a group element
*
* @method _createGraphics
* @private
*/
_createGraphics: function() {
this._styleGroup(group);
return group;
},
/**
* Styles a group element
*
* @method _styleGroup
* @private
*/
_styleGroup: function(group)
{
},
/**
* 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;
},
/**
* Adds a shape instance to the graphic instance.
*
* @method addShape
* @param {Shape} shape The shape instance to be added to the graphic.
*/
{
if(!this._graphicsList)
{
this._graphicsList = [];
}
if(this.autoDraw)
{
this.updateCoordSpace();
}
},
/**
* 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;
},
/**
* 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.
*
* @property resizeDown
* @type Boolean
*/
resizeDown: false,
/**
* @private
*/
_shapeClass: {
},
/**
* @private
*/
_shapeIntances: null,
/**
* 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.autoDraw = false;
method();
this.updateCoordSpace();
this._frag = null;
this.autoDraw = true;
},
/**
* Updates the size of the graphics container and the position of its children.
*
* @method updateCoordSpace
*/
updateCoordSpace: function(e)
{
var bounds,
i,
for(i in queue)
{
if(queue.hasOwnProperty(i))
{
}
}
this._redrawQueue = {};
this.group.setAttribute("viewBox", "" + this._left + " " + this._top + " " + this._width + " " + this._height + "");
},
/**
* Adds a shape to the redraw queue.
*
* @method addToRedrawQueue
* @param shape {SVGShape}
*/
addToRedrawQueue: function(shape)
{
if(this.autoDraw)
{
this.updateCoordSpace();
}
},
/**
* @private
*/
_left: 0,
/**
* @private
*/
_right: 0,
/**
* @private
*/
_top: 0,
/**
* @private
*/
_bottom: 0,
/**
* 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;