VMLGraphic.js revision c093c1aed867e18aa4778708592e1ceb45d18cff
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * VMLGraphic is a simple drawing api that allows for basic drawing operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class VMLGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTrippVMLGraphic = function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp VMLGraphic.superclass.constructor.apply(this, arguments);
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippVMLGraphic.NAME = "vmlGraphic";
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippVMLGraphic.ATTRS = {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
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.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config render
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Node | String
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp render: {},
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Unique id for class instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config id
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type String
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp id: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp valueFn: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return Y.guid();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setter: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var node = this._node;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.setAttribute("id", val);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Key value pairs in which a shape instance is associated with its id.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config shapes
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp shapes: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return this._shapes;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config contentBounds
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp contentBounds: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return this._contentBounds;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * The html element that represents to coordinate system of the Graphic instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type HTMLElement
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._node;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the width of the `Graphic`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config width
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp width: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp setter: function(val)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.width = val + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return val;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the height of the `Graphic`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config height
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp height: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp setter: function(val)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.height = val + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return val;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
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 *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config autoSize
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default false
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp autoSize: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp value: false
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
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.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp resizeDown: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._resizeDown;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setter: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._resizeDown = val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the x-coordinate for the instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config x
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp x: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._x;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setter: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._x = val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.left = val + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Indicates the y-coordinate for the instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config y
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp y: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getter: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._y;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setter: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._y = val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.top = val + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
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.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config autoDraw
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default true
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp autoDraw: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp value: true
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp visible: {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp value: true,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setter: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._toggleVisible(val);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippY.extend(VMLGraphic, Y.BaseGraphic, {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _x: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _y: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Gets the current position of the graphic instance in page coordinates.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method getXY
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Array The XY position of the shape.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var node = Y.one(this._node),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp xy;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xy = node.getXY();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return xy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _resizeDown: false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp initializer: function(config) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var render = this.get("render");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._shapes = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._contentBounds = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp left: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp top: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp right: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp bottom: 0
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node = this._createGraphic();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.setAttribute("id", this.get("id"));
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(render)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.render(render);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds the graphics node to the dom.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method render
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {HTMLElement} parentNode node in which to render the graphics node into.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp render: function(render) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var parentNode = Y.one(render),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp parentNode = parentNode || DOCUMENT.body;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp parentNode.appendChild(this._node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.setSize(w, h);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.parentNode = parentNode;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("width", w);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("height", h);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp destroy: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.clear();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.parentNode.removeChild(this._node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method addShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} type type of shape to generate.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Object} cfg attributes for the shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp addShape: function(cfg)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp cfg.graphic = this;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp var shapeClass = this._getShapeClass(cfg.type),
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp shape = new shapeClass(cfg);
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp this._appendShape(shape);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape instance to the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _appendShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Shape} shape The shape instance to be added to the graphic.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp _appendShape: function(shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var node = shape.node,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp parentNode = this._frag || this._node;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp parentNode.appendChild(node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp else
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._getDocFrag().appendChild(node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes a shape instance from from the graphic instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method removeShape
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {Shape|String} shape The instance or id of the shape to be removed.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp removeShape: function(shape)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(!shape instanceof VMLShape)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(Y_LANG.isString(shape))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shape = this._shapes[shape];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shape && shape instanceof VMLShape)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shape.destroy();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp delete this._shapes[shape.get("id")];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Removes all shape instances from the dom.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method removeAllShapes
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp removeAllShapes: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var shapes = this._shapes,
a89ad754cce3cfc8aee71760e10217b54020360dTripp i;
a89ad754cce3cfc8aee71760e10217b54020360dTripp for(i in shapes)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(shapes.hasOwnProperty(i))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shapes[i].destroy();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._shapes = {};
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 /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Clears the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method clear
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clear: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._removeAllShapes();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._removeChildren(this._node);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Toggles visibility
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _toggleVisible: function(val)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var i,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shapes = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp visibility = val ? "visible" : "hidden";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for(i in shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shapes.hasOwnProperty(i))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shapes[i].set("visible", val);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.visibility = visibility;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method setSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp setSize: function(w, h) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp w = Math.round(w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = Math.round(h);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.width = w + 'px';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.height = h + 'px';
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.coordSize = w + ' ' + h;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
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);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.left = x + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.top = y + "px";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Creates a group element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
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 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 {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp 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 * 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
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a shape class. Used by `addShape`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param {Shape | String} val Indicates which shape class.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return Function
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @private
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp */
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp _getShapeClass: function(val)
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp {
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp var shape = this._shapeClass[val];
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp if(shape)
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp {
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp return shape;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp }
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp return val;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp },
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Look up for shape classes. Used by `addShape` to retrieve a class for instantiation.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @property _shapeClass
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _shapeClass: {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circle: Y.VMLCircle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: Y.VMLRect,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: Y.VMLPath,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp ellipse: Y.VMLEllipse,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp pieslice: Y.VMLPieSlice
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
9eaaa502227248d304ac9170902697d02158c1d9Tripp * Allows for creating multiple shapes in order to batch appending and redraw operations.
9eaaa502227248d304ac9170902697d02158c1d9Tripp *
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @method batch
9eaaa502227248d304ac9170902697d02158c1d9Tripp * @param {Function} method Method to execute.
9eaaa502227248d304ac9170902697d02158c1d9Tripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp batch: function(method)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp var autoDraw = this.get("autoDraw");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("autoDraw", false);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp method.apply();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("autoDraw", autoDraw);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a document fragment to for attaching shapes.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _getDocFrag
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return DocumentFragment
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _getDocFrag: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(!this._frag)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp this._frag = DOCUMENT.createDocumentFragment();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._frag;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape to the redraw queue and calculates the contentBounds.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method addToRedrawQueue
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param shape {SVGShape}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp addToRedrawQueue: function(shape)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var shapeBox,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._shapes[shape.get("id")] = shape;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(!this.get("resizeDown"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shapeBox = shape.getBounds();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box = this._contentBounds;
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;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.width = box.right - box.left;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.height = box.bottom - box.top;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._contentBounds = box;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Redraws all shapes.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _redraw
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _redraw: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var box = this.get("resizeDown") ? this._getUpdatedContentBounds() : this._contentBounds;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoSize"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.setSize(box.right, box.bottom);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._frag)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.appendChild(this._frag);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._frag = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Recalculates and returns the `contentBounds` for the `Graphic` instance.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _getUpdateContentBounds
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {Object}
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _getUpdatedContentBounds: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var bounds,
a89ad754cce3cfc8aee71760e10217b54020360dTripp i,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp queue = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp left: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp top: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp right: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp bottom: 0
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for(i in queue)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(queue.hasOwnProperty(i))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shape = queue[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bounds = shape.getBounds();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.left = Math.min(box.left, bounds.left);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.top = Math.min(box.top, bounds.top);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.right = Math.max(box.right, bounds.right);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.bottom = Math.max(box.bottom, bounds.bottom);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.width = box.right - box.left;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box.height = box.bottom - box.top;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = box;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return box;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp});
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippY.VMLGraphic = VMLGraphic;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp