VMLGraphic.js revision c093c1aed867e18aa4778708592e1ceb45d18cff
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class VMLGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
a89ad754cce3cfc8aee71760e10217b54020360dTrippVMLGraphic = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp VMLGraphic.superclass.constructor.apply(this, arguments);
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Whether or not to render the `Graphic` automatically after to a specified parent node after init. This can be a Node instance or a CSS selector string.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config render
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Node | String
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Unique id for class instance.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config id
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type String
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp valueFn: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return Y.guid();
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Key value pairs in which a shape instance is associated with its id.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config shapes
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp return this._shapes;
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config contentBounds
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The html element that represents to coordinate system of the Graphic instance.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type HTMLElement
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._node;
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the width of the `Graphic`.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config width
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the height of the `Graphic`.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config height
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config autoSize
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default false
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp * When overflow is set to true, by default, the contentBounds will resize to greater values but not values. (for performance)
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp * When resizing the contentBounds down is desirable, set the resizeDown value to true.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._resizeDown;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the x-coordinate for the instance.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config x
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._x;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the y-coordinate for the instance.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config y
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * This property will get set to false when batching operations.
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config autoDraw
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default true
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Gets the current position of the graphic instance in page coordinates.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method getXY
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Array The XY position of the shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds the graphics node to the dom.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method render
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.setSize(w, h);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all nodes.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method destroy
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp destroy: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Generates a shape instance by type.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method addShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} type type of shape to generate.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Object} cfg attributes for the shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape instance to the graphic instance.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _appendShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Shape} shape The shape instance to be added to the graphic.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes a shape instance from from the graphic instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method removeShape
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {Shape|String} shape The instance or id of the shape to be removed.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Removes all shape instances from the dom.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method removeAllShapes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all child nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _removeChildren
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Clears the graphics object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method clear
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clear: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Toggles visibility
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = Math.round(w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = Math.round(h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the positon of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setPosition
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setPosition: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = Math.round(x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = Math.round(y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a group element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphic: function() {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp var group = DOCUMENT.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a graphic node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphicNode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type node type to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} pe specified pointer-events value
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return HTMLElement
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp return DOCUMENT.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a shape based on the id of its dom node.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShapeById
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} id Dom id of the shape's node attribute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a shape class. Used by `addShape`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param {Shape | String} val Indicates which shape class.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return Function
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Look up for shape classes. Used by `addShape` to retrieve a class for instantiation.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @property _shapeClass
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Object
9eaaa502227248d304ac9170902697d02158c1d9Tripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @method batch
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @param {Function} method Method to execute.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a document fragment to for attaching shapes.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _getDocFrag
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return DocumentFragment
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._frag;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape to the redraw queue and calculates the contentBounds.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method addToRedrawQueue
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param shape {SVGShape}
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.left = box.left < shapeBox.left ? box.left : shapeBox.left;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.top = box.top < shapeBox.top ? box.top : shapeBox.top;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.right = box.right > shapeBox.right ? box.right : shapeBox.right;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.bottom = box.bottom > shapeBox.bottom ? box.bottom : shapeBox.bottom;
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Redraws all shapes.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _redraw
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _redraw: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var box = this.get("resizeDown") ? this._getUpdatedContentBounds() : this._contentBounds;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._frag = null;
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Recalculates and returns the `contentBounds` for the `Graphic` instance.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _getUpdateContentBounds
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {Object}