From 8789391f036ffded3ac919d62ee652e7cae15c5c Mon Sep 17 00:00:00 2001 From: wout Date: Thu, 28 Aug 2014 18:44:14 +0200 Subject: [PATCH] Fixed instantiation issue in SVG.Number --- CHANGELOG.md | 10 +++---- README.md | 18 +++++++++---- dist/svg.js | 42 +++++++++++++----------------- dist/svg.min.js | 4 +-- spec/spec/number.js | 63 ++++++++++++++++++++++++++------------------- src/number.js | 40 ++++++++++++---------------- 6 files changed, 91 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d86cec6..1d7c42a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,10 @@ # 1.0.0-rc.11 (?/09/2014) - +- added specs for `SVG.FX` -> __TODO!__ +- fixed a bug in clipping and masking where empty nodes persists after removal -> __TODO!__ +- fixed a bug where events are not detached properly -> __TODO!__ +- fixed a bug in IE11 with `mouseenter` and `mouseleave` -> __TODO!__ # 1.0.0-rc.10 (?/09/2014) @@ -34,13 +37,10 @@ - changed `lines` reference to `lines()` on `SVG.Text` - changed `track` reference to `track()` on `SVG.Text` - changed `textPath` reference to `textPath()` on `SVG.Text` -- fixed a bug in clipping and masking where empty nodes persists after removal -> __TODO!__ - added raw svg import functionality with the `svg()` method - reworked sup-pixel offset implementation to be more compact - added `native()` method to elements and matrix to get to the native api - added `untransform()` method to remove all transformations -- fixed a bug where events are not detached properly -> __TODO!__ -- fixed a bug in IE11 with `mouseenter` and `mouseleave` -> __TODO!__ - switched from Ruby's `rake` to Node's `gulp` for building [thanks to Alex Ewerlöf] - added coding style description to README - changed `to()` method to `at()` method in `SVG.FX` @@ -48,9 +48,9 @@ - documented the `situation` object in `SVG.FX` - renamed `SVG.SetFX` to `SVG.FX.Set` - added distinction between relative and absolute matrix transformations -- added specs for `SVG.FX` -> __TODO!__ - implemented the `element()` method using the `SVG.Bare` class to create elements that are not described by SVG.js - removed `SVG.Symbol` but kept the `symbol()` method using the new `element()` method +- reworked `SVG.Number` to return new instances with calculations rather than itself # 1.0.0-rc.9 (17/06/2014) diff --git a/README.md b/README.md index 4481437..daae606 100755 --- a/README.md +++ b/README.md @@ -442,7 +442,7 @@ _Javascript inheritance stack: `SVG.Image` < `SVG.Shape` < `SVG.Element`_ Loading another image can be done with the `load()` method: ```javascript -draw.image('/path/to/another/image.jpg') +image.load('/path/to/another/image.jpg') ``` __`returns`: `itself`__ @@ -884,6 +884,14 @@ element.node ``` __`returns`: `node`__ +### native() +The same can be achieved with the `native()` method: +```javascript +element.native() +``` +__`returns`: `node`__ + + ### instance Similar, the node carries a reference to the SVG.js `instance`: @@ -2824,7 +2832,7 @@ Addition: number.plus('3%') ``` -__`returns`: `itself`__ +__`returns`: `SVG.Number`__ ### minus() Subtraction: @@ -2833,7 +2841,7 @@ Subtraction: number.minus('3%') ``` -__`returns`: `itself`__ +__`returns`: `SVG.Number`__ ### times() Multiplication: @@ -2842,7 +2850,7 @@ Multiplication: number.times(2) ``` -__`returns`: `itself`__ +__`returns`: `SVG.Number`__ ### divide() Division: @@ -2851,7 +2859,7 @@ Division: number.divide('3%') ``` -__`returns`: `itself`__ +__`returns`: `SVG.Number`__ ### to() Change number to another unit: diff --git a/dist/svg.js b/dist/svg.js index 5c2a59c..af662fa 100755 --- a/dist/svg.js +++ b/dist/svg.js @@ -6,7 +6,7 @@ * @copyright Wout Fierens * @license MIT * -* BUILT: Mon Aug 25 2014 09:53:20 GMT+0200 (CEST) +* BUILT: Thu Aug 28 2014 18:38:34 GMT+0200 (CEST) */; (function(root, factory) { @@ -745,31 +745,31 @@ SVG.extend(SVG.PathArray, { // Module for unit convertions SVG.Number = SVG.invent({ // Initialize - create: function(value) { - // Initialize defaults + create: function(value, unit) { + // initialize defaults this.value = 0 - this.unit = '' + this.unit = unit || '' - // Parse value + // parse value if (typeof value === 'number') { - // Ensure a valid numeric value + // ensure a valid numeric value this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value } else if (typeof value === 'string') { - var match = value.match(SVG.regex.unit) + unit = value.match(SVG.regex.unit) - if (match) { - // Make value numeric - this.value = parseFloat(match[1]) + if (unit) { + // make value numeric + this.value = parseFloat(unit[1]) - // Normalize - if (match[2] == '%') + // normalize + if (unit[2] == '%') this.value /= 100 - else if (match[2] == 's') + else if (unit[2] == 's') this.value *= 1000 - // Store unit - this.unit = match[2] + // store unit + this.unit = unit[2] } } else { @@ -798,9 +798,7 @@ SVG.Number = SVG.invent({ } // Add number , plus: function(number) { - this.value = this + new SVG.Number(number) - - return this + return new SVG.Number(this + new SVG.Number(number), this.unit) } // Subtract number , minus: function(number) { @@ -808,15 +806,11 @@ SVG.Number = SVG.invent({ } // Multiply number , times: function(number) { - this.value = this * new SVG.Number(number) - - return this + return new SVG.Number(this * new SVG.Number(number), this.unit) } // Divide number , divide: function(number) { - this.value = this / new SVG.Number(number) - - return this + return new SVG.Number(this / new SVG.Number(number), this.unit) } // Convert to different unit , to: function(unit) { diff --git a/dist/svg.min.js b/dist/svg.min.js index 9335b1f..a90c6e7 100755 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1,2 +1,2 @@ -/*! SVG.js v1.0.0-rc.10 MIT*/;!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.SVG=e()}(this,function(){function t(t){return t.toLowerCase().replace(/-(.)/g,function(t,e){return e.toUpperCase()})}function e(t){return t.charAt(0).toUpperCase()+t.slice(1)}function n(t){return 4==t.length?["#",t.substring(1,2),t.substring(1,2),t.substring(2,3),t.substring(2,3),t.substring(3,4),t.substring(3,4)].join(""):t}function i(t){var e=t.toString(16);return 1==e.length?"0"+e:e}function r(t,e,n){return null==n?n=t.height/t.width*e:null==e&&(e=t.width/t.height*n),{width:e,height:n}}function s(t,e,n){return{x:e*t.a+n*t.c+0,y:e*t.b+n*t.d+0}}function o(t){return{a:t[0],b:t[1],c:t[2],d:t[3],e:t[4],f:t[5]}}function a(t){return t instanceof m.Matrix||(t=new m.Matrix(t)),t}function h(t){return t=t.replace(m.regex.whitespace,"").replace(m.regex.matrix,"").split(","),o(m.utils.map(t,function(t){return parseFloat(t)}))}function u(t,e){return"number"==typeof t.from?t.from+(t.to-t.from)*e:t instanceof m.Color||t instanceof m.Number||t instanceof m.Matrix?t.at(e):1>e?t.from:t.to}function l(t){for(var e=0,n=t.length,i="";n>e;e++)i+=t[e][0],null!=t[e][1]&&(i+=t[e][1],null!=t[e][2]&&(i+=" ",i+=t[e][2],null!=t[e][3]&&(i+=" ",i+=t[e][3],i+=" ",i+=t[e][4],null!=t[e][5]&&(i+=" ",i+=t[e][5],i+=" ",i+=t[e][6],null!=t[e][7]&&(i+=" ",i+=t[e][7])))));return i+" "}function c(t){for(var e=t.childNodes.length-1;e>=0;e--)t.childNodes[e]instanceof SVGElement&&c(t.childNodes[e]);return m.adopt(t).id(m.eid(t.nodeName))}function f(t){return t.x2=t.x+t.width,t.y2=t.y+t.height,t.cx=t.x+t.width/2,t.cy=t.y+t.height/2,t}function d(t){var e=t.toString().match(m.regex.reference);return e?e[1]:void 0}function p(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n}var m=this.SVG=function(t){return m.supported?(t=new m.Doc(t),m.parser||m.prepare(t),t):void 0};if(m.ns="http://www.w3.org/2000/svg",m.xmlns="http://www.w3.org/2000/xmlns/",m.xlink="http://www.w3.org/1999/xlink",m.supported=function(){return!!document.createElementNS&&!!document.createElementNS(m.ns,"svg").createSVGRect}(),!m.supported)return!1;m.did=1e3,m.eid=function(t){return"Svgjs"+e(t)+m.did++},m.create=function(t){var e=document.createElementNS(this.ns,t);return e.setAttribute("id",this.eid(t)),e},m.extend=function(){var t,e,n,i;for(t=[].slice.call(arguments),e=t.pop(),i=t.length-1;i>=0;i--)if(t[i])for(n in e)t[i].prototype[n]=e[n];m.Set&&m.Set.inherit&&m.Set.inherit()},m.invent=function(t){var e="function"==typeof t.create?t.create:function(){this.constructor.call(this,m.create(t.create))};return t.inherit&&(e.prototype=new t.inherit),t.extend&&m.extend(e,t.extend),t.construct&&m.extend(t.parent||m.Container,t.construct),e},m.adopt=function(t){if(t.instance)return t.instance;var n;return n="svg"==t.nodeName?t.parentNode instanceof SVGElement?new m.Nested:new m.Doc:"lineairGradient"==t.nodeName?new m.Gradient("lineair"):"radialGradient"==t.nodeName?new m.Gradient("radial"):m[e(t.nodeName)]?new(m[e(t.nodeName)]):new m.Element(t),n.type=t.nodeName,n.node=t,t.instance=n,n instanceof m.Doc&&n.namespace().defs(),n},m.prepare=function(t){var e=document.getElementsByTagName("body")[0],n=(e?new m.Doc(e):t.nested()).size(2,0),i=m.create("path");n.node.appendChild(i),m.parser={body:e||t.parent(),draw:n.style("opacity:0;position:fixed;left:100%;top:100%;overflow:hidden"),poly:n.polyline().node,path:i}},m.regex={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+)\)/,reference:/#([a-z0-9\-_]+)/i,matrix:/matrix\(|\)/g,whitespace:/\s/g,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isCss:/[^:]+:[^;]+;?/,isBlank:/^(\s+)?$/,isNumber:/^-?[\d\.]+$/,isPercent:/^-?[\d\.]+%$/,isImage:/\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i},m.utils={map:function(t,e){var n,i=t.length,r=[];for(n=0;i>n;n++)r.push(e(t[n]));return r},radians:function(t){return t%360*Math.PI/180},degrees:function(t){return 180*t/Math.PI%360}},m.defaults={attrs:{"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"}},m.Color=function(t){var e;this.r=0,this.g=0,this.b=0,"string"==typeof t?m.regex.isRgb.test(t)?(e=m.regex.rgb.exec(t.replace(/\s/g,"")),this.r=parseInt(e[1]),this.g=parseInt(e[2]),this.b=parseInt(e[3])):m.regex.isHex.test(t)&&(e=m.regex.hex.exec(n(t)),this.r=parseInt(e[1],16),this.g=parseInt(e[2],16),this.b=parseInt(e[3],16)):"object"==typeof t&&(this.r=t.r,this.g=t.g,this.b=t.b)},m.extend(m.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+i(this.r)+i(this.g)+i(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},morph:function(t){return this.destination=new m.Color(t),this},at:function(t){return this.destination?(t=0>t?0:t>1?1:t,new m.Color({r:~~(this.r+(this.destination.r-this.r)*t),g:~~(this.g+(this.destination.g-this.g)*t),b:~~(this.b+(this.destination.b-this.b)*t)})):this}}),m.Color.test=function(t){return t+="",m.regex.isHex.test(t)||m.regex.isRgb.test(t)},m.Color.isRgb=function(t){return t&&"number"==typeof t.r&&"number"==typeof t.g&&"number"==typeof t.b},m.Color.isColor=function(t){return m.Color.isRgb(t)||m.Color.test(t)},m.Array=function(t,e){t=(t||[]).valueOf(),0==t.length&&e&&(t=e.valueOf()),this.value=this.parse(t)},m.extend(m.Array,{morph:function(t){if(this.destination=this.parse(t),this.value.length!=this.destination.length){for(var e=this.value[this.value.length-1],n=this.destination[this.destination.length-1];this.value.length>this.destination.length;)this.destination.push(n);for(;this.value.lengtht;t++)-1==n.indexOf(this.value[t])&&n.push(this.value[t]);return this.value=n},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];n>e;e++)i.push(this.value[e]+(this.destination[e]-this.value[e])*t);return new m.Array(i)},toString:function(){return this.value.join(" ")},valueOf:function(){return this.value},parse:function(t){return t=t.valueOf(),Array.isArray(t)?t:this.split(t)},split:function(t){return t.replace(/\s+/g," ").replace(/^\s+|\s+$/g,"").split(" ")},reverse:function(){return this.value.reverse(),this}}),m.PointArray=function(t,e){this.constructor.call(this,t,e||[[0,0]])},m.PointArray.prototype=new m.Array,m.extend(m.PointArray,{toString:function(){for(var t=0,e=this.value.length,n=[];e>t;t++)n.push(this.value[t].join(","));return n.join(" ")},toLine:function(){return{x1:this.value[0][0],y1:this.value[0][1],x2:this.value[1][0],y2:this.value[1][1]}},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];n>e;e++)i.push([this.value[e][0]+(this.destination[e][0]-this.value[e][0])*t,this.value[e][1]+(this.destination[e][1]-this.value[e][1])*t]);return new m.PointArray(i)},parse:function(t){if(t=t.valueOf(),Array.isArray(t))return t;t=this.split(t);for(var e,n=0,i=t.length,r=[];i>n;n++)e=t[n].split(","),r.push([parseFloat(e[0]),parseFloat(e[1])]);return r},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i=this.value.length-1;i>=0;i--)this.value[i]=[this.value[i][0]+t,this.value[i][1]+e];return this},size:function(t,e){var n,i=this.bbox();for(n=this.value.length-1;n>=0;n--)this.value[n][0]=(this.value[n][0]-i.x)*t/i.width+i.x,this.value[n][1]=(this.value[n][1]-i.y)*e/i.height+i.y;return this},bbox:function(){return m.parser.poly.setAttribute("points",this.toString()),m.parser.poly.getBBox()}}),m.PathArray=function(t,e){this.constructor.call(this,t,e||[["M",0,0]])},m.PathArray.prototype=new m.Array,m.extend(m.PathArray,{toString:function(){return l(this.value)},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i,r=this.value.length-1;r>=0;r--)i=this.value[r][0],"M"==i||"L"==i||"T"==i?(this.value[r][1]+=t,this.value[r][2]+=e):"H"==i?this.value[r][1]+=t:"V"==i?this.value[r][1]+=e:"C"==i||"S"==i||"Q"==i?(this.value[r][1]+=t,this.value[r][2]+=e,this.value[r][3]+=t,this.value[r][4]+=e,"C"==i&&(this.value[r][5]+=t,this.value[r][6]+=e)):"A"==i&&(this.value[r][6]+=t,this.value[r][7]+=e);return this},size:function(t,e){var n,i,r=this.bbox();for(n=this.value.length-1;n>=0;n--)i=this.value[n][0],"M"==i||"L"==i||"T"==i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y):"H"==i?this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x:"V"==i?this.value[n][1]=(this.value[n][1]-r.y)*e/r.height+r.y:"C"==i||"S"==i||"Q"==i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y,this.value[n][3]=(this.value[n][3]-r.x)*t/r.width+r.x,this.value[n][4]=(this.value[n][4]-r.y)*e/r.height+r.y,"C"==i&&(this.value[n][5]=(this.value[n][5]-r.x)*t/r.width+r.x,this.value[n][6]=(this.value[n][6]-r.y)*e/r.height+r.y)):"A"==i&&(this.value[n][1]=this.value[n][1]*t/r.width,this.value[n][2]=this.value[n][2]*e/r.height,this.value[n][6]=(this.value[n][6]-r.x)*t/r.width+r.x,this.value[n][7]=(this.value[n][7]-r.y)*e/r.height+r.y);return this},parse:function(t){if(t instanceof m.PathArray)return t.valueOf();var e,n,i,r,s,o,a,h,u,c,f,d=0,p=0;for(m.parser.path.setAttribute("d","string"==typeof t?t:l(t)),f=m.parser.path.pathSegList,e=0,n=f.numberOfItems;n>e;++e)c=f.getItem(e),u=c.pathSegTypeAsLetter,"M"==u||"L"==u||"H"==u||"V"==u||"C"==u||"S"==u||"Q"==u||"T"==u||"A"==u?("x"in c&&(d=c.x),"y"in c&&(p=c.y)):("x1"in c&&(s=d+c.x1),"x2"in c&&(a=d+c.x2),"y1"in c&&(o=p+c.y1),"y2"in c&&(h=p+c.y2),"x"in c&&(d+=c.x),"y"in c&&(p+=c.y),"m"==u?f.replaceItem(m.parser.path.createSVGPathSegMovetoAbs(d,p),e):"l"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoAbs(d,p),e):"h"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoHorizontalAbs(d),e):"v"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoVerticalAbs(p),e):"c"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoCubicAbs(d,p,s,o,a,h),e):"s"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoCubicSmoothAbs(d,p,a,h),e):"q"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoQuadraticAbs(d,p,s,o),e):"t"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoQuadraticSmoothAbs(d,p),e):"a"==u?f.replaceItem(m.parser.path.createSVGPathSegArcAbs(d,p,c.r1,c.r2,c.angle,c.largeArcFlag,c.sweepFlag),e):("z"==u||"Z"==u)&&(d=i,p=r)),("M"==u||"m"==u)&&(i=d,r=p);for(t=[],f=m.parser.path.pathSegList,e=0,n=f.numberOfItems;n>e;++e)c=f.getItem(e),u=c.pathSegTypeAsLetter,d=[u],"M"==u||"L"==u||"T"==u?d.push(c.x,c.y):"H"==u?d.push(c.x):"V"==u?d.push(c.y):"C"==u?d.push(c.x1,c.y1,c.x2,c.y2,c.x,c.y):"S"==u?d.push(c.x2,c.y2,c.x,c.y):"Q"==u?d.push(c.x1,c.y1,c.x,c.y):"A"==u&&d.push(c.r1,c.r2,c.angle,0|c.largeArcFlag,0|c.sweepFlag,c.x,c.y),t.push(d);return t},bbox:function(){return m.parser.path.setAttribute("d",this.toString()),m.parser.path.getBBox()}}),m.Number=m.invent({create:function(t){if(this.value=0,this.unit="","number"==typeof t)this.value=isNaN(t)?0:isFinite(t)?t:0>t?-3.4e38:3.4e38;else if("string"==typeof t){var e=t.match(m.regex.unit);e&&(this.value=parseFloat(e[1]),"%"==e[2]?this.value/=100:"s"==e[2]&&(this.value*=1e3),this.unit=e[2])}else t instanceof m.Number&&(this.value=t.value,this.unit=t.unit)},extend:{toString:function(){return("%"==this.unit?~~(1e8*this.value)/1e6:"s"==this.unit?this.value/1e3:this.value)+this.unit},valueOf:function(){return this.value},plus:function(t){return this.value=this+new m.Number(t),this},minus:function(t){return this.plus(-new m.Number(t))},times:function(t){return this.value=this*new m.Number(t),this},divide:function(t){return this.value=this/new m.Number(t),this},to:function(t){return"string"==typeof t&&(this.unit=t),this},morph:function(t){return this.destination=new m.Number(t),this},at:function(t){return this.destination?new m.Number(this.destination).minus(this).times(t).plus(this):this}}}),m.ViewBox=function(t){var e,n,i,r,s=1,o=1,a=t.bbox(),h=(t.attr("viewBox")||"").match(/-?[\d\.]+/g),u=t,l=t;for(i=new m.Number(t.width()),r=new m.Number(t.height());"%"==i.unit;)s*=i.value,i=new m.Number(u instanceof m.Doc?u.parent().offsetWidth:u.parent().width()),u=u.parent();for(;"%"==r.unit;)o*=r.value,r=new m.Number(l instanceof m.Doc?l.parent().offsetHeight:l.parent().height()),l=l.parent();this.x=a.x,this.y=a.y,this.width=i*s,this.height=r*o,this.zoom=1,h&&(e=parseFloat(h[0]),n=parseFloat(h[1]),i=parseFloat(h[2]),r=parseFloat(h[3]),this.zoom=this.width/this.height>i/r?this.height/r:this.width/i,this.x=e,this.y=n,this.width=i,this.height=r)},m.extend(m.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),m.Element=m.invent({create:function(t){this._stroke=m.defaults.attrs.stroke,(this.node=t)&&(this.type=t.nodeName,this.node.instance=this,this._stroke=t.getAttribute("stroke")||this._stroke)},extend:{x:function(t){return null!=t&&(t=new m.Number(t),t.value/=this.transform("scaleX")),this.attr("x",t)},y:function(t){return null!=t&&(t=new m.Number(t),t.value/=this.transform("scaleY")),this.attr("y",t)},cx:function(t){return null==t?this.x()+this.width()/2:this.x(t-this.width()/2)},cy:function(t){return null==t?this.y()+this.height()/2:this.y(t-this.height()/2)},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},width:function(t){return this.attr("width",t)},height:function(t){return this.attr("height",t)},size:function(t,e){var n=r(this.bbox(),t,e);return this.width(new m.Number(n.width)).height(new m.Number(n.height))},clone:function(){return c(this.node.cloneNode(!0))},remove:function(){return this.parent()&&this.parent().removeElement(this),this},replace:function(t){return this.after(t).remove(),t},addTo:function(t){return t.put(this)},putIn:function(t){return t.add(this)},id:function(t){return this.attr("id",t)},inside:function(t,e){var n=this.bbox();return t>n.x&&e>n.y&&t/,"").replace(/<\/svg>$/,"");e.innerHTML=""+t.replace(/\n/,"").replace(/<(\w+)([^<]+?)\/>/g,"<$1$2>")+"";for(var n=0,i=e.firstChild.childNodes.length;i>n;n++)this.node.appendChild(e.firstChild.childNodes[n]);return this}}}),m.FX=m.invent({create:function(t){this.target=t},extend:{animate:function(t,e,n){var i,r,s,o=this.target,a=this;return"object"==typeof t&&(n=t.delay,e=t.ease,t=t.duration),t="="==t?t:null==t?1e3:new m.Number(t).valueOf(),e=e||"<>",a.at=function(t){var n;if(t=0>t?0:t>1?1:t,null==i){i=[];for(s in a.attrs)i.push(s);if(o.morphArray&&(a.destination.plot||i.indexOf("points")>-1)){var h,l=new o.morphArray(a.destination.plot||a.attrs.points||o.array);a.destination.size&&l.size(a.destination.size.width.to,a.destination.size.height.to),h=l.bbox(),a.destination.x?l.move(a.destination.x.to,h.y):a.destination.cx&&l.move(a.destination.cx.to-h.width/2,h.y),h=l.bbox(),a.destination.y?l.move(h.x,a.destination.y.to):a.destination.cy&&l.move(h.x,a.destination.cy.to-h.height/2),a.destination={plot:o.array.morph(l)}}}if(null==r){r=[];for(s in a.styles)r.push(s)}for(t="<>"==e?-Math.cos(t*Math.PI)/2+.5:">"==e?Math.sin(t*Math.PI/2):"<"==e?-Math.cos(t*Math.PI/2)+1:"-"==e?t:"function"==typeof e?e(t):t,a.destination.plot?o.plot(a.destination.plot.at(t)):(a.destination.x?o.x(a.destination.x.at(t)):a.destination.cx&&o.cx(a.destination.cx.at(t)),a.destination.y?o.y(a.destination.y.at(t)):a.destination.cy&&o.cy(a.destination.cy.at(t)),a.destination.size&&o.size(a.destination.size.width.at(t),a.destination.size.height.at(t))),a.destination.viewbox&&o.viewbox(a.destination.viewbox.x.at(t),a.destination.viewbox.y.at(t),a.destination.viewbox.width.at(t),a.destination.viewbox.height.at(t)),a.destination.leading&&o.leading(a.destination.leading.at(t)),n=i.length-1;n>=0;n--)o.attr(i[n],u(a.attrs[i[n]],t));for(n=r.length-1;n>=0;n--)o.style(r[n],u(a.styles[r[n]],t));a.situation.during&&a.situation.during.call(o,t,function(e,n){return u({from:e,to:n},t)})},"number"==typeof t&&(this.timeout=setTimeout(function(){var i=(new Date).getTime();a.situation.start=i,a.situation.play=!0,a.situation.finish=i+t,a.situation.duration=t,a.situation.ease=e,a.render=function(){if(a.situation.play===!0){var i=(new Date).getTime(),r=i>a.situation.finish?1:(i-a.situation.start)/t;a.situation.reversing&&(r=-r+1),a.at(r),i>a.situation.finish?(a.destination.plot&&o.plot(new m.PointArray(a.destination.plot.destination).settle()),a.situation.loop===!0||"number"==typeof a.situation.loop&&a.situation.loop>0?(a.situation.reverse&&(a.situation.reversing=!a.situation.reversing),"number"==typeof a.situation.loop&&((!a.situation.reverse||a.situation.reversing)&&--a.situation.loop,a.situation.reverse||1!=a.situation.loop||--a.situation.loop),a.animate(t,e,n)):a.situation.after?a.situation.after.apply(o,[a]):a.stop()):requestAnimFrame(a.render)}else requestAnimFrame(a.render)},a.render()},new m.Number(n).valueOf())),this},bbox:function(){return this.target.bbox()},attr:function(t,e){if("object"==typeof t)for(var n in t)this.attr(n,t[n]);else{var i=this.target.attr(t);this.attrs[t]="transform"==t?this.target.ctm().morph(e):m.Color.isColor(e)?new m.Color(i).morph(e):m.regex.unit.test(e)?new m.Number(i).morph(e):{from:i,to:e}}return this},style:function(t,e){if("object"==typeof t)for(var n in t)this.style(n,t[n]);else this.styles[t]={from:this.target.style(t),to:e};return this},x:function(t){return this.destination.x=new m.Number(this.target.x()).morph(t),this},y:function(t){return this.destination.y=new m.Number(this.target.y()).morph(t),this},cx:function(t){return this.destination.cx=new m.Number(this.target.cx()).morph(t),this},cy:function(t){return this.destination.cy=new m.Number(this.target.cy()).morph(t),this},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},size:function(t,e){if(this.target instanceof m.Text)this.attr("font-size",t);else{var n=this.target.bbox();this.destination.size={width:new m.Number(n.width).morph(t),height:new m.Number(n.height).morph(e)}}return this},plot:function(t){return this.destination.plot=t,this},leading:function(t){return this.target.destination.leading&&(this.destination.leading=new m.Number(this.target.destination.leading).morph(t)),this},viewbox:function(t,e,n,i){if(this.target instanceof m.Container){var r=this.target.viewbox();this.destination.viewbox={x:new m.Number(r.x).morph(t),y:new m.Number(r.y).morph(e),width:new m.Number(r.width).morph(n),height:new m.Number(r.height).morph(i)}}return this},update:function(t){return this.target instanceof m.Stop&&(null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",new m.Number(t.offset))),this},during:function(t){return this.situation.during=t,this},after:function(t){return this.situation.after=t,this},loop:function(t,e){return this.situation.loop=this.situation.loops=t||!0,this.situation.reverse=!!e,this},stop:function(t){return t===!0?(this.animate(0),this.situation.after&&this.situation.after.apply(this.target,[this])):(clearTimeout(this.timeout),this.attrs={},this.styles={},this.situation={},this.destination={}),this},pause:function(){return this.situation.play===!0&&(this.situation.play=!1,this.situation.pause=(new Date).getTime()),this},play:function(){if(this.situation.play===!1){var t=(new Date).getTime()-this.situation.pause;this.situation.finish+=t,this.situation.start+=t,this.situation.play=!0}return this}},parent:m.Element,construct:{animate:function(t,e,n){return(this.fx||(this.fx=new m.FX(this))).stop().animate(t,e,n)},stop:function(t){return this.fx&&this.fx.stop(t),this},pause:function(){return this.fx&&this.fx.pause(),this},play:function(){return this.fx&&this.fx.play(),this}}}),m.BBox=m.invent({create:function(t){var e;if(this.x=0,this.y=0,this.width=0,this.height=0,t){var n=new m.Matrix(t).extract();e=t.node.getBBox?t.node.getBBox():{x:t.node.clientLeft,y:t.node.clientTop,width:t.node.clientWidth,height:t.node.clientHeight},this.x=e.x+n.x,this.y=e.y+n.y,this.width=e.width*n.scaleX,this.height=e.height*n.scaleY}f(this)},parent:m.Element,construct:{bbox:function(){return new m.BBox(this)}}}),m.RBox=m.invent({create:function(t){var e={};if(this.x=0,this.y=0,this.width=0,this.height=0,t){var n=t.doc().parent(),i=1;for(e=t.node.getBoundingClientRect(),this.x=e.left,this.y=e.top,this.x-=n.offsetLeft,this.y-=n.offsetTop;n=n.offsetParent;)this.x-=n.offsetLeft,this.y-=n.offsetTop;for(n=t;n.parent&&(n=n.parent());)n.viewbox&&(i*=n.viewbox().zoom,this.x-=n.x()||0,this.y-=n.y()||0)}this.width=e.width/=i,this.height=e.height/=i,this.x+=window.scrollX,this.y+=window.scrollY,f(this)},parent:m.Element,construct:{rbox:function(){return new m.RBox(this)}}}),[m.BBox,m.RBox].forEach(function(t){m.extend(t,{merge:function(e){var n=new t;return n.x=Math.min(this.x,e.x),n.y=Math.min(this.y,e.y),n.width=Math.max(this.x+this.width,e.x+e.width)-n.x,n.height=Math.max(this.y+this.height,e.y+e.height)-n.y,f(n)}})}),m.Matrix=m.invent({create:function(t){var e,n=o([1,0,0,1,0,0]);for(t=t&&t.node&&t.node.getCTM?t.node.getCTM():"string"==typeof t?h(t):6==arguments.length?o([].slice.call(arguments)):"object"==typeof t?t:n,e=g.length-1;e>=0;e--)this[g[e]]="number"==typeof t[g[e]]?t[g[e]]:n[g[e]]},extend:{extract:function(){var t=s(this,0,1),e=s(this,1,0),n=180/Math.PI*Math.atan2(t.y,t.x)-90;return{x:this.e,y:this.f,skewX:-n,skewY:180/Math.PI*Math.atan2(e.y,e.x),scaleX:Math.sqrt(this.a*this.a+this.b*this.b),scaleY:Math.sqrt(this.c*this.c+this.d*this.d),rotation:n}},clone:function(){return new m.Matrix(this)},morph:function(t){return this.destination=new m.Matrix(t),this},at:function(t){return this.destination?new m.Matrix({a:this.a+(this.destination.a-this.a)*t,b:this.b+(this.destination.b-this.b)*t,c:this.c+(this.destination.c-this.c)*t,d:this.d+(this.destination.d-this.d)*t,e:this.e+(this.destination.e-this.e)*t,f:this.f+(this.destination.f-this.f)*t}):this},multiply:function(t){return new m.Matrix(this.native().multiply(a(t).native()))},add:function(t){return t=a(t),new m.Matrix({a:this.a+t.a-1,b:this.b+t.b,c:this.c+t.c,d:this.d+t.d-1,e:this.e+t.e,f:this.f+t.f})},inverse:function(){return new m.Matrix(this.native().inverse())},translate:function(t,e){return new m.Matrix(this.native().translate(t||0,e||0))},scale:function(t,e,n,i){return(1==arguments.length||3==arguments.length)&&(e=t),3==arguments.length&&(i=n,n=e),this.around(n,i,new m.Matrix(t,0,0,e,0,0))},rotate:function(t,e,n){return t=m.utils.radians(t),this.around(e,n,new m.Matrix(Math.cos(t),Math.sin(t),-Math.sin(t),Math.cos(t),0,0))},flip:function(t,e){return"x"==t?this.scale(-1,1,e,0):this.scale(1,-1,0,e)},skew:function(t,e,n,i){return this.around(n,i,this.native().skewX(t||0).skewY(e||0))},around:function(t,e,n){return this.multiply(new m.Matrix(1,0,0,1,t||0,e||0)).multiply(n).multiply(new m.Matrix(1,0,0,1,-t||0,-e||0))},"native":function(){for(var t=m.parser.draw.node.createSVGMatrix(),e=g.length-1;e>=0;e--)t[g[e]]=this[g[e]];return t},toString:function(){return"matrix("+this.toArray().join()+")"},toArray:function(){return[this.a,this.b,this.c,this.d,this.e,this.f]}},parent:m.Element,construct:{ctm:function(){return new m.Matrix(this)}}}),m.extend(m.Element,{attr:function(t,e,n){if(null==t){for(t={},e=this.node.attributes,n=e.length-1;n>=0;n--)t[e[n].nodeName]=m.regex.isNumber.test(e[n].nodeValue)?parseFloat(e[n].nodeValue):e[n].nodeValue;return t}if("object"==typeof t)for(e in t)this.attr(e,t[e]);else if(null===e)this.node.removeAttribute(t);else{if(null==e)return e=this.node.getAttribute(t),null==e?m.defaults.attrs[t]:m.regex.isNumber.test(e)?parseFloat(e):e;"stroke-width"==t?this.attr("stroke",parseFloat(e)>0?this._stroke:null):"stroke"==t&&(this._stroke=e),("fill"==t||"stroke"==t)&&(m.regex.isImage.test(e)&&(e=this.doc().defs().image(e,0,0)),e instanceof m.Image&&(e=this.doc().defs().pattern(0,0,function(){this.add(e)}))),"number"==typeof e?e=new m.Number(e):m.Color.isColor(e)?e=new m.Color(e):Array.isArray(e)&&(e=new m.Array(e)),"leading"==t?this.leading&&this.leading(e):"string"==typeof n?this.node.setAttributeNS(n,t,e.toString()):this.node.setAttribute(t,e.toString()),!this.rebuild||"font-size"!=t&&"x"!=t||this.rebuild(t,e)}return this}}),m.extend(m.Element,m.FX,{transform:function(t,e){var n=this.target||this;if(null==t)return n.ctm().extract();if("string"==typeof t)return n.ctm().extract()[t];var i=new m.Matrix(n);if(e=!!e||!!t.relative,null!=t.a)i=e?i.multiply(new m.Matrix(t)):new m.Matrix(t);else if(null!=t.rotation)t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,i=e?n.attr("transform",i+" rotate("+[t.rotation,t.cx,t.cy].join()+")").ctm():i.rotate(t.rotation-i.extract().rotation,t.cx,t.cy);else if(null!=t.scale||null!=t.scaleX||null!=t.scaleY){if(t.scaleX=null!=t.scale?t.scale:null!=t.scaleX?t.scaleX:1,t.scaleY=null!=t.scale?t.scale:null!=t.scaleY?t.scaleY:1,t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,!e){var r=i.extract();t.scaleX=1*t.scaleX/r.scaleX,t.scaleY=1*t.scaleY/r.scaleY}i=i.scale(t.scaleX,t.scaleY,t.cx,t.cy)}else if(null!=t.skewX||null!=t.skewY){if(t.skewX=null!=t.skewX?t.skewX:0,t.skewY=null!=t.skewY?t.skewY:0,t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,!e){var r=i.extract();i=i.multiply((new m.Matrix).skew(r.skewX,r.skewY,t.cx,t.cy).inverse())}i=i.skew(t.skewX,t.skewY,t.cx,t.cy)}else t.flip?i=i.flip(t.flip,null==t.offset?n.bbox()["c"+t.flip]:t.offset):(null!=t.x||null!=t.y)&&(e?i=i.translate(t.x,t.y):(null!=t.x&&(i.e=t.x),null!=t.y&&(i.f=t.y)));return this.attr("transform",i)}}),m.extend(m.Element,{untransform:function(){return this.attr("transform",null)}}),m.extend(m.Element,{style:function(e,n){if(0==arguments.length)return this.node.style.cssText||"";if(arguments.length<2)if("object"==typeof e)for(n in e)this.style(n,e[n]);else{if(!m.regex.isCss.test(e))return this.node.style[t(e)];e=e.split(";");for(var i=0;i=0},index:function(t){return this.children().indexOf(t)},get:function(t){return this.children()[t]},first:function(){return this.children()[0]},last:function(){return this.children()[this.children().length-1]},each:function(t,e){var n,i,r=this.children();for(n=0,i=r.length;i>n;n++)r[n]instanceof m.Element&&t.apply(r[n],[n,r]),e&&r[n]instanceof m.Container&&r[n].each(t,e);return this},removeElement:function(t){return this.node.removeChild(t.node),this},clear:function(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return delete this._defs,this},defs:function(){return this.doc().defs()}}}),m.Container=m.invent({create:function(t){this.constructor.call(this,t)},inherit:m.Parent,extend:{viewbox:function(t){return 0==arguments.length?new m.ViewBox(this):(t=1==arguments.length?[t.x,t.y,t.width,t.height]:[].slice.call(arguments),this.attr("viewBox",t))}}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchmove","touchleave","touchend","touchcancel"].forEach(function(t){m.Element.prototype[t]=function(e){var n=this;return this.node["on"+t]="function"==typeof e?function(){return e.apply(n,arguments)}:null,this}}),m.events={},m.listeners={},m.registerEvent=function(t){m.events[t]||(m.events[t]=new p(t))},m.on=function(t,e,n){var i=n.bind(t.instance||t);m.listeners[n]=i,t.addEventListener(e,i,!1)},m.off=function(t,e,n){t.removeEventListener(e,m.listeners[n],!1),delete m.listeners[n]},m.extend(m.Element,{on:function(t,e){return m.on(this.node,t,e),this},off:function(t,e){return m.off(this.node,t,e),this},fire:function(t,e){return m.events[t].detail=e,this.node.dispatchEvent(m.events[t]),delete m.events[t].detail,this}}),m.Defs=m.invent({create:"defs",inherit:m.Container}),m.G=m.invent({create:"g",inherit:m.Container,extend:{x:function(t){return null==t?this.transform("x"):this.transform({x:-this.x()+t},!0)},y:function(t){return null==t?this.transform("y"):this.transform({y:-this.y()+t},!0)},cx:function(t){return null==t?this.bbox().cx:this.x(t-this.bbox().width/2)},cy:function(t){return null==t?this.bbox().cy:this.y(t-this.bbox().height/2)}},construct:{group:function(){return this.put(new m.G)}}}),m.extend(m.Element,{siblings:function(){return this.parent().children()},position:function(){return this.parent().index(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){var t=this.position()+1,e=this.parent();return e.removeElement(this).add(this,t),e instanceof m.Doc&&e.node.appendChild(e.defs().node),this},backward:function(){var t=this.position();return t>0&&this.parent().removeElement(this).add(this,t-1),this},front:function(){var t=this.parent();return t.node.appendChild(this.node),t instanceof m.Doc&&t.node.appendChild(t.defs().node),this},back:function(){return this.position()>0&&this.parent().removeElement(this).add(this,0),this},before:function(t){t.remove();var e=this.position();return this.parent().add(t,e),this},after:function(t){t.remove();var e=this.position();return this.parent().add(t,e+1),this}}),m.Mask=m.invent({create:function(){this.constructor.call(this,m.create("mask")),this.targets=[]},inherit:m.Container,extend:{remove:function(){for(var t=this.targets.length-1;t>=0;t--)this.targets[t]&&this.targets[t].unmask();return delete this.targets,this.parent().removeElement(this),this}},construct:{mask:function(){return this.defs().put(new m.Mask)}}}),m.extend(m.Element,{maskWith:function(t){return this.masker=t instanceof m.Mask?t:this.parent().mask().add(t),this.masker.targets.push(this),this.attr("mask",'url("#'+this.masker.attr("id")+'")')},unmask:function(){return delete this.masker,this.attr("mask",null)}}),m.ClipPath=m.invent({create:function(){this.constructor.call(this,m.create("clipPath")),this.targets=[]},inherit:m.Container,extend:{remove:function(){for(var t=this.targets.length-1;t>=0;t--)this.targets[t]&&this.targets[t].unclip();return delete this.targets,this.parent().removeElement(this),this}},construct:{clip:function(){return this.defs().put(new m.ClipPath) -}}}),m.extend(m.Element,{clipWith:function(t){return this.clipper=t instanceof m.ClipPath?t:this.parent().clip().add(t),this.clipper.targets.push(this),this.attr("clip-path",'url("#'+this.clipper.attr("id")+'")')},unclip:function(){return delete this.clipper,this.attr("clip-path",null)}}),m.Gradient=m.invent({create:function(t){this.constructor.call(this,m.create(t+"Gradient")),this.type=t},inherit:m.Container,extend:{at:function(t,e,n){return this.put(new m.Stop).update(t,e,n)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},fill:function(){return"url(#"+this.id()+")"},toString:function(){return this.fill()}},construct:{gradient:function(t,e){return this.defs().gradient(t,e)}}}),m.extend(m.Gradient,m.FX,{from:function(t,e){return this.attr("radial"==(this.target||this).type?{fx:new m.Number(t),fy:new m.Number(e)}:{x1:new m.Number(t),y1:new m.Number(e)})},to:function(t,e){return this.attr("radial"==(this.target||this).type?{cx:new m.Number(t),cy:new m.Number(e)}:{x2:new m.Number(t),y2:new m.Number(e)})}}),m.extend(m.Defs,{gradient:function(t,e){return this.put(new m.Gradient(t)).update(e)}}),m.Stop=m.invent({create:"stop",inherit:m.Element,extend:{update:function(t){return("number"==typeof t||t instanceof m.Number)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",new m.Number(t.offset)),this}}}),m.Pattern=m.invent({create:"pattern",inherit:m.Container,extend:{fill:function(){return"url(#"+this.id()+")"},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return this.fill()}},construct:{pattern:function(t,e,n){return this.defs().pattern(t,e,n)}}}),m.extend(m.Defs,{pattern:function(t,e,n){return this.put(new m.Pattern).update(n).attr({x:0,y:0,width:t,height:e,patternUnits:"userSpaceOnUse"})}}),m.Doc=m.invent({create:function(t){t&&(t="string"==typeof t?document.getElementById(t):t,"svg"==t.nodeName?this.constructor.call(this,t):(this.constructor.call(this,m.create("svg")),t.appendChild(this.node)),this.namespace().size("100%","100%").defs())},inherit:m.Container,extend:{namespace:function(){return this.attr({xmlns:m.ns,version:"1.1"}).attr("xmlns:xlink",m.xlink,m.xmlns)},defs:function(){if(!this._defs){var t;this._defs=(t=this.node.getElementsByTagName("defs")[0])?m.adopt(t):new m.Defs,this.node.appendChild(this._defs.node)}return this._defs},parent:function(){return"#document"==this.node.parentNode.nodeName?null:this.node.parentNode},spof:function(){var t=this.node.getScreenCTM();return t&&this.style("left",-t.e%1+"px").style("top",-t.f%1+"px"),this}}}),m.Shape=m.invent({create:function(t){this.constructor.call(this,t)},inherit:m.Element}),m.Bare=m.invent({create:function(t,e){if(this.constructor.call(this,m.create(t)),e)for(var n in e.prototype)"function"==typeof e.prototype[n]&&(t[n]=e.prototype[n])},inherit:m.Element,extend:{words:function(t){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this.node.appendChild(document.createTextNode(t)),this}}}),m.extend(m.Parent,{element:function(t,e){return this.put(new m.Bare(t,e))},symbol:function(){return this.defs().element("symbol",m.Container)}}),m.Use=m.invent({create:"use",inherit:m.Shape,extend:{element:function(t){return this.target=t,this.attr("href","#"+t,m.xlink)}},construct:{use:function(t){return this.put(new m.Use).element(t)}}}),m.Rect=m.invent({create:"rect",inherit:m.Shape,construct:{rect:function(t,e){return this.put((new m.Rect).size(t,e))}}}),m.Circle=m.invent({create:"circle",inherit:m.Shape,construct:{circle:function(t){return this.put(new m.Circle).rx(new m.Number(t).divide(2)).move(0,0)}}}),m.extend(m.Circle,m.FX,{rx:function(t){return this.attr("r",t)},ry:function(t){return this.rx(t)}}),m.Ellipse=m.invent({create:"ellipse",inherit:m.Shape,construct:{ellipse:function(t,e){return this.put(new m.Ellipse).size(t,e).move(0,0)}}}),m.extend(m.Ellipse,m.Rect,m.FX,{rx:function(t){return this.attr("rx",t)},ry:function(t){return this.attr("ry",t)}}),m.extend(m.Circle,m.Ellipse,{x:function(t){return null==t?this.cx()-this.rx():this.cx(t+this.rx())},y:function(t){return null==t?this.cy()-this.ry():this.cy(t+this.ry())},cx:function(t){return null==t?this.attr("cx"):this.attr("cx",new m.Number(t).divide(this.transform("scaleX")))},cy:function(t){return null==t?this.attr("cy"):this.attr("cy",new m.Number(t).divide(this.transform("scaleY")))},width:function(t){return null==t?2*this.rx():this.rx(new m.Number(t).divide(2))},height:function(t){return null==t?2*this.ry():this.ry(new m.Number(t).divide(2))},size:function(t,e){var n=r(this.bbox(),t,e);return this.rx(new m.Number(n.width).divide(2)).ry(new m.Number(n.height).divide(2))}}),m.Line=m.invent({create:"line",inherit:m.Shape,extend:{array:function(){return new m.PointArray([[this.attr("x1"),this.attr("y1")],[this.attr("x2"),this.attr("y2")]])},plot:function(t,e,n,i){return t=4==arguments.length?{x1:t,y1:e,x2:n,y2:i}:new m.PointArray(t).toLine(),this.attr(t)},move:function(t,e){return this.attr(this.array().move(t,e).toLine())},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr(this.array().size(n.width,n.height).toLine())}},construct:{line:function(t,e,n,i){return this.put(new m.Line).plot(t,e,n,i)}}}),m.Polyline=m.invent({create:"polyline",inherit:m.Shape,construct:{polyline:function(t){return this.put(new m.Polyline).plot(t)}}}),m.Polygon=m.invent({create:"polygon",inherit:m.Shape,construct:{polygon:function(t){return this.put(new m.Polygon).plot(t)}}}),m.extend(m.Polyline,m.Polygon,{array:function(){return this._array||(this._array=new m.PointArray(this.attr("points")))},plot:function(t){return this.attr("points",this._array=new m.PointArray(t))},move:function(t,e){return this.attr("points",this.array().move(t,e))},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr("points",this.array().size(n.width,n.height))}}),m.extend(m.Line,m.Polyline,m.Polygon,{morphArray:m.PointArray,x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},width:function(t){var e=this.bbox();return null==t?e.width:this.size(t,e.height)},height:function(t){var e=this.bbox();return null==t?e.height:this.size(e.width,t)}}),m.Path=m.invent({create:"path",inherit:m.Shape,extend:{morphArray:m.PathArray,array:function(){return this._array||(this._array=new m.PathArray(this.attr("d")))},plot:function(t){return this.attr("d",this._array=new m.PathArray(t))},move:function(t,e){return this.attr("d",this.array().move(t,e))},x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr("d",this.array().size(n.width,n.height))},width:function(t){return null==t?this.bbox().width:this.size(t,this.bbox().height)},height:function(t){return null==t?this.bbox().height:this.size(this.bbox().width,t)}},construct:{path:function(t){return this.put(new m.Path).plot(t)}}}),m.Image=m.invent({create:"image",inherit:m.Shape,extend:{load:function(t){if(!t)return this;var e=this,n=document.createElement("img");return n.onload=function(){var i=e.doc(m.Pattern);0==e.width()&&0==e.height()&&e.size(n.width,n.height),i&&0==i.width()&&0==i.height()&&i.size(e.width(),e.height()),"function"==typeof e._loaded&&e._loaded.call(e,{width:n.width,height:n.height,ratio:n.width/n.height,url:t})},this.attr("href",n.src=this.src=t,m.xlink)},loaded:function(t){return this._loaded=t,this}},construct:{image:function(t,e,n){return this.put(new m.Image).load(t).size(e||0,n||e||0)}}}),m.Text=m.invent({create:function(){this.constructor.call(this,m.create("text")),this._leading=new m.Number(1.3),this._rebuild=!0,this._build=!1,this.attr("font-family",m.defaults.attrs["font-family"])},inherit:m.Shape,extend:{x:function(t){return null==t?this.attr("x"):(this.textPath||this.lines().each(function(){this.newLined&&this.x(t)}),this.attr("x",t))},y:function(t){var e=this.attr("y"),n="number"==typeof e?e-this.bbox().y:0;return null==t?"number"==typeof e?e-n:e:this.attr("y","number"==typeof t?t+n:t)},cx:function(t){return null==t?this.bbox().cx:this.x(t-this.bbox().width/2)},cy:function(t){return null==t?this.bbox().cy:this.y(t-this.bbox().height/2)},text:function(t){if("undefined"==typeof t)return this.content;if(this.clear().build(!0),"function"==typeof t)t.call(this,this);else{t=(this.content=t).split("\n");for(var e=0,n=t.length;n>e;e++)this.tspan(t[e]).newLine()}return this.build(!1).rebuild()},size:function(t){return this.attr("font-size",t).rebuild()},leading:function(t){return null==t?this._leading:(this._leading=new m.Number(t),this.rebuild())},lines:function(){for(var t=0,e=this.node.childNodes.length,n=[];e>t;t++)this.node.childNodes[t]instanceof SVGElement&&n.push(m.adopt(this.node.childNodes[t]));return new m.Set(n)},rebuild:function(t){if("boolean"==typeof t&&(this._rebuild=t),this._rebuild){var e=this;this.lines().each(function(){this.newLined&&(this.textPath||this.attr("x",e.attr("x")),this.attr("dy",e._leading*new m.Number(e.attr("font-size"))))}),this.fire("rebuild")}return this},build:function(t){return this._build=!!t,this}},construct:{text:function(t){return this.put(new m.Text).text(t)},plain:function(t){return this.put(new m.Text).plain(t)}}}),m.Tspan=m.invent({create:"tspan",inherit:m.Shape,extend:{text:function(t){return"function"==typeof t?t.call(this,this):this.plain(t),this},dx:function(t){return this.attr("dx",t)},dy:function(t){return this.attr("dy",t)},newLine:function(){var t=this.doc(m.Text);return this.newLined=!0,this.dy(t._leading*t.attr("font-size")).attr("x",t.x())}}}),m.extend(m.Text,m.Tspan,{plain:function(t){return this._build===!1&&this.clear(),this.node.appendChild(document.createTextNode(this.content=t)),this},tspan:function(t){var e=(this.textPath()||this).node,n=new m.Tspan;return this._build===!1&&this.clear(),e.appendChild(n.node),this instanceof m.Text&&this.lines().add(n),n.text(t)},clear:function(){for(var t=(this.textPath()||this).node;t.hasChildNodes();)t.removeChild(t.lastChild);return this instanceof m.Text&&(this.content=""),this},length:function(){return this.node.getComputedTextLength()}}),m.registerEvent("rebuild"),m.TextPath=m.invent({create:"textPath",inherit:m.Element,parent:m.Text,construct:{path:function(t){for(var e=new m.TextPath,n=this.doc().defs().path(t);this.node.hasChildNodes();)e.node.appendChild(this.node.firstChild);return this.node.appendChild(e.node),e.attr("href","#"+n,m.xlink),this},plot:function(t){var e=this.track();return e&&e.plot(t),this},track:function(){var t=this.textPath();return t?t.reference("href"):void 0},textPath:function(){return this.node.firstChild&&"textPath"==this.node.firstChild.nodeName?m.adopt(this.node.firstChild):void 0}}}),m.Nested=m.invent({create:function(){this.constructor.call(this,m.create("svg")),this.style("overflow","visible")},inherit:m.Container,construct:{nested:function(){return this.put(new m.Nested)}}}),m.A=m.invent({create:"a",inherit:m.Container,extend:{to:function(t){return this.attr("href",t,m.xlink)},show:function(t){return this.attr("show",t,m.xlink)},target:function(t){return this.attr("target",t)}},construct:{link:function(t){return this.put(new m.A).to(t)}}}),m.extend(m.Element,{linkTo:function(t){var e=new m.A;return"function"==typeof t?t.call(e,e):e.to(t),this.parent().put(e).put(this)}}),m.Marker=m.invent({create:"marker",inherit:m.Container,extend:{width:function(t){return this.attr("markerWidth",t)},height:function(t){return this.attr("markerHeight",t)},ref:function(t,e){return this.attr("refX",t).attr("refY",e)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return"url(#"+this.id()+")"}},construct:{marker:function(t,e,n){return this.defs().marker(t,e,n)}}}),m.extend(m.Defs,{marker:function(t,e,n){return this.put(new m.Marker).size(t,e).ref(t/2,e/2).viewbox(0,0,t,e).attr("orient","auto").update(n)}}),m.extend(m.Line,m.Polyline,m.Polygon,m.Path,{marker:function(t,e,n,i){var r=["marker"];return"all"!=t&&r.push(t),r=r.join("-"),t=arguments[1]instanceof m.Marker?arguments[1]:this.doc().marker(e,n,i),this.attr(r,t)}});var x={stroke:["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],fill:["color","opacity","rule"],prefix:function(t,e){return"color"==e?t:t+"-"+e}};["fill","stroke"].forEach(function(t){var e,n={};n[t]=function(n){if("string"==typeof n||m.Color.isRgb(n)||n&&"function"==typeof n.fill)this.attr(t,n);else for(e=x[t].length-1;e>=0;e--)null!=n[x[t][e]]&&this.attr(x.prefix(t,x[t][e]),n[x[t][e]]);return this},m.extend(m.Element,m.FX,n)}),m.extend(m.Element,m.FX,{rotate:function(t,e,n){return this.transform({rotation:t,cx:e,cy:n})},skew:function(t,e,n,i){return this.transform({skewX:t,skewY:e,cx:n,cy:i})},scale:function(t,e,n,i){return this.transform(1==arguments.length||3==arguments.length?{scale:t,cx:e,cy:n}:{scaleX:t,scaleY:e,cx:n,cy:i})},translate:function(t,e){return this.transform({x:t,y:e})},flip:function(t,e){return this.transform({flip:t,offset:e})},matrix:function(t){return this.attr("transform",new m.Matrix(t))},opacity:function(t){return this.attr("opacity",t)},dx:function(t){return this.x((this.target||this).x()+t)},dy:function(t){return this.y((this.target||this).y()+t)},dmove:function(t,e){return this.dx(t).dy(e)}}),m.extend(m.Rect,m.Ellipse,m.Circle,m.Gradient,m.FX,{radius:function(t,e){return"radial"==(this.target||this).type?this.attr({r:new m.Number(t)}):this.rx(t).ry(null==e?t:e)}}),m.extend(m.Path,{length:function(){return this.node.getTotalLength()},pointAt:function(t){return this.node.getPointAtLength(t)}}),m.extend(m.Parent,m.Text,m.FX,{font:function(t){for(var e in t)"leading"==e?this.leading(t[e]):"anchor"==e?this.attr("text-anchor",t[e]):"size"==e||"family"==e||"weight"==e||"stretch"==e||"variant"==e||"style"==e?this.attr("font-"+e,t[e]):this.attr(e,t[e]);return this}}),m.Set=m.invent({create:function(t){Array.isArray(t)?this.members=t:this.clear()},extend:{add:function(){var t,e,n=[].slice.call(arguments);for(t=0,e=n.length;e>t;t++)this.members.push(n[t]);return this},remove:function(t){var e=this.index(t);return e>-1&&this.members.splice(e,1),this},each:function(t){for(var e=0,n=this.members.length;n>e;e++)t.apply(this.members[e],[e,this.members]);return this},clear:function(){return this.members=[],this},length:function(){return this.members.length},has:function(t){return this.index(t)>=0},index:function(t){return this.members.indexOf(t)},get:function(t){return this.members[t]},first:function(){return this.get(0)},last:function(){return this.get(this.members.length-1)},valueOf:function(){return this.members},bbox:function(){var t=new m.BBox;if(0==this.members.length)return t;var e=this.members[0].rbox();return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,this.each(function(){t=t.merge(this.rbox())}),t}},construct:{set:function(t){return new m.Set(t)}}}),m.FX.Set=m.invent({create:function(t){this.set=t}}),m.Set.inherit=function(){var t,e=[];for(var t in m.Shape.prototype)"function"==typeof m.Shape.prototype[t]&&"function"!=typeof m.Set.prototype[t]&&e.push(t);e.forEach(function(t){m.Set.prototype[t]=function(){for(var e=0,n=this.members.length;n>e;e++)this.members[e]&&"function"==typeof this.members[e][t]&&this.members[e][t].apply(this.members[e],arguments);return"animate"==t?this.fx||(this.fx=new m.FX.Set(this)):this}}),e=[];for(var t in m.FX.prototype)"function"==typeof m.FX.prototype[t]&&"function"!=typeof m.FX.Set.prototype[t]&&e.push(t);e.forEach(function(t){m.FX.Set.prototype[t]=function(){for(var e=0,n=this.set.members.length;n>e;e++)this.set.members[e].fx[t].apply(this.set.members[e].fx,arguments);return this}})},m.extend(m.Element,{data:function(t,e,n){if("object"==typeof t)for(e in t)this.data(e,t[e]);else if(arguments.length<2)try{return JSON.parse(this.attr("data-"+t))}catch(i){return this.attr("data-"+t)}else this.attr("data-"+t,null===e?null:n===!0||"string"==typeof e||"number"==typeof e?e:JSON.stringify(e));return this}}),m.extend(m.Element,{remember:function(t,e){if("object"==typeof arguments[0])for(var e in t)this.remember(e,t[e]);else{if(1==arguments.length)return this.memory()[t];this.memory()[t]=e}return this},forget:function(){if(0==arguments.length)this._memory={};else for(var t=arguments.length-1;t>=0;t--)delete this.memory()[arguments[t]];return this},memory:function(){return this._memory||(this._memory={})}}),m.get=function(t){var e=document.getElementById(d(t)||t);return e?m.adopt(e):void 0},m.select=function(t,e){return new m.Set(m.utils.map((e||document).querySelectorAll(t),function(t){return m.adopt(t)}))},m.extend(m.Parent,{select:function(t){return m.select(t,this.node)}});var g="abcdef".split("");return window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}(),"function"!=typeof p&&(p.prototype=window.Event.prototype,window.CustomEvent=p),m}); \ No newline at end of file +/*! SVG.js v1.0.0-rc.10 MIT*/;!function(t,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):t.SVG=e()}(this,function(){function t(t){return t.toLowerCase().replace(/-(.)/g,function(t,e){return e.toUpperCase()})}function e(t){return t.charAt(0).toUpperCase()+t.slice(1)}function n(t){return 4==t.length?["#",t.substring(1,2),t.substring(1,2),t.substring(2,3),t.substring(2,3),t.substring(3,4),t.substring(3,4)].join(""):t}function i(t){var e=t.toString(16);return 1==e.length?"0"+e:e}function r(t,e,n){return null==n?n=t.height/t.width*e:null==e&&(e=t.width/t.height*n),{width:e,height:n}}function s(t,e,n){return{x:e*t.a+n*t.c+0,y:e*t.b+n*t.d+0}}function o(t){return{a:t[0],b:t[1],c:t[2],d:t[3],e:t[4],f:t[5]}}function a(t){return t instanceof m.Matrix||(t=new m.Matrix(t)),t}function h(t){return t=t.replace(m.regex.whitespace,"").replace(m.regex.matrix,"").split(","),o(m.utils.map(t,function(t){return parseFloat(t)}))}function u(t,e){return"number"==typeof t.from?t.from+(t.to-t.from)*e:t instanceof m.Color||t instanceof m.Number||t instanceof m.Matrix?t.at(e):1>e?t.from:t.to}function l(t){for(var e=0,n=t.length,i="";n>e;e++)i+=t[e][0],null!=t[e][1]&&(i+=t[e][1],null!=t[e][2]&&(i+=" ",i+=t[e][2],null!=t[e][3]&&(i+=" ",i+=t[e][3],i+=" ",i+=t[e][4],null!=t[e][5]&&(i+=" ",i+=t[e][5],i+=" ",i+=t[e][6],null!=t[e][7]&&(i+=" ",i+=t[e][7])))));return i+" "}function c(t){for(var e=t.childNodes.length-1;e>=0;e--)t.childNodes[e]instanceof SVGElement&&c(t.childNodes[e]);return m.adopt(t).id(m.eid(t.nodeName))}function f(t){return t.x2=t.x+t.width,t.y2=t.y+t.height,t.cx=t.x+t.width/2,t.cy=t.y+t.height/2,t}function d(t){var e=t.toString().match(m.regex.reference);return e?e[1]:void 0}function p(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),n}var m=this.SVG=function(t){return m.supported?(t=new m.Doc(t),m.parser||m.prepare(t),t):void 0};if(m.ns="http://www.w3.org/2000/svg",m.xmlns="http://www.w3.org/2000/xmlns/",m.xlink="http://www.w3.org/1999/xlink",m.supported=function(){return!!document.createElementNS&&!!document.createElementNS(m.ns,"svg").createSVGRect}(),!m.supported)return!1;m.did=1e3,m.eid=function(t){return"Svgjs"+e(t)+m.did++},m.create=function(t){var e=document.createElementNS(this.ns,t);return e.setAttribute("id",this.eid(t)),e},m.extend=function(){var t,e,n,i;for(t=[].slice.call(arguments),e=t.pop(),i=t.length-1;i>=0;i--)if(t[i])for(n in e)t[i].prototype[n]=e[n];m.Set&&m.Set.inherit&&m.Set.inherit()},m.invent=function(t){var e="function"==typeof t.create?t.create:function(){this.constructor.call(this,m.create(t.create))};return t.inherit&&(e.prototype=new t.inherit),t.extend&&m.extend(e,t.extend),t.construct&&m.extend(t.parent||m.Container,t.construct),e},m.adopt=function(t){if(t.instance)return t.instance;var n;return n="svg"==t.nodeName?t.parentNode instanceof SVGElement?new m.Nested:new m.Doc:"lineairGradient"==t.nodeName?new m.Gradient("lineair"):"radialGradient"==t.nodeName?new m.Gradient("radial"):m[e(t.nodeName)]?new(m[e(t.nodeName)]):new m.Element(t),n.type=t.nodeName,n.node=t,t.instance=n,n instanceof m.Doc&&n.namespace().defs(),n},m.prepare=function(t){var e=document.getElementsByTagName("body")[0],n=(e?new m.Doc(e):t.nested()).size(2,0),i=m.create("path");n.node.appendChild(i),m.parser={body:e||t.parent(),draw:n.style("opacity:0;position:fixed;left:100%;top:100%;overflow:hidden"),poly:n.polyline().node,path:i}},m.regex={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+)\)/,reference:/#([a-z0-9\-_]+)/i,matrix:/matrix\(|\)/g,whitespace:/\s/g,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isCss:/[^:]+:[^;]+;?/,isBlank:/^(\s+)?$/,isNumber:/^-?[\d\.]+$/,isPercent:/^-?[\d\.]+%$/,isImage:/\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i},m.utils={map:function(t,e){var n,i=t.length,r=[];for(n=0;i>n;n++)r.push(e(t[n]));return r},radians:function(t){return t%360*Math.PI/180},degrees:function(t){return 180*t/Math.PI%360}},m.defaults={attrs:{"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"}},m.Color=function(t){var e;this.r=0,this.g=0,this.b=0,"string"==typeof t?m.regex.isRgb.test(t)?(e=m.regex.rgb.exec(t.replace(/\s/g,"")),this.r=parseInt(e[1]),this.g=parseInt(e[2]),this.b=parseInt(e[3])):m.regex.isHex.test(t)&&(e=m.regex.hex.exec(n(t)),this.r=parseInt(e[1],16),this.g=parseInt(e[2],16),this.b=parseInt(e[3],16)):"object"==typeof t&&(this.r=t.r,this.g=t.g,this.b=t.b)},m.extend(m.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+i(this.r)+i(this.g)+i(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},morph:function(t){return this.destination=new m.Color(t),this},at:function(t){return this.destination?(t=0>t?0:t>1?1:t,new m.Color({r:~~(this.r+(this.destination.r-this.r)*t),g:~~(this.g+(this.destination.g-this.g)*t),b:~~(this.b+(this.destination.b-this.b)*t)})):this}}),m.Color.test=function(t){return t+="",m.regex.isHex.test(t)||m.regex.isRgb.test(t)},m.Color.isRgb=function(t){return t&&"number"==typeof t.r&&"number"==typeof t.g&&"number"==typeof t.b},m.Color.isColor=function(t){return m.Color.isRgb(t)||m.Color.test(t)},m.Array=function(t,e){t=(t||[]).valueOf(),0==t.length&&e&&(t=e.valueOf()),this.value=this.parse(t)},m.extend(m.Array,{morph:function(t){if(this.destination=this.parse(t),this.value.length!=this.destination.length){for(var e=this.value[this.value.length-1],n=this.destination[this.destination.length-1];this.value.length>this.destination.length;)this.destination.push(n);for(;this.value.lengtht;t++)-1==n.indexOf(this.value[t])&&n.push(this.value[t]);return this.value=n},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];n>e;e++)i.push(this.value[e]+(this.destination[e]-this.value[e])*t);return new m.Array(i)},toString:function(){return this.value.join(" ")},valueOf:function(){return this.value},parse:function(t){return t=t.valueOf(),Array.isArray(t)?t:this.split(t)},split:function(t){return t.replace(/\s+/g," ").replace(/^\s+|\s+$/g,"").split(" ")},reverse:function(){return this.value.reverse(),this}}),m.PointArray=function(t,e){this.constructor.call(this,t,e||[[0,0]])},m.PointArray.prototype=new m.Array,m.extend(m.PointArray,{toString:function(){for(var t=0,e=this.value.length,n=[];e>t;t++)n.push(this.value[t].join(","));return n.join(" ")},toLine:function(){return{x1:this.value[0][0],y1:this.value[0][1],x2:this.value[1][0],y2:this.value[1][1]}},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];n>e;e++)i.push([this.value[e][0]+(this.destination[e][0]-this.value[e][0])*t,this.value[e][1]+(this.destination[e][1]-this.value[e][1])*t]);return new m.PointArray(i)},parse:function(t){if(t=t.valueOf(),Array.isArray(t))return t;t=this.split(t);for(var e,n=0,i=t.length,r=[];i>n;n++)e=t[n].split(","),r.push([parseFloat(e[0]),parseFloat(e[1])]);return r},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i=this.value.length-1;i>=0;i--)this.value[i]=[this.value[i][0]+t,this.value[i][1]+e];return this},size:function(t,e){var n,i=this.bbox();for(n=this.value.length-1;n>=0;n--)this.value[n][0]=(this.value[n][0]-i.x)*t/i.width+i.x,this.value[n][1]=(this.value[n][1]-i.y)*e/i.height+i.y;return this},bbox:function(){return m.parser.poly.setAttribute("points",this.toString()),m.parser.poly.getBBox()}}),m.PathArray=function(t,e){this.constructor.call(this,t,e||[["M",0,0]])},m.PathArray.prototype=new m.Array,m.extend(m.PathArray,{toString:function(){return l(this.value)},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i,r=this.value.length-1;r>=0;r--)i=this.value[r][0],"M"==i||"L"==i||"T"==i?(this.value[r][1]+=t,this.value[r][2]+=e):"H"==i?this.value[r][1]+=t:"V"==i?this.value[r][1]+=e:"C"==i||"S"==i||"Q"==i?(this.value[r][1]+=t,this.value[r][2]+=e,this.value[r][3]+=t,this.value[r][4]+=e,"C"==i&&(this.value[r][5]+=t,this.value[r][6]+=e)):"A"==i&&(this.value[r][6]+=t,this.value[r][7]+=e);return this},size:function(t,e){var n,i,r=this.bbox();for(n=this.value.length-1;n>=0;n--)i=this.value[n][0],"M"==i||"L"==i||"T"==i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y):"H"==i?this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x:"V"==i?this.value[n][1]=(this.value[n][1]-r.y)*e/r.height+r.y:"C"==i||"S"==i||"Q"==i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y,this.value[n][3]=(this.value[n][3]-r.x)*t/r.width+r.x,this.value[n][4]=(this.value[n][4]-r.y)*e/r.height+r.y,"C"==i&&(this.value[n][5]=(this.value[n][5]-r.x)*t/r.width+r.x,this.value[n][6]=(this.value[n][6]-r.y)*e/r.height+r.y)):"A"==i&&(this.value[n][1]=this.value[n][1]*t/r.width,this.value[n][2]=this.value[n][2]*e/r.height,this.value[n][6]=(this.value[n][6]-r.x)*t/r.width+r.x,this.value[n][7]=(this.value[n][7]-r.y)*e/r.height+r.y);return this},parse:function(t){if(t instanceof m.PathArray)return t.valueOf();var e,n,i,r,s,o,a,h,u,c,f,d=0,p=0;for(m.parser.path.setAttribute("d","string"==typeof t?t:l(t)),f=m.parser.path.pathSegList,e=0,n=f.numberOfItems;n>e;++e)c=f.getItem(e),u=c.pathSegTypeAsLetter,"M"==u||"L"==u||"H"==u||"V"==u||"C"==u||"S"==u||"Q"==u||"T"==u||"A"==u?("x"in c&&(d=c.x),"y"in c&&(p=c.y)):("x1"in c&&(s=d+c.x1),"x2"in c&&(a=d+c.x2),"y1"in c&&(o=p+c.y1),"y2"in c&&(h=p+c.y2),"x"in c&&(d+=c.x),"y"in c&&(p+=c.y),"m"==u?f.replaceItem(m.parser.path.createSVGPathSegMovetoAbs(d,p),e):"l"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoAbs(d,p),e):"h"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoHorizontalAbs(d),e):"v"==u?f.replaceItem(m.parser.path.createSVGPathSegLinetoVerticalAbs(p),e):"c"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoCubicAbs(d,p,s,o,a,h),e):"s"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoCubicSmoothAbs(d,p,a,h),e):"q"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoQuadraticAbs(d,p,s,o),e):"t"==u?f.replaceItem(m.parser.path.createSVGPathSegCurvetoQuadraticSmoothAbs(d,p),e):"a"==u?f.replaceItem(m.parser.path.createSVGPathSegArcAbs(d,p,c.r1,c.r2,c.angle,c.largeArcFlag,c.sweepFlag),e):("z"==u||"Z"==u)&&(d=i,p=r)),("M"==u||"m"==u)&&(i=d,r=p);for(t=[],f=m.parser.path.pathSegList,e=0,n=f.numberOfItems;n>e;++e)c=f.getItem(e),u=c.pathSegTypeAsLetter,d=[u],"M"==u||"L"==u||"T"==u?d.push(c.x,c.y):"H"==u?d.push(c.x):"V"==u?d.push(c.y):"C"==u?d.push(c.x1,c.y1,c.x2,c.y2,c.x,c.y):"S"==u?d.push(c.x2,c.y2,c.x,c.y):"Q"==u?d.push(c.x1,c.y1,c.x,c.y):"A"==u&&d.push(c.r1,c.r2,c.angle,0|c.largeArcFlag,0|c.sweepFlag,c.x,c.y),t.push(d);return t},bbox:function(){return m.parser.path.setAttribute("d",this.toString()),m.parser.path.getBBox()}}),m.Number=m.invent({create:function(t,e){this.value=0,this.unit=e||"","number"==typeof t?this.value=isNaN(t)?0:isFinite(t)?t:0>t?-3.4e38:3.4e38:"string"==typeof t?(e=t.match(m.regex.unit),e&&(this.value=parseFloat(e[1]),"%"==e[2]?this.value/=100:"s"==e[2]&&(this.value*=1e3),this.unit=e[2])):t instanceof m.Number&&(this.value=t.value,this.unit=t.unit)},extend:{toString:function(){return("%"==this.unit?~~(1e8*this.value)/1e6:"s"==this.unit?this.value/1e3:this.value)+this.unit},valueOf:function(){return this.value},plus:function(t){return new m.Number(this+new m.Number(t),this.unit)},minus:function(t){return this.plus(-new m.Number(t))},times:function(t){return new m.Number(this*new m.Number(t),this.unit)},divide:function(t){return new m.Number(this/new m.Number(t),this.unit)},to:function(t){return"string"==typeof t&&(this.unit=t),this},morph:function(t){return this.destination=new m.Number(t),this},at:function(t){return this.destination?new m.Number(this.destination).minus(this).times(t).plus(this):this}}}),m.ViewBox=function(t){var e,n,i,r,s=1,o=1,a=t.bbox(),h=(t.attr("viewBox")||"").match(/-?[\d\.]+/g),u=t,l=t;for(i=new m.Number(t.width()),r=new m.Number(t.height());"%"==i.unit;)s*=i.value,i=new m.Number(u instanceof m.Doc?u.parent().offsetWidth:u.parent().width()),u=u.parent();for(;"%"==r.unit;)o*=r.value,r=new m.Number(l instanceof m.Doc?l.parent().offsetHeight:l.parent().height()),l=l.parent();this.x=a.x,this.y=a.y,this.width=i*s,this.height=r*o,this.zoom=1,h&&(e=parseFloat(h[0]),n=parseFloat(h[1]),i=parseFloat(h[2]),r=parseFloat(h[3]),this.zoom=this.width/this.height>i/r?this.height/r:this.width/i,this.x=e,this.y=n,this.width=i,this.height=r)},m.extend(m.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),m.Element=m.invent({create:function(t){this._stroke=m.defaults.attrs.stroke,(this.node=t)&&(this.type=t.nodeName,this.node.instance=this,this._stroke=t.getAttribute("stroke")||this._stroke)},extend:{x:function(t){return null!=t&&(t=new m.Number(t),t.value/=this.transform("scaleX")),this.attr("x",t)},y:function(t){return null!=t&&(t=new m.Number(t),t.value/=this.transform("scaleY")),this.attr("y",t)},cx:function(t){return null==t?this.x()+this.width()/2:this.x(t-this.width()/2)},cy:function(t){return null==t?this.y()+this.height()/2:this.y(t-this.height()/2)},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},width:function(t){return this.attr("width",t)},height:function(t){return this.attr("height",t)},size:function(t,e){var n=r(this.bbox(),t,e);return this.width(new m.Number(n.width)).height(new m.Number(n.height))},clone:function(){return c(this.node.cloneNode(!0))},remove:function(){return this.parent()&&this.parent().removeElement(this),this},replace:function(t){return this.after(t).remove(),t},addTo:function(t){return t.put(this)},putIn:function(t){return t.add(this)},id:function(t){return this.attr("id",t)},inside:function(t,e){var n=this.bbox();return t>n.x&&e>n.y&&t/,"").replace(/<\/svg>$/,"");e.innerHTML=""+t.replace(/\n/,"").replace(/<(\w+)([^<]+?)\/>/g,"<$1$2>")+"";for(var n=0,i=e.firstChild.childNodes.length;i>n;n++)this.node.appendChild(e.firstChild.childNodes[n]);return this}}}),m.FX=m.invent({create:function(t){this.target=t},extend:{animate:function(t,e,n){var i,r,s,o=this.target,a=this;return"object"==typeof t&&(n=t.delay,e=t.ease,t=t.duration),t="="==t?t:null==t?1e3:new m.Number(t).valueOf(),e=e||"<>",a.at=function(t){var n;if(t=0>t?0:t>1?1:t,null==i){i=[];for(s in a.attrs)i.push(s);if(o.morphArray&&(a.destination.plot||i.indexOf("points")>-1)){var h,l=new o.morphArray(a.destination.plot||a.attrs.points||o.array);a.destination.size&&l.size(a.destination.size.width.to,a.destination.size.height.to),h=l.bbox(),a.destination.x?l.move(a.destination.x.to,h.y):a.destination.cx&&l.move(a.destination.cx.to-h.width/2,h.y),h=l.bbox(),a.destination.y?l.move(h.x,a.destination.y.to):a.destination.cy&&l.move(h.x,a.destination.cy.to-h.height/2),a.destination={plot:o.array.morph(l)}}}if(null==r){r=[];for(s in a.styles)r.push(s)}for(t="<>"==e?-Math.cos(t*Math.PI)/2+.5:">"==e?Math.sin(t*Math.PI/2):"<"==e?-Math.cos(t*Math.PI/2)+1:"-"==e?t:"function"==typeof e?e(t):t,a.destination.plot?o.plot(a.destination.plot.at(t)):(a.destination.x?o.x(a.destination.x.at(t)):a.destination.cx&&o.cx(a.destination.cx.at(t)),a.destination.y?o.y(a.destination.y.at(t)):a.destination.cy&&o.cy(a.destination.cy.at(t)),a.destination.size&&o.size(a.destination.size.width.at(t),a.destination.size.height.at(t))),a.destination.viewbox&&o.viewbox(a.destination.viewbox.x.at(t),a.destination.viewbox.y.at(t),a.destination.viewbox.width.at(t),a.destination.viewbox.height.at(t)),a.destination.leading&&o.leading(a.destination.leading.at(t)),n=i.length-1;n>=0;n--)o.attr(i[n],u(a.attrs[i[n]],t));for(n=r.length-1;n>=0;n--)o.style(r[n],u(a.styles[r[n]],t));a.situation.during&&a.situation.during.call(o,t,function(e,n){return u({from:e,to:n},t)})},"number"==typeof t&&(this.timeout=setTimeout(function(){var i=(new Date).getTime();a.situation.start=i,a.situation.play=!0,a.situation.finish=i+t,a.situation.duration=t,a.situation.ease=e,a.render=function(){if(a.situation.play===!0){var i=(new Date).getTime(),r=i>a.situation.finish?1:(i-a.situation.start)/t;a.situation.reversing&&(r=-r+1),a.at(r),i>a.situation.finish?(a.destination.plot&&o.plot(new m.PointArray(a.destination.plot.destination).settle()),a.situation.loop===!0||"number"==typeof a.situation.loop&&a.situation.loop>0?(a.situation.reverse&&(a.situation.reversing=!a.situation.reversing),"number"==typeof a.situation.loop&&((!a.situation.reverse||a.situation.reversing)&&--a.situation.loop,a.situation.reverse||1!=a.situation.loop||--a.situation.loop),a.animate(t,e,n)):a.situation.after?a.situation.after.apply(o,[a]):a.stop()):requestAnimFrame(a.render)}else requestAnimFrame(a.render)},a.render()},new m.Number(n).valueOf())),this},bbox:function(){return this.target.bbox()},attr:function(t,e){if("object"==typeof t)for(var n in t)this.attr(n,t[n]);else{var i=this.target.attr(t);this.attrs[t]="transform"==t?this.target.ctm().morph(e):m.Color.isColor(e)?new m.Color(i).morph(e):m.regex.unit.test(e)?new m.Number(i).morph(e):{from:i,to:e}}return this},style:function(t,e){if("object"==typeof t)for(var n in t)this.style(n,t[n]);else this.styles[t]={from:this.target.style(t),to:e};return this},x:function(t){return this.destination.x=new m.Number(this.target.x()).morph(t),this},y:function(t){return this.destination.y=new m.Number(this.target.y()).morph(t),this},cx:function(t){return this.destination.cx=new m.Number(this.target.cx()).morph(t),this},cy:function(t){return this.destination.cy=new m.Number(this.target.cy()).morph(t),this},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},size:function(t,e){if(this.target instanceof m.Text)this.attr("font-size",t);else{var n=this.target.bbox();this.destination.size={width:new m.Number(n.width).morph(t),height:new m.Number(n.height).morph(e)}}return this},plot:function(t){return this.destination.plot=t,this},leading:function(t){return this.target.destination.leading&&(this.destination.leading=new m.Number(this.target.destination.leading).morph(t)),this},viewbox:function(t,e,n,i){if(this.target instanceof m.Container){var r=this.target.viewbox();this.destination.viewbox={x:new m.Number(r.x).morph(t),y:new m.Number(r.y).morph(e),width:new m.Number(r.width).morph(n),height:new m.Number(r.height).morph(i)}}return this},update:function(t){return this.target instanceof m.Stop&&(null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",new m.Number(t.offset))),this},during:function(t){return this.situation.during=t,this},after:function(t){return this.situation.after=t,this},loop:function(t,e){return this.situation.loop=this.situation.loops=t||!0,this.situation.reverse=!!e,this},stop:function(t){return t===!0?(this.animate(0),this.situation.after&&this.situation.after.apply(this.target,[this])):(clearTimeout(this.timeout),this.attrs={},this.styles={},this.situation={},this.destination={}),this},pause:function(){return this.situation.play===!0&&(this.situation.play=!1,this.situation.pause=(new Date).getTime()),this},play:function(){if(this.situation.play===!1){var t=(new Date).getTime()-this.situation.pause;this.situation.finish+=t,this.situation.start+=t,this.situation.play=!0}return this}},parent:m.Element,construct:{animate:function(t,e,n){return(this.fx||(this.fx=new m.FX(this))).stop().animate(t,e,n)},stop:function(t){return this.fx&&this.fx.stop(t),this},pause:function(){return this.fx&&this.fx.pause(),this},play:function(){return this.fx&&this.fx.play(),this}}}),m.BBox=m.invent({create:function(t){var e;if(this.x=0,this.y=0,this.width=0,this.height=0,t){var n=new m.Matrix(t).extract();e=t.node.getBBox?t.node.getBBox():{x:t.node.clientLeft,y:t.node.clientTop,width:t.node.clientWidth,height:t.node.clientHeight},this.x=e.x+n.x,this.y=e.y+n.y,this.width=e.width*n.scaleX,this.height=e.height*n.scaleY}f(this)},parent:m.Element,construct:{bbox:function(){return new m.BBox(this)}}}),m.RBox=m.invent({create:function(t){var e={};if(this.x=0,this.y=0,this.width=0,this.height=0,t){var n=t.doc().parent(),i=1;for(e=t.node.getBoundingClientRect(),this.x=e.left,this.y=e.top,this.x-=n.offsetLeft,this.y-=n.offsetTop;n=n.offsetParent;)this.x-=n.offsetLeft,this.y-=n.offsetTop;for(n=t;n.parent&&(n=n.parent());)n.viewbox&&(i*=n.viewbox().zoom,this.x-=n.x()||0,this.y-=n.y()||0)}this.width=e.width/=i,this.height=e.height/=i,this.x+=window.scrollX,this.y+=window.scrollY,f(this)},parent:m.Element,construct:{rbox:function(){return new m.RBox(this)}}}),[m.BBox,m.RBox].forEach(function(t){m.extend(t,{merge:function(e){var n=new t;return n.x=Math.min(this.x,e.x),n.y=Math.min(this.y,e.y),n.width=Math.max(this.x+this.width,e.x+e.width)-n.x,n.height=Math.max(this.y+this.height,e.y+e.height)-n.y,f(n)}})}),m.Matrix=m.invent({create:function(t){var e,n=o([1,0,0,1,0,0]);for(t=t&&t.node&&t.node.getCTM?t.node.getCTM():"string"==typeof t?h(t):6==arguments.length?o([].slice.call(arguments)):"object"==typeof t?t:n,e=g.length-1;e>=0;e--)this[g[e]]="number"==typeof t[g[e]]?t[g[e]]:n[g[e]]},extend:{extract:function(){var t=s(this,0,1),e=s(this,1,0),n=180/Math.PI*Math.atan2(t.y,t.x)-90;return{x:this.e,y:this.f,skewX:-n,skewY:180/Math.PI*Math.atan2(e.y,e.x),scaleX:Math.sqrt(this.a*this.a+this.b*this.b),scaleY:Math.sqrt(this.c*this.c+this.d*this.d),rotation:n}},clone:function(){return new m.Matrix(this)},morph:function(t){return this.destination=new m.Matrix(t),this},at:function(t){return this.destination?new m.Matrix({a:this.a+(this.destination.a-this.a)*t,b:this.b+(this.destination.b-this.b)*t,c:this.c+(this.destination.c-this.c)*t,d:this.d+(this.destination.d-this.d)*t,e:this.e+(this.destination.e-this.e)*t,f:this.f+(this.destination.f-this.f)*t}):this},multiply:function(t){return new m.Matrix(this.native().multiply(a(t).native()))},add:function(t){return t=a(t),new m.Matrix({a:this.a+t.a-1,b:this.b+t.b,c:this.c+t.c,d:this.d+t.d-1,e:this.e+t.e,f:this.f+t.f})},inverse:function(){return new m.Matrix(this.native().inverse())},translate:function(t,e){return new m.Matrix(this.native().translate(t||0,e||0))},scale:function(t,e,n,i){return(1==arguments.length||3==arguments.length)&&(e=t),3==arguments.length&&(i=n,n=e),this.around(n,i,new m.Matrix(t,0,0,e,0,0))},rotate:function(t,e,n){return t=m.utils.radians(t),this.around(e,n,new m.Matrix(Math.cos(t),Math.sin(t),-Math.sin(t),Math.cos(t),0,0))},flip:function(t,e){return"x"==t?this.scale(-1,1,e,0):this.scale(1,-1,0,e)},skew:function(t,e,n,i){return this.around(n,i,this.native().skewX(t||0).skewY(e||0))},around:function(t,e,n){return this.multiply(new m.Matrix(1,0,0,1,t||0,e||0)).multiply(n).multiply(new m.Matrix(1,0,0,1,-t||0,-e||0))},"native":function(){for(var t=m.parser.draw.node.createSVGMatrix(),e=g.length-1;e>=0;e--)t[g[e]]=this[g[e]];return t},toString:function(){return"matrix("+this.toArray().join()+")"},toArray:function(){return[this.a,this.b,this.c,this.d,this.e,this.f]}},parent:m.Element,construct:{ctm:function(){return new m.Matrix(this)}}}),m.extend(m.Element,{attr:function(t,e,n){if(null==t){for(t={},e=this.node.attributes,n=e.length-1;n>=0;n--)t[e[n].nodeName]=m.regex.isNumber.test(e[n].nodeValue)?parseFloat(e[n].nodeValue):e[n].nodeValue;return t}if("object"==typeof t)for(e in t)this.attr(e,t[e]);else if(null===e)this.node.removeAttribute(t);else{if(null==e)return e=this.node.getAttribute(t),null==e?m.defaults.attrs[t]:m.regex.isNumber.test(e)?parseFloat(e):e;"stroke-width"==t?this.attr("stroke",parseFloat(e)>0?this._stroke:null):"stroke"==t&&(this._stroke=e),("fill"==t||"stroke"==t)&&(m.regex.isImage.test(e)&&(e=this.doc().defs().image(e,0,0)),e instanceof m.Image&&(e=this.doc().defs().pattern(0,0,function(){this.add(e)}))),"number"==typeof e?e=new m.Number(e):m.Color.isColor(e)?e=new m.Color(e):Array.isArray(e)&&(e=new m.Array(e)),"leading"==t?this.leading&&this.leading(e):"string"==typeof n?this.node.setAttributeNS(n,t,e.toString()):this.node.setAttribute(t,e.toString()),!this.rebuild||"font-size"!=t&&"x"!=t||this.rebuild(t,e)}return this}}),m.extend(m.Element,m.FX,{transform:function(t,e){var n=this.target||this;if(null==t)return n.ctm().extract();if("string"==typeof t)return n.ctm().extract()[t];var i=new m.Matrix(n);if(e=!!e||!!t.relative,null!=t.a)i=e?i.multiply(new m.Matrix(t)):new m.Matrix(t);else if(null!=t.rotation)t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,i=e?n.attr("transform",i+" rotate("+[t.rotation,t.cx,t.cy].join()+")").ctm():i.rotate(t.rotation-i.extract().rotation,t.cx,t.cy);else if(null!=t.scale||null!=t.scaleX||null!=t.scaleY){if(t.scaleX=null!=t.scale?t.scale:null!=t.scaleX?t.scaleX:1,t.scaleY=null!=t.scale?t.scale:null!=t.scaleY?t.scaleY:1,t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,!e){var r=i.extract();t.scaleX=1*t.scaleX/r.scaleX,t.scaleY=1*t.scaleY/r.scaleY}i=i.scale(t.scaleX,t.scaleY,t.cx,t.cy)}else if(null!=t.skewX||null!=t.skewY){if(t.skewX=null!=t.skewX?t.skewX:0,t.skewY=null!=t.skewY?t.skewY:0,t.cx=null==t.cx?n.bbox().cx:t.cx,t.cy=null==t.cy?n.bbox().cy:t.cy,!e){var r=i.extract();i=i.multiply((new m.Matrix).skew(r.skewX,r.skewY,t.cx,t.cy).inverse())}i=i.skew(t.skewX,t.skewY,t.cx,t.cy)}else t.flip?i=i.flip(t.flip,null==t.offset?n.bbox()["c"+t.flip]:t.offset):(null!=t.x||null!=t.y)&&(e?i=i.translate(t.x,t.y):(null!=t.x&&(i.e=t.x),null!=t.y&&(i.f=t.y)));return this.attr("transform",i)}}),m.extend(m.Element,{untransform:function(){return this.attr("transform",null)}}),m.extend(m.Element,{style:function(e,n){if(0==arguments.length)return this.node.style.cssText||"";if(arguments.length<2)if("object"==typeof e)for(n in e)this.style(n,e[n]);else{if(!m.regex.isCss.test(e))return this.node.style[t(e)];e=e.split(";");for(var i=0;i=0},index:function(t){return this.children().indexOf(t)},get:function(t){return this.children()[t]},first:function(){return this.children()[0]},last:function(){return this.children()[this.children().length-1]},each:function(t,e){var n,i,r=this.children();for(n=0,i=r.length;i>n;n++)r[n]instanceof m.Element&&t.apply(r[n],[n,r]),e&&r[n]instanceof m.Container&&r[n].each(t,e);return this},removeElement:function(t){return this.node.removeChild(t.node),this},clear:function(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return delete this._defs,this},defs:function(){return this.doc().defs()}}}),m.Container=m.invent({create:function(t){this.constructor.call(this,t)},inherit:m.Parent,extend:{viewbox:function(t){return 0==arguments.length?new m.ViewBox(this):(t=1==arguments.length?[t.x,t.y,t.width,t.height]:[].slice.call(arguments),this.attr("viewBox",t))}}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchmove","touchleave","touchend","touchcancel"].forEach(function(t){m.Element.prototype[t]=function(e){var n=this;return this.node["on"+t]="function"==typeof e?function(){return e.apply(n,arguments)}:null,this}}),m.events={},m.listeners={},m.registerEvent=function(t){m.events[t]||(m.events[t]=new p(t))},m.on=function(t,e,n){var i=n.bind(t.instance||t);m.listeners[n]=i,t.addEventListener(e,i,!1)},m.off=function(t,e,n){t.removeEventListener(e,m.listeners[n],!1),delete m.listeners[n]},m.extend(m.Element,{on:function(t,e){return m.on(this.node,t,e),this},off:function(t,e){return m.off(this.node,t,e),this},fire:function(t,e){return m.events[t].detail=e,this.node.dispatchEvent(m.events[t]),delete m.events[t].detail,this}}),m.Defs=m.invent({create:"defs",inherit:m.Container}),m.G=m.invent({create:"g",inherit:m.Container,extend:{x:function(t){return null==t?this.transform("x"):this.transform({x:-this.x()+t},!0)},y:function(t){return null==t?this.transform("y"):this.transform({y:-this.y()+t},!0)},cx:function(t){return null==t?this.bbox().cx:this.x(t-this.bbox().width/2)},cy:function(t){return null==t?this.bbox().cy:this.y(t-this.bbox().height/2)}},construct:{group:function(){return this.put(new m.G)}}}),m.extend(m.Element,{siblings:function(){return this.parent().children()},position:function(){return this.parent().index(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){var t=this.position()+1,e=this.parent();return e.removeElement(this).add(this,t),e instanceof m.Doc&&e.node.appendChild(e.defs().node),this},backward:function(){var t=this.position();return t>0&&this.parent().removeElement(this).add(this,t-1),this},front:function(){var t=this.parent();return t.node.appendChild(this.node),t instanceof m.Doc&&t.node.appendChild(t.defs().node),this},back:function(){return this.position()>0&&this.parent().removeElement(this).add(this,0),this},before:function(t){t.remove();var e=this.position();return this.parent().add(t,e),this},after:function(t){t.remove();var e=this.position();return this.parent().add(t,e+1),this}}),m.Mask=m.invent({create:function(){this.constructor.call(this,m.create("mask")),this.targets=[]},inherit:m.Container,extend:{remove:function(){for(var t=this.targets.length-1;t>=0;t--)this.targets[t]&&this.targets[t].unmask();return delete this.targets,this.parent().removeElement(this),this}},construct:{mask:function(){return this.defs().put(new m.Mask)}}}),m.extend(m.Element,{maskWith:function(t){return this.masker=t instanceof m.Mask?t:this.parent().mask().add(t),this.masker.targets.push(this),this.attr("mask",'url("#'+this.masker.attr("id")+'")')},unmask:function(){return delete this.masker,this.attr("mask",null)}}),m.ClipPath=m.invent({create:function(){this.constructor.call(this,m.create("clipPath")),this.targets=[]},inherit:m.Container,extend:{remove:function(){for(var t=this.targets.length-1;t>=0;t--)this.targets[t]&&this.targets[t].unclip();return delete this.targets,this.parent().removeElement(this),this +}},construct:{clip:function(){return this.defs().put(new m.ClipPath)}}}),m.extend(m.Element,{clipWith:function(t){return this.clipper=t instanceof m.ClipPath?t:this.parent().clip().add(t),this.clipper.targets.push(this),this.attr("clip-path",'url("#'+this.clipper.attr("id")+'")')},unclip:function(){return delete this.clipper,this.attr("clip-path",null)}}),m.Gradient=m.invent({create:function(t){this.constructor.call(this,m.create(t+"Gradient")),this.type=t},inherit:m.Container,extend:{at:function(t,e,n){return this.put(new m.Stop).update(t,e,n)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},fill:function(){return"url(#"+this.id()+")"},toString:function(){return this.fill()}},construct:{gradient:function(t,e){return this.defs().gradient(t,e)}}}),m.extend(m.Gradient,m.FX,{from:function(t,e){return this.attr("radial"==(this.target||this).type?{fx:new m.Number(t),fy:new m.Number(e)}:{x1:new m.Number(t),y1:new m.Number(e)})},to:function(t,e){return this.attr("radial"==(this.target||this).type?{cx:new m.Number(t),cy:new m.Number(e)}:{x2:new m.Number(t),y2:new m.Number(e)})}}),m.extend(m.Defs,{gradient:function(t,e){return this.put(new m.Gradient(t)).update(e)}}),m.Stop=m.invent({create:"stop",inherit:m.Element,extend:{update:function(t){return("number"==typeof t||t instanceof m.Number)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",new m.Number(t.offset)),this}}}),m.Pattern=m.invent({create:"pattern",inherit:m.Container,extend:{fill:function(){return"url(#"+this.id()+")"},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return this.fill()}},construct:{pattern:function(t,e,n){return this.defs().pattern(t,e,n)}}}),m.extend(m.Defs,{pattern:function(t,e,n){return this.put(new m.Pattern).update(n).attr({x:0,y:0,width:t,height:e,patternUnits:"userSpaceOnUse"})}}),m.Doc=m.invent({create:function(t){t&&(t="string"==typeof t?document.getElementById(t):t,"svg"==t.nodeName?this.constructor.call(this,t):(this.constructor.call(this,m.create("svg")),t.appendChild(this.node)),this.namespace().size("100%","100%").defs())},inherit:m.Container,extend:{namespace:function(){return this.attr({xmlns:m.ns,version:"1.1"}).attr("xmlns:xlink",m.xlink,m.xmlns)},defs:function(){if(!this._defs){var t;this._defs=(t=this.node.getElementsByTagName("defs")[0])?m.adopt(t):new m.Defs,this.node.appendChild(this._defs.node)}return this._defs},parent:function(){return"#document"==this.node.parentNode.nodeName?null:this.node.parentNode},spof:function(){var t=this.node.getScreenCTM();return t&&this.style("left",-t.e%1+"px").style("top",-t.f%1+"px"),this}}}),m.Shape=m.invent({create:function(t){this.constructor.call(this,t)},inherit:m.Element}),m.Bare=m.invent({create:function(t,e){if(this.constructor.call(this,m.create(t)),e)for(var n in e.prototype)"function"==typeof e.prototype[n]&&(t[n]=e.prototype[n])},inherit:m.Element,extend:{words:function(t){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this.node.appendChild(document.createTextNode(t)),this}}}),m.extend(m.Parent,{element:function(t,e){return this.put(new m.Bare(t,e))},symbol:function(){return this.defs().element("symbol",m.Container)}}),m.Use=m.invent({create:"use",inherit:m.Shape,extend:{element:function(t){return this.target=t,this.attr("href","#"+t,m.xlink)}},construct:{use:function(t){return this.put(new m.Use).element(t)}}}),m.Rect=m.invent({create:"rect",inherit:m.Shape,construct:{rect:function(t,e){return this.put((new m.Rect).size(t,e))}}}),m.Circle=m.invent({create:"circle",inherit:m.Shape,construct:{circle:function(t){return this.put(new m.Circle).rx(new m.Number(t).divide(2)).move(0,0)}}}),m.extend(m.Circle,m.FX,{rx:function(t){return this.attr("r",t)},ry:function(t){return this.rx(t)}}),m.Ellipse=m.invent({create:"ellipse",inherit:m.Shape,construct:{ellipse:function(t,e){return this.put(new m.Ellipse).size(t,e).move(0,0)}}}),m.extend(m.Ellipse,m.Rect,m.FX,{rx:function(t){return this.attr("rx",t)},ry:function(t){return this.attr("ry",t)}}),m.extend(m.Circle,m.Ellipse,{x:function(t){return null==t?this.cx()-this.rx():this.cx(t+this.rx())},y:function(t){return null==t?this.cy()-this.ry():this.cy(t+this.ry())},cx:function(t){return null==t?this.attr("cx"):this.attr("cx",new m.Number(t).divide(this.transform("scaleX")))},cy:function(t){return null==t?this.attr("cy"):this.attr("cy",new m.Number(t).divide(this.transform("scaleY")))},width:function(t){return null==t?2*this.rx():this.rx(new m.Number(t).divide(2))},height:function(t){return null==t?2*this.ry():this.ry(new m.Number(t).divide(2))},size:function(t,e){var n=r(this.bbox(),t,e);return this.rx(new m.Number(n.width).divide(2)).ry(new m.Number(n.height).divide(2))}}),m.Line=m.invent({create:"line",inherit:m.Shape,extend:{array:function(){return new m.PointArray([[this.attr("x1"),this.attr("y1")],[this.attr("x2"),this.attr("y2")]])},plot:function(t,e,n,i){return t=4==arguments.length?{x1:t,y1:e,x2:n,y2:i}:new m.PointArray(t).toLine(),this.attr(t)},move:function(t,e){return this.attr(this.array().move(t,e).toLine())},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr(this.array().size(n.width,n.height).toLine())}},construct:{line:function(t,e,n,i){return this.put(new m.Line).plot(t,e,n,i)}}}),m.Polyline=m.invent({create:"polyline",inherit:m.Shape,construct:{polyline:function(t){return this.put(new m.Polyline).plot(t)}}}),m.Polygon=m.invent({create:"polygon",inherit:m.Shape,construct:{polygon:function(t){return this.put(new m.Polygon).plot(t)}}}),m.extend(m.Polyline,m.Polygon,{array:function(){return this._array||(this._array=new m.PointArray(this.attr("points")))},plot:function(t){return this.attr("points",this._array=new m.PointArray(t))},move:function(t,e){return this.attr("points",this.array().move(t,e))},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr("points",this.array().size(n.width,n.height))}}),m.extend(m.Line,m.Polyline,m.Polygon,{morphArray:m.PointArray,x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},width:function(t){var e=this.bbox();return null==t?e.width:this.size(t,e.height)},height:function(t){var e=this.bbox();return null==t?e.height:this.size(e.width,t)}}),m.Path=m.invent({create:"path",inherit:m.Shape,extend:{morphArray:m.PathArray,array:function(){return this._array||(this._array=new m.PathArray(this.attr("d")))},plot:function(t){return this.attr("d",this._array=new m.PathArray(t))},move:function(t,e){return this.attr("d",this.array().move(t,e))},x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},size:function(t,e){var n=r(this.bbox(),t,e);return this.attr("d",this.array().size(n.width,n.height))},width:function(t){return null==t?this.bbox().width:this.size(t,this.bbox().height)},height:function(t){return null==t?this.bbox().height:this.size(this.bbox().width,t)}},construct:{path:function(t){return this.put(new m.Path).plot(t)}}}),m.Image=m.invent({create:"image",inherit:m.Shape,extend:{load:function(t){if(!t)return this;var e=this,n=document.createElement("img");return n.onload=function(){var i=e.doc(m.Pattern);0==e.width()&&0==e.height()&&e.size(n.width,n.height),i&&0==i.width()&&0==i.height()&&i.size(e.width(),e.height()),"function"==typeof e._loaded&&e._loaded.call(e,{width:n.width,height:n.height,ratio:n.width/n.height,url:t})},this.attr("href",n.src=this.src=t,m.xlink)},loaded:function(t){return this._loaded=t,this}},construct:{image:function(t,e,n){return this.put(new m.Image).load(t).size(e||0,n||e||0)}}}),m.Text=m.invent({create:function(){this.constructor.call(this,m.create("text")),this._leading=new m.Number(1.3),this._rebuild=!0,this._build=!1,this.attr("font-family",m.defaults.attrs["font-family"])},inherit:m.Shape,extend:{x:function(t){return null==t?this.attr("x"):(this.textPath||this.lines().each(function(){this.newLined&&this.x(t)}),this.attr("x",t))},y:function(t){var e=this.attr("y"),n="number"==typeof e?e-this.bbox().y:0;return null==t?"number"==typeof e?e-n:e:this.attr("y","number"==typeof t?t+n:t)},cx:function(t){return null==t?this.bbox().cx:this.x(t-this.bbox().width/2)},cy:function(t){return null==t?this.bbox().cy:this.y(t-this.bbox().height/2)},text:function(t){if("undefined"==typeof t)return this.content;if(this.clear().build(!0),"function"==typeof t)t.call(this,this);else{t=(this.content=t).split("\n");for(var e=0,n=t.length;n>e;e++)this.tspan(t[e]).newLine()}return this.build(!1).rebuild()},size:function(t){return this.attr("font-size",t).rebuild()},leading:function(t){return null==t?this._leading:(this._leading=new m.Number(t),this.rebuild())},lines:function(){for(var t=0,e=this.node.childNodes.length,n=[];e>t;t++)this.node.childNodes[t]instanceof SVGElement&&n.push(m.adopt(this.node.childNodes[t]));return new m.Set(n)},rebuild:function(t){if("boolean"==typeof t&&(this._rebuild=t),this._rebuild){var e=this;this.lines().each(function(){this.newLined&&(this.textPath||this.attr("x",e.attr("x")),this.attr("dy",e._leading*new m.Number(e.attr("font-size"))))}),this.fire("rebuild")}return this},build:function(t){return this._build=!!t,this}},construct:{text:function(t){return this.put(new m.Text).text(t)},plain:function(t){return this.put(new m.Text).plain(t)}}}),m.Tspan=m.invent({create:"tspan",inherit:m.Shape,extend:{text:function(t){return"function"==typeof t?t.call(this,this):this.plain(t),this},dx:function(t){return this.attr("dx",t)},dy:function(t){return this.attr("dy",t)},newLine:function(){var t=this.doc(m.Text);return this.newLined=!0,this.dy(t._leading*t.attr("font-size")).attr("x",t.x())}}}),m.extend(m.Text,m.Tspan,{plain:function(t){return this._build===!1&&this.clear(),this.node.appendChild(document.createTextNode(this.content=t)),this},tspan:function(t){var e=(this.textPath()||this).node,n=new m.Tspan;return this._build===!1&&this.clear(),e.appendChild(n.node),this instanceof m.Text&&this.lines().add(n),n.text(t)},clear:function(){for(var t=(this.textPath()||this).node;t.hasChildNodes();)t.removeChild(t.lastChild);return this instanceof m.Text&&(this.content=""),this},length:function(){return this.node.getComputedTextLength()}}),m.registerEvent("rebuild"),m.TextPath=m.invent({create:"textPath",inherit:m.Element,parent:m.Text,construct:{path:function(t){for(var e=new m.TextPath,n=this.doc().defs().path(t);this.node.hasChildNodes();)e.node.appendChild(this.node.firstChild);return this.node.appendChild(e.node),e.attr("href","#"+n,m.xlink),this},plot:function(t){var e=this.track();return e&&e.plot(t),this},track:function(){var t=this.textPath();return t?t.reference("href"):void 0},textPath:function(){return this.node.firstChild&&"textPath"==this.node.firstChild.nodeName?m.adopt(this.node.firstChild):void 0}}}),m.Nested=m.invent({create:function(){this.constructor.call(this,m.create("svg")),this.style("overflow","visible")},inherit:m.Container,construct:{nested:function(){return this.put(new m.Nested)}}}),m.A=m.invent({create:"a",inherit:m.Container,extend:{to:function(t){return this.attr("href",t,m.xlink)},show:function(t){return this.attr("show",t,m.xlink)},target:function(t){return this.attr("target",t)}},construct:{link:function(t){return this.put(new m.A).to(t)}}}),m.extend(m.Element,{linkTo:function(t){var e=new m.A;return"function"==typeof t?t.call(e,e):e.to(t),this.parent().put(e).put(this)}}),m.Marker=m.invent({create:"marker",inherit:m.Container,extend:{width:function(t){return this.attr("markerWidth",t)},height:function(t){return this.attr("markerHeight",t)},ref:function(t,e){return this.attr("refX",t).attr("refY",e)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return"url(#"+this.id()+")"}},construct:{marker:function(t,e,n){return this.defs().marker(t,e,n)}}}),m.extend(m.Defs,{marker:function(t,e,n){return this.put(new m.Marker).size(t,e).ref(t/2,e/2).viewbox(0,0,t,e).attr("orient","auto").update(n)}}),m.extend(m.Line,m.Polyline,m.Polygon,m.Path,{marker:function(t,e,n,i){var r=["marker"];return"all"!=t&&r.push(t),r=r.join("-"),t=arguments[1]instanceof m.Marker?arguments[1]:this.doc().marker(e,n,i),this.attr(r,t)}});var x={stroke:["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],fill:["color","opacity","rule"],prefix:function(t,e){return"color"==e?t:t+"-"+e}};["fill","stroke"].forEach(function(t){var e,n={};n[t]=function(n){if("string"==typeof n||m.Color.isRgb(n)||n&&"function"==typeof n.fill)this.attr(t,n);else for(e=x[t].length-1;e>=0;e--)null!=n[x[t][e]]&&this.attr(x.prefix(t,x[t][e]),n[x[t][e]]);return this},m.extend(m.Element,m.FX,n)}),m.extend(m.Element,m.FX,{rotate:function(t,e,n){return this.transform({rotation:t,cx:e,cy:n})},skew:function(t,e,n,i){return this.transform({skewX:t,skewY:e,cx:n,cy:i})},scale:function(t,e,n,i){return this.transform(1==arguments.length||3==arguments.length?{scale:t,cx:e,cy:n}:{scaleX:t,scaleY:e,cx:n,cy:i})},translate:function(t,e){return this.transform({x:t,y:e})},flip:function(t,e){return this.transform({flip:t,offset:e})},matrix:function(t){return this.attr("transform",new m.Matrix(t))},opacity:function(t){return this.attr("opacity",t)},dx:function(t){return this.x((this.target||this).x()+t)},dy:function(t){return this.y((this.target||this).y()+t)},dmove:function(t,e){return this.dx(t).dy(e)}}),m.extend(m.Rect,m.Ellipse,m.Circle,m.Gradient,m.FX,{radius:function(t,e){return"radial"==(this.target||this).type?this.attr({r:new m.Number(t)}):this.rx(t).ry(null==e?t:e)}}),m.extend(m.Path,{length:function(){return this.node.getTotalLength()},pointAt:function(t){return this.node.getPointAtLength(t)}}),m.extend(m.Parent,m.Text,m.FX,{font:function(t){for(var e in t)"leading"==e?this.leading(t[e]):"anchor"==e?this.attr("text-anchor",t[e]):"size"==e||"family"==e||"weight"==e||"stretch"==e||"variant"==e||"style"==e?this.attr("font-"+e,t[e]):this.attr(e,t[e]);return this}}),m.Set=m.invent({create:function(t){Array.isArray(t)?this.members=t:this.clear()},extend:{add:function(){var t,e,n=[].slice.call(arguments);for(t=0,e=n.length;e>t;t++)this.members.push(n[t]);return this},remove:function(t){var e=this.index(t);return e>-1&&this.members.splice(e,1),this},each:function(t){for(var e=0,n=this.members.length;n>e;e++)t.apply(this.members[e],[e,this.members]);return this},clear:function(){return this.members=[],this},length:function(){return this.members.length},has:function(t){return this.index(t)>=0},index:function(t){return this.members.indexOf(t)},get:function(t){return this.members[t]},first:function(){return this.get(0)},last:function(){return this.get(this.members.length-1)},valueOf:function(){return this.members},bbox:function(){var t=new m.BBox;if(0==this.members.length)return t;var e=this.members[0].rbox();return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,this.each(function(){t=t.merge(this.rbox())}),t}},construct:{set:function(t){return new m.Set(t)}}}),m.FX.Set=m.invent({create:function(t){this.set=t}}),m.Set.inherit=function(){var t,e=[];for(var t in m.Shape.prototype)"function"==typeof m.Shape.prototype[t]&&"function"!=typeof m.Set.prototype[t]&&e.push(t);e.forEach(function(t){m.Set.prototype[t]=function(){for(var e=0,n=this.members.length;n>e;e++)this.members[e]&&"function"==typeof this.members[e][t]&&this.members[e][t].apply(this.members[e],arguments);return"animate"==t?this.fx||(this.fx=new m.FX.Set(this)):this}}),e=[];for(var t in m.FX.prototype)"function"==typeof m.FX.prototype[t]&&"function"!=typeof m.FX.Set.prototype[t]&&e.push(t);e.forEach(function(t){m.FX.Set.prototype[t]=function(){for(var e=0,n=this.set.members.length;n>e;e++)this.set.members[e].fx[t].apply(this.set.members[e].fx,arguments);return this}})},m.extend(m.Element,{data:function(t,e,n){if("object"==typeof t)for(e in t)this.data(e,t[e]);else if(arguments.length<2)try{return JSON.parse(this.attr("data-"+t))}catch(i){return this.attr("data-"+t)}else this.attr("data-"+t,null===e?null:n===!0||"string"==typeof e||"number"==typeof e?e:JSON.stringify(e));return this}}),m.extend(m.Element,{remember:function(t,e){if("object"==typeof arguments[0])for(var e in t)this.remember(e,t[e]);else{if(1==arguments.length)return this.memory()[t];this.memory()[t]=e}return this},forget:function(){if(0==arguments.length)this._memory={};else for(var t=arguments.length-1;t>=0;t--)delete this.memory()[arguments[t]];return this},memory:function(){return this._memory||(this._memory={})}}),m.get=function(t){var e=document.getElementById(d(t)||t);return e?m.adopt(e):void 0},m.select=function(t,e){return new m.Set(m.utils.map((e||document).querySelectorAll(t),function(t){return m.adopt(t)}))},m.extend(m.Parent,{select:function(t){return m.select(t,this.node)}});var g="abcdef".split("");return window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}(),"function"!=typeof p&&(p.prototype=window.Event.prototype,window.CustomEvent=p),m}); \ No newline at end of file diff --git a/spec/spec/number.js b/spec/spec/number.js index f35be5f..986338b 100755 --- a/spec/spec/number.js +++ b/spec/spec/number.js @@ -12,6 +12,11 @@ describe('Number', function() { it('has a blank unit', function() { expect(number.unit).toBe('') }) + it('accepts the unit as a second argument', function() { + number = new SVG.Number(30, '%') + expect(number.value).toBe(30) + expect(number.unit).toBe('%') + }) it('parses a pixel value', function() { number = new SVG.Number('20px') expect(number.value).toBe(20) @@ -91,7 +96,10 @@ describe('Number', function() { describe('to()', function() { beforeEach(function() { - number.plus(4) + number = number.plus(4) + }) + it('returns itself', function() { + expect(number.to('em')).toBe(number) }) it('changes the unit value', function() { number.to('%') @@ -105,72 +113,67 @@ describe('Number', function() { }) describe('plus()', function() { + it('returns a new instance', function() { + expect(number.plus(4.5)).not.toBe(number) + expect(number.plus(4.5) instanceof SVG.Number).toBeTruthy() + }) it('adds a given number', function() { - number.plus(3.5) - expect(number.valueOf()).toBe(3.5) + expect(number.plus(3.5).valueOf()).toBe(3.5) }) it('adds a given percentage value', function() { - number.plus('225%') - expect(number.valueOf()).toBe(2.25) + expect(number.plus('225%').valueOf()).toBe(2.25) }) it('adds a given pixel value', function() { - number.plus('83px') - expect(number.valueOf()).toBe(83) + expect(number.plus('83px').valueOf()).toBe(83) }) }) describe('minus()', function() { it('subtracts a given number', function() { - number.minus(3.7) - expect(number.valueOf()).toBe(-3.7) + expect(number.minus(3.7).valueOf()).toBe(-3.7) }) it('subtracts a given percentage value', function() { - number.minus('223%') - expect(number.valueOf()).toBe(-2.23) + expect(number.minus('223%').valueOf()).toBe(-2.23) }) it('subtracts a given pixel value', function() { - number.minus('85px') - expect(number.valueOf()).toBe(-85) + expect(number.minus('85px').valueOf()).toBe(-85) }) }) describe('times()', function() { beforeEach(function() { - number.plus(4) + number = number.plus(4) }) it('multiplies with a given number', function() { - number.times(3) - expect(number.valueOf()).toBe(12) + expect(number.times(3).valueOf()).toBe(12) }) it('multiplies with a given percentage value', function() { - number.times('110%') - expect(number.valueOf()).toBe(4.4) + expect(number.times('110%').valueOf()).toBe(4.4) }) it('multiplies with a given pixel value', function() { - number.times('85px') - expect(number.valueOf()).toBe(340) + expect(number.times('85px').valueOf()).toBe(340) }) }) describe('divide()', function() { beforeEach(function() { - number.plus(90) + number = number.plus(90) }) it('divides by a given number', function() { - number.divide(3) - expect(number.valueOf()).toBe(30) + expect(number.divide(3).valueOf()).toBe(30) }) it('divides by a given percentage value', function() { - number.divide('3000%') - expect(number.valueOf()).toBe(3) + expect(number.divide('3000%').valueOf()).toBe(3) }) it('divides by a given pixel value', function() { - number.divide('45px') - expect(number.valueOf()).toBe(2) + expect(number.divide('45px').valueOf()).toBe(2) }) }) describe('morph()', function() { + it('returns itself', function() { + expect(number.morph(new SVG.Number)).toBe(number) + }) it('prepares the color for morphing', function() { var destination = new SVG.Number number.morph(destination) @@ -179,6 +182,12 @@ describe('Number', function() { }) describe('at()', function() { + it('returns a new instance', function() { + var destination = new SVG.Number(200) + var morphed = number.morph(destination).at(0.4) + expect(morphed).not.toBe(number) + expect(morphed).not.toBe(destination) + }) it('morphes number to a given position', function() { var destination = new SVG.Number(200) var morphed = number.morph(destination).at(0.4) diff --git a/src/number.js b/src/number.js index 22915b9..ace511c 100755 --- a/src/number.js +++ b/src/number.js @@ -1,31 +1,31 @@ // Module for unit convertions SVG.Number = SVG.invent({ // Initialize - create: function(value) { - // Initialize defaults + create: function(value, unit) { + // initialize defaults this.value = 0 - this.unit = '' + this.unit = unit || '' - // Parse value + // parse value if (typeof value === 'number') { - // Ensure a valid numeric value + // ensure a valid numeric value this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value } else if (typeof value === 'string') { - var match = value.match(SVG.regex.unit) + unit = value.match(SVG.regex.unit) - if (match) { - // Make value numeric - this.value = parseFloat(match[1]) + if (unit) { + // make value numeric + this.value = parseFloat(unit[1]) - // Normalize - if (match[2] == '%') + // normalize + if (unit[2] == '%') this.value /= 100 - else if (match[2] == 's') + else if (unit[2] == 's') this.value *= 1000 - // Store unit - this.unit = match[2] + // store unit + this.unit = unit[2] } } else { @@ -54,9 +54,7 @@ SVG.Number = SVG.invent({ } // Add number , plus: function(number) { - this.value = this + new SVG.Number(number) - - return this + return new SVG.Number(this + new SVG.Number(number), this.unit) } // Subtract number , minus: function(number) { @@ -64,15 +62,11 @@ SVG.Number = SVG.invent({ } // Multiply number , times: function(number) { - this.value = this * new SVG.Number(number) - - return this + return new SVG.Number(this * new SVG.Number(number), this.unit) } // Divide number , divide: function(number) { - this.value = this / new SVG.Number(number) - - return this + return new SVG.Number(this / new SVG.Number(number), this.unit) } // Convert to different unit , to: function(unit) { -- 2.39.5