SVGGraphic.js revision 7947db4b7d8682ea81598e3a4283e659a8103be6
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Graphic is a simple drawing api that allows for basic drawing operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class Graphic
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @constructor
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTrippvar SVGGraphic = function(cfg) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp SVGGraphic.superclass.constructor.apply(this, arguments);
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippSVGGraphic.NAME = "svgGraphic";
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippSVGGraphic.ATTRS = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp render: {},
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Key value pairs in which a shape instance is associated with its id.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute 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 *
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @attribute 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 *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute coordPlaneNode
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type HTMLElement
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @readOnly
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp coordPlaneNode: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp readOnly: true,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp getter: function()
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp return this._coordPlaneNode;
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp width: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._coordPlaneNode.setStyle("width", val + "px");
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp height: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._coordPlaneNode.setStyle("height", val + "px");
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp visible: {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp value: true,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp setter: function(val)
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._toggleVisible(val);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp return val;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Indicates the pointer-events setting for the svg:svg element.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @attribute pointerEvents
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type String
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp pointerEvents: {
a89ad754cce3cfc8aee71760e10217b54020360dTripp value: "none"
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippY.extend(SVGGraphic, Y.BaseGraphic, {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Gets the current position of the node's parentNode in page coordinates.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getXY
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Array The XY position of the shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getXY: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var parentNode = Y.one(this.parentNode),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentXY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(parentNode)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentXY = parentNode.getXY();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return parentXY;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Indicates whether or not the instance will automatically redraw after a change is made to a shape.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * This property will get set to false when batching operations.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property autoDraw
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @default true
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp autoDraw: true,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Initializes the class.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method initializer
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp initializer: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var render = this.get("render");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapeInstances = {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ellipse: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circle: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: null,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: null
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes = {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._redrawQueue = {};
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = {
a89ad754cce3cfc8aee71760e10217b54020360dTripp left: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp top: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp right: 0,
a89ad754cce3cfc8aee71760e10217b54020360dTripp bottom: 0
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._gradients = {};
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._coordPlaneNode = Y.one(DOCUMENT.createElement('div'));
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._coordPlaneNode.setStyle("position", "absolute");
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode = this._createGraphics();
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("id", this.get("id"));
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._coordPlaneNode.appendChild(this._contentNode);
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(render)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.render(render);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method destroy
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp destroy: function()
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.removeAllShapes();
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._removeChildren(this._coordPlaneNode);
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(this._coordPlaneNode && this._coordPlaneNode.parentNode)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._coordPlaneNode.parentNode.removeChild(this._coordPlaneNode);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
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)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(shapes.hasOwnProperty(i))
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shapes[i].destroy();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._shapes = {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes all child nodes.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _removeChildren
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _removeChildren: function(node)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(node.hasChildNodes())
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var child;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp while(node.firstChild)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp child = node.firstChild;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._removeChildren(child);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.removeChild(child);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Toggles visibility
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _toggleVisible
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {HTMLElement} node element to toggle
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Boolean} val indicates visibilitye
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _toggleVisible: function(node, val)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp var i,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp shapes = this._shapes,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp visibility = val ? "visible" : "hidden";
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp if(shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp for(i in shapes)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp if(shapes.hasOwnProperty(i))
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp shapes[i].set("visible", val);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentNode.style.visibility = visibility;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._coordPlaneNode.setStyle("visibility", visibility);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Clears the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method clear
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp clear: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.removeAllShapes();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Sets the size of the graphics object.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _updateContentSize
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param w {Number} width to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param h {Number} height to set for the instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp _updateContentSize: function(w, h) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(w > this._contentNode.getAttribute("width"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("width", w);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(h > this._contentNode.getAttribute("height"))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("height", h);
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);
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode = parentNode || DOCUMENT.body;
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode.appendChild(this._coordPlaneNode);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._updateContentSize(w, h);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.parentNode = parentNode;
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("width", w);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.set("height", h);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.parentNode = parentNode;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Creates a contentNode element
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _createGraphics
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _createGraphics: function() {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var contentNode = this._createGraphicNode("svg"),
a89ad754cce3cfc8aee71760e10217b54020360dTripp pointerEvents = this.get("pointerEvents");
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.style.position = "absolute";
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.style.top = "0px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.style.left = "0px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.style.overflow = "auto";
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.setAttribute("overflow", "auto");
a89ad754cce3cfc8aee71760e10217b54020360dTripp contentNode.setAttribute("pointer-events", pointerEvents);
a89ad754cce3cfc8aee71760e10217b54020360dTripp return contentNode;
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, pe)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = document.createElementNS("http://www.w3.org/2000/svg", "svg:" + type),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp v = pe || "none";
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(type !== "defs" && type !== "stop" && type !== "linearGradient" && type != "radialGradient")
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.setAttribute("pointer-events", v);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return node;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a shape instance to the graphic instance.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Shape} shape The shape instance to be added to the graphic.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp addShape: function(shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var node = shape.node,
a89ad754cce3cfc8aee71760e10217b54020360dTripp parentNode = this._frag || this._contentNode;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp parentNode.appendChild(node);
a89ad754cce3cfc8aee71760e10217b54020360dTripp if(this.autoDraw)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.updateContentBox();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Removes a shape instance from from the graphic instance.
a89ad754cce3cfc8aee71760e10217b54020360dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method removeShape
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param {Shape|String}
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp removeShape: function(shape)
a89ad754cce3cfc8aee71760e10217b54020360dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var node;
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 {
a89ad754cce3cfc8aee71760e10217b54020360dTripp shape.destroy();
a89ad754cce3cfc8aee71760e10217b54020360dTripp delete this._shapes[shape.get("id")];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(this.autoDraw)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.updateContentBox();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Generates a shape instance by type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getShape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {String} type type of shape to generate.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param {Object} cfg attributes for the shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return Shape
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp getShape: function(cfg)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp cfg.graphic = this;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var shape = new this._shapeClass[cfg.type](cfg);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._shapes[shape.get("id")] = shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.addShape(shape);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * When overflow is set to true, by default, the viewBox will resize to greater values but not values. (for performance)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * When resizing the viewBox down is desirable, set the resizeDown value to true.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property resizeDown
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Boolean
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp resizeDown: false,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _shapeClass: {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp circle: Y.SVGCircle,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp rect: Y.SVGRect,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp path: Y.SVGPath,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ellipse: Y.SVGEllipse
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _shapeIntances: null,
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 {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var node = this._contentNode,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp frag = document.createDocumentFragment();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = frag;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp method();
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.updateContentBox();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp node.appendChild(frag);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._frag = null;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this.autoDraw = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Updates the size of the graphics container and the position of its children.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method updateContentBox
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp updateContentBox: function(e)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var bounds,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp i,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape,
a89ad754cce3cfc8aee71760e10217b54020360dTripp queue = this.resizeDown ? this._shapes : this._redrawQueue,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp box = this._contentBounds,
a89ad754cce3cfc8aee71760e10217b54020360dTripp left = box.left,
a89ad754cce3cfc8aee71760e10217b54020360dTripp top = box.top,
a89ad754cce3cfc8aee71760e10217b54020360dTripp right = box.right,
a89ad754cce3cfc8aee71760e10217b54020360dTripp bottom = box.bottom;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp for(i in queue)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(queue.hasOwnProperty(i))
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp shape = queue[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp bounds = shape.getBounds();
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.left = Math.min(left, bounds.left);
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.top = Math.min(top, bounds.top);
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.right = Math.max(right, bounds.right);
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.bottom = Math.max(bottom, bounds.bottom);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._redrawQueue = {};
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.width = box.right - box.left;
a89ad754cce3cfc8aee71760e10217b54020360dTripp box.height = box.bottom - box.top;
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.style.left = box.left + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.style.top = box.top + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("width", box.width);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("height", box.height);
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.style.width = box.width + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.style.height = box.height + "px";
a89ad754cce3cfc8aee71760e10217b54020360dTripp this._contentNode.setAttribute("viewBox", "" + box.left + " " + box.top + " " + box.width + " " + box.height + "");
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp this._contentBounds = box;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds a shape to the redraw queue.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method addToRedrawQueue
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param shape {SVGShape}
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp addToRedrawQueue: function(shape)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var id = shape.get("id");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp this._redrawQueue[id] = shape;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if(this.autoDraw)
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp {
a89ad754cce3cfc8aee71760e10217b54020360dTripp this.updateContentBox();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Returns a reference to a gradient definition based on an id and type.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp *
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method getGradientNode
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @key {String} id that references the gradient definition
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type {String} description of the gradient type
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @return HTMLElement
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