VMLGraphic.js revision a89ad754cce3cfc8aee71760e10217b54020360d
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp/**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @class VMLGraphic
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @constructor
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippVMLGraphic = function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp VMLGraphic.superclass.constructor.apply(this, arguments);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp};
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTrippVMLGraphic.NAME = "vmlGraphic";
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTrippVMLGraphic.ATTRS = {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp render: {},
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Key value pairs in which a shape instance is associated with its id.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute shapes
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
16178708ecddc36b034aea99e129ceffa009ac05Tripp * @readOnly
16178708ecddc36b034aea99e129ceffa009ac05Tripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp shapes: {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp readOnly: true,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp getter: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._shapes;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @attribute _coordPlaneNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type Object
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp contentBox: {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp readOnly: true,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
f69d245bb21be88752420e834a6b6be37e9b525fTripp getter: function()
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return this._contentBox;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * The html element that represents to coordinate system of the Graphic instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @attribute coordPlaneNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @type HTMLElement
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp coordPlaneNode: {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp readOnly: true,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp getter: function()
f69d245bb21be88752420e834a6b6be37e9b525fTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return this._coordPlaneNode;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp width: {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setter: function(val)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(this._coordPlaneNode)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._coordPlaneNode.style.width = val + 'px';
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return val;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp height: {
f69d245bb21be88752420e834a6b6be37e9b525fTripp setter: function(val)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(this._coordPlaneNode)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.style.height = val + 'px';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return val;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp};
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippY.extend(VMLGraphic, Y.BaseGraphic, {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getXY: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var node = Y.one(this.parentNode),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp xy = node.getXY();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return xy;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Initializes the class.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method initializer
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @private
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp initializer: function(config) {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var render = this.get("render");
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._coordPlaneNode = this._createGraphic();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.setAttribute("id", this.get("id"));
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._initProps();
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(render)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.render(render);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * This property will get set to false when batching operations.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @property autoDraw
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @type Boolean
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @default true
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp autoDraw: true,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Clears the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method clear
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp clear: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._path = '';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._removeAllShapes();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._removeChildren(this._coordPlaneNode);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes all nodes.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method destroy
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp destroy: function()
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.clear();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.parentNode.removeChild(this._coordPlaneNode);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
f69d245bb21be88752420e834a6b6be37e9b525fTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes all shape instances from the dom.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method removeAllShapes
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp removeAllShapes: function()
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var shapes = this._shapes,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp i;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(i in shapes)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(shapes.hasOwnProperty(i))
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp shapes[i].destroy();
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._shapes = {};
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
f69d245bb21be88752420e834a6b6be37e9b525fTripp * Removes all child nodes.
f69d245bb21be88752420e834a6b6be37e9b525fTripp *
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @method _removeChildren
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @param node
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp _removeChildren: function(node)
f69d245bb21be88752420e834a6b6be37e9b525fTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(node.hasChildNodes())
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var child;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp while(node.firstChild)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp child = node.firstChild;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._removeChildren(child);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp node.removeChild(child);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Shows and and hides a the graphic instance.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method toggleVisible
f69d245bb21be88752420e834a6b6be37e9b525fTripp * @param val {Boolean} indicates whether the instance should be visible.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp toggleVisible: function(val)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._toggleVisible(this._coordPlaneNode, val);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Toggles visibility
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _toggleVisible
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {HTMLElement} node element to toggle
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Boolean} val indicates visibilitye
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _toggleVisible: function(node, val)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var children = Y.one(node).get("children"),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp visibility = val ? "visible" : "hidden",
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp i = 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp len;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp if(children)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp len = children.length;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp for(; i < len; ++i)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._toggleVisible(children[i], val);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp node.style.visibility = visibility;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Sets the size of the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method setContentSize
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param w {Number} width to set for the instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param h {Number} height to set for the instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setContentSize: function(w, h) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = Math.round(w);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp h = Math.round(h);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.style.width = w + 'px';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.style.height = h + 'px';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.coordSize = w + ' ' + h;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Sets the positon of the graphics object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method setPosition
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} x x-coordinate for the object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {Number} y y-coordinate for the object.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp setPosition: function(x, y)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp x = Math.round(x);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp y = Math.round(y);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.style.left = x + "px";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._coordPlaneNode.style.top = y + "px";
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Adds the graphics node to the dom.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method render
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp render: function(render) {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var parentNode = Y.one(render),
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
f69d245bb21be88752420e834a6b6be37e9b525fTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp parentNode = parentNode || DOCUMENT.body;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp parentNode.appendChild(this._coordPlaneNode);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.setContentSize(w, h);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.parentNode = parentNode;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("width", w);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.set("height", h);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Clears the properties
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _initProps
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _initProps: function() {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._fillColor = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._strokeColor = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._strokeOpacity = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._strokeWeight = 0;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._fillProps = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._path = '';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._contentBox = {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp left: 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp top: 0,
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp right: 0,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp bottom: 0
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp };
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._x = 0;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._y = 0;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._fill = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._stroke = 0;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._stroked = false;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this._dashstyle = null;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Creates a group element
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method _createGraphic
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @private
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp _createGraphic: function() {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var group = document.createElement('<group xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:block;zoom:1;" />');
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp group.style.display = "block";
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp group.style.position = 'absolute';
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return group;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Creates a graphic node
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method _createGraphicNode
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} type node type to create
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} pe specified pointer-events value
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @return HTMLElement
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @private
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp _createGraphicNode: function(type)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp return document.createElement('<' + type + ' xmlns="urn:schemas-microsft.com:vml" style="behavior:url(#default#VML);display:inline-block;zoom:1;" />');
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Adds a shape instance to the graphic instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method addShape
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {Shape} shape The shape instance to be added to the graphic.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp addShape: function(shape)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp var node = shape.node,
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp parentNode = this._frag || this._coordPlaneNode;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp parentNode.appendChild(node);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(!this._shapes)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._shapes = {};
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._shapes[shape.get("id")] = shape;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp if(this.autoDraw)
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp {
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this.updateContentBox();
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp /**
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * Returns a shape based on the id of its dom node.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method getShapeById
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @param {String} id Dom id of the shape's node attribute.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return Shape
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getShapeById: function(id)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return this._shapes[id];
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Generates a shape instance by type.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @method getShape
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {String} type type of shape to generate.
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @param {Object} cfg attributes for the shape
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * @return Shape
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp */
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp getShape: function(cfg)
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp {
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp cfg.graphic = this;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp var shape = new this._shapeClass[cfg.type](cfg);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp this.addShape(shape);
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp return shape;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp },
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp /**
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp * Removes a shape instance from from the graphic instance.
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp *
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp * @method removeShape
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {Shape|String}
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp */
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp removeShape: function(shape)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if(!shape instanceof VMLShape)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if(Y_LANG.isString(shape))
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp shape = this._shapes[shape];
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if(shape && shape instanceof VMLShape)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp shape.destroy();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp delete this._shapes[shape.get("id")];
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if(this.autoDraw)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.updateContentBox();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp }
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp /**
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @private
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp */
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp _shapeClass: {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp circle: Y.VMLCircle,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp rect: Y.VMLRect,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp path: Y.VMLPath,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp ellipse: Y.VMLEllipse
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp /**
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Adds a child to the <code>node</code>.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp *
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method addChild
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {HTMLElement} element to add
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @private
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp */
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp addChild: function(child)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this._coordPlaneNode.appendChild(child);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp /**
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp *
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method batch
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @param {Function} method Method to execute.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp */
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp batch: function(method)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp var node = this._coordPlaneNode,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp frag = document.createDocumentFragment();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this._frag = frag;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.autoDraw = false;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp method();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.updateContentBox();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp node.appendChild(frag);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this._frag = null;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp this.autoDraw = true;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp },
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp /**
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * Updates the size of the graphics container and.
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp *
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp * @method updateContentBox
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp */
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp updateContentBox: function(e)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp var bounds,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp i,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp shape,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp shapes = this._shapes,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp w,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp h,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp box = this._contentBox,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp left = box.left,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp top = box.top,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp right = box.right,
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp bottom = box.bottom;
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp for(i in shapes)
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp if(shapes.hasOwnProperty(i))
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp {
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp shape = this._shapes[i];
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp bounds = shape.getBounds();
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp box.left = Math.min(left, bounds.left);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp box.top = Math.min(top, bounds.top);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp box.right = Math.max(right, bounds.right);
1dc743f5ebb81123e0c921f2d70392f1d160ddbfTripp box.bottom = Math.max(bottom, bounds.bottom);
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp }
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp w = box.width = box.right - box.left;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp h = box.height = box.bottom - box.top;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp this._contentBox = box;
82d0cf8c731b23f6a2fbb31e3e696e629444363eTripp }
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp});
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTrippY.VMLGraphic = VMLGraphic;
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp
e393eced613f9b4a5fb6bdd461d0e0bf5064d5ecTripp