VMLGraphic.js revision 09688ec5ffb8b9cf9883a770e2f9ebd60b28888d
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class VMLGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippvar VMLGraphic = function(config) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.initializer.apply(this, arguments);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippVMLGraphic.prototype = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = Y.one(this.parentNode),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xy = node.getXY();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return xy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp initializer: function(config) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp config = config || {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var w = config.width || 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = config.height || 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.id = Y.guid();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node = this._createGraphic();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.setAttribute("id", this.id);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(w, h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._initProps();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This property will get set to false when batching operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property autoDraw
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @default true
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp autoDraw: true,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method clear
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp clear: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._path = '';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._removeChildren(this.node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp destroy: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._removeChildren(this.node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.parentNode.removeChild(this.node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all child nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _removeChildren
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _removeChildren: function(node)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(node.hasChildNodes())
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var child;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp while(node.firstChild)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp child = node.firstChild;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._removeChildren(child);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.removeChild(child);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Shows and and hides a the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param val {Boolean} indicates whether the instance should be visible.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp toggleVisible: function(val)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._toggleVisible(this.node, val);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Toggles visibility
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} node element to toggle
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _toggleVisible: function(node, val)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var children = Y.one(node).get("children"),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp visibility = val ? "visible" : "hidden",
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp len;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(children)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp len = children.length;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._toggleVisible(children[i], val);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.style.visibility = visibility;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = Math.round(w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = Math.round(h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.width = w + 'px';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.height = h + 'px';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.coordSize = w + ' ' + h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._canvasWidth = w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._canvasHeight = h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the positon of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method setPosition
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} x x-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} y y-coordinate for the object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp setPosition: function(x, y)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp x = Math.round(x);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp y = Math.round(y);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.left = x + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.style.top = y + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds the graphics node to the dom.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method render
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp render: function(parentNode, addToDom) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var w,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode = Y.one(parentNode);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = parseInt(parentNode.getComputedStyle("width"), 10);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = parseInt(parentNode.getComputedStyle("height"), 10);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode = parentNode || Y.config.doc.body;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode.appendChild(this.node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(w, h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._initProps();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.parentNode = parentNode._node;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _trackSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} w width
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Number} h height
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _trackSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (w > this._width) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._width = w;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (h > this._height) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._height = h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears the properties
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _initProps
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _initProps: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fillColor = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._strokeColor = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._strokeOpacity = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._strokeWeight = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fillProps = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._path = '';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._width = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._height = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._x = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._y = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._fill = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._stroke = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._stroked = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._dashstyle = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a group element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphic: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var group = document.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp group.style.display = "block";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp group.style.position = 'absolute';
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return group;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a graphic node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphicNode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type node type to create
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} pe specified pointer-events value
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return HTMLElement
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphicNode: function(type)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return document.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a shape instance to the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Shape} shape The shape instance to be added to the graphic.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp addShape: function(shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = shape.node,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode = this._frag || this.node;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode.appendChild(node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._graphicsList)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._graphicsList = [];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes = {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._graphicsList.push(node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes[shape.get("id")] = shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a shape based on the id of its dom node.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShapeById
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} id Dom id of the shape's node attribute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getShapeById: function(id)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this._shapes[id];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type type of shape to generate.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} cfg attributes for the shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getShape: function(cfg)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cfg.graphic = this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var shapeClassHash = this._shapeClass,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape = new this._shapeClass[cfg.type](cfg);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.addShape(shape);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _shapeClass: {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circle: Y.VMLCircle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: Y.VMLRect,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: Y.VMLPath,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ellipse: Y.VMLEllipse
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a child to the <code>node</code>.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addChild
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} element to add
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp addChild: function(child)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.node.appendChild(child);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method batch
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Function} method Method to execute.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp batch: function(method)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = this.node,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp frag = document.createDocumentFragment();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = frag;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp method();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.updateSize();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.appendChild(frag);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics container and.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method updateSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp updateSize: function(e)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var bounds,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i,// = 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shapes = this._shapes,//this._graphicsList,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //len = shapes.length,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._left = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._right = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._top = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._bottom = 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(i in shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //for(; i < len; ++i)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(shapes.hasOwnProperty(i))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //shape = this.getShapeById(shapes[i].getAttribute("id"));
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape = this._shapes[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bounds = shape.getBounds();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._left = Math.min(this._left, bounds.left);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._top = Math.min(this._top, bounds.top);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._right = Math.max(this._right, bounds.right);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._bottom = Math.max(this._bottom, bounds.bottom);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = this._width = this._right - this._left;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = this._height = this._bottom - this._top;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.setSize(this._width, this._height);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _left: 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _right: 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _top: 0,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _bottom: 0
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippY.VMLGraphic = VMLGraphic;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp