CanvasGraphic.js revision c790ee5b4dcc7d98b68c124495c76d7d515bdc8d
/**
* CanvasGraphic is a simple drawing api that allows for basic drawing operations.
*
* @class CanvasGraphic
* @constructor
*/
function CanvasGraphic(config) {
}
CanvasGraphic.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 graphic instance's position.
*
* @attribute contentBounds
* @type Object
* @readOnly
*/
readOnly: true,
getter: function()
{
return this._contentBounds;
}
},
/**
* The outermost html element of the Graphic instance.
*
* @attribute node
* @type HTMLElement
* @readOnly
*/
node: {
readOnly: true,
getter: function()
{
return this._node;
}
},
width: {
{
if(this._node)
{
}
return val;
}
},
height: {
{
if(this._node)
{
}
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;
}
}
};
/**
* @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(config) {
this._shapes = {};
this._redrawQueue = {};
this._contentBounds = {
left: 0,
top: 0,
right: 0,
bottom: 0
};
this.set("width", w);
this.set("height", h);
if(render)
{
}
},
/**
* Adds the graphics node to the dom.
*
* @method render
* @param {HTMLElement} parentNode node in which to render the graphics node into.
*/
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(!(shape instanceof CanvasShape))
{
{
}
}
{
}
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);
}
}
},
/**
* 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: {
circle: Y.CanvasCircle,
rect: Y.CanvasRect,
path: Y.CanvasPath,
},
/**
* 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()
{
if(this.get("autoSize"))
{
}
if(this._frag)
{
this._frag = null;
}
},
/**
* Adds a shape to the redraw queue.
*
* @method addToRedrawQueue
* @param shape {CanvasShape}
*/
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;
}
});