VMLGraphic.js revision 7947db4b7d8682ea81598e3a4283e659a8103be6
/**
* VMLGraphic is a simple drawing api that allows for basic drawing operations.
*
* @class VMLGraphic
* @constructor
*/
VMLGraphic = function() {
};
VMLGraphic.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 _coordPlaneNode
* @type Object
*/
readOnly: true,
getter: function()
{
return this._contentBounds;
}
},
/**
* 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;
}
}
};
getXY: function()
{
return xy;
},
/**
* Initializes the class.
*
* @method initializer
* @private
*/
initializer: function(config) {
this._coordPlaneNode = this._createGraphic();
this._initProps();
if(render)
{
}
},
/**
* 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,
/**
* Clears the graphics object.
*
* @method clear
*/
clear: function() {
this._path = '';
this._removeAllShapes();
this._removeChildren(this._coordPlaneNode);
},
/**
* Removes all nodes.
*
* @method destroy
*/
destroy: function()
{
this.clear();
},
/**
* 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 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)
{
}
}
},
/**
* Sets the size of the graphics object.
*
* @method setContentSize
* @param w {Number} width to set for the instance.
* @param h {Number} height to set for the instance.
*/
setContentSize: function(w, h) {
w = Math.round(w);
h = Math.round(h);
},
/**
* 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)
{
x = Math.round(x);
y = Math.round(y);
},
/**
* Adds the graphics node to the dom.
*
* @method render
* @param {HTMLElement} parentNode node in which to render the graphics node into.
*/
this.setContentSize(w, h);
this.parentNode = parentNode;
this.set("width", w);
this.set("height", h);
return this;
},
/**
* Clears the properties
*
* @method _initProps
* @private
*/
_initProps: function() {
this._fillColor = null;
this._strokeColor = null;
this._strokeOpacity = null;
this._strokeWeight = 0;
this._fillProps = null;
this._path = '';
this._contentBounds = {
left: 0,
top: 0,
right: 0,
bottom: 0
};
this._x = 0;
this._y = 0;
this._fill = null;
this._stroke = 0;
this._stroked = false;
this._dashstyle = null;
},
/**
* Creates a group element
*
* @method _createGraphic
* @private
*/
_createGraphic: function() {
var group = document.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
return group;
},
/**
* Creates a graphic node
*
* @method _createGraphicNode
* @param {String} type node type to create
* @param {String} pe specified pointer-events value
* @return HTMLElement
* @private
*/
_createGraphicNode: function(type)
{
return document.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
},
/**
* Adds a shape instance to the graphic instance.
*
* @method addShape
* @param {Shape} shape The shape instance to be added to the graphic.
*/
{
if(!this._shapes)
{
this._shapes = {};
}
if(this.autoDraw)
{
this.updateContentBox();
}
},
/**
* 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)
{
},
/**
* 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)
{
{
{
}
}
{
}
if(this.autoDraw)
{
this.updateContentBox();
}
},
/**
* @private
*/
_shapeClass: {
},
/**
* Adds a child to the <code>node</code>.
*
* @method addChild
* @param {HTMLElement} element to add
* @private
*/
{
},
/**
* 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;
},
/**
* Updates the size of the graphics container and.
*
* @method updateContentBox
*/
updateContentBox: function(e)
{
var bounds,
i,
w,
h,
box = this._contentBounds,
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
}
}
this._contentBounds = box;
}
});
Y.VMLGraphic = VMLGraphic;