From a736acc12e4ca1a71b9f563f7ed361e2a3540469 Mon Sep 17 00:00:00 2001 From: wout Date: Mon, 15 Apr 2013 13:17:20 +0100 Subject: [PATCH] Parsing numeric values as a global getter --- dist/svg.js | 4 ++-- dist/svg.min.js | 4 ++-- spec/spec/element.js | 16 ++++++++++++++++ src/element.js | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/dist/svg.js b/dist/svg.js index e904375..0692488 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js v0.13-5-g801a9e1 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ +/* svg.js v0.13-6-gd0c34f7 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ ;(function() { this.SVG = function(element) { @@ -501,7 +501,7 @@ a = {} v = this.node.attributes for (n = v.length - 1; n >= 0; n--) - a[v[n].nodeName] = v[n].nodeValue + a[v[n].nodeName] = SVG.regex.test(v[n].nodeValue, 'isNumber') ? parseFloat(v[n].nodeValue) : v[n].nodeValue return a diff --git a/dist/svg.min.js b/dist/svg.min.js index 1b83a00..94731a5 100644 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1,2 +1,2 @@ -/* svg.js v0.13-5-g801a9e1 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ -(function(){this.SVG=function(e){if(SVG.supported)return new SVG.Doc(e)},this.svg=function(e){return console.warn("WARNING: svg() is deprecated, please use SVG() instead."),SVG(e)},SVG.ns="http://www.w3.org/2000/svg",SVG.xlink="http://www.w3.org/1999/xlink",SVG.did=1e3,SVG.eid=function(e){return"Svgjs"+e.charAt(0).toUpperCase()+e.slice(1)+SVG.did++},SVG.create=function(e){var t=document.createElementNS(this.ns,e);return t.setAttribute("id",this.eid(e)),t},SVG.extend=function(){var e,t,n,r;e=[].slice.call(arguments),t=e.pop();for(r=e.length-1;r>=0;r--)if(e[r])for(n in t)e[r].prototype[n]=t[n]},SVG.get=function(e){var t=document.getElementById(e);if(t)return t.instance},SVG.supported=function(){return!!document.createElementNS&&!!document.createElementNS(SVG.ns,"svg").createSVGRect}();if(!SVG.supported)return!1;SVG.regex={test:function(e,t){return this[t].test(e)},unit:/^([\d\.]+)([a-z%]{0,2})$/,hex:/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,rgb:/rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/,hsb:/hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isHsb:/^hsb\(/,isCss:/[^:]+:[^;]+;?/,isStyle:/^font|text|leading|cursor/,isBlank:/^(\s+)?$/,isNumber:/^-?[\d\.]+$/},SVG.defaults={matrix:"1,0,0,1,0,0",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,offset:0},trans:function(){return{x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0,matrix:this.matrix,a:1,b:0,c:0,d:1,e:0,f:0}}},SVG.Color=function(e){var t;this.r=0,this.g=0,this.b=0,typeof e=="string"?SVG.regex.isRgb.test(e)?(t=SVG.regex.rgb.exec(e.replace(/\s/g,"")),this.r=parseInt(m[1]),this.g=parseInt(m[2]),this.b=parseInt(m[3])):SVG.regex.isHex.test(e)?(t=SVG.regex.hex.exec(this._fullHex(e)),this.r=parseInt(t[1],16),this.g=parseInt(t[2],16),this.b=parseInt(t[3],16)):SVG.regex.isHsb.test(e)&&(t=SVG.regex.hsb.exec(e.replace(/\s/g,"")),e=this._hsbToRgb(t[1],t[2],t[3])):typeof e=="object"&&(SVG.Color.isHsb(e)&&(e=this._hsbToRgb(e.h,e.s,e.b)),this.r=e.r,this.g=e.g,this.b=e.b)},SVG.extend(SVG.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+this._compToHex(this.r)+this._compToHex(this.g)+this._compToHex(this.b)},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},_hsbToRgb:function(e,t,n){var i,s;e=parseInt(e)%360,e<0&&(e+=360),t=parseInt(t),t=t>100?100:t,n=parseInt(n),n=(n<0?0:n>100?100:n)*255/100,i=n*t/100,s=i*(e*256/60%256)/256;switch(Math.floor(e/60)){case 0:r=n,g=n-i+s,b=n-i;break;case 1:r=n-s,g=n,b=n-i;break;case 2:r=n-i,g=n,b=n-i+s;break;case 3:r=n-i,g=n-s,b=n;break;case 4:r=n-i+s,g=n-i,b=n;break;case 5:r=n,g=n-i,b=n-s}return{r:Math.floor(r+.5),g:Math.floor(g+.5),b:Math.floor(b+.5)}},_fullHex: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},_compToHex:function(e){var t=e.toString(16);return t.length==1?"0"+t:t}}),SVG.Color.test=function(e){return e+="",SVG.regex.isHex.test(e)||SVG.regex.isRgb.test(e)||SVG.regex.isHsb.test(e)},SVG.Color.isRgb=function(e){return e&&typeof e.r=="number"},SVG.Color.isHsb=function(e){return e&&typeof e.h=="number"},SVG.ViewBox=function(e){var t,n,r,i,s=e.bbox(),o=(e.attr("viewBox")||"").match(/-?[\d\.]+/g);this.x=s.x,this.y=s.y,this.width=e.node.offsetWidth||e.attr("width"),this.height=e.node.offsetHeight||e.attr("height"),o&&(t=parseFloat(o[0]),n=parseFloat(o[1]),r=parseFloat(o[2]),i=parseFloat(o[3]),this.zoom=this.width/this.height>r/i?this.height/i:this.width/r,this.x=t,this.y=n,this.width=r,this.height=i),this.zoom=this.zoom||1},SVG.extend(SVG.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),SVG.BBox=function(e){var t;try{t=e.node.getBBox()}catch(n){t={x:e.node.clientLeft,y:e.node.clientTop,width:e.node.clientWidth,height:e.node.clientHeight}}this.x=t.x+e.trans.x,this.y=t.y+e.trans.y,this.width=t.width*e.trans.scaleX,this.height=t.height*e.trans.scaleY,this.cx=this.x+this.width/2,this.cy=this.y+this.height/2},SVG.Element=function(e){this._stroke=SVG.defaults.attrs.stroke,this.styles={},this.trans=SVG.defaults.trans();if(this.node=e)this.type=e.nodeName,this.node.instance=this},SVG.extend(SVG.Element,{x:function(e){return e&&(e/=this.trans.scaleX),this.attr("x",e)},y:function(e){return e&&(e/=this.trans.scaleY),this.attr("y",e)},cx:function(e){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e){return e==null?this.bbox().cy:this.y(e-this.bbox().height/2)},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e,t,n=this.type;return e=n=="rect"||n=="ellipse"?this.parent[n](0,0):n=="line"?this.parent[n](0,0,0,0):n=="image"?this.parent[n](this.src):n=="text"?this.parent[n](this.content):n=="path"?this.parent[n](this.attr("d")):n=="polyline"||n=="polygon"?this.parent[n](this.attr("points")):n=="g"?this.parent.group():this.parent[n](),t=this.attr(),delete t.id,e.attr(t),e.trans=this.trans,e.transform({})},remove:function(){return this.parent&&this.parent.removeElement(this),this},doc:function(e){return this._parent(e||SVG.Doc)},attr:function(e,t,n){if(e==null){e={},t=this.node.attributes;for(n=t.length-1;n>=0;n--)e[t[n].nodeName]=t[n].nodeValue;return e}if(typeof e=="object")for(t in e)this.attr(t,e[t]);else if(t===null)this.node.removeAttribute(e);else{if(t==null)return this._isStyle(e)?e=="text"?this.content:e=="leading"&&this.leading?this.leading():this.style(e):(t=this.node.getAttribute(e),t==null?SVG.defaults.attrs[e]:SVG.regex.test(t,"isNumber")?parseFloat(t):t);if(e=="style")return this.style(t);if(e=="x"&&Array.isArray(this.lines))for(n=this.lines.length-1;n>=0;n--)this.lines[n].attr(e,t);e=="stroke-width"?this.attr("stroke",parseFloat(t)>0?this._stroke:null):e=="stroke"&&(this._stroke=t);if(SVG.Color.test(t)||SVG.Color.isRgb(t)||SVG.Color.isHsb(t))t=(new SVG.Color(t)).toHex();n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t),this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"&&this.leading?this.leading(t):this.style(e,t),this.rebuild&&this.rebuild(e,t))}return this},transform:function(e,t){if(arguments.length==0)return this.trans;if(typeof e=="string"){if(arguments.length<2)return this.trans[e];var n={};return n[e]=t,this.transform(n)}var n=[];e=this._parseMatrix(e),e.rotation!=null&&(e.cx==null&&(e.cx=this.bbox().cx),e.cy==null&&(e.cy=this.bbox().cy));for(t in e)e[t]!=null&&(this.trans[t]=e[t]);return this.trans.matrix=this.trans.a+","+this.trans.b+","+this.trans.c+","+this.trans.d+","+this.trans.e+","+this.trans.f,e=this.trans,e.matrix!=SVG.defaults.matrix&&n.push("matrix("+e.matrix+")"),e.rotation!=0&&n.push("rotate("+e.rotation+","+e.cx+","+e.cy+")"),(e.scaleX!=1||e.scaleY!=1)&&n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),(e.x!=0||e.y!=0)&&n.push("translate("+e.x/e.scaleX+","+e.y/e.scaleY+")"),this._offset&&n.push("translate("+ -this._offset.x+","+ -this._offset.y+")"),n.length==0?this.node.removeAttribute("transform"):this.node.setAttribute("transform",n.join(" ")),this},style:function(e,t){if(arguments.length==0)return this.attr("style")||"";if(arguments.length<2)if(typeof e=="object")for(t in e)this.style(t,e[t]);else{if(!SVG.regex.isCss.test(e))return this.styles[e];e=e.split(";");for(var n=0;nn.x&&t>n.y&&e=0},each:function(e){var t,n=this.children();for(t=0,length=n.length;t=0;e--)this.removeElement(this.children()[e]);return this.defs(),this}}),SVG.FX=function(e){this.target=e},SVG.extend(SVG.FX,{animate:function(e,t,n){var r=this;return typeof e=="object"&&(n=e.delay,t=e.ease,e=e.duration),this.timeout=setTimeout(function(){e=e==null?1e3:e,t=t||"<>";var n,i,s,o=1e3/60,u=r.target,a=(new Date).getTime(),f=a+e;r.interval=setInterval(function(){var o,l,c=(new Date).getTime(),h=c>f?1:(c-a)/e;if(n==null){n=[];for(l in r.attrs)n.push(l)}if(i==null){i=[];for(l in r.trans)i.push(l)}if(s==null){s=[];for(l in r.styles)s.push(l)}h=t=="<>"?-Math.cos(h*Math.PI)/2+.5:t==">"?Math.sin(h*Math.PI/2):t=="<"?-Math.cos(h*Math.PI/2)+1:t=="-"?h:typeof t=="function"?t(h):h,r._x?u.x(r._at(r._x,h)):r._cx&&u.cx(r._at(r._cx,h)),r._y?u.y(r._at(r._y,h)):r._cy&&u.cy(r._at(r._cy,h)),r._size&&u.size(r._at(r._size.width,h),r._at(r._size.height,h)),r._viewbox&&u.viewbox(r._at(r._viewbox.x,h),r._at(r._viewbox.y,h),r._at(r._viewbox.width,h),r._at(r._viewbox.height,h));for(o=n.length-1;o>=0;o--)u.attr(n[o],r._at(r.attrs[n[o]],h));for(o=i.length-1;o>=0;o--)u.transform(i[o],r._at(r.trans[i[o]],h));for(o=s.length-1;o>=0;o--)u.style(s[o],r._at(r.styles[s[o]],h));r._during&&r._during.call(u,h,function(e,t){return r._at({from:e,to:t},h)}),c>f&&(clearInterval(r.interval),r._after?r._after.apply(u,[r]):r.stop())},e>o?o:e)},n||0),this},bbox:function(){return this.target.bbox()},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,t){if(arguments.length==1){e=this.target._parseMatrix(e),delete e.matrix;for(t in e)this.trans[t]={from:this.target.trans[t],to:e[t]}}else{var n={};n[e]=t,this.transform(n)}return this},style:function(e,t){if(typeof e=="object")for(var n in e)this.style(n,e[n]);else this.styles[e]={from:this.target.style(e),to:t};return this},x:function(e){return this._x={from:this.target.x(),to:e},this},y:function(e){return this._y={from:this.target.y(),to:e},this},cx:function(e){return this._cx={from:this.target.cx(),to:e},this},cy:function(e){return this._cy={from:this.target.cy(),to:e},this},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){if(this.target instanceof SVG.Text)this.attr("font-size",e);else{var n=this.target.bbox();this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}}}return this},viewbox:function(e,t,n,r){if(this.target instanceof SVG.Container){var i=this.target.viewbox();this._viewbox={x:{from:i.x,to:e},y:{from:i.y,to:t},width:{from:i.width,to:n},height:{from:i.height,to:r}}}return this},during:function(e){return this._during=e,this},after:function(e){return this._after=e,this},stop:function(){return clearTimeout(this.timeout),clearInterval(this.interval),this.attrs={},this.trans={},this.styles={},delete this._x,delete this._y,delete this._cx,delete this._cy,delete this._size,delete this._after,delete this._during,delete this._viewbox,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:SVG.regex.unit.test(e.to)?this._unit(e,t):e.to&&(e.to.r||SVG.Color.test(e.to))?this._color(e,t):t<1?e.from:e.to},_unit:function(e,t){var n,r;return n=SVG.regex.unit.exec(e.from.toString()),r=parseFloat(n?n[1]:0),n=SVG.regex.unit.exec(e.to),r+(parseFloat(n[1])-r)*t+n[2]},_color:function(e,t){var n,r;return t=t<0?0:t>1?1:t,n=new SVG.Color(e.from),r=new SVG.Color(e.to),(new SVG.Color({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})).toHex()}}),SVG.extend(SVG.Element,{animate:function(e,t,n){return(this.fx||(this.fx=new SVG.FX(this))).stop().animate(e,t,n)},stop:function(){return this.fx&&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]=typeof t=="function"?function(){return t.apply(n,arguments)}:null,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,{x:function(e){return e==null?this.trans.x:this.transform("x",e)},y:function(e){return e==null?this.trans.y:this.transform("y",e)},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.removeElement(this).put(this,this.position()+1)},backward:function(){this.parent.level();var e=this.position();return e>1&&this.parent.removeElement(this).add(this,e-1),this},front:function(){return this.parent.removeElement(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.removeElement(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"))},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.mask=e instanceof SVG.Mask?e:this.parent.mask().add(e),this.attr("mask","url(#"+this.mask.attr("id")+")")}}),SVG.Clip=function(){this.constructor.call(this,SVG.create("clipPath"))},SVG.Clip.prototype=new SVG.Container,SVG.extend(SVG.Element,{clipWith:function(e){return this.clip=e instanceof SVG.Clip?e:this.parent.clip().add(e),this.attr("clip-path","url(#"+this.clip.attr("id")+")")}}),SVG.Pattern=function(e){this.constructor.call(this,SVG.create("pattern"))},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.attr("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(e){this.constructor.call(this,SVG.create(e+"Gradient")),this.type=e},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.attr("id")+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(e){this.constructor.call(this,SVG.create("stop")),this.update(e)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n=["opacity","color"];for(t=n.length-1;t>=0;t--)e[n[t]]!=null&&this.style("stop-"+n[t],e[n[t]]);return this.attr("offset",(e.offset!=null?e.offset:this.attr("offset"))+"%")}}),SVG.Doc=function(e){this.parent=typeof e=="string"?document.getElementById(e):e,this.constructor.call(this,this.parent.nodeName=="svg"?this.parent:SVG.create("svg")),this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.parent.nodeName!="svg"&&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.style("position:absolute;"),setTimeout(function(){t.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(e){this.constructor.call(this,e)},SVG.Shape.prototype=new SVG.Element,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,{x:function(e){return e==null?this.cx()-this.attr("rx"):this.cx(e+this.attr("rx"))},y:function(e){return e==null?this.cy()-this.attr("ry"):this.cy(e+this.attr("ry"))},cx:function(e){return e==null?this.attr("cx"):this.attr("cx",e/this.trans.scaleX)},cy:function(e){return e==null?this.attr("cy"):this.attr("cy",e/this.trans.scaleY)},size:function(e,t){return this.attr({rx:e/2,ry:t/2})}}),SVG.Line=function(){this.constructor.call(this,SVG.create("line"))},SVG.Line.prototype=new SVG.Shape,SVG.extend(SVG.Line,{x:function(e){var t=this.bbox();return e==null?t.x:this.attr({x1:this.attr("x1")-t.x+e,x2:this.attr("x2")-t.x+e})},y:function(e){var t=this.bbox();return e==null?t.y:this.attr({y1:this.attr("y1")-t.y+e,y2:this.attr("y2")-t.y+e})},cx:function(e){var t=this.bbox().width/2;return e==null?this.x()+t:this.x(e-t)},cy:function(e){var t=this.bbox().height/2;return e==null?this.y()+t:this.y(e-t)},size:function(e,t){var n=this.bbox();return this.attr(this.attr("x1")0?r.join(" "):"0,0"}return this.attr("points",e||"0,0")}}),SVG.Path=function(e){this.constructor.call(this,SVG.create("path")),this.unbiased=e},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{_plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.extend(SVG.Polyline,SVG.Polygon,SVG.Path,{x:function(e){return e==null?this.bbox().x:this.transform("x",e)},y:function(e){return e==null?this.bbox().y:this.transform("y",e)},size:function(e,t){var n=e/this._offset.width;return this.transform({scaleX:n,scaleY:t!=null?t/this._offset.height:n})},plot:function(e){var t=this.trans.scaleX,n=this.trans.scaleY;return this._plot(e),this._offset=this.transform({scaleX:1,scaleY:1}).bbox(),this.unbiased?this._offset.x=this._offset.y=0:(this._offset.x-=this.trans.x,this._offset.y-=this.trans.y),this.transform({scaleX:t,scaleY:n})}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return e?this.attr("xlink:href",this.src=e,SVG.xlink):this}});var e="size family weight stretch variant style".split(" ");SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.styles={"font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"},this._leading=1.2,this._base=.276666666},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{x:function(e,t){return e==null?t?this.attr("x"):this.bbox().x:(t||(t=this.style("text-anchor"),e=t=="start"?e:t=="end"?e+this.bbox().width:e+this.bbox().width/2),this.attr("x",e))},cx:function(e,t){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e,t){return e==null?this.bbox().cy:this.y(t?e:e-this.bbox().height/2)},move:function(e,t,n){return this.x(e,n).y(t)},center:function(e,t,n){return this.cx(e,n).cy(t,n)},text:function(e){if(e==null)return this.content;this.clear(),this.content=SVG.regex.isBlank.test(e)?"text":e;var t,n,r=e.split("\n");for(t=0,n=r.length;t=0;index--)n[SVG["_"+e][index]]!=null&&this.attr(t(e,SVG["_"+e][index]),n[SVG["_"+e][index]]);return this},SVG.extend(SVG.Shape,SVG.FX,n)}),SVG.extend(SVG.Element,SVG.FX,{rotate:function(e,t,n){return this.transform({rotation:e||0,cx:t,cy:n})},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})},matrix:function(e){return this.transform({matrix:e})},opacity:function(e){return this.attr("opacity",e)}}),SVG.Text&&SVG.extend(SVG.Text,SVG.FX,{font:function(t){for(var n in t)n=="anchor"?this.attr("text-anchor",t[n]):e.indexOf(n)>-1?this.attr("font-"+n,t[n]):this.attr(n,t[n]);return this}})}).call(this); \ No newline at end of file +/* svg.js v0.13-6-gd0c34f7 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ +(function(){this.SVG=function(e){if(SVG.supported)return new SVG.Doc(e)},this.svg=function(e){return console.warn("WARNING: svg() is deprecated, please use SVG() instead."),SVG(e)},SVG.ns="http://www.w3.org/2000/svg",SVG.xlink="http://www.w3.org/1999/xlink",SVG.did=1e3,SVG.eid=function(e){return"Svgjs"+e.charAt(0).toUpperCase()+e.slice(1)+SVG.did++},SVG.create=function(e){var t=document.createElementNS(this.ns,e);return t.setAttribute("id",this.eid(e)),t},SVG.extend=function(){var e,t,n,r;e=[].slice.call(arguments),t=e.pop();for(r=e.length-1;r>=0;r--)if(e[r])for(n in t)e[r].prototype[n]=t[n]},SVG.get=function(e){var t=document.getElementById(e);if(t)return t.instance},SVG.supported=function(){return!!document.createElementNS&&!!document.createElementNS(SVG.ns,"svg").createSVGRect}();if(!SVG.supported)return!1;SVG.regex={test:function(e,t){return this[t].test(e)},unit:/^([\d\.]+)([a-z%]{0,2})$/,hex:/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,rgb:/rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/,hsb:/hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isHsb:/^hsb\(/,isCss:/[^:]+:[^;]+;?/,isStyle:/^font|text|leading|cursor/,isBlank:/^(\s+)?$/,isNumber:/^-?[\d\.]+$/},SVG.defaults={matrix:"1,0,0,1,0,0",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,offset:0},trans:function(){return{x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0,matrix:this.matrix,a:1,b:0,c:0,d:1,e:0,f:0}}},SVG.Color=function(e){var t;this.r=0,this.g=0,this.b=0,typeof e=="string"?SVG.regex.isRgb.test(e)?(t=SVG.regex.rgb.exec(e.replace(/\s/g,"")),this.r=parseInt(m[1]),this.g=parseInt(m[2]),this.b=parseInt(m[3])):SVG.regex.isHex.test(e)?(t=SVG.regex.hex.exec(this._fullHex(e)),this.r=parseInt(t[1],16),this.g=parseInt(t[2],16),this.b=parseInt(t[3],16)):SVG.regex.isHsb.test(e)&&(t=SVG.regex.hsb.exec(e.replace(/\s/g,"")),e=this._hsbToRgb(t[1],t[2],t[3])):typeof e=="object"&&(SVG.Color.isHsb(e)&&(e=this._hsbToRgb(e.h,e.s,e.b)),this.r=e.r,this.g=e.g,this.b=e.b)},SVG.extend(SVG.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+this._compToHex(this.r)+this._compToHex(this.g)+this._compToHex(this.b)},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},_hsbToRgb:function(e,t,n){var i,s;e=parseInt(e)%360,e<0&&(e+=360),t=parseInt(t),t=t>100?100:t,n=parseInt(n),n=(n<0?0:n>100?100:n)*255/100,i=n*t/100,s=i*(e*256/60%256)/256;switch(Math.floor(e/60)){case 0:r=n,g=n-i+s,b=n-i;break;case 1:r=n-s,g=n,b=n-i;break;case 2:r=n-i,g=n,b=n-i+s;break;case 3:r=n-i,g=n-s,b=n;break;case 4:r=n-i+s,g=n-i,b=n;break;case 5:r=n,g=n-i,b=n-s}return{r:Math.floor(r+.5),g:Math.floor(g+.5),b:Math.floor(b+.5)}},_fullHex: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},_compToHex:function(e){var t=e.toString(16);return t.length==1?"0"+t:t}}),SVG.Color.test=function(e){return e+="",SVG.regex.isHex.test(e)||SVG.regex.isRgb.test(e)||SVG.regex.isHsb.test(e)},SVG.Color.isRgb=function(e){return e&&typeof e.r=="number"},SVG.Color.isHsb=function(e){return e&&typeof e.h=="number"},SVG.ViewBox=function(e){var t,n,r,i,s=e.bbox(),o=(e.attr("viewBox")||"").match(/-?[\d\.]+/g);this.x=s.x,this.y=s.y,this.width=e.node.offsetWidth||e.attr("width"),this.height=e.node.offsetHeight||e.attr("height"),o&&(t=parseFloat(o[0]),n=parseFloat(o[1]),r=parseFloat(o[2]),i=parseFloat(o[3]),this.zoom=this.width/this.height>r/i?this.height/i:this.width/r,this.x=t,this.y=n,this.width=r,this.height=i),this.zoom=this.zoom||1},SVG.extend(SVG.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),SVG.BBox=function(e){var t;try{t=e.node.getBBox()}catch(n){t={x:e.node.clientLeft,y:e.node.clientTop,width:e.node.clientWidth,height:e.node.clientHeight}}this.x=t.x+e.trans.x,this.y=t.y+e.trans.y,this.width=t.width*e.trans.scaleX,this.height=t.height*e.trans.scaleY,this.cx=this.x+this.width/2,this.cy=this.y+this.height/2},SVG.Element=function(e){this._stroke=SVG.defaults.attrs.stroke,this.styles={},this.trans=SVG.defaults.trans();if(this.node=e)this.type=e.nodeName,this.node.instance=this},SVG.extend(SVG.Element,{x:function(e){return e&&(e/=this.trans.scaleX),this.attr("x",e)},y:function(e){return e&&(e/=this.trans.scaleY),this.attr("y",e)},cx:function(e){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e){return e==null?this.bbox().cy:this.y(e-this.bbox().height/2)},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e,t,n=this.type;return e=n=="rect"||n=="ellipse"?this.parent[n](0,0):n=="line"?this.parent[n](0,0,0,0):n=="image"?this.parent[n](this.src):n=="text"?this.parent[n](this.content):n=="path"?this.parent[n](this.attr("d")):n=="polyline"||n=="polygon"?this.parent[n](this.attr("points")):n=="g"?this.parent.group():this.parent[n](),t=this.attr(),delete t.id,e.attr(t),e.trans=this.trans,e.transform({})},remove:function(){return this.parent&&this.parent.removeElement(this),this},doc:function(e){return this._parent(e||SVG.Doc)},attr:function(e,t,n){if(e==null){e={},t=this.node.attributes;for(n=t.length-1;n>=0;n--)e[t[n].nodeName]=SVG.regex.test(t[n].nodeValue,"isNumber")?parseFloat(t[n].nodeValue):t[n].nodeValue;return e}if(typeof e=="object")for(t in e)this.attr(t,e[t]);else if(t===null)this.node.removeAttribute(e);else{if(t==null)return this._isStyle(e)?e=="text"?this.content:e=="leading"&&this.leading?this.leading():this.style(e):(t=this.node.getAttribute(e),t==null?SVG.defaults.attrs[e]:SVG.regex.test(t,"isNumber")?parseFloat(t):t);if(e=="style")return this.style(t);if(e=="x"&&Array.isArray(this.lines))for(n=this.lines.length-1;n>=0;n--)this.lines[n].attr(e,t);e=="stroke-width"?this.attr("stroke",parseFloat(t)>0?this._stroke:null):e=="stroke"&&(this._stroke=t);if(SVG.Color.test(t)||SVG.Color.isRgb(t)||SVG.Color.isHsb(t))t=(new SVG.Color(t)).toHex();n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t),this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"&&this.leading?this.leading(t):this.style(e,t),this.rebuild&&this.rebuild(e,t))}return this},transform:function(e,t){if(arguments.length==0)return this.trans;if(typeof e=="string"){if(arguments.length<2)return this.trans[e];var n={};return n[e]=t,this.transform(n)}var n=[];e=this._parseMatrix(e),e.rotation!=null&&(e.cx==null&&(e.cx=this.bbox().cx),e.cy==null&&(e.cy=this.bbox().cy));for(t in e)e[t]!=null&&(this.trans[t]=e[t]);return this.trans.matrix=this.trans.a+","+this.trans.b+","+this.trans.c+","+this.trans.d+","+this.trans.e+","+this.trans.f,e=this.trans,e.matrix!=SVG.defaults.matrix&&n.push("matrix("+e.matrix+")"),e.rotation!=0&&n.push("rotate("+e.rotation+","+e.cx+","+e.cy+")"),(e.scaleX!=1||e.scaleY!=1)&&n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),(e.x!=0||e.y!=0)&&n.push("translate("+e.x/e.scaleX+","+e.y/e.scaleY+")"),this._offset&&n.push("translate("+ -this._offset.x+","+ -this._offset.y+")"),n.length==0?this.node.removeAttribute("transform"):this.node.setAttribute("transform",n.join(" ")),this},style:function(e,t){if(arguments.length==0)return this.attr("style")||"";if(arguments.length<2)if(typeof e=="object")for(t in e)this.style(t,e[t]);else{if(!SVG.regex.isCss.test(e))return this.styles[e];e=e.split(";");for(var n=0;nn.x&&t>n.y&&e=0},each:function(e){var t,n=this.children();for(t=0,length=n.length;t=0;e--)this.removeElement(this.children()[e]);return this.defs(),this}}),SVG.FX=function(e){this.target=e},SVG.extend(SVG.FX,{animate:function(e,t,n){var r=this;return typeof e=="object"&&(n=e.delay,t=e.ease,e=e.duration),this.timeout=setTimeout(function(){e=e==null?1e3:e,t=t||"<>";var n,i,s,o=1e3/60,u=r.target,a=(new Date).getTime(),f=a+e;r.interval=setInterval(function(){var o,l,c=(new Date).getTime(),h=c>f?1:(c-a)/e;if(n==null){n=[];for(l in r.attrs)n.push(l)}if(i==null){i=[];for(l in r.trans)i.push(l)}if(s==null){s=[];for(l in r.styles)s.push(l)}h=t=="<>"?-Math.cos(h*Math.PI)/2+.5:t==">"?Math.sin(h*Math.PI/2):t=="<"?-Math.cos(h*Math.PI/2)+1:t=="-"?h:typeof t=="function"?t(h):h,r._x?u.x(r._at(r._x,h)):r._cx&&u.cx(r._at(r._cx,h)),r._y?u.y(r._at(r._y,h)):r._cy&&u.cy(r._at(r._cy,h)),r._size&&u.size(r._at(r._size.width,h),r._at(r._size.height,h)),r._viewbox&&u.viewbox(r._at(r._viewbox.x,h),r._at(r._viewbox.y,h),r._at(r._viewbox.width,h),r._at(r._viewbox.height,h));for(o=n.length-1;o>=0;o--)u.attr(n[o],r._at(r.attrs[n[o]],h));for(o=i.length-1;o>=0;o--)u.transform(i[o],r._at(r.trans[i[o]],h));for(o=s.length-1;o>=0;o--)u.style(s[o],r._at(r.styles[s[o]],h));r._during&&r._during.call(u,h,function(e,t){return r._at({from:e,to:t},h)}),c>f&&(clearInterval(r.interval),r._after?r._after.apply(u,[r]):r.stop())},e>o?o:e)},n||0),this},bbox:function(){return this.target.bbox()},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,t){if(arguments.length==1){e=this.target._parseMatrix(e),delete e.matrix;for(t in e)this.trans[t]={from:this.target.trans[t],to:e[t]}}else{var n={};n[e]=t,this.transform(n)}return this},style:function(e,t){if(typeof e=="object")for(var n in e)this.style(n,e[n]);else this.styles[e]={from:this.target.style(e),to:t};return this},x:function(e){return this._x={from:this.target.x(),to:e},this},y:function(e){return this._y={from:this.target.y(),to:e},this},cx:function(e){return this._cx={from:this.target.cx(),to:e},this},cy:function(e){return this._cy={from:this.target.cy(),to:e},this},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){if(this.target instanceof SVG.Text)this.attr("font-size",e);else{var n=this.target.bbox();this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}}}return this},viewbox:function(e,t,n,r){if(this.target instanceof SVG.Container){var i=this.target.viewbox();this._viewbox={x:{from:i.x,to:e},y:{from:i.y,to:t},width:{from:i.width,to:n},height:{from:i.height,to:r}}}return this},during:function(e){return this._during=e,this},after:function(e){return this._after=e,this},stop:function(){return clearTimeout(this.timeout),clearInterval(this.interval),this.attrs={},this.trans={},this.styles={},delete this._x,delete this._y,delete this._cx,delete this._cy,delete this._size,delete this._after,delete this._during,delete this._viewbox,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:SVG.regex.unit.test(e.to)?this._unit(e,t):e.to&&(e.to.r||SVG.Color.test(e.to))?this._color(e,t):t<1?e.from:e.to},_unit:function(e,t){var n,r;return n=SVG.regex.unit.exec(e.from.toString()),r=parseFloat(n?n[1]:0),n=SVG.regex.unit.exec(e.to),r+(parseFloat(n[1])-r)*t+n[2]},_color:function(e,t){var n,r;return t=t<0?0:t>1?1:t,n=new SVG.Color(e.from),r=new SVG.Color(e.to),(new SVG.Color({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})).toHex()}}),SVG.extend(SVG.Element,{animate:function(e,t,n){return(this.fx||(this.fx=new SVG.FX(this))).stop().animate(e,t,n)},stop:function(){return this.fx&&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]=typeof t=="function"?function(){return t.apply(n,arguments)}:null,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,{x:function(e){return e==null?this.trans.x:this.transform("x",e)},y:function(e){return e==null?this.trans.y:this.transform("y",e)},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.removeElement(this).put(this,this.position()+1)},backward:function(){this.parent.level();var e=this.position();return e>1&&this.parent.removeElement(this).add(this,e-1),this},front:function(){return this.parent.removeElement(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.removeElement(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"))},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.mask=e instanceof SVG.Mask?e:this.parent.mask().add(e),this.attr("mask","url(#"+this.mask.attr("id")+")")}}),SVG.Clip=function(){this.constructor.call(this,SVG.create("clipPath"))},SVG.Clip.prototype=new SVG.Container,SVG.extend(SVG.Element,{clipWith:function(e){return this.clip=e instanceof SVG.Clip?e:this.parent.clip().add(e),this.attr("clip-path","url(#"+this.clip.attr("id")+")")}}),SVG.Pattern=function(e){this.constructor.call(this,SVG.create("pattern"))},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.attr("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(e){this.constructor.call(this,SVG.create(e+"Gradient")),this.type=e},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.attr("id")+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(e){this.constructor.call(this,SVG.create("stop")),this.update(e)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n=["opacity","color"];for(t=n.length-1;t>=0;t--)e[n[t]]!=null&&this.style("stop-"+n[t],e[n[t]]);return this.attr("offset",(e.offset!=null?e.offset:this.attr("offset"))+"%")}}),SVG.Doc=function(e){this.parent=typeof e=="string"?document.getElementById(e):e,this.constructor.call(this,this.parent.nodeName=="svg"?this.parent:SVG.create("svg")),this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.parent.nodeName!="svg"&&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.style("position:absolute;"),setTimeout(function(){t.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(e){this.constructor.call(this,e)},SVG.Shape.prototype=new SVG.Element,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,{x:function(e){return e==null?this.cx()-this.attr("rx"):this.cx(e+this.attr("rx"))},y:function(e){return e==null?this.cy()-this.attr("ry"):this.cy(e+this.attr("ry"))},cx:function(e){return e==null?this.attr("cx"):this.attr("cx",e/this.trans.scaleX)},cy:function(e){return e==null?this.attr("cy"):this.attr("cy",e/this.trans.scaleY)},size:function(e,t){return this.attr({rx:e/2,ry:t/2})}}),SVG.Line=function(){this.constructor.call(this,SVG.create("line"))},SVG.Line.prototype=new SVG.Shape,SVG.extend(SVG.Line,{x:function(e){var t=this.bbox();return e==null?t.x:this.attr({x1:this.attr("x1")-t.x+e,x2:this.attr("x2")-t.x+e})},y:function(e){var t=this.bbox();return e==null?t.y:this.attr({y1:this.attr("y1")-t.y+e,y2:this.attr("y2")-t.y+e})},cx:function(e){var t=this.bbox().width/2;return e==null?this.x()+t:this.x(e-t)},cy:function(e){var t=this.bbox().height/2;return e==null?this.y()+t:this.y(e-t)},size:function(e,t){var n=this.bbox();return this.attr(this.attr("x1")0?r.join(" "):"0,0"}return this.attr("points",e||"0,0")}}),SVG.Path=function(e){this.constructor.call(this,SVG.create("path")),this.unbiased=e},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{_plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.extend(SVG.Polyline,SVG.Polygon,SVG.Path,{x:function(e){return e==null?this.bbox().x:this.transform("x",e)},y:function(e){return e==null?this.bbox().y:this.transform("y",e)},size:function(e,t){var n=e/this._offset.width;return this.transform({scaleX:n,scaleY:t!=null?t/this._offset.height:n})},plot:function(e){var t=this.trans.scaleX,n=this.trans.scaleY;return this._plot(e),this._offset=this.transform({scaleX:1,scaleY:1}).bbox(),this.unbiased?this._offset.x=this._offset.y=0:(this._offset.x-=this.trans.x,this._offset.y-=this.trans.y),this.transform({scaleX:t,scaleY:n})}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return e?this.attr("xlink:href",this.src=e,SVG.xlink):this}});var e="size family weight stretch variant style".split(" ");SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.styles={"font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"},this._leading=1.2,this._base=.276666666},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{x:function(e,t){return e==null?t?this.attr("x"):this.bbox().x:(t||(t=this.style("text-anchor"),e=t=="start"?e:t=="end"?e+this.bbox().width:e+this.bbox().width/2),this.attr("x",e))},cx:function(e,t){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e,t){return e==null?this.bbox().cy:this.y(t?e:e-this.bbox().height/2)},move:function(e,t,n){return this.x(e,n).y(t)},center:function(e,t,n){return this.cx(e,n).cy(t,n)},text:function(e){if(e==null)return this.content;this.clear(),this.content=SVG.regex.isBlank.test(e)?"text":e;var t,n,r=e.split("\n");for(t=0,n=r.length;t=0;index--)n[SVG["_"+e][index]]!=null&&this.attr(t(e,SVG["_"+e][index]),n[SVG["_"+e][index]]);return this},SVG.extend(SVG.Shape,SVG.FX,n)}),SVG.extend(SVG.Element,SVG.FX,{rotate:function(e,t,n){return this.transform({rotation:e||0,cx:t,cy:n})},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})},matrix:function(e){return this.transform({matrix:e})},opacity:function(e){return this.attr("opacity",e)}}),SVG.Text&&SVG.extend(SVG.Text,SVG.FX,{font:function(t){for(var n in t)n=="anchor"?this.attr("text-anchor",t[n]):e.indexOf(n)>-1?this.attr("font-"+n,t[n]):this.attr(n,t[n]);return this}})}).call(this); \ No newline at end of file diff --git a/spec/spec/element.js b/spec/spec/element.js index 757025a..167c0b9 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -64,6 +64,22 @@ describe('Element', function() { rect.style('style', '') expect(rect.node.getAttribute('style')).toBe(null) }) + it('should act as a global getter when no arguments are given', function() { + rect.fill('#ff0066') + expect(rect.attr().fill).toBe('#ff0066') + }) + it('should correctly parse numeric values as a global getter', function() { + rect.stroke({ width: 20 }) + expect(rect.attr()['stroke-width']).toBe(20) + }) + it('should correctly parse negative numeric values as a global getter', function() { + rect.x(-30) + expect(rect.attr().x).toBe(-30) + }) + it('should leave unit values alone as a global getter', function() { + rect.attr('x', '69%') + expect(rect.attr().x).toBe('69%') + }) }) describe('style()', function() { diff --git a/src/element.js b/src/element.js index 3665dc2..8869f2b 100644 --- a/src/element.js +++ b/src/element.js @@ -105,7 +105,7 @@ SVG.extend(SVG.Element, { a = {} v = this.node.attributes for (n = v.length - 1; n >= 0; n--) - a[v[n].nodeName] = v[n].nodeValue + a[v[n].nodeName] = SVG.regex.test(v[n].nodeValue, 'isNumber') ? parseFloat(v[n].nodeValue) : v[n].nodeValue return a -- 2.39.5