VMLGraphic.js revision e1d9c39d1eb1062e5c99cf8994b981636d8841cc
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Graphic.html">`Graphic`</a> class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * `VMLGraphic` is not intended to be used directly. Instead, use the <a href="Graphic.html">`Graphic`</a> class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * capabilities, the <a href="Graphic.html">`Graphic`</a> class will point to the `VMLGraphic` class.
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp * @module graphics
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @class VMLGraphic
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @constructor
a89ad754cce3cfc8aee71760e10217b54020360dTrippVMLGraphic = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp VMLGraphic.superclass.constructor.apply(this, arguments);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * 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.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config render
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Node | String
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Unique id for class instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @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.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @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.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @config contentBounds
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The html element that represents to coordinate system of the Graphic instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type HTMLElement
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp getter: function()
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return this._node;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * Indicates the width of the `Graphic`.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config width
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the height of the `Graphic`.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config height
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @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.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config autoSize
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default false
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The contentBounds will resize to greater values but not values. (for performance)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * When resizing the contentBounds down is desirable, set the resizeDown value to true.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._resizeDown;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the x-coordinate for the instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config x
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._x;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the y-coordinate for the instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @config y
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp getter: function()
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return this._y;
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * This property will get set to false when batching operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @config autoDraw
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @default true
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Storage for `x` attribute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _x
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Storage for `y` attribute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property _y
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Gets the current position of the graphic instance in page coordinates.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method getXY
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @return Array The XY position of the shape.
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp getXY: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _resizeDown
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @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);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(w, h);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method destroy
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp destroy: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} cfg attributes for the shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Adds a shape instance to the graphic instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _appendShape
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param {Shape} shape The shape instance to be added to the graphic.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes a shape instance from from the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method removeShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Shape|String} shape The instance or id of the shape to be removed.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all shape instances from the dom.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method removeAllShapes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all child nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _removeChildren
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Clears the graphics object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method clear
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clear: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Toggles visibility
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _toggleVisible
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
9eaaa502227248d304ac9170902697d02158c1d9Tripp setSize: function(w, h) {
9eaaa502227248d304ac9170902697d02158c1d9Tripp w = Math.round(w);
9eaaa502227248d304ac9170902697d02158c1d9Tripp h = Math.round(h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the positon of the graphics object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method setPosition
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Number} x x-coordinate for the object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Number} y y-coordinate for the object.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setPosition: function(x, y)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp x = Math.round(x);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp y = Math.round(y);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Creates a group element
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _createGraphic
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _createGraphic: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var group = DOCUMENT.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Creates a graphic node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _createGraphicNode
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} type node type to create
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} pe specified pointer-events value
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return HTMLElement
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return DOCUMENT.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a shape based on the id of its dom node.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method getShapeById
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} id Dom id of the shape's node attribute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a shape class. Used by `addShape`.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _getShapeClass
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Shape | String} val Indicates which shape class.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Function
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Look up for shape classes. Used by `addShape` to retrieve a class for instantiation.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _shapeClass
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method batch
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @param {Function} method Method to execute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a document fragment to for attaching shapes.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _getDocFrag
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return DocumentFragment
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._frag;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape to the redraw queue and calculates the contentBounds.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method addToRedrawQueue
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param shape {VMLShape}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @protected
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp box.left = box.left < shapeBox.left ? box.left : shapeBox.left;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp box.top = box.top < shapeBox.top ? box.top : shapeBox.top;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp box.right = box.right > shapeBox.right ? box.right : shapeBox.right;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp box.bottom = box.bottom > shapeBox.bottom ? box.bottom : shapeBox.bottom;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Redraws all shapes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _redraw
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _redraw: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp var box = this._resizeDown ? this._getUpdatedContentBounds() : this._contentBounds;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Recalculates and returns the `contentBounds` for the `Graphic` instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _getUpdatedContentBounds
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return {Object}
_getUpdatedContentBounds: function()
var bounds,
box = {
for(i in queue)
return box;