SVGGraphic.js revision b09ec2603db26c15cf616ef2705b862065e2a12e
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * <a href="http://www.w3.org/TR/SVG/">SVG</a> implementation of the <a href="Graphic.html">`Graphic`</a> class.
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * `SVGGraphic` is not intended to be used directly. Instead, use the <a href="Graphic.html">`Graphic`</a> class.
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * If the browser has <a href="http://www.w3.org/TR/SVG/">SVG</a> capabilities, the <a href="Graphic.html">`Graphic`</a>
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * class will point to the `SVGGraphic` class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * @module graphics
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @class SVGGraphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
4ef2f7e4cb7c7d255be077c47d542199f7bf8607TrippSVGGraphic = function(cfg) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp SVGGraphic.superclass.constructor.apply(this, arguments);
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippSVGGraphic.NAME = "svgGraphic";
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippSVGGraphic.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 * @readOnly
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 * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return this._node;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the width of the `Graphic`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config width
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp width: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
527cf651dc5df871799abd06cf589bca3f3a665fTripp if(this._node)
527cf651dc5df871799abd06cf589bca3f3a665fTripp {
527cf651dc5df871799abd06cf589bca3f3a665fTripp this._node.style.width = val + "px";
527cf651dc5df871799abd06cf589bca3f3a665fTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Indicates the height of the `Graphic`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @config height
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @type Number
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp height: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
527cf651dc5df871799abd06cf589bca3f3a665fTripp if(this._node)
527cf651dc5df871799abd06cf589bca3f3a665fTripp {
527cf651dc5df871799abd06cf589bca3f3a665fTripp this._node.style.height = val + "px";
527cf651dc5df871799abd06cf589bca3f3a665fTripp }
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 to 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._contentNode)
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)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.top = val + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
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
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp visible: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp value: true,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._toggleVisible(val);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp //
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp // Indicates the pointer-events setting for the svg:svg element.
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp //
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp // @config pointerEvents
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp // @type String
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp //
a89ad754cce3cfc8aee71760e10217b54020360dTripp pointerEvents: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: "none"
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
6c2524a3f545f556615ff052e6676c5adb53c5d5TrippY.extend(SVGGraphic, Y.GraphicBase, {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
cec703a844d9691646231634fe709f4ea41d278aTripp * Storage for `x` attribute.
cec703a844d9691646231634fe709f4ea41d278aTripp *
cec703a844d9691646231634fe709f4ea41d278aTripp * @property _x
cec703a844d9691646231634fe709f4ea41d278aTripp * @type Number
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _x: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
cec703a844d9691646231634fe709f4ea41d278aTripp * Storage for `y` attribute.
cec703a844d9691646231634fe709f4ea41d278aTripp *
cec703a844d9691646231634fe709f4ea41d278aTripp * @property _y
cec703a844d9691646231634fe709f4ea41d278aTripp * @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 {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var node = Y.one(this._node),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp xy;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(node)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp xy = node.getXY();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return xy;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property _resizeDown
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _resizeDown: false,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp initializer: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var render = this.get("render");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes = {};
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp left: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp top: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp right: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp bottom: 0
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._gradients = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node = DOCUMENT.createElement('div');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.position = "absolute";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.left = this.get("x") + "px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.top = this.get("y") + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode = this._createGraphics();
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("id", this.get("id"));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.appendChild(this._contentNode);
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) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var parentNode = Y.one(render),
a89ad754cce3cfc8aee71760e10217b54020360dTripp w = this.get("width") || parseInt(parentNode.getComputedStyle("width"), 10),
a89ad754cce3cfc8aee71760e10217b54020360dTripp h = this.get("height") || parseInt(parentNode.getComputedStyle("height"), 10);
117557654069e56f5003be755819b76fe0f77107Tripp parentNode = parentNode || Y.one(DOCUMENT.body);
117557654069e56f5003be755819b76fe0f77107Tripp parentNode.append(this._node);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.parentNode = parentNode;
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("width", w);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("height", h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp destroy: function()
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.removeAllShapes();
117557654069e56f5003be755819b76fe0f77107Tripp if(this._contentNode)
117557654069e56f5003be755819b76fe0f77107Tripp {
117557654069e56f5003be755819b76fe0f77107Tripp this._removeChildren(this._contentNode);
117557654069e56f5003be755819b76fe0f77107Tripp if(this._contentNode.parentNode)
117557654069e56f5003be755819b76fe0f77107Tripp {
117557654069e56f5003be755819b76fe0f77107Tripp this._contentNode.parentNode.removeChild(this._contentNode);
117557654069e56f5003be755819b76fe0f77107Tripp }
117557654069e56f5003be755819b76fe0f77107Tripp this._contentNode = null;
117557654069e56f5003be755819b76fe0f77107Tripp }
117557654069e56f5003be755819b76fe0f77107Tripp if(this._node)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
117557654069e56f5003be755819b76fe0f77107Tripp this._removeChildren(this._node);
117557654069e56f5003be755819b76fe0f77107Tripp Y.one(this._node).remove(true);
117557654069e56f5003be755819b76fe0f77107Tripp this._node = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method addShape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {Object} cfg attributes for the shape
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp addShape: function(cfg)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
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 /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a shape instance to the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _appendShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Shape} shape The shape instance to be added to the graphic.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp _appendShape: function(shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = shape.node,
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode = this._frag || this._contentNode;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp parentNode.appendChild(node);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._getDocFrag().appendChild(node);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
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 SVGShape))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(Y_LANG.isString(shape))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape = this._shapes[shape];
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(shape && shape instanceof SVGShape)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
117557654069e56f5003be755819b76fe0f77107Tripp shape._destroy();
a89ad754cce3cfc8aee71760e10217b54020360dTripp delete this._shapes[shape.get("id")];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoDraw"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._redraw();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Removes all shape instances from the dom.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method removeAllShapes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp removeAllShapes: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var shapes = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp i;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for(i in shapes)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(shapes.hasOwnProperty(i))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
117557654069e56f5003be755819b76fe0f77107Tripp shapes[i]._destroy();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._shapes = {};
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
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 }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Clears the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method clear
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp clear: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.removeAllShapes();
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._contentNode.style.visibility = visibility;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._node.style.visibility = visibility;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Returns a shape class. Used by `addShape`.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
cec703a844d9691646231634fe709f4ea41d278aTripp * @method _getShapeClass
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.SVGCircle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: Y.SVGRect,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: Y.SVGPath,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp ellipse: Y.SVGEllipse,
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp pieslice: Y.SVGPieSlice
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 var shape = this._shapes[id];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return shape;
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);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp method();
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;
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;
b09ec2603db26c15cf616ef2705b862065e2a12eTripp if(this._contentNode)
b09ec2603db26c15cf616ef2705b862065e2a12eTripp {
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.style.left = box.left + "px";
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.style.top = box.top + "px";
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.setAttribute("width", box.width);
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.setAttribute("height", box.height);
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.style.width = box.width + "px";
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.style.height = box.height + "px";
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.setAttribute("viewBox", "" + box.left + " " + box.top + " " + box.width + " " + box.height + "");
b09ec2603db26c15cf616ef2705b862065e2a12eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this.get("autoSize"))
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("width", box.right);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this.set("height", box.bottom);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(this._frag)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp {
b09ec2603db26c15cf616ef2705b862065e2a12eTripp if(this._contentNode)
b09ec2603db26c15cf616ef2705b862065e2a12eTripp {
b09ec2603db26c15cf616ef2705b862065e2a12eTripp this._contentNode.appendChild(this._frag);
b09ec2603db26c15cf616ef2705b862065e2a12eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp this._frag = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * Adds a shape to the redraw queue and calculates the contentBounds. Used internally
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * by `Shape` instances.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method addToRedrawQueue
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param shape {SVGShape}
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @protected
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 * Recalculates and returns the `contentBounds` for the `Graphic` instance.
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp *
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp * @method _getUpdatedContentBounds
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {Object}
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _getUpdatedContentBounds: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var bounds,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp queue = this._shapes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp box = {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp left: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp top: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp right: 0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp bottom: 0
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(i in queue)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(queue.hasOwnProperty(i))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp 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 }
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.width = box.right - box.left;
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.height = box.bottom - box.top;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = box;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return box;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Creates a contentNode element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _createGraphics
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _createGraphics: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var contentNode = this._createGraphicNode("svg"),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp pointerEvents = this.get("pointerEvents");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp contentNode.style.position = "absolute";
bcdc7c6587a2fd7747c2263389920611e24082d7Tripp contentNode.style.top = "0px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp contentNode.style.left = "0px";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp contentNode.style.overflow = "auto";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp contentNode.setAttribute("overflow", "auto");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp contentNode.setAttribute("pointer-events", pointerEvents);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return contentNode;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Creates a graphic node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp *
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _createGraphicNode
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} type node type to create
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param {String} pe specified pointer-events value
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return HTMLElement
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _createGraphicNode: function(type, pe)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp var node = DOCUMENT.createElementNS("http://www.w3.org/2000/svg", "svg:" + type),
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp v = pe || "none";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if(type !== "defs" && type !== "stop" && type !== "linearGradient" && type != "radialGradient")
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp node.setAttribute("pointer-events", v);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return node;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a reference to a gradient definition based on an id and type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getGradientNode
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {String} key id that references the gradient definition
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @param {String} type description of the gradient type
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return HTMLElement
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * @protected
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getGradientNode: function(key, type)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var gradients = this._gradients,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp nodeType = type + "Gradient";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(gradients.hasOwnProperty(key) && gradients[key].tagName.indexOf(type) > -1)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient = this._gradients[key];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp else
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient = this._createGraphicNode(nodeType);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(!this._defs)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._defs = this._createGraphicNode("defs");
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.appendChild(this._defs);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._defs.appendChild(gradient);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp key = key || "gradient" + Math.round(100000 * Math.random());
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradient.setAttribute("id", key);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(gradients.hasOwnProperty(key))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._defs.removeChild(gradients[key]);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp gradients[key] = gradient;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return gradient;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp});
a89ad754cce3cfc8aee71760e10217b54020360dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippY.SVGGraphic = SVGGraphic;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp