CanvasGraphic.js revision a89ad754cce3cfc8aee71760e10217b54020360d
/**
* CanvasGraphic is a simple drawing api that allows for basic drawing operations.
*
* @class CanvasGraphic
* @constructor
*/
function CanvasGraphic(config) {
}
CanvasGraphic.ATTRS = {
render: {},
/**
* 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 contentBox
* @type Object
*/
contentBox: {
readOnly: true,
getter: function()
{
return this._contentBox;
}
},
/**
* The html element that represents to coordinate system of the Graphic instance.
*
* @attribute coordPlaneNode
* @type HTMLElement
*/
readOnly: true,
getter: function()
{
return this._coordPlaneNode;
}
},
width: {
{
if(this._coordPlaneNode)
{
}
return val;
}
},
height: {
{
if(this._coordPlaneNode)
{
}
return val;
}
}
};
/**
* Gets the current position of the node in page coordinates.
*
* @method getXY
* @return Array The XY position of the shape.
*/
getXY: function()
{
return xy;
},
/**
* Indicates whether or not the instance will size itself based on its contents.
*
* @property autoSize
* @type String
*/
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._shapes = {};
this._redrawQueue = {};
this._contentBox = {
left: 0,
top: 0,
right: 0,
bottom: 0
};
this.set("width", w);
this.set("height", h);
if(render)
{
}
},
/**
* Sets the positon of the graphics object.
*
* @method setPosition
* @param {Number} x x-coordinate for the object.
* @param {Number} y y-coordinate for the object.
*/
setPosition: function(x, y)
{
},
/**
* Adds the graphics node to the dom.
*
* @method render
* @param {HTMLElement} parentNode node in which to render the graphics node into.
*/
node = this._coordPlaneNode,
this.set("width", w);
this.set("height", h);
this.parentNode = parentNode;
return this;
},
/**
* Shows and and hides a the graphic instance.
*
* @method toggleVisible
* @param val {Boolean} indicates whether the instance should be visible.
*/
toggleVisible: function(val)
{
},
/**
* 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.updateContentBox();
}
},
/**
* 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;
},
/**
* Removes a shape instance from from the graphic instance.
*
* @method removeShape
* @param {Shape|String}
*/
removeShape: function(shape)
{
var node;
if(!(shape instanceof CanvasShape))
{
{
}
}
{
}
if(this.autoDraw)
{
this.updateContentBox();
}
return shape;
},
/**
* Removes all shape instances from the dom.
*
* @method removeAllShapes
*/
removeAllShapes: function()
{
i;
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
}
}
this._shapes = {};
},
/**
* @private
*/
_shapeClass: {
circle: Y.CanvasCircle,
rect: Y.CanvasRect,
path: Y.CanvasPath,
},
/**
* Allows for creating multiple shapes in order to batch appending and redraw operations.
*
* @method batch
* @param {Function} method Method to execute.
*/
{
var node = this._coordPlaneNode,
this.autoDraw = false;
method();
this.updateContentBox();
this._frag = null;
this.autoDraw = true;
},
/**
* Removes all nodes.
*
* @method destroy
*/
destroy: function()
{
this._removeChildren(this._coordPlaneNode);
{
}
},
/**
* Removes all child nodes.
*
* @method _removeChildren
* @param {HTMLElement} node
* @private
*/
_removeChildren: function(node)
{
if(node.hasChildNodes())
{
var child;
while(node.firstChild)
{
this._removeChildren(child);
}
}
},
/**
* Updates the size of the graphics container and the position of its children.
*
* @method updateContentBox
*/
updateContentBox: function(e)
{
var bounds,
i,
box = this._contentBox,
for(i in queue)
{
if(queue.hasOwnProperty(i))
{
}
}
this._redrawQueue = {};
this._contentBox = box;
},
/**
* Adds a shape to the redraw queue.
*
* @method addToRedrawQueue
* @param shape {CanvasShape}
*/
addToRedrawQueue: function(shape)
{
if(this.autoDraw)
{
this.updateContentBox();
}
}
});