_This functionality requires the group.js module which is included in the default distribution._
+### Gradients
+There are linear and radial gradients. The linear gradient can be created like this:
+```javascript
+var gradient = draw.gradient('linear', function(stop) {
+ stop.at({ offset: 0, color: '#333', opacity: 1 });
+ stop.at({ offset: 100, color: '#fff', opacity: 1 });
+});
+```
+The 'offset' and 'color' parameters are required for stops, 'opacity' is optional. Offset is an integer expressed in percentage. To define the direction you can set from x, y and to x, y:
+```javascript
+gradient.from(0, 0).to(0, 100);
+```
+The from and to values are also expressed in percent.
+Finally, to use the gradient on an element:
+```javascript
+rect.attr({ fill: gradient.fill() });
+```
+Radial gradients have a 'radius()' method to define the outermost radius to where the inner color should develop:
+```javascript
+var gradient = draw.gradient('radial', function(stop) {
+ stop.at({ offset: 0, color: '#333', opacity: 1 });
+ stop.at({ offset: 100, color: '#fff', opacity: 1 });
+});
+
+gradient.from(50, 50).to(50, 50).radius(50);
+```
+A gradient can also be updated afterwards:
+```javascript
+gradient.update(function(stop) {
+ stop.at({ offset: 10, color: '#333', opacity: 0.2 });
+ stop.at({ offset: 90, color: '#f03', opacity: 1 });
+});
+```
+And even a single stop can be updated:
+```javascript
+var s1, s2, s3;
+
+draw.gradient('radial', function(stop) {
+ s1 = stop.at({ offset: 0, color: '#000', opacity: 1 });
+ s2 = stop.at({ offset: 50, color: '#f03', opacity: 1 });
+ s3 = stop.at({ offset: 100, color: '#066', opacity: 1 });
+});
+
+stop1.update({ offset: 10, color: '#0f0', opacity: 1 });
+```
+
+_This functionality requires the gradient.js module which is included in the default distribution._
+
+
## Extending functionality
Svg.js has a modular structure. It is very easy to add you own methods at different levels. Let's say we want to add a method to all shape types then we would add our method to SVG.Shape:
```javascript
- Animation module (element animation, path tweens and easing)
- Draggable module (make elements and groups draggable)
- Shapes module (add preset shapes like star, n-gon)
-- Gradient module (for linear and radial gradients)
- Text on path module (write text along paths)
-/* svg.js v0.1-2-gcf1bd17 - svg container element group arrange defs clip doc shape rect circle ellipse path image text sugar - svgjs.com/license */
+/* svg.js v0.1-4-g740392e - svg container element group arrange defs clip gradient doc shape rect circle ellipse path image text sugar - svgjs.com/license */
(function() {
this.SVG = {
return this.place(new SVG.Text(), v);
},
+ gradient: function(t, b) {
+ return this.defs().gradient(t, b);
+ },
+
place: function(e, v) {
if (v != null) {
e.move(v.x || 0, v.y || 0);
+
if (v.width != null && v.height != null)
e.size(v.width, v.height);
SVG.Clip = function Clip() {
this.constructor.call(this, SVG.create('clipPath'));
- this.id = '_' + (clipID++);
+ this.id = 'svgjs_clip_' + (clipID++);
this.attr('id', this.id);
};
// clip element using another element
clip: function(b) {
- var p = this.mother().defs().clipPath();
+ var p = this.mother().defs().clip();
b(p);
return this.clipTo(p);
SVG.extend(SVG.Defs, {
// define clippath
- clipPath: function() {
+ clip: function() {
var e = new SVG.Clip();
this.add(e);
});
+ var gradID = 0;
+
+ SVG.Gradient = function Gradient(t) {
+ this.constructor.call(this, SVG.create(t + 'Gradient'));
+ this.id = 'svgjs_grad_' + (gradID++);
+ this.type = t;
+
+ this.attr('id', this.id);
+ };
+
+ // inherit from SVG.Element
+ SVG.Gradient.prototype = new SVG.Element();
+
+ // include the container object
+ SVG.extend(SVG.Gradient, SVG.Container);
+
+ // add gradient-specific functions
+ SVG.extend(SVG.Gradient, {
+
+ // from position
+ from: function(x, y) {
+ return this.type == 'radial' ?
+ this.attr({ fx: x + '%', fy: y + '%' }) :
+ this.attr({ x1: x + '%', y1: y + '%' });
+ },
+
+ // to position
+ to: function(x, y) {
+ return this.type == 'radial' ?
+ this.attr({ cx: x + '%', cy: y + '%' }) :
+ this.attr({ x2: x + '%', y2: y + '%' });
+ },
+
+ // radius for radial gradient
+ radius: function(r) {
+ return this.type == 'radial' ?
+ this.attr({ r: r + '%' }) :
+ this;
+ },
+
+ // add color stops
+ at: function(o) {
+ var m = new SVG.Stop(o);
+ this.add(m);
+
+ return m;
+ },
+
+ // update gradient
+ update: function(b) {
+ while (this.node.hasChildNodes())
+ this.node.removeChild(this.node.lastChild);
+
+ b(this);
+
+ return this;
+ },
+
+ // return the fill id
+ fill: function() {
+ return 'url(#' + this.id + ')';
+ }
+
+ });
+
+ // add def-specific functions
+ SVG.extend(SVG.Defs, {
+
+ // define clippath
+ gradient: function(t, b) {
+ var e = new SVG.Gradient(t);
+ this.add(e);
+ b(e);
+
+ return e;
+ }
+
+ });
+
+
+ SVG.Stop = function Stop(o) {
+ this.constructor.call(this, SVG.create('stop'));
+
+ this.update(o);
+ };
+
+ // inherit from SVG.Element
+ SVG.Stop.prototype = new SVG.Element();
+
+ // add mark-specific functions
+ SVG.extend(SVG.Stop, {
+
+ // add color stops
+ update: function(o) {
+ var s = '',
+ a = ['opacity', 'color'];
+
+ for (var i = a.length - 1; i >= 0; i--)
+ if (o[a[i]] != null)
+ s += 'stop-' + a[i] + ':' + o[a[i]] + ';';
+
+ return this.attr({
+ offset: (o.offset != null ? o.offset : this.attr('offset') || 0) + '%',
+ style: s
+ });
+ }
+
+ });
+
+
+
SVG.Doc = function Doc(e) {
this.constructor.call(this, SVG.create('svg'));
// inherit from SVG.Element
SVG.Image.prototype = new SVG.Shape();
- // Add image-specific functions
+ // add image-specific functions
SVG.extend(SVG.Image, {
// (re)load image
}).call(this);
-window.svg = function(e) { return new SVG.Doc(e); };
+function svg(e) { return new SVG.Doc(e); };
-/* svg.js v0.1-2-gcf1bd17 - svg container element group arrange defs clip doc shape rect circle ellipse path image text sugar - svgjs.com/license */
-(function(){function t(){this.constructor.call(this,SVG.create("tspan"))}this.SVG={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",create:function(e){return document.createElementNS(this.ns,e)},extend:function(e,t){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]),e.parent=this),this},has:function(e){return this.children().indexOf(e)>=0},children:function(){return this._children||(this._children=[])},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==null&&(this._defs=new SVG.Defs,this.add(this._defs,0)),this._defs},levelDefs:function(){var e=this.defs();return this.remove(e).add(e,0),this},group:function(){var e=new SVG.G;return this.add(e),e},rect:function(e){return this.place(new SVG.Rect,e)},circle:function(e){var t;return e!=null&&(t={x:e.x,y:e.y},e.r||e.radius?t.width=t.height=(e.r||e.radius)*2:t.width=t.height=e.width||e.height),this.place(new SVG.Circle,t)},ellipse:function(e){var t;return e!=null&&(t={x:e.x,y:e.y},e.width&&(t.width=e.width),e.height&&(t.height=e.height),e.rx&&(t.width=e.rx*2),e.ry&&(t.height=e.ry*2)),this.place(new SVG.Ellipse,t)},path:function(e){return this.place(new SVG.Path,e)},image:function(e){return this.place(new SVG.Image,e)},text:function(e){return this.place(new SVG.Text,e)},place:function(e,t){return t!=null&&(e.move(t.x||0,t.y||0),t.width!=null&&t.height!=null&&e.size(t.width,t.height),t.data!=null?e.plot(t.data):t.src!=null?e.load(t.src):t.text!=null?e.text(t.text):void 0),this.add(e),e}},SVG.Element=function(t){this.node=t,this.attrs={},this._s="size family weight stretch variant style".split(" ")},SVG.extend(SVG.Element,{move:function(e,t){return this.attr({x:e,y:t})},size:function(e,t){return this.attr({width:e,height:t})},remove:function(){return this.parent!=null?this.parent.remove(this):void 0},parentDoc:function(){return this._parent(SVG.Doc)},mother:function(){return this.parentDoc()},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,t){var n=[],r=this.attr("transform")||"",i=r.match(/([a-z]+\([^\)]+\))/g)||[];if(t!==!0){var s=e.match(/^([A-Za-z\-]+)/)[1],t=new RegExp("^"+s);for(var o=0,r=i.length;o<r;o++)t.test(i[o])||n.push(i[o])}else n=i;return n.push(e),this.attr("transform",n.join(" "))},bbox:function(){var e=this.node.getBBox();return e.cx=e.x+e.width/2,e.cy=e.y+e.height/2,e},_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.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Element,SVG.extend(SVG.G,SVG.Container),SVG.extend(SVG.Element,{siblings:function(){return this.mother().children()},forward:function(){var e=this.siblings().indexOf(this);return this.mother().remove(this).add(this,e+1),this},backward:function(){var e,t=this.mother().levelDefs();return e=this.siblings().indexOf(this),e>1&&t.remove(this).add(this,e-1),this},front:function(){return this.mother().remove(this).add(this),this},back:function(){var e,t=this.mother().levelDefs();return e=this.siblings().indexOf(this),e>1&&t.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);var e=0;SVG.Clip=function(){this.constructor.call(this,SVG.create("clipPath")),this.id="_"+e++,this.attr("id",this.id)},SVG.Clip.prototype=new SVG.Element,SVG.extend(SVG.Clip,SVG.Container),SVG.extend(SVG.Element,{clip:function(e){var t=this.mother().defs().clipPath();return e(t),this.clipTo(t)},clipTo:function(e){return this.attr("clip-path","url(#"+e.id+")")}}),SVG.extend(SVG.Defs,{clipPath:function(){var e=new SVG.Clip;return this.add(e),e}}),SVG.Doc=function(t){this.constructor.call(this,SVG.create("svg")),typeof t=="string"&&(t=document.getElementById(t)),this.attr({xmlns:SVG.ns,version:"1.1"}).attr("xlink",SVG.xlink,SVG.ns).size(t.offsetWidth,t.offsetHeight).defs(),t.appendChild(this.node)},SVG.Doc.prototype=new SVG.Element,SVG.extend(SVG.Doc,SVG.Container),SVG.Shape=function(t){this.constructor.call(this,t)},SVG.Shape.prototype=new SVG.Element,SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Circle=function(){this.constructor.call(this,SVG.create("circle"))},SVG.Circle.prototype=new SVG.Shape,SVG.extend(SVG.Circle,{move:function(e,t){return this.attrs.x=e,this.attrs.y=t,this.center()},size:function(e){return this.attr("r",e/2).center()},center:function(e,t){var n=this.attrs.r||0;return this.attr({cx:e||(this.attrs.x||0)+n,cy:t||(this.attrs.y||0)+n})}}),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/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.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{plot:function(e){return this.attr("d",e)}}),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.attr("xlink:href",e,SVG.xlink)}}),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,this.lines=[]},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{text:function(e){this.content=e=e||"text",this.lines=[];var n,r,i=this._style(),s=this.parentDoc(),o=e.split("\n");while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);for(n=0,l=o.length;n<l;n++)r=(new t).text(o[n]).attr({dy:this.style["font-size"]*this.leading,x:this.attr("x")||0,style:i}),this.node.appendChild(r.node),this.lines.push(r);return this.attr("style",i)},_style:function(){var e,t="",n=this._s;for(e=n.length-1;e>=0;e--)this.style["font-"+n[e]]!=null&&(t+="font-"+n[e]+":"+this.style["font-"+n[e]]+";");return t+="text-anchor:"+this.style["text-anchor"]+";",t}}),t.prototype=new SVG.Shape,SVG.extend(t,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.extend(SVG.Shape,{fill:function(e){return e.color!=null&&this.attr("fill",e.color),e.opacity!=null&&this.attr("fill-opacity",e.opacity),this},stroke:function(e){e.color&&this.attr("stroke",e.color);var t="width opacity linecap linejoin miterlimit dasharray dashoffset".split(" ");for(var n=t.length-1;n>=0;n--)e[t[n]]!=null&&this.attr("stroke-"+t[n],e[t[n]]);return this}}),SVG.extend(SVG.Element,{rotate:function(e){var t=this.bbox();return e.x==null&&(e.x=t.cx),e.y==null&&(e.y=t.cy),this.transform("rotate("+(e.deg||0)+" "+e.x+" "+e.y+")",e.relative)}}),SVG.extend(SVG.G,{move:function(e,t){return this.transform("translate("+e+" "+t+")")}}),SVG.extend(SVG.Text,{font:function(e){var t={};for(var n in e)n=="leading"?t[n]=e[n]:n=="anchor"?t["text-anchor"]=e[n]:this._s.indexOf(n)>-1?t["font-"+n]=e[n]:void 0;return this.attr(t).text(this.content)}})}).call(this),window.svg=function(e){return new SVG.Doc(e)};
\ No newline at end of file
+/* svg.js v0.1-4-g740392e - svg container element group arrange defs clip gradient doc shape rect circle ellipse path image text sugar - svgjs.com/license */
+function svg(e){return new SVG.Doc(e)}(function(){function n(){this.constructor.call(this,SVG.create("tspan"))}this.SVG={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",create:function(e){return document.createElementNS(this.ns,e)},extend:function(e,t){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]),e.parent=this),this},has:function(e){return this.children().indexOf(e)>=0},children:function(){return this._children||(this._children=[])},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==null&&(this._defs=new SVG.Defs,this.add(this._defs,0)),this._defs},levelDefs:function(){var e=this.defs();return this.remove(e).add(e,0),this},group:function(){var e=new SVG.G;return this.add(e),e},rect:function(e){return this.place(new SVG.Rect,e)},circle:function(e){var t;return e!=null&&(t={x:e.x,y:e.y},e.r||e.radius?t.width=t.height=(e.r||e.radius)*2:t.width=t.height=e.width||e.height),this.place(new SVG.Circle,t)},ellipse:function(e){var t;return e!=null&&(t={x:e.x,y:e.y},e.width&&(t.width=e.width),e.height&&(t.height=e.height),e.rx&&(t.width=e.rx*2),e.ry&&(t.height=e.ry*2)),this.place(new SVG.Ellipse,t)},path:function(e){return this.place(new SVG.Path,e)},image:function(e){return this.place(new SVG.Image,e)},text:function(e){return this.place(new SVG.Text,e)},gradient:function(e,t){return this.defs().gradient(e,t)},place:function(e,t){return t!=null&&(e.move(t.x||0,t.y||0),t.width!=null&&t.height!=null&&e.size(t.width,t.height),t.data!=null?e.plot(t.data):t.src!=null?e.load(t.src):t.text!=null?e.text(t.text):void 0),this.add(e),e}},SVG.Element=function(t){this.node=t,this.attrs={},this._s="size family weight stretch variant style".split(" ")},SVG.extend(SVG.Element,{move:function(e,t){return this.attr({x:e,y:t})},size:function(e,t){return this.attr({width:e,height:t})},remove:function(){return this.parent!=null?this.parent.remove(this):void 0},parentDoc:function(){return this._parent(SVG.Doc)},mother:function(){return this.parentDoc()},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,t){var n=[],r=this.attr("transform")||"",i=r.match(/([a-z]+\([^\)]+\))/g)||[];if(t!==!0){var s=e.match(/^([A-Za-z\-]+)/)[1],t=new RegExp("^"+s);for(var o=0,r=i.length;o<r;o++)t.test(i[o])||n.push(i[o])}else n=i;return n.push(e),this.attr("transform",n.join(" "))},bbox:function(){var e=this.node.getBBox();return e.cx=e.x+e.width/2,e.cy=e.y+e.height/2,e},_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.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Element,SVG.extend(SVG.G,SVG.Container),SVG.extend(SVG.Element,{siblings:function(){return this.mother().children()},forward:function(){var e=this.siblings().indexOf(this);return this.mother().remove(this).add(this,e+1),this},backward:function(){var e,t=this.mother().levelDefs();return e=this.siblings().indexOf(this),e>1&&t.remove(this).add(this,e-1),this},front:function(){return this.mother().remove(this).add(this),this},back:function(){var e,t=this.mother().levelDefs();return e=this.siblings().indexOf(this),e>1&&t.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);var e=0;SVG.Clip=function(){this.constructor.call(this,SVG.create("clipPath")),this.id="svgjs_clip_"+e++,this.attr("id",this.id)},SVG.Clip.prototype=new SVG.Element,SVG.extend(SVG.Clip,SVG.Container),SVG.extend(SVG.Element,{clip:function(e){var t=this.mother().defs().clip();return e(t),this.clipTo(t)},clipTo:function(e){return this.attr("clip-path","url(#"+e.id+")")}}),SVG.extend(SVG.Defs,{clip:function(){var e=new SVG.Clip;return this.add(e),e}});var t=0;SVG.Gradient=function(n){this.constructor.call(this,SVG.create(n+"Gradient")),this.id="svgjs_grad_"+t++,this.type=n,this.attr("id",this.id)},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){var t=new SVG.Stop(e);return this.add(t),t},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=new SVG.Gradient(e);return this.add(n),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=["opacity","color"];for(var r=n.length-1;r>=0;r--)e[n[r]]!=null&&(t+="stop-"+n[r]+":"+e[n[r]]+";");return this.attr({offset:(e.offset!=null?e.offset:this.attr("offset")||0)+"%",style:t})}}),SVG.Doc=function(t){this.constructor.call(this,SVG.create("svg")),typeof t=="string"&&(t=document.getElementById(t)),this.attr({xmlns:SVG.ns,version:"1.1"}).attr("xlink",SVG.xlink,SVG.ns).size(t.offsetWidth,t.offsetHeight).defs(),t.appendChild(this.node)},SVG.Doc.prototype=new SVG.Element,SVG.extend(SVG.Doc,SVG.Container),SVG.Shape=function(t){this.constructor.call(this,t)},SVG.Shape.prototype=new SVG.Element,SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Circle=function(){this.constructor.call(this,SVG.create("circle"))},SVG.Circle.prototype=new SVG.Shape,SVG.extend(SVG.Circle,{move:function(e,t){return this.attrs.x=e,this.attrs.y=t,this.center()},size:function(e){return this.attr("r",e/2).center()},center:function(e,t){var n=this.attrs.r||0;return this.attr({cx:e||(this.attrs.x||0)+n,cy:t||(this.attrs.y||0)+n})}}),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/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.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{plot:function(e){return this.attr("d",e)}}),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.attr("xlink:href",e,SVG.xlink)}}),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,this.lines=[]},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{text:function(e){this.content=e=e||"text",this.lines=[];var t,r,i=this._style(),s=this.parentDoc(),o=e.split("\n");while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);for(t=0,l=o.length;t<l;t++)r=(new n).text(o[t]).attr({dy:this.style["font-size"]*this.leading,x:this.attr("x")||0,style:i}),this.node.appendChild(r.node),this.lines.push(r);return this.attr("style",i)},_style:function(){var e,t="",n=this._s;for(e=n.length-1;e>=0;e--)this.style["font-"+n[e]]!=null&&(t+="font-"+n[e]+":"+this.style["font-"+n[e]]+";");return t+="text-anchor:"+this.style["text-anchor"]+";",t}}),n.prototype=new SVG.Shape,SVG.extend(n,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.extend(SVG.Shape,{fill:function(e){return e.color!=null&&this.attr("fill",e.color),e.opacity!=null&&this.attr("fill-opacity",e.opacity),this},stroke:function(e){e.color&&this.attr("stroke",e.color);var t="width opacity linecap linejoin miterlimit dasharray dashoffset".split(" ");for(var n=t.length-1;n>=0;n--)e[t[n]]!=null&&this.attr("stroke-"+t[n],e[t[n]]);return this}}),SVG.extend(SVG.Element,{rotate:function(e){var t=this.bbox();return e.x==null&&(e.x=t.cx),e.y==null&&(e.y=t.cy),this.transform("rotate("+(e.deg||0)+" "+e.x+" "+e.y+")",e.relative)}}),SVG.extend(SVG.G,{move:function(e,t){return this.transform("translate("+e+" "+t+")")}}),SVG.extend(SVG.Text,{font:function(e){var t={};for(var n in e)n=="leading"?t[n]=e[n]:n=="anchor"?t["text-anchor"]=e[n]:this._s.indexOf(n)>-1?t["font-"+n]=e[n]:void 0;return this.attr(t).text(this.content)}})}).call(this);
\ No newline at end of file