aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-02-02 11:14:21 +0100
committerwout <wout@impinc.co.uk>2013-02-02 11:14:21 +0100
commit7323d05f9d09141ec81dcd78d09bdba714c1c5dd (patch)
tree191d1a1e74f8f6b2ab5b7e473897e5daf8759dde
parent4a7588695a1b385f41acd6cbbfaf76b38b2a1439 (diff)
downloadsvg.js-7323d05f9d09141ec81dcd78d09bdba714c1c5dd.tar.gz
svg.js-7323d05f9d09141ec81dcd78d09bdba714c1c5dd.zip
Reworked SVG.Container inheritance
-rw-r--r--Rakefile4
-rw-r--r--dist/svg.js350
-rw-r--r--dist/svg.min.js4
-rw-r--r--src/container.js11
-rw-r--r--src/defs.js7
-rw-r--r--src/doc.js7
-rw-r--r--src/gradient.js7
-rw-r--r--src/group.js7
-rw-r--r--src/mask.js7
-rw-r--r--src/nested.js7
-rw-r--r--src/pattern.js7
-rw-r--r--src/sugar.js15
-rw-r--r--src/svg.js12
13 files changed, 207 insertions, 238 deletions
diff --git a/Rakefile b/Rakefile
index f16254a..43bec97 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,7 +1,7 @@
-SVGJS_VERSION = '0.3'
+SVGJS_VERSION = '0.4'
# all available modules in the correct loading order
-MODULES = %w[ svg container element fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar ]
+MODULES = %w[ svg element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar ]
# how many bytes in a "kilobyte"
KILO = 1024
diff --git a/dist/svg.js b/dist/svg.js
index 67da181..3fd2f5a 100644
--- a/dist/svg.js
+++ b/dist/svg.js
@@ -1,4 +1,4 @@
-/* svg.js v0.3-2-g610e40c - svg container element fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar - svgjs.com/license */
+/* svg.js v0.3-3-g4a75886 - svg element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar - svgjs.com/license */
(function() {
this.svg = function(element) {
@@ -20,148 +20,8 @@
},
// Method for extending objects
extend: function(object, module) {
- /* extend all container modules */
- if (object == SVG.Container)
- ('Clip Defs Doc Gradient Group Mask Nested Pattern').split(' ').forEach(function(m) {
- if (SVG[m])
- SVG.extend(SVG[m], module);
- });
- /* extend given module */
- else
- for (var key in module)
- object.prototype[key] = module[key];
- }
-
- };
-
- SVG.Container = {
- // Add given element at a position
- add: function(element, index) {
- if (!this.has(element)) {
- index = index == null ? this.children().length : index;
- this.children().splice(index, 0, element);
- this.node.insertBefore(element.node, this.node.childNodes[index] || null);
- element.parent = this;
- }
-
- return this;
- },
- // Basically does the same as `add()` but returns the added element
- put: function(element, index) {
- this.add(element, index);
- return element;
- },
- // Checks if the given element is a child
- has: function(element) {
- return this.children().indexOf(element) >= 0;
- },
- // Returns all child elements
- children: function() {
- return this._children || (this._children = []);
- },
- // Iterates over all children and invokes a given block
- each: function(block) {
- var index,
- children = this.children();
-
- for (index = 0, length = children.length; index < length; index++)
- if (children[index] instanceof SVG.Shape)
- block.apply(children[index], [index, children]);
-
- return this;
- },
- // Remove a given child element
- remove: function(element) {
- return this.removeAt(this.children().indexOf(element));
- },
- // Remove a child element at a given position
- removeAt: function(index) {
- if (0 <= index && index < this.children().length) {
- var element = this.children()[index];
- this.children().splice(index, 1);
- this.node.removeChild(element.node);
- element.parent = null;
- }
-
- return this;
- },
- // Returns defs element
- defs: function() {
- return this._defs || (this._defs = this.put(new SVG.Defs(), 0));
- },
- // Re-level defs to first positon in element stack
- level: function() {
- return this.remove(this.defs()).put(this.defs(), 0);
- },
- // Create a group element
- group: function() {
- return this.put(new SVG.G());
- },
- // Create a rect element
- rect: function(width, height) {
- return this.put(new SVG.Rect().size(width, height));
- },
- // Create circle element, based on ellipse
- circle: function(diameter) {
- return this.ellipse(diameter);
- },
- // Create an ellipse
- ellipse: function(width, height) {
- return this.put(new SVG.Ellipse().size(width, height));
- },
- // Create a wrapped polyline element
- polyline: function(points) {
- return this.put(new SVG.Wrap(new SVG.Polyline())).plot(points);
- },
- // Create a wrapped polygon element
- polygon: function(points) {
- return this.put(new SVG.Wrap(new SVG.Polygon())).plot(points);
- },
- // Create a wrapped path element
- path: function(data) {
- return this.put(new SVG.Wrap(new SVG.Path())).plot(data);
- },
- // Create image element, load image and set its size
- image: function(source, width, height) {
- width = width != null ? width : 100;
- return this.put(new SVG.Image().load(source).size(width, height != null ? height : width));
- },
- // Create text element
- text: function(text) {
- return this.put(new SVG.Text().text(text));
- },
- // Create nested svg document
- nested: function() {
- return this.put(new SVG.Nested());
- },
- // Create gradient element in defs
- gradient: function(type, block) {
- return this.defs().gradient(type, block);
- },
- // Create pattern element in defs
- pattern: function(width, height, block) {
- return this.defs().pattern(width, height, block);
- },
- // Create masking element
- mask: function() {
- return this.defs().put(new SVG.Mask());
- },
- // Get first child, skipping the defs node
- first: function() {
- return this.children()[0] instanceof SVG.Defs ? this.children()[1] : this.children()[0];
- },
- // Get the last child
- last: function() {
- return this.children()[this.children().length - 1];
- },
- // Remove all elements in this container
- clear: function() {
- this._children = [];
-
- while (this.node.hasChildNodes())
- this.node.removeChild(this.node.lastChild);
-
- return this;
+ for (var key in module)
+ object.prototype[key] = module[key];
}
};
@@ -450,6 +310,146 @@
});
+ SVG.Container = function Container(element) {
+ this.constructor.call(this, element);
+ };
+
+ // Inherit from SVG.Element
+ SVG.Container.prototype = new SVG.Element();
+
+ //
+ SVG.extend(SVG.Container, {
+ // Add given element at a position
+ add: function(element, index) {
+ if (!this.has(element)) {
+ index = index == null ? this.children().length : index;
+ this.children().splice(index, 0, element);
+ this.node.insertBefore(element.node, this.node.childNodes[index] || null);
+ element.parent = this;
+ }
+
+ return this;
+ },
+ // Basically does the same as `add()` but returns the added element
+ put: function(element, index) {
+ this.add(element, index);
+ return element;
+ },
+ // Checks if the given element is a child
+ has: function(element) {
+ return this.children().indexOf(element) >= 0;
+ },
+ // Returns all child elements
+ children: function() {
+ return this._children || (this._children = []);
+ },
+ // Iterates over all children and invokes a given block
+ each: function(block) {
+ var index,
+ children = this.children();
+
+ for (index = 0, length = children.length; index < length; index++)
+ if (children[index] instanceof SVG.Shape)
+ block.apply(children[index], [index, children]);
+
+ return this;
+ },
+ // Remove a given child element
+ remove: function(element) {
+ return this.removeAt(this.children().indexOf(element));
+ },
+ // Remove a child element at a given position
+ removeAt: function(index) {
+ if (0 <= index && index < this.children().length) {
+ var element = this.children()[index];
+ this.children().splice(index, 1);
+ this.node.removeChild(element.node);
+ element.parent = null;
+ }
+
+ return this;
+ },
+ // Returns defs element
+ defs: function() {
+ return this._defs || (this._defs = this.put(new SVG.Defs(), 0));
+ },
+ // Re-level defs to first positon in element stack
+ level: function() {
+ return this.remove(this.defs()).put(this.defs(), 0);
+ },
+ // Create a group element
+ group: function() {
+ return this.put(new SVG.G());
+ },
+ // Create a rect element
+ rect: function(width, height) {
+ return this.put(new SVG.Rect().size(width, height));
+ },
+ // Create circle element, based on ellipse
+ circle: function(diameter) {
+ return this.ellipse(diameter);
+ },
+ // Create an ellipse
+ ellipse: function(width, height) {
+ return this.put(new SVG.Ellipse().size(width, height));
+ },
+ // Create a wrapped polyline element
+ polyline: function(points) {
+ return this.put(new SVG.Wrap(new SVG.Polyline())).plot(points);
+ },
+ // Create a wrapped polygon element
+ polygon: function(points) {
+ return this.put(new SVG.Wrap(new SVG.Polygon())).plot(points);
+ },
+ // Create a wrapped path element
+ path: function(data) {
+ return this.put(new SVG.Wrap(new SVG.Path())).plot(data);
+ },
+ // Create image element, load image and set its size
+ image: function(source, width, height) {
+ width = width != null ? width : 100;
+ return this.put(new SVG.Image().load(source).size(width, height != null ? height : width));
+ },
+ // Create text element
+ text: function(text) {
+ return this.put(new SVG.Text().text(text));
+ },
+ // Create nested svg document
+ nested: function() {
+ return this.put(new SVG.Nested());
+ },
+ // Create gradient element in defs
+ gradient: function(type, block) {
+ return this.defs().gradient(type, block);
+ },
+ // Create pattern element in defs
+ pattern: function(width, height, block) {
+ return this.defs().pattern(width, height, block);
+ },
+ // Create masking element
+ mask: function() {
+ return this.defs().put(new SVG.Mask());
+ },
+ // Get first child, skipping the defs node
+ first: function() {
+ return this.children()[0] instanceof SVG.Defs ? this.children()[1] : this.children()[0];
+ },
+ // Get the last child
+ last: function() {
+ return this.children()[this.children().length - 1];
+ },
+ // Remove all elements in this container
+ clear: function() {
+ this._children = [];
+
+ while (this.node.hasChildNodes())
+ this.node.removeChild(this.node.lastChild);
+
+ return this;
+ }
+
+ });
+
SVG.FX = function FX(element) {
/* store target element */
this.target = element;
@@ -755,11 +755,8 @@
this.constructor.call(this, SVG.create('g'));
};
- // Inherit from SVG.Element
- SVG.G.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.G, SVG.Container);
+ // Inherit from SVG.Container
+ SVG.G.prototype = new SVG.Container();
SVG.extend(SVG.G, {
@@ -823,11 +820,8 @@
this.constructor.call(this, SVG.create('defs'));
};
- // Inherits from SVG.Element
- SVG.Defs.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Defs, SVG.Container);
+ // Inherits from SVG.Container
+ SVG.Defs.prototype = new SVG.Container();
SVG.Mask = function Mask() {
this.constructor.call(this, SVG.create('mask'));
@@ -836,11 +830,8 @@
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
- // Inherit from SVG.Element
- SVG.Mask.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Mask, SVG.Container);
+ // Inherit from SVG.Container
+ SVG.Mask.prototype = new SVG.Container();
SVG.extend(SVG.Element, {
@@ -858,11 +849,8 @@
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
- // Inherit from SVG.Element
- SVG.Pattern.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Pattern, SVG.Container);
+ // Inherit from SVG.Container
+ SVG.Pattern.prototype = new SVG.Container();
//
SVG.extend(SVG.Pattern, {
@@ -904,11 +892,8 @@
this.type = type;
};
- // Inherit from SVG.Element
- SVG.Gradient.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Gradient, SVG.Container);
+ // Inherit from SVG.Container
+ SVG.Gradient.prototype = new SVG.Container();
//
SVG.extend(SVG.Gradient, {
@@ -1021,11 +1006,8 @@
this.stage();
};
- // Inherits from SVG.Element
- SVG.Doc.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Doc, SVG.Container);
+ // Inherits from SVG.Container
+ SVG.Doc.prototype = new SVG.Container();
// Hack for safari preventing text to be rendered in one line.
// Basically it sets the position of the svg node to absolute
@@ -1357,11 +1339,8 @@
this.attr('overflow', 'visible');
};
- // Inherit from SVG.Element
- SVG.Nested.prototype = new SVG.Element();
-
- // Include the container object
- SVG.extend(SVG.Nested, SVG.Container);
+ // Inherit from SVG.Container
+ SVG.Nested.prototype = new SVG.Container();
SVG._stroke = ['color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset'];
SVG._fill = ['color', 'opacity', 'rule'];
@@ -1418,10 +1397,17 @@
},
// Opacity
opacity: function(value) {
- if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1)
- this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
- else
- this.attr('opacity', value);
+ if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1) {
+ if (value == null)
+ return this.attr('fill-opacity');
+ else
+ this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
+ } else {
+ if (value == null)
+ return this.attr('opacity');
+ else
+ this.attr('opacity', value);
+ }
return this;
}
diff --git a/dist/svg.min.js b/dist/svg.min.js
index c6d43fe..87c1ab8 100644
--- a/dist/svg.min.js
+++ b/dist/svg.min.js
@@ -1,2 +1,2 @@
-/* svg.js v0.3-2-g610e40c - svg container element fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar - svgjs.com/license */
-(function(){function t(){this.constructor.call(this,SVG.create("tspan"))}this.svg=function(e){return new SVG.Doc(e)},this.SVG={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",did:0,create:function(e){return document.createElementNS(this.ns,e)},extend:function(e,t){if(e==SVG.Container)"Clip Defs Doc Gradient Group Mask Nested Pattern".split(" ").forEach(function(e){SVG[e]&&SVG.extend(SVG[e],t)});else for(var n in t)e.prototype[n]=t[n]}},SVG.Container={add:function(e,t){return this.has(e)||(t=t==null?this.children().length:t,this.children().splice(t,0,e),this.node.insertBefore(e.node,this.node.childNodes[t]||null),e.parent=this),this},put:function(e,t){return this.add(e,t),e},has:function(e){return this.children().indexOf(e)>=0},children:function(){return this._children||(this._children=[])},each:function(e){var t,n=this.children();for(t=0,length=n.length;t<length;t++)n[t]instanceof SVG.Shape&&e.apply(n[t],[t,n]);return this},remove:function(e){return this.removeAt(this.children().indexOf(e))},removeAt:function(e){if(0<=e&&e<this.children().length){var t=this.children()[e];this.children().splice(e,1),this.node.removeChild(t.node),t.parent=null}return this},defs:function(){return this._defs||(this._defs=this.put(new SVG.Defs,0))},level:function(){return this.remove(this.defs()).put(this.defs(),0)},group:function(){return this.put(new SVG.G)},rect:function(e,t){return this.put((new SVG.Rect).size(e,t))},circle:function(e){return this.ellipse(e)},ellipse:function(e,t){return this.put((new SVG.Ellipse).size(e,t))},polyline:function(e){return this.put(new SVG.Wrap(new SVG.Polyline)).plot(e)},polygon:function(e){return this.put(new SVG.Wrap(new SVG.Polygon)).plot(e)},path:function(e){return this.put(new SVG.Wrap(new SVG.Path)).plot(e)},image:function(e,t,n){return t=t!=null?t:100,this.put((new SVG.Image).load(e).size(t,n!=null?n:t))},text:function(e){return this.put((new SVG.Text).text(e))},nested:function(){return this.put(new SVG.Nested)},gradient:function(e,t){return this.defs().gradient(e,t)},pattern:function(e,t,n){return this.defs().pattern(e,t,n)},mask:function(){return this.defs().put(new SVG.Mask)},first:function(){return this.children()[0]instanceof SVG.Defs?this.children()[1]:this.children()[0]},last:function(){return this.children()[this.children().length-1]},clear:function(){this._children=[];while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return this}},SVG.Element=function(t){if(this.node=t)this.type=t.nodeName;this.attrs={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,fill:"#000",stroke:"#000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0},this.trans={x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0}},SVG.extend(SVG.Element,{move:function(e,t){return this.attr({x:e,y:t})},center:function(e,t){var n=this.bbox();return this.move(e-n.width/2,t-n.height/2)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e;if(this instanceof SVG.Wrap)e=this.parent[this.child.node.nodeName](),e.attrs=this.attrs,e.child.trans=this.child.trans,e.child.attr(this.child.attrs).transform({}),e.plot&&e.plot(this.child.attrs[this.child instanceof SVG.Path?"d":"points"]);else{var t=this.node.nodeName;e=t=="rect"?this.parent[t](this.attrs.width,this.attrs.height):t=="ellipse"?this.parent[t](this.attrs.rx*2,this.attrs.ry*2):t=="image"?this.parent[t](this.src):t=="text"?this.parent[t](this.content):t=="g"?this.parent.group():this.parent[t](),e.attr(this.attrs)}return e.trans=this.trans,e.transform({})},remove:function(){return this.parent!=null?this.parent.remove(this):void 0},doc:function(){return this._parent(SVG.Doc)},nested:function(){return this._parent(SVG.Nested)},attr:function(e,t,n){if(arguments.length<2){if(typeof e!="object")return this._isStyle(e)?e=="text"?this.content:e=="leading"?this[e]:this.style[e]:this.attrs[e];for(t in e)this.attr(t,e[t])}else{this.attrs[e]=t;if(e=="x"&&this._isText())for(var r=this.lines.length-1;r>=0;r--)this.lines[r].attr(e,t);else n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t);this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"?this[e]=t:this.style[e]=t,this.text(this.content))}return this},transform:function(e){if(typeof e=="string")return this.trans[e];var t,n=[];for(t in e)e[t]!=null&&(this.trans[t]=e[t]);e=this.trans;if(e.rotation!=0){var r=this.bbox();n.push("rotate("+e.rotation+","+(e.cx!=null?e.cx:r.cx)+","+(e.cy!=null?e.cy:r.cy)+")")}return n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),n.push("translate("+e.x+","+e.y+")"),this.attr("transform",n.join(" "))},data:function(e,t){if(arguments.length<2)try{return JSON.parse(this.attr("data-"+e))}catch(n){return this.attr("data-"+e)}else t===null?this.node.removeAttribute("data-"+e):this.attr("data-"+e,JSON.stringify(t));return this},bbox:function(){var e=this.node.getBBox();return{x:e.x+this.trans.x,y:e.y+this.trans.y,cx:e.x+this.trans.x+e.width/2,cy:e.y+this.trans.y+e.height/2,width:e.width,height:e.height}},inside:function(e,t){var n=this.bbox();return e>n.x&&t>n.y&&e<n.x+n.width&&t<n.y+n.height},show:function(){return this.node.style.display="",this},hide:function(){return this.node.style.display="none",this},visible:function(){return this.node.style.display!="none"},_parent:function(e){var t=this;while(t!=null&&!(t instanceof e))t=t.parent;return t},_isStyle:function(e){return typeof e=="string"&&this._isText()?/^font|text|leading/.test(e):!1},_isText:function(){return this instanceof SVG.Text}}),SVG.FX=function(t){this.target=t},SVG.extend(SVG.FX,{animate:function(e,t){e=e==null?1e3:e,t=t||"<>";var n,r,i,s=this.target,o=this,u=(new Date).getTime(),a=u+e;return this.interval=setInterval(function(){var f,l=(new Date).getTime(),c=l>a?1:(l-u)/e;if(n==null){n=[];for(var h in o.attrs)n.push(h)}if(r==null){r=[];for(var h in o.trans)r.push(h);i={}}c=t=="<>"?-Math.cos(c*Math.PI)/2+.5:t==">"?Math.sin(c*Math.PI/2):t=="<"?-Math.cos(c*Math.PI/2)+1:t=="-"?c:typeof t=="function"?t(c):c,o._move?s.move(o._at(o._move.x,c),o._at(o._move.y,c)):o._center&&s.move(o._at(o._center.x,c),o._at(o._center.y,c)),o._size&&s.size(o._at(o._size.width,c),o._at(o._size.height,c));for(f=n.length-1;f>=0;f--)s.attr(n[f],o._at(o.attrs[n[f]],c));if(r.length>0){for(f=r.length-1;f>=0;f--)i[r[f]]=o._at(o.trans[r[f]],c);s.transform(i)}l>a&&(clearInterval(o.interval),o._after?o._after.apply(s,[o]):o.stop())},e>10?10:e),this},attr:function(e,t,n){if(typeof e=="object")for(var r in e)this.attr(r,e[r]);else this.attrs[e]={from:this.target.attr(e),to:t};return this},transform:function(e){for(var t in e)this.trans[t]={from:this.target.trans[t],to:e[t]};return this},move:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.x,to:e},y:{from:n.y,to:t}},this},size:function(e,t){var n=this.target.bbox();return this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}},this},center:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.cx,to:e},y:{from:n.cy,to:t}},this},after:function(e){return this._after=e,this},stop:function(){return clearInterval(this.interval),this.attrs={},this.trans={},this._move=null,this._size=null,this._after=null,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:e.to.r||/^#/.test(e.to)?this._color(e,t):t<1?e.from:e.to},_color:function(e,t){var n,r;return n=this._h2r(e.from||"#000"),r=this._h2r(e.to),this._r2h({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})},_h2r:function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this._fh(e));return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}},_r2h:function(e){return"#"+this._c2h(e.r)+this._c2h(e.g)+this._c2h(e.b)},_c2h:function(e){var t=e.toString(16);return t.length==1?"0"+t:t},_fh:function(e){return e.length==4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e}}),SVG.extend(SVG.Element,{animate:function(e,t){return(this._fx||(this._fx=new SVG.FX(this))).stop().animate(e,t)},stop:function(){return this._fx.stop(),this}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchend","touchmove","touchcancel"].forEach(function(e){SVG.Element.prototype[e]=function(t){var n=this;return this.node["on"+e]=function(){return t.apply(n,arguments)},this}}),SVG.on=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},SVG.off=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},SVG.extend(SVG.Element,{on:function(e,t){return SVG.on(this.node,e,t),this},off:function(e,t){return SVG.off(this.node,e,t),this}}),SVG.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Element,SVG.extend(SVG.G,SVG.Container),SVG.extend(SVG.G,{defs:function(){return this.doc().defs()}}),SVG.extend(SVG.Element,{siblings:function(){return this.parent.children()},position:function(){return this.siblings().indexOf(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){return this.parent.remove(this).put(this,this.position()+1)},backward:function(){var e;return this.parent.level(),e=this.position(),e>1&&this.parent.remove(this).add(this,e-1),this},front:function(){return this.parent.remove(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.remove(this).add(this,0),this}}),SVG.Defs=function(){this.constructor.call(this,SVG.create("defs"))},SVG.Defs.prototype=new SVG.Element,SVG.extend(SVG.Defs,SVG.Container),SVG.Mask=function(){this.constructor.call(this,SVG.create("mask")),this.attr("id",this.id="svgjs_element_"+SVG.did++)},SVG.Mask.prototype=new SVG.Element,SVG.extend(SVG.Mask,SVG.Container),SVG.extend(SVG.Element,{maskWith:function(e){return this.attr("mask","url(#"+(e instanceof SVG.Mask?e:this.parent.mask().add(e)).id+")")}}),SVG.Pattern=function(t){this.constructor.call(this,SVG.create("pattern")),this.attr("id",this.id="svgjs_element_"+SVG.did++)},SVG.Pattern.prototype=new SVG.Element,SVG.extend(SVG.Pattern,SVG.Container),SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.id+")"}}),SVG.extend(SVG.Defs,{pattern:function(e,t,n){var r=this.put(new SVG.Pattern);return n(r),r.attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})}}),SVG.Gradient=function(t){this.constructor.call(this,SVG.create(t+"Gradient")),this.attr("id",this.id="svgjs_element_"+SVG.did++),this.type=t},SVG.Gradient.prototype=new SVG.Element,SVG.extend(SVG.Gradient,SVG.Container),SVG.extend(SVG.Gradient,{from:function(e,t){return this.type=="radial"?this.attr({fx:e+"%",fy:t+"%"}):this.attr({x1:e+"%",y1:t+"%"})},to:function(e,t){return this.type=="radial"?this.attr({cx:e+"%",cy:t+"%"}):this.attr({x2:e+"%",y2:t+"%"})},radius:function(e){return this.type=="radial"?this.attr({r:e+"%"}):this},at:function(e){return this.put(new SVG.Stop(e))},update:function(e){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return e(this),this},fill:function(){return"url(#"+this.id+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(t){this.constructor.call(this,SVG.create("stop")),this.update(t)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n="",r=["opacity","color"];for(t=r.length-1;t>=0;t--)e[r[t]]!=null&&(n+="stop-"+r[t]+":"+e[r[t]]+";");return this.attr({offset:(e.offset!=null?e.offset:this.attrs.offset||0)+"%",style:n})}}),SVG.Doc=function(t){this.constructor.call(this,SVG.create("svg")),this.parent=typeof t=="string"?document.getElementById(t):t,this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.stage()},SVG.Doc.prototype=new SVG.Element,SVG.extend(SVG.Doc,SVG.Container),SVG.Doc.prototype.stage=function(){var e,t=this,n=document.createElement("div");return n.style.cssText="position:relative;height:100%;",t.parent.appendChild(n),n.appendChild(t.node),e=function(){document.readyState==="complete"?(t.attr("style","position:absolute;"),setTimeout(function(){t.attr("style","position:relative;"),t.parent.removeChild(t.node.parentNode),t.node.parentNode.removeChild(t.node),t.parent.appendChild(t.node)},5)):setTimeout(e,10)},e(),this},SVG.Shape=function(t){this.constructor.call(this,t)},SVG.Shape.prototype=new SVG.Element,SVG.Wrap=function(t){this.constructor.call(this,SVG.create("g")),this.node.insertBefore(t.node,null),this.child=t,this.type=t.node.nodeName},SVG.Wrap.prototype=new SVG.Shape,SVG.extend(SVG.Wrap,{move:function(e,t){return this.transform({x:e,y:t})},size:function(e,t){var n=e/this._b.width;return this.child.transform({scaleX:n,scaleY:t!=null?t/this._b.height:n}),this},center:function(e,t){return this.move(e+this._b.width*this.child.trans.scaleX/-2,t+this._b.height*this.child.trans.scaleY/-2)},attr:function(e,t,n){if(typeof e=="object")for(t in e)this.attr(t,e[t]);else{if(arguments.length<2)return e=="transform"?this.attrs[e]:this.child.attrs[e];e=="transform"?(this.attrs[e]=t,n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)):this.child.attr(e,t,n)}return this},plot:function(e){return this.child.plot(e),this._b=this.child.bbox(),this.child.transform({x:-this._b.x,y:-this._b.y}),this}}),SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Ellipse=function(){this.constructor.call(this,SVG.create("ellipse"))},SVG.Ellipse.prototype=new SVG.Shape,SVG.extend(SVG.Ellipse,{move:function(e,t){return this.attrs.x=e,this.attrs.y=t,this.center()},size:function(e,t){return this.attr({rx:e/2,ry:(t!=null?t:e)/2}).center()},center:function(e,t){return this.attr({cx:e||(this.attrs.x||0)+(this.attrs.rx||0),cy:t||(this.attrs.y||0)+(this.attrs.ry||0)})}}),SVG.Poly={plot:function(e){return this.attr("points",e||"0,0"),this}},SVG.Polyline=function(){this.constructor.call(this,SVG.create("polyline"))},SVG.Polyline.prototype=new SVG.Shape,SVG.extend(SVG.Polyline,SVG.Poly),SVG.Polygon=function(){this.constructor.call(this,SVG.create("polygon"))},SVG.Polygon.prototype=new SVG.Shape,SVG.extend(SVG.Polygon,SVG.Poly),SVG.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{move:function(e,t){this.transform({x:e,y:t})},plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return this.src=e,e?this.attr("xlink:href",e,SVG.xlink):this}});var e=["size","family","weight","stretch","variant","style"];SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.style={"font-size":16,"font-family":"Helvetica","text-anchor":"start"},this.leading=1.2},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{text:function(e){this.content=e=e||"text",this.lines=[];var n,r,i,s=this._style(),o=this.doc(),u=e.split("\n"),a=this.style["font-size"];while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);for(n=0,r=u.length;n<r;n++)i=(new t).text(u[n]).attr({dy:a*this.leading-(n==0?a*.3:0),x:this.attrs.x||0,style:s}),this.node.appendChild(i.node),this.lines.push(i);return this.attr("style",s)},_style:function(){var t,n="";for(t=e.length-1;t>=0;t--)this.style["font-"+e[t]]!=null&&(n+="font-"+e[t]+":"+this.style["font-"+e[t]]+";");return n+="text-anchor:"+this.style["text-anchor"]+";",n}}),t.prototype=new SVG.Shape,SVG.extend(t,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.Nested=function(){this.constructor.call(this,SVG.create("svg")),this.attr("overflow","visible")},SVG.Nested.prototype=new SVG.Element,SVG.extend(SVG.Nested,SVG.Container),SVG._stroke=["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],SVG._fill=["color","opacity","rule"];var n=function(e,t){return t=="color"?e:e+"-"+t};["fill","stroke"].forEach(function(e){SVG.Shape.prototype[e]=function(t){var r;if(typeof t=="string")this.attr(e,t);else for(r=SVG["_"+e].length-1;r>=0;r--)t[SVG["_"+e][r]]!=null&&this.attr(n(e,SVG["_"+e][r]),t[SVG["_"+e][r]]);return this}}),[SVG.Element,SVG.FX].forEach(function(e){e&&SVG.extend(e,{rotate:function(e){return this.transform({rotation:e||0})},skew:function(e,t){return this.transform({skewX:e||0,skewY:t||0})},scale:function(e,t){return this.transform({scaleX:e,scaleY:t==null?e:t})},opacity:function(e){return["rect","ellipse","polygon","path","polyline","line","text"].indexOf(this.type)>-1?this.attr({"fill-opacity":e,"stroke-opacity":e}):this.attr("opacity",e),this}})}),SVG.G&&SVG.extend(SVG.G,{move:function(e,t){return this.transform({x:e,y:t})}}),SVG.Text&&SVG.extend(SVG.Text,{font:function(t){var n,r={};for(n in t)n=="leading"?r[n]=t[n]:n=="anchor"?r["text-anchor"]=t[n]:e.indexOf(n)>-1?r["font-"+n]=t[n]:void 0;return this.attr(r).text(this.content)}})}).call(this); \ No newline at end of file
+/* svg.js v0.3-3-g4a75886 - svg element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse poly path image text nested sugar - svgjs.com/license */
+(function(){function t(){this.constructor.call(this,SVG.create("tspan"))}this.svg=function(e){return new SVG.Doc(e)},this.SVG={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",did:0,create:function(e){return document.createElementNS(this.ns,e)},extend:function(e,t){for(var n in t)e.prototype[n]=t[n]}},SVG.Element=function(t){if(this.node=t)this.type=t.nodeName;this.attrs={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,fill:"#000",stroke:"#000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0},this.trans={x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0}},SVG.extend(SVG.Element,{move:function(e,t){return this.attr({x:e,y:t})},center:function(e,t){var n=this.bbox();return this.move(e-n.width/2,t-n.height/2)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e;if(this instanceof SVG.Wrap)e=this.parent[this.child.node.nodeName](),e.attrs=this.attrs,e.child.trans=this.child.trans,e.child.attr(this.child.attrs).transform({}),e.plot&&e.plot(this.child.attrs[this.child instanceof SVG.Path?"d":"points"]);else{var t=this.node.nodeName;e=t=="rect"?this.parent[t](this.attrs.width,this.attrs.height):t=="ellipse"?this.parent[t](this.attrs.rx*2,this.attrs.ry*2):t=="image"?this.parent[t](this.src):t=="text"?this.parent[t](this.content):t=="g"?this.parent.group():this.parent[t](),e.attr(this.attrs)}return e.trans=this.trans,e.transform({})},remove:function(){return this.parent!=null?this.parent.remove(this):void 0},doc:function(){return this._parent(SVG.Doc)},nested:function(){return this._parent(SVG.Nested)},attr:function(e,t,n){if(arguments.length<2){if(typeof e!="object")return this._isStyle(e)?e=="text"?this.content:e=="leading"?this[e]:this.style[e]:this.attrs[e];for(t in e)this.attr(t,e[t])}else{this.attrs[e]=t;if(e=="x"&&this._isText())for(var r=this.lines.length-1;r>=0;r--)this.lines[r].attr(e,t);else n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t);this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"?this[e]=t:this.style[e]=t,this.text(this.content))}return this},transform:function(e){if(typeof e=="string")return this.trans[e];var t,n=[];for(t in e)e[t]!=null&&(this.trans[t]=e[t]);e=this.trans;if(e.rotation!=0){var r=this.bbox();n.push("rotate("+e.rotation+","+(e.cx!=null?e.cx:r.cx)+","+(e.cy!=null?e.cy:r.cy)+")")}return n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),n.push("translate("+e.x+","+e.y+")"),this.attr("transform",n.join(" "))},data:function(e,t){if(arguments.length<2)try{return JSON.parse(this.attr("data-"+e))}catch(n){return this.attr("data-"+e)}else t===null?this.node.removeAttribute("data-"+e):this.attr("data-"+e,JSON.stringify(t));return this},bbox:function(){var e=this.node.getBBox();return{x:e.x+this.trans.x,y:e.y+this.trans.y,cx:e.x+this.trans.x+e.width/2,cy:e.y+this.trans.y+e.height/2,width:e.width,height:e.height}},inside:function(e,t){var n=this.bbox();return e>n.x&&t>n.y&&e<n.x+n.width&&t<n.y+n.height},show:function(){return this.node.style.display="",this},hide:function(){return this.node.style.display="none",this},visible:function(){return this.node.style.display!="none"},_parent:function(e){var t=this;while(t!=null&&!(t instanceof e))t=t.parent;return t},_isStyle:function(e){return typeof e=="string"&&this._isText()?/^font|text|leading/.test(e):!1},_isText:function(){return this instanceof SVG.Text}}),SVG.Container=function(t){this.constructor.call(this,t)},SVG.Container.prototype=new SVG.Element,SVG.extend(SVG.Container,{add:function(e,t){return this.has(e)||(t=t==null?this.children().length:t,this.children().splice(t,0,e),this.node.insertBefore(e.node,this.node.childNodes[t]||null),e.parent=this),this},put:function(e,t){return this.add(e,t),e},has:function(e){return this.children().indexOf(e)>=0},children:function(){return this._children||(this._children=[])},each:function(e){var t,n=this.children();for(t=0,length=n.length;t<length;t++)n[t]instanceof SVG.Shape&&e.apply(n[t],[t,n]);return this},remove:function(e){return this.removeAt(this.children().indexOf(e))},removeAt:function(e){if(0<=e&&e<this.children().length){var t=this.children()[e];this.children().splice(e,1),this.node.removeChild(t.node),t.parent=null}return this},defs:function(){return this._defs||(this._defs=this.put(new SVG.Defs,0))},level:function(){return this.remove(this.defs()).put(this.defs(),0)},group:function(){return this.put(new SVG.G)},rect:function(e,t){return this.put((new SVG.Rect).size(e,t))},circle:function(e){return this.ellipse(e)},ellipse:function(e,t){return this.put((new SVG.Ellipse).size(e,t))},polyline:function(e){return this.put(new SVG.Wrap(new SVG.Polyline)).plot(e)},polygon:function(e){return this.put(new SVG.Wrap(new SVG.Polygon)).plot(e)},path:function(e){return this.put(new SVG.Wrap(new SVG.Path)).plot(e)},image:function(e,t,n){return t=t!=null?t:100,this.put((new SVG.Image).load(e).size(t,n!=null?n:t))},text:function(e){return this.put((new SVG.Text).text(e))},nested:function(){return this.put(new SVG.Nested)},gradient:function(e,t){return this.defs().gradient(e,t)},pattern:function(e,t,n){return this.defs().pattern(e,t,n)},mask:function(){return this.defs().put(new SVG.Mask)},first:function(){return this.children()[0]instanceof SVG.Defs?this.children()[1]:this.children()[0]},last:function(){return this.children()[this.children().length-1]},clear:function(){this._children=[];while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return this}}),SVG.FX=function(t){this.target=t},SVG.extend(SVG.FX,{animate:function(e,t){e=e==null?1e3:e,t=t||"<>";var n,r,i,s=this.target,o=this,u=(new Date).getTime(),a=u+e;return this.interval=setInterval(function(){var f,l=(new Date).getTime(),c=l>a?1:(l-u)/e;if(n==null){n=[];for(var h in o.attrs)n.push(h)}if(r==null){r=[];for(var h in o.trans)r.push(h);i={}}c=t=="<>"?-Math.cos(c*Math.PI)/2+.5:t==">"?Math.sin(c*Math.PI/2):t=="<"?-Math.cos(c*Math.PI/2)+1:t=="-"?c:typeof t=="function"?t(c):c,o._move?s.move(o._at(o._move.x,c),o._at(o._move.y,c)):o._center&&s.move(o._at(o._center.x,c),o._at(o._center.y,c)),o._size&&s.size(o._at(o._size.width,c),o._at(o._size.height,c));for(f=n.length-1;f>=0;f--)s.attr(n[f],o._at(o.attrs[n[f]],c));if(r.length>0){for(f=r.length-1;f>=0;f--)i[r[f]]=o._at(o.trans[r[f]],c);s.transform(i)}l>a&&(clearInterval(o.interval),o._after?o._after.apply(s,[o]):o.stop())},e>10?10:e),this},attr:function(e,t,n){if(typeof e=="object")for(var r in e)this.attr(r,e[r]);else this.attrs[e]={from:this.target.attr(e),to:t};return this},transform:function(e){for(var t in e)this.trans[t]={from:this.target.trans[t],to:e[t]};return this},move:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.x,to:e},y:{from:n.y,to:t}},this},size:function(e,t){var n=this.target.bbox();return this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}},this},center:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.cx,to:e},y:{from:n.cy,to:t}},this},after:function(e){return this._after=e,this},stop:function(){return clearInterval(this.interval),this.attrs={},this.trans={},this._move=null,this._size=null,this._after=null,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:e.to.r||/^#/.test(e.to)?this._color(e,t):t<1?e.from:e.to},_color:function(e,t){var n,r;return n=this._h2r(e.from||"#000"),r=this._h2r(e.to),this._r2h({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})},_h2r:function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(this._fh(e));return t?{r:parseInt(t[1],16),g:parseInt(t[2],16),b:parseInt(t[3],16)}:{r:0,g:0,b:0}},_r2h:function(e){return"#"+this._c2h(e.r)+this._c2h(e.g)+this._c2h(e.b)},_c2h:function(e){var t=e.toString(16);return t.length==1?"0"+t:t},_fh:function(e){return e.length==4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e}}),SVG.extend(SVG.Element,{animate:function(e,t){return(this._fx||(this._fx=new SVG.FX(this))).stop().animate(e,t)},stop:function(){return this._fx.stop(),this}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchend","touchmove","touchcancel"].forEach(function(e){SVG.Element.prototype[e]=function(t){var n=this;return this.node["on"+e]=function(){return t.apply(n,arguments)},this}}),SVG.on=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},SVG.off=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},SVG.extend(SVG.Element,{on:function(e,t){return SVG.on(this.node,e,t),this},off:function(e,t){return SVG.off(this.node,e,t),this}}),SVG.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Container,SVG.extend(SVG.G,{defs:function(){return this.doc().defs()}}),SVG.extend(SVG.Element,{siblings:function(){return this.parent.children()},position:function(){return this.siblings().indexOf(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){return this.parent.remove(this).put(this,this.position()+1)},backward:function(){var e;return this.parent.level(),e=this.position(),e>1&&this.parent.remove(this).add(this,e-1),this},front:function(){return this.parent.remove(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.remove(this).add(this,0),this}}),SVG.Defs=function(){this.constructor.call(this,SVG.create("defs"))},SVG.Defs.prototype=new SVG.Container,SVG.Mask=function(){this.constructor.call(this,SVG.create("mask")),this.attr("id",this.id="svgjs_element_"+SVG.did++)},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.attr("mask","url(#"+(e instanceof SVG.Mask?e:this.parent.mask().add(e)).id+")")}}),SVG.Pattern=function(t){this.constructor.call(this,SVG.create("pattern")),this.attr("id",this.id="svgjs_element_"+SVG.did++)},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.id+")"}}),SVG.extend(SVG.Defs,{pattern:function(e,t,n){var r=this.put(new SVG.Pattern);return n(r),r.attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})}}),SVG.Gradient=function(t){this.constructor.call(this,SVG.create(t+"Gradient")),this.attr("id",this.id="svgjs_element_"+SVG.did++),this.type=t},SVG.Gradient.prototype=new SVG.Container,SVG.extend(SVG.Gradient,{from:function(e,t){return this.type=="radial"?this.attr({fx:e+"%",fy:t+"%"}):this.attr({x1:e+"%",y1:t+"%"})},to:function(e,t){return this.type=="radial"?this.attr({cx:e+"%",cy:t+"%"}):this.attr({x2:e+"%",y2:t+"%"})},radius:function(e){return this.type=="radial"?this.attr({r:e+"%"}):this},at:function(e){return this.put(new SVG.Stop(e))},update:function(e){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return e(this),this},fill:function(){return"url(#"+this.id+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(t){this.constructor.call(this,SVG.create("stop")),this.update(t)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n="",r=["opacity","color"];for(t=r.length-1;t>=0;t--)e[r[t]]!=null&&(n+="stop-"+r[t]+":"+e[r[t]]+";");return this.attr({offset:(e.offset!=null?e.offset:this.attrs.offset||0)+"%",style:n})}}),SVG.Doc=function(t){this.constructor.call(this,SVG.create("svg")),this.parent=typeof t=="string"?document.getElementById(t):t,this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.stage()},SVG.Doc.prototype=new SVG.Container,SVG.Doc.prototype.stage=function(){var e,t=this,n=document.createElement("div");return n.style.cssText="position:relative;height:100%;",t.parent.appendChild(n),n.appendChild(t.node),e=function(){document.readyState==="complete"?(t.attr("style","position:absolute;"),setTimeout(function(){t.attr("style","position:relative;"),t.parent.removeChild(t.node.parentNode),t.node.parentNode.removeChild(t.node),t.parent.appendChild(t.node)},5)):setTimeout(e,10)},e(),this},SVG.Shape=function(t){this.constructor.call(this,t)},SVG.Shape.prototype=new SVG.Element,SVG.Wrap=function(t){this.constructor.call(this,SVG.create("g")),this.node.insertBefore(t.node,null),this.child=t,this.type=t.node.nodeName},SVG.Wrap.prototype=new SVG.Shape,SVG.extend(SVG.Wrap,{move:function(e,t){return this.transform({x:e,y:t})},size:function(e,t){var n=e/this._b.width;return this.child.transform({scaleX:n,scaleY:t!=null?t/this._b.height:n}),this},center:function(e,t){return this.move(e+this._b.width*this.child.trans.scaleX/-2,t+this._b.height*this.child.trans.scaleY/-2)},attr:function(e,t,n){if(typeof e=="object")for(t in e)this.attr(t,e[t]);else{if(arguments.length<2)return e=="transform"?this.attrs[e]:this.child.attrs[e];e=="transform"?(this.attrs[e]=t,n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)):this.child.attr(e,t,n)}return this},plot:function(e){return this.child.plot(e),this._b=this.child.bbox(),this.child.transform({x:-this._b.x,y:-this._b.y}),this}}),SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Ellipse=function(){this.constructor.call(this,SVG.create("ellipse"))},SVG.Ellipse.prototype=new SVG.Shape,SVG.extend(SVG.Ellipse,{move:function(e,t){return this.attrs.x=e,this.attrs.y=t,this.center()},size:function(e,t){return this.attr({rx:e/2,ry:(t!=null?t:e)/2}).center()},center:function(e,t){return this.attr({cx:e||(this.attrs.x||0)+(this.attrs.rx||0),cy:t||(this.attrs.y||0)+(this.attrs.ry||0)})}}),SVG.Poly={plot:function(e){return this.attr("points",e||"0,0"),this}},SVG.Polyline=function(){this.constructor.call(this,SVG.create("polyline"))},SVG.Polyline.prototype=new SVG.Shape,SVG.extend(SVG.Polyline,SVG.Poly),SVG.Polygon=function(){this.constructor.call(this,SVG.create("polygon"))},SVG.Polygon.prototype=new SVG.Shape,SVG.extend(SVG.Polygon,SVG.Poly),SVG.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{move:function(e,t){this.transform({x:e,y:t})},plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return this.src=e,e?this.attr("xlink:href",e,SVG.xlink):this}});var e=["size","family","weight","stretch","variant","style"];SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.style={"font-size":16,"font-family":"Helvetica","text-anchor":"start"},this.leading=1.2},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{text:function(e){this.content=e=e||"text",this.lines=[];var n,r,i,s=this._style(),o=this.doc(),u=e.split("\n"),a=this.style["font-size"];while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);for(n=0,r=u.length;n<r;n++)i=(new t).text(u[n]).attr({dy:a*this.leading-(n==0?a*.3:0),x:this.attrs.x||0,style:s}),this.node.appendChild(i.node),this.lines.push(i);return this.attr("style",s)},_style:function(){var t,n="";for(t=e.length-1;t>=0;t--)this.style["font-"+e[t]]!=null&&(n+="font-"+e[t]+":"+this.style["font-"+e[t]]+";");return n+="text-anchor:"+this.style["text-anchor"]+";",n}}),t.prototype=new SVG.Shape,SVG.extend(t,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.Nested=function(){this.constructor.call(this,SVG.create("svg")),this.attr("overflow","visible")},SVG.Nested.prototype=new SVG.Container,SVG._stroke=["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],SVG._fill=["color","opacity","rule"];var n=function(e,t){return t=="color"?e:e+"-"+t};["fill","stroke"].forEach(function(e){SVG.Shape.prototype[e]=function(t){var r;if(typeof t=="string")this.attr(e,t);else for(r=SVG["_"+e].length-1;r>=0;r--)t[SVG["_"+e][r]]!=null&&this.attr(n(e,SVG["_"+e][r]),t[SVG["_"+e][r]]);return this}}),[SVG.Element,SVG.FX].forEach(function(e){e&&SVG.extend(e,{rotate:function(e){return this.transform({rotation:e||0})},skew:function(e,t){return this.transform({skewX:e||0,skewY:t||0})},scale:function(e,t){return this.transform({scaleX:e,scaleY:t==null?e:t})},opacity:function(e){if(["rect","ellipse","polygon","path","polyline","line","text"].indexOf(this.type)>-1){if(e==null)return this.attr("fill-opacity");this.attr({"fill-opacity":e,"stroke-opacity":e})}else{if(e==null)return this.attr("opacity");this.attr("opacity",e)}return this}})}),SVG.G&&SVG.extend(SVG.G,{move:function(e,t){return this.transform({x:e,y:t})}}),SVG.Text&&SVG.extend(SVG.Text,{font:function(t){var n,r={};for(n in t)n=="leading"?r[n]=t[n]:n=="anchor"?r["text-anchor"]=t[n]:e.indexOf(n)>-1?r["font-"+n]=t[n]:void 0;return this.attr(r).text(this.content)}})}).call(this); \ No newline at end of file
diff --git a/src/container.js b/src/container.js
index d828371..1f0998a 100644
--- a/src/container.js
+++ b/src/container.js
@@ -1,7 +1,12 @@
-// ### A module used for container elements like SVG.Doc, SVG.Group, SVG.Defs, ...
+SVG.Container = function Container(element) {
+ this.constructor.call(this, element);
+};
+
+// Inherit from SVG.Element
+SVG.Container.prototype = new SVG.Element();
//
-SVG.Container = {
+SVG.extend(SVG.Container, {
// Add given element at a position
add: function(element, index) {
if (!this.has(element)) {
@@ -131,4 +136,4 @@ SVG.Container = {
return this;
}
-}; \ No newline at end of file
+}); \ No newline at end of file
diff --git a/src/defs.js b/src/defs.js
index 875013b..8714663 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -5,8 +5,5 @@ SVG.Defs = function Defs() {
this.constructor.call(this, SVG.create('defs'));
};
-// Inherits from SVG.Element
-SVG.Defs.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Defs, SVG.Container); \ No newline at end of file
+// Inherits from SVG.Container
+SVG.Defs.prototype = new SVG.Container(); \ No newline at end of file
diff --git a/src/doc.js b/src/doc.js
index 7afea7a..ce67b1c 100644
--- a/src/doc.js
+++ b/src/doc.js
@@ -19,11 +19,8 @@ SVG.Doc = function Doc(element) {
this.stage();
};
-// Inherits from SVG.Element
-SVG.Doc.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Doc, SVG.Container);
+// Inherits from SVG.Container
+SVG.Doc.prototype = new SVG.Container();
// Hack for safari preventing text to be rendered in one line.
// Basically it sets the position of the svg node to absolute
diff --git a/src/gradient.js b/src/gradient.js
index 6554c92..07bb748 100644
--- a/src/gradient.js
+++ b/src/gradient.js
@@ -8,11 +8,8 @@ SVG.Gradient = function Gradient(type) {
this.type = type;
};
-// Inherit from SVG.Element
-SVG.Gradient.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Gradient, SVG.Container);
+// Inherit from SVG.Container
+SVG.Gradient.prototype = new SVG.Container();
//
SVG.extend(SVG.Gradient, {
diff --git a/src/group.js b/src/group.js
index df97c3e..cbb635f 100644
--- a/src/group.js
+++ b/src/group.js
@@ -2,11 +2,8 @@ SVG.G = function G() {
this.constructor.call(this, SVG.create('g'));
};
-// Inherit from SVG.Element
-SVG.G.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.G, SVG.Container);
+// Inherit from SVG.Container
+SVG.G.prototype = new SVG.Container();
SVG.extend(SVG.G, {
diff --git a/src/mask.js b/src/mask.js
index e7e94a4..5ffd790 100644
--- a/src/mask.js
+++ b/src/mask.js
@@ -5,11 +5,8 @@ SVG.Mask = function Mask() {
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
-// Inherit from SVG.Element
-SVG.Mask.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Mask, SVG.Container);
+// Inherit from SVG.Container
+SVG.Mask.prototype = new SVG.Container();
SVG.extend(SVG.Element, {
diff --git a/src/nested.js b/src/nested.js
index 9cf54a9..d2aafdb 100644
--- a/src/nested.js
+++ b/src/nested.js
@@ -3,8 +3,5 @@ SVG.Nested = function Nested() {
this.attr('overflow', 'visible');
};
-// Inherit from SVG.Element
-SVG.Nested.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Nested, SVG.Container); \ No newline at end of file
+// Inherit from SVG.Container
+SVG.Nested.prototype = new SVG.Container(); \ No newline at end of file
diff --git a/src/pattern.js b/src/pattern.js
index 9b37297..c12978e 100644
--- a/src/pattern.js
+++ b/src/pattern.js
@@ -5,11 +5,8 @@ SVG.Pattern = function Pattern(type) {
this.attr('id', (this.id = 'svgjs_element_' + (SVG.did++)));
};
-// Inherit from SVG.Element
-SVG.Pattern.prototype = new SVG.Element();
-
-// Include the container object
-SVG.extend(SVG.Pattern, SVG.Container);
+// Inherit from SVG.Container
+SVG.Pattern.prototype = new SVG.Container();
//
SVG.extend(SVG.Pattern, {
diff --git a/src/sugar.js b/src/sugar.js
index bd8930e..d53054e 100644
--- a/src/sugar.js
+++ b/src/sugar.js
@@ -54,10 +54,17 @@ var _colorPrefix = function(type, attr) {
},
// Opacity
opacity: function(value) {
- if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1)
- this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
- else
- this.attr('opacity', value);
+ if (['rect', 'ellipse', 'polygon', 'path', 'polyline', 'line', 'text'].indexOf(this.type) > -1) {
+ if (value == null)
+ return this.attr('fill-opacity');
+ else
+ this.attr({ 'fill-opacity': value, 'stroke-opacity': value });
+ } else {
+ if (value == null)
+ return this.attr('opacity');
+ else
+ this.attr('opacity', value);
+ }
return this;
}
diff --git a/src/svg.js b/src/svg.js
index 409aa37..9306232 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -26,16 +26,8 @@ this.SVG = {
},
// Method for extending objects
extend: function(object, module) {
- /* extend all container modules */
- if (object == SVG.Container)
- ('Clip Defs Doc Gradient Group Mask Nested Pattern').split(' ').forEach(function(m) {
- if (SVG[m])
- SVG.extend(SVG[m], module);
- });
- /* extend given module */
- else
- for (var key in module)
- object.prototype[key] = module[key];
+ for (var key in module)
+ object.prototype[key] = module[key];
}
}; \ No newline at end of file