CanvasGraphic.js revision c09beb6ef319616edc832f6f6d137350d74096e0
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> implementation of the `Graphic` class.
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * `CanvasGraphic` is not intended to be used directly. Instead, use the <a href="Graphic.html">`Graphic`</a> class.
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities but has
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> capabilities, the <a href="Graphic.html">`Graphic`</a>
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * class will point to the `CanvasGraphic` class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * @module graphics
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class CanvasGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippfunction CanvasGraphic(config) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp CanvasGraphic.superclass.constructor.apply(this, arguments);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippCanvasGraphic.NAME = "canvasGraphic";
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippCanvasGraphic.ATTRS = {
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * 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.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config render
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Node | String
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
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 /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Object containing size and coordinate data for the content of a Graphic in relation to the graphic instance's position.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config contentBounds
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type Object
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp contentBounds: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return this._contentBounds;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The outermost html element of the Graphic instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type HTMLElement
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._node;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Indicates the width of the `Graphic`.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config width
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Number
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
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
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Indicates the height of the `Graphic`.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config height
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Number
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp height: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp setter: function(val)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.height = val + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return val;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
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 /**
bf801d6851ecf7ed14742ef3639a077daecb5cf8Tripp * The contentBounds will resize to greater values but not smaller 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;
c09beb6ef319616edc832f6f6d137350d74096e0Tripp if(this._node)
c09beb6ef319616edc832f6f6d137350d74096e0Tripp {
c09beb6ef319616edc832f6f6d137350d74096e0Tripp this._redraw();
c09beb6ef319616edc832f6f6d137350d74096e0Tripp }
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)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.top = val + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return val;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
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
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Indicates whether the `Graphic` and its children are visible.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config visible
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Boolean
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp visible: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp value: true,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._toggleVisible(val);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippY.extend(CanvasGraphic, Y.BaseGraphic, {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Storage for `x` attribute.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @property _x
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _x: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Storage for `y` attribute.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @property _y
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _y: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Gets the current position of the graphic instance in page coordinates.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getXY
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Array The XY position of the shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c790ee5b4dcc7d98b68c124495c76d7d515bdc8dTripp var node = Y.one(this._node),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp xy;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp xy = node.getXY();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return xy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Storage for `resizeDown` attribute.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _resizeDown
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _resizeDown: false,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {Object} config Optional attributes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp initializer: function(config) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var render = this.get("render"),
a89ad754cce3cfc8aee71760e10217b54020360dTripp w = this.get("width") || 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp h = this.get("height") || 0;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes = {};
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._redrawQueue = {};
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp left: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp top: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp right: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp bottom: 0
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node = DOCUMENT.createElement('div');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.position = "absolute";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("width", w);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("height", h);
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(render)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.render(render);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
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(render) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var parentNode = Y.one(render),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node = this._node,
a89ad754cce3cfc8aee71760e10217b54020360dTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
a89ad754cce3cfc8aee71760e10217b54020360dTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode = parentNode || DOCUMENT.body;
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode.appendChild(node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.style.display = "block";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.style.position = "absolute";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.style.left = "0px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.style.top = "0px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("width", w);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("height", h);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.parentNode = parentNode;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp destroy: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
e188eaea1f0e60d808be8a4f6ccdbbd3c9b5039bTripp this.removeAllShapes();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._removeChildren(this._node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._node && this._node.parentNode)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.parentNode.removeChild(this._node);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method addShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} cfg attributes for the shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp addShape: function(cfg)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cfg.graphic = this;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp var shapeClass = this._getShapeClass(cfg.type),
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp shape = new shapeClass(cfg);
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp this._appendShape(shape);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Adds a shape instance to the graphic instance.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _appendShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Shape} shape The shape instance to be added to the graphic.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp _appendShape: function(shape)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
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
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Removes a shape instance from from the graphic instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method removeShape
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {Shape|String} shape The instance or id of the shape to be removed.
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp removeShape: function(shape)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(!(shape instanceof CanvasShape))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(Y_LANG.isString(shape))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape = this._shapes[shape];
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(shape && shape instanceof CanvasShape)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape.destroy();
a89ad754cce3cfc8aee71760e10217b54020360dTripp delete this._shapes[shape.get("id")];
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return shape;
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 = {};
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all child nodes.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _removeChildren
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {HTMLElement} node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _removeChildren: function(node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(node.hasChildNodes())
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var child;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp while(node.firstChild)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp child = node.firstChild;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._removeChildren(child);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.removeChild(child);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Toggles visibility
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _toggleVisible
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Boolean} val indicates visibilitye
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _toggleVisible: function(val)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var i,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shapes = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp visibility = val ? "visible" : "hidden";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shapes)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for(i in shapes)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shapes.hasOwnProperty(i))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp shapes[i].set("visible", val);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.visibility = visibility;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a shape class. Used by `addShape`.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
cec703a844d9691646231634fe709f4ea41d278aTripp * @method _getShapeClass
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {Shape | String} val Indicates which shape class.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @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 },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Look up for shape classes. Used by `addShape` to retrieve a class for instantiation.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @property _shapeClass
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @type Object
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _shapeClass: {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circle: Y.CanvasCircle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: Y.CanvasRect,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: Y.CanvasPath,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp ellipse: Y.CanvasEllipse,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp pieslice: Y.CanvasPieSlice
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns a shape based on the id of its dom node.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method getShapeById
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} id Dom id of the shape's node attribute.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp getShapeById: function(id)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var shape = this._shapes[id];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return shape;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
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);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp method();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp this.set("autoDraw", autoDraw);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Returns a document fragment to for attaching shapes.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @method _getDocFrag
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @return DocumentFragment
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @private
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _getDocFrag: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(!this._frag)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp this._frag = DOCUMENT.createDocumentFragment();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._frag;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Redraws all shapes.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @method _redraw
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @private
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _redraw: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var box = this.get("resizeDown") ? this._getUpdatedContentBounds() : this._contentBounds;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoSize"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("width", box.right);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("height", box.bottom);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._frag)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.appendChild(this._frag);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._frag = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * Adds a shape to the redraw queue and calculates the contentBounds. Used internally
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * by `Shape` instances.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method addToRedrawQueue
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param Shape shape The shape instance to add to the queue
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @protected
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
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
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp /**
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * Recalculates and returns the `contentBounds` for the `Graphic` instance.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp *
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp * @method _getUpdatedContentBounds
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @return {Object}
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @private
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _getUpdatedContentBounds: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var bounds,
a89ad754cce3cfc8aee71760e10217b54020360dTripp i,
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp queue = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp left: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp top: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp right: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp bottom: 0
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp for(i in queue)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(queue.hasOwnProperty(i))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape = queue[i];
a89ad754cce3cfc8aee71760e10217b54020360dTripp 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);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.width = box.right - box.left;
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.height = box.bottom - box.top;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = box;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return box;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp});
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippY.CanvasGraphic = CanvasGraphic;