From: wout Date: Tue, 12 Mar 2013 12:31:09 +0000 (+0100) Subject: Added x(), y(), cx(), cy() and matrix X-Git-Tag: 0.11~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4bd21ec64a0e3c1d4d0acf5685b2230285c7c16b;p=svg.js.git Added x(), y(), cx(), cy() and matrix --- diff --git a/README.md b/README.md index 5092b1b..007f1e5 100644 --- a/README.md +++ b/README.md @@ -234,24 +234,39 @@ rect.transform({ }) ``` +You can also provide two arguments as property and value: + +```javascript +rect.transform('matrix', '1,0.5,0.5,1,0,0') +``` + All available transformations are: ```javascript rect.transform({ x: [translation on x-axis] , y: [translation on y-axis] + , rotation: [degrees] , cx: [x rotation point] , cy: [y rotation point] + , scaleX: [scaling on x-axis] , scaleX: [scaling on y-axis] + , skewX: [skewing on x-axis] , skewY: [skewing on y-axis] + +, matrix: [a 6-digit matrix string; e.g. '1,0,0,1,0,0'] +, a: [the first matrix digit] +, b: [the second matrix digit] +, c: [the third matrix digit] +, d: [the fourth matrix digit] +, e: [the fifth matrix digit] +, f: [the sixth matrix digit] }) ``` -Important: matrix transformations are not yet supported. - ### Style With the `style()` method the `style` attribute can be managed like attributes with `attr`: @@ -294,6 +309,12 @@ Move the element to a given `x` and `y` position by its upper left corner: rect.move(200, 350) ``` +This will have the same effect as: + +```javascript +rect.x(200).y(350) +``` + Note that you can also use the following code to move elements around: ```javascript @@ -302,24 +323,28 @@ rect.attr({ x: 20, y: 60 }) Although `move()` is much more convenient because it will always use the upper left corner as the position reference, whereas with using `attr()` the `x` and `y` reference differ between element types. For example, rect uses the upper left corner with the `x` and `y` attributes, circle and ellipse use their center with the `cx` and `cy` attributes and thereby simply ignoring the `x` and `y` values you might assign. - -### Size -Set the size of an element by a given `width` and `height`: +### Center +This is an extra method to move an element by its center: ```javascript -rect.size(200, 300) +rect.center(150, 150) ``` -Same as with `move()` the size of an element could be set by using `attr()`. But because every type of element is handles its size differently the `size()` method is much more convenient. +This will have the same effect as: +```javascript +rect.cx(150).cy(150) +``` -### Center -This is an extra method to move an element by its center: +### Size +Set the size of an element by a given `width` and `height`: ```javascript -rect.center(150, 150) +rect.size(200, 300) ``` +Same as with `move()` the size of an element could be set by using `attr()`. But because every type of element is handles its size differently the `size()` method is much more convenient. + ### Hide and show We all love to have a little hide: @@ -431,24 +456,24 @@ Of course `attr()`: rect.animate().attr({ fill: '#f03' }) ``` -The `move()` method: +The `x()`, `y()` and `move()` methods: ```javascript rect.animate().move(100, 100) ``` -And the `center()` method: +And the `cx()`, `cy()` and `center()` methods: ```javascript rect.animate().center(200, 200) ``` -If you include the sugar.js module, `rotate()` and `skew()` will be available as well: +If you include the sugar.js module, `fill()`, `stroke()`, `rotate()`, `skew()`, `scale()`, `matrix()` and `opacity()` will be available as well: ```javascript rect.animate().rotate(45).skew(25, 0) ``` You can also animate non-numeric unit values unsing the `attr()` method: ```javascript -rect.attr('x', '10%').animate().attr('x', '50%') +rect.animate().attr('x', '10%').animate().attr('x', '50%') ``` ### Stopping animations diff --git a/Rakefile b/Rakefile index 5e32183..616078a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,7 @@ -SVGJS_VERSION = '0.9' +SVGJS_VERSION = '0.10' # all available modules in the correct loading order -MODULES = %w[ svg regex color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar ] +MODULES = %w[ svg regex default color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar ] # how many bytes in a "kilobyte" KILO = 1024 diff --git a/dist/svg.js b/dist/svg.js index f3a0b84..717ac6f 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js v0.9 - svg regex color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar - svgjs.com/license */ +/* svg.js v0.10 - svg regex default color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar - svgjs.com/license */ ;(function() { this.SVG = function(element) { @@ -61,35 +61,91 @@ SVG.regex = { /* parse unit value */ - unit: /^([\d\.]+)([a-z%]{0,2})$/ + unit: /^([\d\.]+)([a-z%]{0,2})$/ /* parse hex value */ - , hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i + , hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i /* parse rgb value */ - , rgb: /rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/ + , rgb: /rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/ /* parse hsb value */ - , hsb: /hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/ + , hsb: /hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/ /* test hex value */ - , isHex: /^#[a-f0-9]{3,6}$/i + , isHex: /^#[a-f0-9]{3,6}$/i /* test rgb value */ - , isRgb: /^rgb\(/ + , isRgb: /^rgb\(/ /* test hsb value */ - , isHsb: /^hsb\(/ + , isHsb: /^hsb\(/ /* test css declaration */ - , isCss: /[^:]+:[^;]+;?/ + , isCss: /[^:]+:[^;]+;?/ /* test css property */ - , isStyle: /^font|text|leading|cursor/ + , isStyle: /^font|text|leading|cursor/ /* test for blank string */ - , isBlank: /^(\s+)?$/ - + , isBlank: /^(\s+)?$/ + + } + + SVG.default = { + // Default matrix + matrix: '1,0,0,1,0,0' + + // Default attribute values + , attrs: function() { + return { + /* fill and stroke */ + 'fill-opacity': 1 + , 'stroke-opacity': 1 + , 'stroke-width': 0 + , fill: '#000' + , stroke: '#000' + , opacity: 1 + /* position */ + , x: 0 + , y: 0 + , cx: 0 + , cy: 0 + /* size */ + , width: 0 + , height: 0 + /* radius */ + , r: 0 + , rx: 0 + , ry: 0 + } + } + + // Default transformation values + , trans: function() { + return { + /* translate */ + x: 0 + , y: 0 + /* scale */ + , scaleX: 1 + , scaleY: 1 + /* rotate */ + , rotation: 0 + /* skew */ + , skewX: 0 + , skewY: 0 + /* matrix */ + , matrix: this.matrix + , a: 1 + , b: 0 + , c: 0 + , d: 1 + , e: 0 + , f: 0 + } + } + } SVG.Color = function(color) { @@ -319,59 +375,47 @@ SVG.Element = function(node) { /* initialize attribute store with defaults */ - this.attrs = { - 'fill-opacity': 1 - , 'stroke-opacity': 1 - , 'stroke-width': 0 - , fill: '#000' - , stroke: '#000' - , opacity: 1 - , x: 0 - , y: 0 - , cx: 0 - , cy: 0 - , width: 0 - , height: 0 - , r: 0 - , rx: 0 - , ry: 0 - } + this.attrs = SVG.default.attrs() /* initialize style store */ this.styles = {} /* initialize transformation store with defaults */ - this.trans = { - x: 0 - , y: 0 - , scaleX: 1 - , scaleY: 1 - , rotation: 0 - , skewX: 0 - , skewY: 0 - } + this.trans = SVG.default.trans() /* keep reference to the element node */ if (this.node = node) { this.type = node.nodeName this.attrs.id = node.getAttribute('id') } + } // SVG.extend(SVG.Element, { + // Move over x-axis + x: function(x) { + return this.attr('x', x) + } + // Move over y-axis + , y: function(y) { + return this.attr('y', y) + } + // Move by center over x-axis + , cx: function(x) { + return this.x(x - this.bbox().width / 2) + } + // Move by center over y-axis + , cy: function(y) { + return this.y(y - this.bbox().height / 2) + } // Move element to given x and y values - move: function(x, y) { - return this.attr({ - x: x - , y: y - }) + , move: function(x, y) { + return this.x(x).y(y) } // Move element by its center , center: function(x, y) { - var box = this.bbox() - - return this.move(x - box.width / 2, y - box.height / 2) + return this.cx(x).cy(y) } // Set element size to given width and height , size: function(width, height) { @@ -465,6 +509,10 @@ } else if (a == 'style') { /* redirect to the style method */ return this.style(v) + + } else if (a == 'transform') { + /* redirect to the transform method*/ + return this.transform(v) } else { /* store value */ @@ -524,14 +572,29 @@ /* ... otherwise continue as a setter */ var transform = [] + /* parse matrix */ + o = this._parseMatrix(o) + /* merge values */ for (v in o) if (o[v] != null) this.trans[v] = o[v] + /* compile matrix */ + this.trans.matrix = this.trans.a + + ',' + this.trans.b + + ',' + this.trans.c + + ',' + this.trans.d + + ',' + this.trans.e + + ',' + this.trans.f + /* alias current transformations */ o = this.trans + /* add matrix */ + if (o.matrix != SVG.default.matrix) + transform.push('matrix(' + o.matrix + ')') + /* add rotation */ if (o.rotation != 0) { transform.push( @@ -542,7 +605,8 @@ } /* add scale */ - transform.push('scale(' + o.scaleX + ',' + o.scaleY + ')') + if (o.scaleX != 1 || o.scaleY != 1) + transform.push('scale(' + o.scaleX + ',' + o.scaleY + ')') /* add skew on x axis */ if (o.skewX != 0) @@ -553,10 +617,13 @@ transform.push('skewY(' + o.skewY + ')') /* add translation */ - transform.push('translate(' + o.x + ',' + o.y + ')') + if (o.x != 0 || o.y != 0) + transform.push('translate(' + o.x + ',' + o.y + ')') /* add only te required transformations */ - return this.attr('transform', transform.join(' ')) + this.node.setAttribute('transform', transform.join(' ')) + + return this } // Dynamic style generator , style: function(s, v) { @@ -661,6 +728,25 @@ , _isText: function() { return this instanceof SVG.Text } + // Private: parse a matrix string + , _parseMatrix: function(o) { + if (o.matrix) { + /* split matrix string */ + var m = o.matrix.replace(/\s/g, '').split(',') + + /* pasrse values */ + if (m.length == 6) { + o.a = parseFloat(m[0]) + o.b = parseFloat(m[1]) + o.c = parseFloat(m[2]) + o.d = parseFloat(m[3]) + o.e = parseFloat(m[4]) + o.f = parseFloat(m[5]) + } + } + + return o + } }) @@ -745,12 +831,16 @@ return this.put(new SVG.Rect().size(width, height)) } // Create circle element, based on ellipse - , circle: function(diameter) { - return this.ellipse(diameter) + , circle: function(size) { + return this.ellipse(size, size) } // Create an ellipse , ellipse: function(width, height) { - return this.put(new SVG.Ellipse().size(width, height)) + return this.put(new SVG.Ellipse().size(width, height).move(0, 0)) + } + // Create a line element + , line: function(x1, y1, x2, y2) { + return this.put(new SVG.Line().attr({ x1: x1, y1: y1, x2: x2, y2: y2 })) } // Create a wrapped polyline element , polyline: function(points) { @@ -878,11 +968,17 @@ ease(pos) : pos - /* run all position properties */ - if (fx._move) - element.move(fx._at(fx._move.x, pos), fx._at(fx._move.y, pos)) - else if (fx._center) - element.center(fx._at(fx._center.x, pos), fx._at(fx._center.y, pos)) + /* run all x-position properties */ + if (fx._x) + element.x(fx._at(fx._x, pos)) + else if (fx._cx) + element.cx(fx._at(fx._cx, pos)) + + /* run all y-position properties */ + if (fx._y) + element.y(fx._at(fx._y, pos)) + else if (fx._cy) + element.cy(fx._at(fx._cy, pos)) /* run all size properties */ if (fx._size) @@ -916,6 +1012,10 @@ return this } + // Get bounding box of target element + , bbox: function() { + return this.target.bbox() + } // Add animatable attributes , attr: function(a, v, n) { if (typeof a == 'object') @@ -928,9 +1028,25 @@ return this } // Add animatable transformations - , transform: function(t, v) { - for (var key in t) - this.trans[key] = { from: this.target.trans[key], to: t[key] } + , transform: function(o, v) { + if (arguments.length == 1) { + /* parse matrix string */ + o = this.target._parseMatrix(o) + + /* dlete matrixstring from object */ + delete o.matrix + + /* store matrix values */ + for (v in o) + this.trans[v] = { from: this.target.trans[v], to: o[v] } + + } else { + /* apply transformations as object if key value arguments are given*/ + var transform = {} + transform[o] = v + + this.transform(transform) + } return this } @@ -945,17 +1061,42 @@ return this } - // Add animatable move - , move: function(x, y) { - var box = this.target.bbox() + // Animatable x-axis + , x: function(x) { + var b = this.bbox() + this._x = { from: b.x, to: x } - this._move = { - x: { from: box.x, to: x } - , y: { from: box.y, to: y } - } + return this + } + // Animatable y-axis + , y: function(y) { + var b = this.bbox() + this._y = { from: b.y, to: y } return this } + // Animatable center x-axis + , cx: function(x) { + var b = this.bbox() + this._cx = { from: b.cx, to: x } + + return this + } + // Animatable center y-axis + , cy: function(y) { + var b = this.bbox() + this._cy = { from: b.cy, to: y } + + return this + } + // Add animatable move + , move: function(x, y) { + return this.x(x).y(y) + } + // Add animatable center + , center: function(x, y) { + return this.cx(x).cy(y) + } // Add animatable size , size: function(width, height) { if (this.target instanceof SVG.Text) { @@ -974,17 +1115,6 @@ return this } - // Add animatable center - , center: function(x, y) { - var box = this.target.bbox() - - this._move = { - x: { from: box.cx, to: x - box.width / 2 } - , y: { from: box.cy, to: y - box.height / 2 } - } - - return this - } // Add callback for each keyframe , during: function(during) { this._during = during @@ -1153,12 +1283,13 @@ SVG.G.prototype = new SVG.Container SVG.extend(SVG.G, { - // Move using translate - move: function(x, y) { - return this.transform({ - x: x - , y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis + , y: function(y) { + return this.transform('y', y) } // Get defs , defs: function() { @@ -1457,12 +1588,13 @@ SVG.Wrap.prototype = new SVG.Shape() SVG.extend(SVG.Wrap, { - // Move wrapper around - move: function(x, y) { - return this.transform({ - x: x - , y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis + , y: function(y) { + return this.transform('y', y) } // Set the actual size in pixels , size: function(width, height) { @@ -1538,28 +1670,31 @@ } // Inherit from SVG.Shape - SVG.Ellipse.prototype = new SVG.Shape() + SVG.Ellipse.prototype = new SVG.Shape // SVG.extend(SVG.Ellipse, { - // Custom move function - move: function(x, y) { - this.attrs.x = x - this.attrs.y = y - - return this.center() - }, + // Move over x-axis + x: function(x) { + return this.cx(x + this.attrs.rx) + } + // Move over y-axis + , y: function(y) { + return this.cy(y + this.attrs.ry) + } + // Move by center over x-axis + , cx: function(x) { + return this.attr('cx', x) + } + // Move by center over y-axis + , cy: function(y) { + return this.attr('cy', y) + } // Custom size function - size: function(width, height) { - return this - .attr({ rx: width / 2, ry: (height != null ? height : width) / 2 }) - .center() - }, - // Custom center function - center: function(x, y) { + , size: function(width, height) { return this.attr({ - cx: x != null ? x : (this.attrs.x || 0) + (this.attrs.rx || 0) - , cy: y != null ? y : (this.attrs.y || 0) + (this.attrs.ry || 0) + rx: width / 2, + ry: height / 2 }) } @@ -1574,47 +1709,45 @@ } // Inherit from SVG.Shape - SVG.Line.prototype = new SVG.Shape() + SVG.Line.prototype = new SVG.Shape // Add required methods SVG.extend(SVG.Line, { - // Move line - move: function(x, y) { - var bbox = this.bbox() + // Move over x-axis + x: function(x) { + var b = this.bbox() return this.attr({ - x1: this.attr('x1') - bbox.x + x - , y1: this.attr('y1') - bbox.y + y - , x2: this.attr('x2') - bbox.x + x - , y2: this.attr('y2') - bbox.y + y + x1: this.attrs.x1 - b.x + x + , x2: this.attrs.x2 - b.x + x }) } - // Move element by its center - , center: function(x, y) { - var bbox = this.bbox() + // Move over y-axis + , y: function(y) { + var b = this.bbox() - return this.move(x - bbox.width / 2, y - bbox.height / 2) + return this.attr({ + y1: this.attrs.y1 - b.y + y + , y2: this.attrs.y2 - b.y + y + }) + } + // Move by center over x-axis + , cx: function(x) { + return this.x(x - this.bbox().width / 2) + } + // Move by center over y-axis + , cy: function(y) { + return this.y(y - this.bbox().height / 2) } // Set line size by width and height , size: function(width, height) { - var bbox = this.bbox() + var b = this.bbox() return this - .attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', bbox.x + width) - .attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', bbox.y + height) - } - }) - - // Extend all container modules - SVG.extend(SVG.Container, { - line: function(x1, y1, x2, y2) { - return this.put(new SVG.Line().attr({ - x1: x1 - , y1: y1 - , x2: x2 - , y2: y2 - })) + .attr(this.attrs.x1 < this.attrs.x2 ? 'x2' : 'x1', b.x + width) + .attr(this.attrs.y1 < this.attrs.y2 ? 'y2' : 'y1', b.y + height) } + }) SVG.Poly = { @@ -1654,14 +1787,14 @@ SVG.Path.prototype = new SVG.Shape() SVG.extend(SVG.Path, { - // Move using transform - move: function(x, y) { - this.transform({ - x: x, - y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis + , y: function(y) { + return this.transform('y', y) } - // Set path data , plot: function(data) { return this.attr('d', data || 'M0,0') @@ -1874,6 +2007,10 @@ scaleY: y == null ? x : y }) } + // Matrix + , matrix: function(m) { + return this.transform({ matrix: m }) + } // Opacity , opacity: function(value) { return this.attr('opacity', value) diff --git a/dist/svg.min.js b/dist/svg.min.js index b406ded..0893efb 100644 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1,2 +1,2 @@ -/* svg.js v0.9 - svg regex color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar - svgjs.com/license */ -(function(){this.SVG=function(e){if(SVG.supported)return new SVG.Doc(e)},this.svg=function(e){return console.warn("WARNING: svg() is deprecated, please use SVG() instead."),SVG(e)},SVG.ns="http://www.w3.org/2000/svg",SVG.xlink="http://www.w3.org/1999/xlink",SVG.did=1e3,SVG.eid=function(e){return"Svgjs"+e.charAt(0).toUpperCase()+e.slice(1)+"Element"+SVG.did++},SVG.create=function(e){var t=document.createElementNS(this.ns,e);return t.setAttribute("id",this.eid(e)),t},SVG.extend=function(){var e,t,n,r;e=Array.prototype.slice.call(arguments),t=e.pop();for(r=e.length-1;r>=0;r--)if(e[r])for(n in t)e[r].prototype[n]=t[n]},SVG.supported=function(){return!!document.createElementNS&&!!document.createElementNS(SVG.ns,"svg").createSVGRect}();if(!SVG.supported)return!1;SVG.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+),([\d\.]+)\)/,hsb:/hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isHsb:/^hsb\(/,isCss:/[^:]+:[^;]+;?/,isStyle:/^font|text|leading|cursor/,isBlank:/^(\s+)?$/},SVG.Color=function(e){var t;this.r=0,this.g=0,this.b=0,typeof e=="string"?SVG.regex.isRgb.test(e)?(t=SVG.regex.rgb.exec(e.replace(/\s/g,"")),this.r=parseInt(m[1]),this.g=parseInt(m[2]),this.b=parseInt(m[3])):SVG.regex.isHex.test(e)?(t=SVG.regex.hex.exec(this._fullHex(e)),this.r=parseInt(t[1],16),this.g=parseInt(t[2],16),this.b=parseInt(t[3],16)):SVG.regex.isHsb.test(e)&&(t=SVG.regex.hsb.exec(e.replace(/\s/g,"")),e=this._hsbToRgb(t[1],t[2],t[3])):typeof e=="object"&&(SVG.Color.isHsb(e)&&(e=this._hsbToRgb(e.h,e.s,e.b)),this.r=e.r,this.g=e.g,this.b=e.b)},SVG.extend(SVG.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+this._compToHex(this.r)+this._compToHex(this.g)+this._compToHex(this.b)},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},_hsbToRgb:function(e,t,n){var i,s;e=parseInt(e)%360,e<0&&(e+=360),t=parseInt(t),t=t>100?100:t,n=parseInt(n),n=(n<0?0:n>100?100:n)*255/100,i=n*t/100,s=i*(e*256/60%256)/256;switch(Math.floor(e/60)){case 0:r=n,g=n-i+s,b=n-i;break;case 1:r=n-s,g=n,b=n-i;break;case 2:r=n-i,g=n,b=n-i+s;break;case 3:r=n-i,g=n-s,b=n;break;case 4:r=n-i+s,g=n-i,b=n;break;case 5:r=n,g=n-i,b=n-s}return{r:Math.floor(r+.5),g:Math.floor(g+.5),b:Math.floor(b+.5)}},_fullHex:function(e){return e.length==4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e},_compToHex:function(e){var t=e.toString(16);return t.length==1?"0"+t:t}}),SVG.Color.test=function(e){return e+="",SVG.regex.isHex.test(e)||SVG.regex.isRgb.test(e)||SVG.regex.isHsb.test(e)},SVG.Color.isRgb=function(e){return typeof e.r=="number"},SVG.Color.isHsb=function(e){return typeof e.h=="number"},SVG.ViewBox=function(e){var t,n,r,i,s=e.bbox(),o=(e.attr("viewBox")||"").match(/[\d\.]+/g);this.x=s.x,this.y=s.y,this.width=e.node.offsetWidth||e.attr("width"),this.height=e.node.offsetHeight||e.attr("height"),o&&(t=parseFloat(o[0]),n=parseFloat(o[1]),r=parseFloat(o[2])-t,i=parseFloat(o[3])-n,this.zoom=this.width/this.height>r/i?this.height/i:this.width/r,this.x=t,this.y=n,this.width=r,this.height=i),this.zoom=this.zoom||1},SVG.extend(SVG.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),SVG.BBox=function(e){var t=e.node.getBBox();this.x=t.x+e.trans.x,this.y=t.y+e.trans.y,this.cx=t.x+e.trans.x+t.width/2,this.cy=t.y+e.trans.y+t.height/2,this.width=t.width,this.height=t.height},SVG.Element=function(e){this.attrs={"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,fill:"#000",stroke:"#000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0},this.styles={},this.trans={x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0};if(this.node=e)this.type=e.nodeName,this.attrs.id=e.getAttribute("id")},SVG.extend(SVG.Element,{move:function(e,t){return this.attr({x:e,y:t})},center:function(e,t){var n=this.bbox();return this.move(e-n.width/2,t-n.height/2)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e;if(this instanceof SVG.Wrap)e=this.parent[this.child.node.nodeName](),e.attrs=this.attrs,e.child.trans=this.child.trans,e.child.attr(this.child.attrs).transform({}),e.plot&&e.plot(this.child.attrs[this.child instanceof SVG.Path?"d":"points"]);else{var t=this.node.nodeName;e=t=="rect"?this.parent[t](this.attrs.width,this.attrs.height):t=="ellipse"?this.parent[t](this.attrs.rx*2,this.attrs.ry*2):t=="image"?this.parent[t](this.src):t=="text"?this.parent[t](this.content):t=="g"?this.parent.group():this.parent[t](),e.attr(this.attrs)}return e.trans=this.trans,e.transform({})},remove:function(){return this.parent&&this.parent.remove(this),this},doc:function(){return this._parent(SVG.Doc)},nested:function(){return this._parent(SVG.Nested)},attr:function(e,t,n){if(arguments.length<2){if(typeof e!="object")return this._isStyle(e)?e=="text"?this.content:e=="leading"?this.leading():this.style(e):this.attrs[e]||this.node.getAttribute(e);for(t in e)this.attr(t,e[t])}else if(t===null)this.node.removeAttribute(e);else{if(e=="style")return this.style(t);this.attrs[e]=t;if(e=="x"&&this._isText())for(var r=this.lines.length-1;r>=0;r--)this.lines[r].attr(e,t);else{e=="stroke-width"&&this.attr("stroke",parseFloat(t)>0?this.attrs.stroke:null);if(SVG.Color.test(t)||SVG.Color.isRgb(t)||SVG.Color.isHsb(t))t=(new SVG.Color(t)).toHex();n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)}this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"?this.leading(t):this.style(e,t),this.rebuild&&this.rebuild())}return this},transform:function(e,t){if(typeof e=="string"){if(arguments.length<2)return this.trans[e];var n={};return n[e]=t,this.transform(n)}var n=[];for(t in e)e[t]!=null&&(this.trans[t]=e[t]);return e=this.trans,e.rotation!=0&&n.push("rotate("+e.rotation+","+(e.cx!=null?e.cx:this.bbox().cx)+","+(e.cy!=null?e.cy:this.bbox().cy)+")"),n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),n.push("translate("+e.x+","+e.y+")"),this.attr("transform",n.join(" "))},style:function(e,t){if(arguments.length==0)return this.attr("style");if(arguments.length<2)if(typeof e=="object")for(t in e)this.style(t,e[t]);else{if(!SVG.regex.isCss.test(e))return this.styles[e];e=e.split(";");for(var n=0;nn.x&&t>n.y&&e=0},children:function(){return this._children||(this._children=[])},each:function(e){var t,n=this.children();for(t=0,length=n.length;t";var n,r,i,s=this.target,o=this,u=(new Date).getTime(),a=u+e;return this.interval=setInterval(function(){var f,l,c=(new Date).getTime(),h=c>a?1:(c-u)/e;if(n==null){n=[];for(l in o.attrs)n.push(l)}if(r==null){r=[];for(l in o.trans)r.push(l)}if(i==null){i=[];for(l in o.styles)i.push(l)}h=t=="<>"?-Math.cos(h*Math.PI)/2+.5:t==">"?Math.sin(h*Math.PI/2):t=="<"?-Math.cos(h*Math.PI/2)+1:t=="-"?h:typeof t=="function"?t(h):h,o._move?s.move(o._at(o._move.x,h),o._at(o._move.y,h)):o._center&&s.center(o._at(o._center.x,h),o._at(o._center.y,h)),o._size&&s.size(o._at(o._size.width,h),o._at(o._size.height,h));for(f=n.length-1;f>=0;f--)s.attr(n[f],o._at(o.attrs[n[f]],h));for(f=r.length-1;f>=0;f--)s.transform(r[f],o._at(o.trans[r[f]],h));for(f=i.length-1;f>=0;f--)s.style(i[f],o._at(o.styles[i[f]],h));o._during&&o._during.call(s,h,function(e,t){return o._at({from:e,to:t},h)}),c>a&&(clearInterval(o.interval),o._after?o._after.apply(s,[o]):o.stop())},e>10?10:e),this},attr:function(e,t,n){if(typeof e=="object")for(var r in e)this.attr(r,e[r]);else this.attrs[e]={from:this.target.attr(e),to:t};return this},transform:function(e,t){for(var n in e)this.trans[n]={from:this.target.trans[n],to:e[n]};return this},style:function(e,t){if(typeof e=="object")for(var n in e)this.style(n,e[n]);else this.styles[e]={from:this.target.style(e),to:t};return this},move:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.x,to:e},y:{from:n.y,to:t}},this},size:function(e,t){if(this.target instanceof SVG.Text)this.attr("font-size",e);else{var n=this.target.bbox();this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}}}return this},center:function(e,t){var n=this.target.bbox();return this._move={x:{from:n.cx,to:e-n.width/2},y:{from:n.cy,to:t-n.height/2}},this},during:function(e){return this._during=e,this},after:function(e){return this._after=e,this},stop:function(){return clearInterval(this.interval),this.attrs={},this.trans={},this.styles={},this._move=null,this._size=null,this._after=null,this._during=null,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:SVG.regex.unit.test(e.to)?this._unit(e,t):e.to&&(e.to.r||SVG.Color.test(e.to))?this._color(e,t):t<1?e.from:e.to},_unit:function(e,t){var n,r;return n=SVG.regex.unit.exec(e.from.toString()),r=parseFloat(n[1]),n=SVG.regex.unit.exec(e.to),r+(parseFloat(n[1])-r)*t+n[2]},_color:function(e,t){var n,r;return t=t<0?0:t>1?1:t,n=new SVG.Color(e.from),r=new SVG.Color(e.to),(new SVG.Color({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})).toHex()}}),SVG.extend(SVG.Element,{animate:function(e,t){return(this.fx||(this.fx=new SVG.FX(this))).stop().animate(e,t)},stop:function(){return this.fx.stop(),this}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchend","touchmove","touchcancel"].forEach(function(e){SVG.Element.prototype[e]=function(t){var n=this;return this.node["on"+e]=typeof t=="function"?function(){return t.apply(n,arguments)}:null,this}}),SVG.on=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},SVG.off=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},SVG.extend(SVG.Element,{on:function(e,t){return SVG.on(this.node,e,t),this},off:function(e,t){return SVG.off(this.node,e,t),this}}),SVG.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Container,SVG.extend(SVG.G,{move:function(e,t){return this.transform({x:e,y:t})},defs:function(){return this.doc().defs()}}),SVG.extend(SVG.Element,{siblings:function(){return this.parent.children()},position:function(){return this.siblings().indexOf(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){return this.parent.remove(this).put(this,this.position()+1)},backward:function(){this.parent.level();var e=this.position();return e>1&&this.parent.remove(this).add(this,e-1),this},front:function(){return this.parent.remove(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.remove(this).add(this,0),this}}),SVG.Defs=function(){this.constructor.call(this,SVG.create("defs"))},SVG.Defs.prototype=new SVG.Container,SVG.Mask=function(){this.constructor.call(this,SVG.create("mask"))},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.mask=e instanceof SVG.Mask?e:this.parent.mask().add(e),this.attr("mask","url(#"+this.mask.attr("id")+")")}}),SVG.Pattern=function(e){this.constructor.call(this,SVG.create("pattern"))},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{pattern:function(e,t,n){var r=this.put(new SVG.Pattern);return n(r),r.attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})}}),SVG.Gradient=function(e){this.constructor.call(this,SVG.create(e+"Gradient")),this.type=e},SVG.Gradient.prototype=new SVG.Container,SVG.extend(SVG.Gradient,{from:function(e,t){return this.type=="radial"?this.attr({fx:e+"%",fy:t+"%"}):this.attr({x1:e+"%",y1:t+"%"})},to:function(e,t){return this.type=="radial"?this.attr({cx:e+"%",cy:t+"%"}):this.attr({x2:e+"%",y2:t+"%"})},radius:function(e){return this.type=="radial"?this.attr({r:e+"%"}):this},at:function(e){return this.put(new SVG.Stop(e))},update:function(e){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return e(this),this},fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(e){this.constructor.call(this,SVG.create("stop")),this.update(e)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n=["opacity","color"];for(t=n.length-1;t>=0;t--)e[n[t]]!=null&&this.style("stop-"+n[t],e[n[t]]);return this.attr("offset",(e.offset!=null?e.offset:this.attrs.offset||0)+"%")}}),SVG.Doc=function(e){this.constructor.call(this,SVG.create("svg")),this.parent=typeof e=="string"?document.getElementById(e):e,this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.stage()},SVG.Doc.prototype=new SVG.Container,SVG.Doc.prototype.stage=function(){var e,t=this,n=document.createElement("div");return n.style.cssText="position:relative;height:100%;",t.parent.appendChild(n),n.appendChild(t.node),e=function(){document.readyState==="complete"?(t.style("position:absolute;"),setTimeout(function(){t.style("position:relative;"),t.parent.removeChild(t.node.parentNode),t.node.parentNode.removeChild(t.node),t.parent.appendChild(t.node)},5)):setTimeout(e,10)},e(),this},SVG.Shape=function(e){this.constructor.call(this,e)},SVG.Shape.prototype=new SVG.Element,SVG.Wrap=function(e){this.constructor.call(this,SVG.create("g")),this.node.insertBefore(e.node,null),this.child=e,this.type=e.node.nodeName},SVG.Wrap.prototype=new SVG.Shape,SVG.extend(SVG.Wrap,{move:function(e,t){return this.transform({x:e,y:t})},size:function(e,t){var n=e/this._b.width;return this.child.transform({scaleX:n,scaleY:t!=null?t/this._b.height:n}),this},center:function(e,t){return this.move(e+this._b.width*this.child.trans.scaleX/-2,t+this._b.height*this.child.trans.scaleY/-2)},attr:function(e,t,n){if(typeof e=="object")for(t in e)this.attr(t,e[t]);else{if(arguments.length<2)return e=="transform"?this.attrs[e]:this.child.attrs[e];e=="transform"?(this.attrs[e]=t,n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)):this.child.attr(e,t,n)}return this},plot:function(e){return this.child.plot(e),this._b=this.child.bbox(),this.child.transform({x:-this._b.x,y:-this._b.y}),this}}),SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Ellipse=function(){this.constructor.call(this,SVG.create("ellipse"))},SVG.Ellipse.prototype=new SVG.Shape,SVG.extend(SVG.Ellipse,{move:function(e,t){return this.attrs.x=e,this.attrs.y=t,this.center()},size:function(e,t){return this.attr({rx:e/2,ry:(t!=null?t:e)/2}).center()},center:function(e,t){return this.attr({cx:e!=null?e:(this.attrs.x||0)+(this.attrs.rx||0),cy:t!=null?t:(this.attrs.y||0)+(this.attrs.ry||0)})}}),SVG.Line=function(){this.constructor.call(this,SVG.create("line"))},SVG.Line.prototype=new SVG.Shape,SVG.extend(SVG.Line,{move:function(e,t){var n=this.bbox();return this.attr({x1:this.attr("x1")-n.x+e,y1:this.attr("y1")-n.y+t,x2:this.attr("x2")-n.x+e,y2:this.attr("y2")-n.y+t})},center:function(e,t){var n=this.bbox();return this.move(e-n.width/2,t-n.height/2)},size:function(e,t){var n=this.bbox();return this.attr(this.attr("x1")=0;index--)n[SVG["_"+e][index]]!=null&&this.attr(t(e,SVG["_"+e][index]),n[SVG["_"+e][index]]);return this},SVG.extend(SVG.Shape,SVG.FX,n)}),SVG.extend(SVG.Element,SVG.FX,{rotate:function(e,t,n){return this.transform({rotation:e||0,cx:t,cy:n})},skew:function(e,t){return this.transform({skewX:e||0,skewY:t||0})},scale:function(e,t){return this.transform({scaleX:e,scaleY:t==null?e:t})},opacity:function(e){return this.attr("opacity",e)}}),SVG.Text&&SVG.extend(SVG.Text,SVG.FX,{font:function(t){for(var n in t)n=="anchor"?this.attr("text-anchor",t[n]):e.indexOf(n)>-1?this.attr("font-"+n,t[n]):this.attr(n,t[n]);return this}})}).call(this); \ No newline at end of file +/* svg.js v0.10 - svg regex default color viewbox bbox element container fx event group arrange defs mask pattern gradient doc shape wrap rect ellipse line poly path image text nested sugar - svgjs.com/license */ +(function(){this.SVG=function(e){if(SVG.supported)return new SVG.Doc(e)},this.svg=function(e){return console.warn("WARNING: svg() is deprecated, please use SVG() instead."),SVG(e)},SVG.ns="http://www.w3.org/2000/svg",SVG.xlink="http://www.w3.org/1999/xlink",SVG.did=1e3,SVG.eid=function(e){return"Svgjs"+e.charAt(0).toUpperCase()+e.slice(1)+"Element"+SVG.did++},SVG.create=function(e){var t=document.createElementNS(this.ns,e);return t.setAttribute("id",this.eid(e)),t},SVG.extend=function(){var e,t,n,r;e=Array.prototype.slice.call(arguments),t=e.pop();for(r=e.length-1;r>=0;r--)if(e[r])for(n in t)e[r].prototype[n]=t[n]},SVG.supported=function(){return!!document.createElementNS&&!!document.createElementNS(SVG.ns,"svg").createSVGRect}();if(!SVG.supported)return!1;SVG.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+),([\d\.]+)\)/,hsb:/hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isHsb:/^hsb\(/,isCss:/[^:]+:[^;]+;?/,isStyle:/^font|text|leading|cursor/,isBlank:/^(\s+)?$/},SVG.default={matrix:"1,0,0,1,0,0",attrs:function(){return{"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,fill:"#000",stroke:"#000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0}},trans:function(){return{x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0,matrix:this.matrix,a:1,b:0,c:0,d:1,e:0,f:0}}},SVG.Color=function(e){var t;this.r=0,this.g=0,this.b=0,typeof e=="string"?SVG.regex.isRgb.test(e)?(t=SVG.regex.rgb.exec(e.replace(/\s/g,"")),this.r=parseInt(m[1]),this.g=parseInt(m[2]),this.b=parseInt(m[3])):SVG.regex.isHex.test(e)?(t=SVG.regex.hex.exec(this._fullHex(e)),this.r=parseInt(t[1],16),this.g=parseInt(t[2],16),this.b=parseInt(t[3],16)):SVG.regex.isHsb.test(e)&&(t=SVG.regex.hsb.exec(e.replace(/\s/g,"")),e=this._hsbToRgb(t[1],t[2],t[3])):typeof e=="object"&&(SVG.Color.isHsb(e)&&(e=this._hsbToRgb(e.h,e.s,e.b)),this.r=e.r,this.g=e.g,this.b=e.b)},SVG.extend(SVG.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+this._compToHex(this.r)+this._compToHex(this.g)+this._compToHex(this.b)},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},_hsbToRgb:function(e,t,n){var i,s;e=parseInt(e)%360,e<0&&(e+=360),t=parseInt(t),t=t>100?100:t,n=parseInt(n),n=(n<0?0:n>100?100:n)*255/100,i=n*t/100,s=i*(e*256/60%256)/256;switch(Math.floor(e/60)){case 0:r=n,g=n-i+s,b=n-i;break;case 1:r=n-s,g=n,b=n-i;break;case 2:r=n-i,g=n,b=n-i+s;break;case 3:r=n-i,g=n-s,b=n;break;case 4:r=n-i+s,g=n-i,b=n;break;case 5:r=n,g=n-i,b=n-s}return{r:Math.floor(r+.5),g:Math.floor(g+.5),b:Math.floor(b+.5)}},_fullHex:function(e){return e.length==4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e},_compToHex:function(e){var t=e.toString(16);return t.length==1?"0"+t:t}}),SVG.Color.test=function(e){return e+="",SVG.regex.isHex.test(e)||SVG.regex.isRgb.test(e)||SVG.regex.isHsb.test(e)},SVG.Color.isRgb=function(e){return typeof e.r=="number"},SVG.Color.isHsb=function(e){return typeof e.h=="number"},SVG.ViewBox=function(e){var t,n,r,i,s=e.bbox(),o=(e.attr("viewBox")||"").match(/[\d\.]+/g);this.x=s.x,this.y=s.y,this.width=e.node.offsetWidth||e.attr("width"),this.height=e.node.offsetHeight||e.attr("height"),o&&(t=parseFloat(o[0]),n=parseFloat(o[1]),r=parseFloat(o[2])-t,i=parseFloat(o[3])-n,this.zoom=this.width/this.height>r/i?this.height/i:this.width/r,this.x=t,this.y=n,this.width=r,this.height=i),this.zoom=this.zoom||1},SVG.extend(SVG.ViewBox,{toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height}}),SVG.BBox=function(e){var t=e.node.getBBox();this.x=t.x+e.trans.x,this.y=t.y+e.trans.y,this.cx=t.x+e.trans.x+t.width/2,this.cy=t.y+e.trans.y+t.height/2,this.width=t.width,this.height=t.height},SVG.Element=function(e){this.attrs=SVG.default.attrs(),this.styles={},this.trans=SVG.default.trans();if(this.node=e)this.type=e.nodeName,this.attrs.id=e.getAttribute("id")},SVG.extend(SVG.Element,{x:function(e){return this.attr("x",e)},y:function(e){return this.attr("y",e)},cx:function(e){return this.x(e-this.bbox().width/2)},cy:function(e){return this.y(e-this.bbox().height/2)},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e;if(this instanceof SVG.Wrap)e=this.parent[this.child.node.nodeName](),e.attrs=this.attrs,e.child.trans=this.child.trans,e.child.attr(this.child.attrs).transform({}),e.plot&&e.plot(this.child.attrs[this.child instanceof SVG.Path?"d":"points"]);else{var t=this.node.nodeName;e=t=="rect"?this.parent[t](this.attrs.width,this.attrs.height):t=="ellipse"?this.parent[t](this.attrs.rx*2,this.attrs.ry*2):t=="image"?this.parent[t](this.src):t=="text"?this.parent[t](this.content):t=="g"?this.parent.group():this.parent[t](),e.attr(this.attrs)}return e.trans=this.trans,e.transform({})},remove:function(){return this.parent&&this.parent.remove(this),this},doc:function(){return this._parent(SVG.Doc)},nested:function(){return this._parent(SVG.Nested)},attr:function(e,t,n){if(arguments.length<2){if(typeof e!="object")return this._isStyle(e)?e=="text"?this.content:e=="leading"?this.leading():this.style(e):this.attrs[e]||this.node.getAttribute(e);for(t in e)this.attr(t,e[t])}else if(t===null)this.node.removeAttribute(e);else{if(e=="style")return this.style(t);if(e=="transform")return this.transform(t);this.attrs[e]=t;if(e=="x"&&this._isText())for(var r=this.lines.length-1;r>=0;r--)this.lines[r].attr(e,t);else{e=="stroke-width"&&this.attr("stroke",parseFloat(t)>0?this.attrs.stroke:null);if(SVG.Color.test(t)||SVG.Color.isRgb(t)||SVG.Color.isHsb(t))t=(new SVG.Color(t)).toHex();n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)}this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"?this.leading(t):this.style(e,t),this.rebuild&&this.rebuild())}return this},transform:function(e,t){if(typeof e=="string"){if(arguments.length<2)return this.trans[e];var n={};return n[e]=t,this.transform(n)}var n=[];e=this._parseMatrix(e);for(t in e)e[t]!=null&&(this.trans[t]=e[t]);return this.trans.matrix=this.trans.a+","+this.trans.b+","+this.trans.c+","+this.trans.d+","+this.trans.e+","+this.trans.f,e=this.trans,e.matrix!=SVG.default.matrix&&n.push("matrix("+e.matrix+")"),e.rotation!=0&&n.push("rotate("+e.rotation+","+(e.cx!=null?e.cx:this.bbox().cx)+","+(e.cy!=null?e.cy:this.bbox().cy)+")"),(e.scaleX!=1||e.scaleY!=1)&&n.push("scale("+e.scaleX+","+e.scaleY+")"),e.skewX!=0&&n.push("skewX("+e.skewX+")"),e.skewY!=0&&n.push("skewY("+e.skewY+")"),(e.x!=0||e.y!=0)&&n.push("translate("+e.x+","+e.y+")"),this.node.setAttribute("transform",n.join(" ")),this},style:function(e,t){if(arguments.length==0)return this.attr("style");if(arguments.length<2)if(typeof e=="object")for(t in e)this.style(t,e[t]);else{if(!SVG.regex.isCss.test(e))return this.styles[e];e=e.split(";");for(var n=0;nn.x&&t>n.y&&e=0},children:function(){return this._children||(this._children=[])},each:function(e){var t,n=this.children();for(t=0,length=n.length;t";var n,r,i,s=this.target,o=this,u=(new Date).getTime(),a=u+e;return this.interval=setInterval(function(){var f,l,c=(new Date).getTime(),h=c>a?1:(c-u)/e;if(n==null){n=[];for(l in o.attrs)n.push(l)}if(r==null){r=[];for(l in o.trans)r.push(l)}if(i==null){i=[];for(l in o.styles)i.push(l)}h=t=="<>"?-Math.cos(h*Math.PI)/2+.5:t==">"?Math.sin(h*Math.PI/2):t=="<"?-Math.cos(h*Math.PI/2)+1:t=="-"?h:typeof t=="function"?t(h):h,o._x?s.x(o._at(o._x,h)):o._cx&&s.cx(o._at(o._cx,h)),o._y?s.y(o._at(o._y,h)):o._cy&&s.cy(o._at(o._cy,h)),o._size&&s.size(o._at(o._size.width,h),o._at(o._size.height,h));for(f=n.length-1;f>=0;f--)s.attr(n[f],o._at(o.attrs[n[f]],h));for(f=r.length-1;f>=0;f--)s.transform(r[f],o._at(o.trans[r[f]],h));for(f=i.length-1;f>=0;f--)s.style(i[f],o._at(o.styles[i[f]],h));o._during&&o._during.call(s,h,function(e,t){return o._at({from:e,to:t},h)}),c>a&&(clearInterval(o.interval),o._after?o._after.apply(s,[o]):o.stop())},e>10?10:e),this},bbox:function(){return this.target.bbox()},attr:function(e,t,n){if(typeof e=="object")for(var r in e)this.attr(r,e[r]);else this.attrs[e]={from:this.target.attr(e),to:t};return this},transform:function(e,t){if(arguments.length==1){e=this.target._parseMatrix(e),delete e.matrix;for(t in e)this.trans[t]={from:this.target.trans[t],to:e[t]}}else{var n={};n[e]=t,this.transform(n)}return this},style:function(e,t){if(typeof e=="object")for(var n in e)this.style(n,e[n]);else this.styles[e]={from:this.target.style(e),to:t};return this},x:function(e){var t=this.bbox();return this._x={from:t.x,to:e},this},y:function(e){var t=this.bbox();return this._y={from:t.y,to:e},this},cx:function(e){var t=this.bbox();return this._cx={from:t.cx,to:e},this},cy:function(e){var t=this.bbox();return this._cy={from:t.cy,to:e},this},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){if(this.target instanceof SVG.Text)this.attr("font-size",e);else{var n=this.target.bbox();this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}}}return this},during:function(e){return this._during=e,this},after:function(e){return this._after=e,this},stop:function(){return clearInterval(this.interval),this.attrs={},this.trans={},this.styles={},this._move=null,this._size=null,this._after=null,this._during=null,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:SVG.regex.unit.test(e.to)?this._unit(e,t):e.to&&(e.to.r||SVG.Color.test(e.to))?this._color(e,t):t<1?e.from:e.to},_unit:function(e,t){var n,r;return n=SVG.regex.unit.exec(e.from.toString()),r=parseFloat(n[1]),n=SVG.regex.unit.exec(e.to),r+(parseFloat(n[1])-r)*t+n[2]},_color:function(e,t){var n,r;return t=t<0?0:t>1?1:t,n=new SVG.Color(e.from),r=new SVG.Color(e.to),(new SVG.Color({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})).toHex()}}),SVG.extend(SVG.Element,{animate:function(e,t){return(this.fx||(this.fx=new SVG.FX(this))).stop().animate(e,t)},stop:function(){return this.fx.stop(),this}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchend","touchmove","touchcancel"].forEach(function(e){SVG.Element.prototype[e]=function(t){var n=this;return this.node["on"+e]=typeof t=="function"?function(){return t.apply(n,arguments)}:null,this}}),SVG.on=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},SVG.off=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},SVG.extend(SVG.Element,{on:function(e,t){return SVG.on(this.node,e,t),this},off:function(e,t){return SVG.off(this.node,e,t),this}}),SVG.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Container,SVG.extend(SVG.G,{x:function(e){return this.transform("x",e)},y:function(e){return this.transform("y",e)},defs:function(){return this.doc().defs()}}),SVG.extend(SVG.Element,{siblings:function(){return this.parent.children()},position:function(){return this.siblings().indexOf(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){return this.parent.remove(this).put(this,this.position()+1)},backward:function(){this.parent.level();var e=this.position();return e>1&&this.parent.remove(this).add(this,e-1),this},front:function(){return this.parent.remove(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.remove(this).add(this,0),this}}),SVG.Defs=function(){this.constructor.call(this,SVG.create("defs"))},SVG.Defs.prototype=new SVG.Container,SVG.Mask=function(){this.constructor.call(this,SVG.create("mask"))},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.mask=e instanceof SVG.Mask?e:this.parent.mask().add(e),this.attr("mask","url(#"+this.mask.attr("id")+")")}}),SVG.Pattern=function(e){this.constructor.call(this,SVG.create("pattern"))},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{pattern:function(e,t,n){var r=this.put(new SVG.Pattern);return n(r),r.attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})}}),SVG.Gradient=function(e){this.constructor.call(this,SVG.create(e+"Gradient")),this.type=e},SVG.Gradient.prototype=new SVG.Container,SVG.extend(SVG.Gradient,{from:function(e,t){return this.type=="radial"?this.attr({fx:e+"%",fy:t+"%"}):this.attr({x1:e+"%",y1:t+"%"})},to:function(e,t){return this.type=="radial"?this.attr({cx:e+"%",cy:t+"%"}):this.attr({x2:e+"%",y2:t+"%"})},radius:function(e){return this.type=="radial"?this.attr({r:e+"%"}):this},at:function(e){return this.put(new SVG.Stop(e))},update:function(e){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return e(this),this},fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(e){this.constructor.call(this,SVG.create("stop")),this.update(e)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n=["opacity","color"];for(t=n.length-1;t>=0;t--)e[n[t]]!=null&&this.style("stop-"+n[t],e[n[t]]);return this.attr("offset",(e.offset!=null?e.offset:this.attrs.offset||0)+"%")}}),SVG.Doc=function(e){this.constructor.call(this,SVG.create("svg")),this.parent=typeof e=="string"?document.getElementById(e):e,this.attr({xmlns:SVG.ns,version:"1.1",width:"100%",height:"100%"}).attr("xlink",SVG.xlink,SVG.ns).defs(),this.stage()},SVG.Doc.prototype=new SVG.Container,SVG.Doc.prototype.stage=function(){var e,t=this,n=document.createElement("div");return n.style.cssText="position:relative;height:100%;",t.parent.appendChild(n),n.appendChild(t.node),e=function(){document.readyState==="complete"?(t.style("position:absolute;"),setTimeout(function(){t.style("position:relative;"),t.parent.removeChild(t.node.parentNode),t.node.parentNode.removeChild(t.node),t.parent.appendChild(t.node)},5)):setTimeout(e,10)},e(),this},SVG.Shape=function(e){this.constructor.call(this,e)},SVG.Shape.prototype=new SVG.Element,SVG.Wrap=function(e){this.constructor.call(this,SVG.create("g")),this.node.insertBefore(e.node,null),this.child=e,this.type=e.node.nodeName},SVG.Wrap.prototype=new SVG.Shape,SVG.extend(SVG.Wrap,{x:function(e){return this.transform("x",e)},y:function(e){return this.transform("y",e)},size:function(e,t){var n=e/this._b.width;return this.child.transform({scaleX:n,scaleY:t!=null?t/this._b.height:n}),this},center:function(e,t){return this.move(e+this._b.width*this.child.trans.scaleX/-2,t+this._b.height*this.child.trans.scaleY/-2)},attr:function(e,t,n){if(typeof e=="object")for(t in e)this.attr(t,e[t]);else{if(arguments.length<2)return e=="transform"?this.attrs[e]:this.child.attrs[e];e=="transform"?(this.attrs[e]=t,n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t)):this.child.attr(e,t,n)}return this},plot:function(e){return this.child.plot(e),this._b=this.child.bbox(),this.child.transform({x:-this._b.x,y:-this._b.y}),this}}),SVG.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Ellipse=function(){this.constructor.call(this,SVG.create("ellipse"))},SVG.Ellipse.prototype=new SVG.Shape,SVG.extend(SVG.Ellipse,{x:function(e){return this.cx(e+this.attrs.rx)},y:function(e){return this.cy(e+this.attrs.ry)},cx:function(e){return this.attr("cx",e)},cy:function(e){return this.attr("cy",e)},size:function(e,t){return this.attr({rx:e/2,ry:t/2})}}),SVG.Line=function(){this.constructor.call(this,SVG.create("line"))},SVG.Line.prototype=new SVG.Shape,SVG.extend(SVG.Line,{x:function(e){var t=this.bbox();return this.attr({x1:this.attrs.x1-t.x+e,x2:this.attrs.x2-t.x+e})},y:function(e){var t=this.bbox();return this.attr({y1:this.attrs.y1-t.y+e,y2:this.attrs.y2-t.y+e})},cx:function(e){return this.x(e-this.bbox().width/2)},cy:function(e){return this.y(e-this.bbox().height/2)},size:function(e,t){var n=this.bbox();return this.attr(this.attrs.x1=0;index--)n[SVG["_"+e][index]]!=null&&this.attr(t(e,SVG["_"+e][index]),n[SVG["_"+e][index]]);return this},SVG.extend(SVG.Shape,SVG.FX,n)}),SVG.extend(SVG.Element,SVG.FX,{rotate:function(e,t,n){return this.transform({rotation:e||0,cx:t,cy:n})},skew:function(e,t){return this.transform({skewX:e||0,skewY:t||0})},scale:function(e,t){return this.transform({scaleX:e,scaleY:t==null?e:t})},matrix:function(e){return this.transform({matrix:e})},opacity:function(e){return this.attr("opacity",e)}}),SVG.Text&&SVG.extend(SVG.Text,SVG.FX,{font:function(t){for(var n in t)n=="anchor"?this.attr("text-anchor",t[n]):e.indexOf(n)>-1?this.attr("font-"+n,t[n]):this.attr(n,t[n]);return this}})}).call(this); \ No newline at end of file diff --git a/src/container.js b/src/container.js index fd41a96..3549bee 100644 --- a/src/container.js +++ b/src/container.js @@ -78,12 +78,16 @@ SVG.extend(SVG.Container, { return this.put(new SVG.Rect().size(width, height)) } // Create circle element, based on ellipse -, circle: function(diameter) { - return this.ellipse(diameter) +, circle: function(size) { + return this.ellipse(size, size) } // Create an ellipse , ellipse: function(width, height) { - return this.put(new SVG.Ellipse().size(width, height)) + return this.put(new SVG.Ellipse().size(width, height).move(0, 0)) + } + // Create a line element +, line: function(x1, y1, x2, y2) { + return this.put(new SVG.Line().attr({ x1: x1, y1: y1, x2: x2, y2: y2 })) } // Create a wrapped polyline element , polyline: function(points) { diff --git a/src/default.js b/src/default.js new file mode 100644 index 0000000..abcac88 --- /dev/null +++ b/src/default.js @@ -0,0 +1,56 @@ + +SVG.default = { + // Default matrix + matrix: '1,0,0,1,0,0' + + // Default attribute values +, attrs: function() { + return { + /* fill and stroke */ + 'fill-opacity': 1 + , 'stroke-opacity': 1 + , 'stroke-width': 0 + , fill: '#000' + , stroke: '#000' + , opacity: 1 + /* position */ + , x: 0 + , y: 0 + , cx: 0 + , cy: 0 + /* size */ + , width: 0 + , height: 0 + /* radius */ + , r: 0 + , rx: 0 + , ry: 0 + } + } + + // Default transformation values +, trans: function() { + return { + /* translate */ + x: 0 + , y: 0 + /* scale */ + , scaleX: 1 + , scaleY: 1 + /* rotate */ + , rotation: 0 + /* skew */ + , skewX: 0 + , skewY: 0 + /* matrix */ + , matrix: this.matrix + , a: 1 + , b: 0 + , c: 0 + , d: 1 + , e: 0 + , f: 0 + } + } + +} \ No newline at end of file diff --git a/src/element.js b/src/element.js index 2e7ebb2..664bc0f 100644 --- a/src/element.js +++ b/src/element.js @@ -4,59 +4,47 @@ // SVG.Element = function(node) { /* initialize attribute store with defaults */ - this.attrs = { - 'fill-opacity': 1 - , 'stroke-opacity': 1 - , 'stroke-width': 0 - , fill: '#000' - , stroke: '#000' - , opacity: 1 - , x: 0 - , y: 0 - , cx: 0 - , cy: 0 - , width: 0 - , height: 0 - , r: 0 - , rx: 0 - , ry: 0 - } + this.attrs = SVG.default.attrs() /* initialize style store */ this.styles = {} /* initialize transformation store with defaults */ - this.trans = { - x: 0 - , y: 0 - , scaleX: 1 - , scaleY: 1 - , rotation: 0 - , skewX: 0 - , skewY: 0 - } + this.trans = SVG.default.trans() /* keep reference to the element node */ if (this.node = node) { this.type = node.nodeName this.attrs.id = node.getAttribute('id') } + } // SVG.extend(SVG.Element, { + // Move over x-axis + x: function(x) { + return this.attr('x', x) + } + // Move over y-axis +, y: function(y) { + return this.attr('y', y) + } + // Move by center over x-axis +, cx: function(x) { + return this.x(x - this.bbox().width / 2) + } + // Move by center over y-axis +, cy: function(y) { + return this.y(y - this.bbox().height / 2) + } // Move element to given x and y values - move: function(x, y) { - return this.attr({ - x: x - , y: y - }) +, move: function(x, y) { + return this.x(x).y(y) } // Move element by its center , center: function(x, y) { - var box = this.bbox() - - return this.move(x - box.width / 2, y - box.height / 2) + return this.cx(x).cy(y) } // Set element size to given width and height , size: function(width, height) { @@ -150,6 +138,10 @@ SVG.extend(SVG.Element, { } else if (a == 'style') { /* redirect to the style method */ return this.style(v) + + } else if (a == 'transform') { + /* redirect to the transform method*/ + return this.transform(v) } else { /* store value */ @@ -209,14 +201,29 @@ SVG.extend(SVG.Element, { /* ... otherwise continue as a setter */ var transform = [] + /* parse matrix */ + o = this._parseMatrix(o) + /* merge values */ for (v in o) if (o[v] != null) this.trans[v] = o[v] + /* compile matrix */ + this.trans.matrix = this.trans.a + + ',' + this.trans.b + + ',' + this.trans.c + + ',' + this.trans.d + + ',' + this.trans.e + + ',' + this.trans.f + /* alias current transformations */ o = this.trans + /* add matrix */ + if (o.matrix != SVG.default.matrix) + transform.push('matrix(' + o.matrix + ')') + /* add rotation */ if (o.rotation != 0) { transform.push( @@ -227,7 +234,8 @@ SVG.extend(SVG.Element, { } /* add scale */ - transform.push('scale(' + o.scaleX + ',' + o.scaleY + ')') + if (o.scaleX != 1 || o.scaleY != 1) + transform.push('scale(' + o.scaleX + ',' + o.scaleY + ')') /* add skew on x axis */ if (o.skewX != 0) @@ -238,10 +246,13 @@ SVG.extend(SVG.Element, { transform.push('skewY(' + o.skewY + ')') /* add translation */ - transform.push('translate(' + o.x + ',' + o.y + ')') + if (o.x != 0 || o.y != 0) + transform.push('translate(' + o.x + ',' + o.y + ')') /* add only te required transformations */ - return this.attr('transform', transform.join(' ')) + this.node.setAttribute('transform', transform.join(' ')) + + return this } // Dynamic style generator , style: function(s, v) { @@ -346,5 +357,24 @@ SVG.extend(SVG.Element, { , _isText: function() { return this instanceof SVG.Text } + // Private: parse a matrix string +, _parseMatrix: function(o) { + if (o.matrix) { + /* split matrix string */ + var m = o.matrix.replace(/\s/g, '').split(',') + + /* pasrse values */ + if (m.length == 6) { + o.a = parseFloat(m[0]) + o.b = parseFloat(m[1]) + o.c = parseFloat(m[2]) + o.d = parseFloat(m[3]) + o.e = parseFloat(m[4]) + o.f = parseFloat(m[5]) + } + } + + return o + } }) diff --git a/src/ellipse.js b/src/ellipse.js index 6ff5608..1f9ef41 100644 --- a/src/ellipse.js +++ b/src/ellipse.js @@ -4,28 +4,31 @@ SVG.Ellipse = function() { } // Inherit from SVG.Shape -SVG.Ellipse.prototype = new SVG.Shape() +SVG.Ellipse.prototype = new SVG.Shape // SVG.extend(SVG.Ellipse, { - // Custom move function - move: function(x, y) { - this.attrs.x = x - this.attrs.y = y - - return this.center() - }, + // Move over x-axis + x: function(x) { + return this.cx(x + this.attrs.rx) + } + // Move over y-axis +, y: function(y) { + return this.cy(y + this.attrs.ry) + } + // Move by center over x-axis +, cx: function(x) { + return this.attr('cx', x) + } + // Move by center over y-axis +, cy: function(y) { + return this.attr('cy', y) + } // Custom size function - size: function(width, height) { - return this - .attr({ rx: width / 2, ry: (height != null ? height : width) / 2 }) - .center() - }, - // Custom center function - center: function(x, y) { +, size: function(width, height) { return this.attr({ - cx: x != null ? x : (this.attrs.x || 0) + (this.attrs.rx || 0) - , cy: y != null ? y : (this.attrs.y || 0) + (this.attrs.ry || 0) + rx: width / 2, + ry: height / 2 }) } diff --git a/src/fx.js b/src/fx.js index c17dcd8..a9b652d 100644 --- a/src/fx.js +++ b/src/fx.js @@ -58,11 +58,17 @@ SVG.extend(SVG.FX, { ease(pos) : pos - /* run all position properties */ - if (fx._move) - element.move(fx._at(fx._move.x, pos), fx._at(fx._move.y, pos)) - else if (fx._center) - element.center(fx._at(fx._center.x, pos), fx._at(fx._center.y, pos)) + /* run all x-position properties */ + if (fx._x) + element.x(fx._at(fx._x, pos)) + else if (fx._cx) + element.cx(fx._at(fx._cx, pos)) + + /* run all y-position properties */ + if (fx._y) + element.y(fx._at(fx._y, pos)) + else if (fx._cy) + element.cy(fx._at(fx._cy, pos)) /* run all size properties */ if (fx._size) @@ -96,6 +102,10 @@ SVG.extend(SVG.FX, { return this } + // Get bounding box of target element +, bbox: function() { + return this.target.bbox() + } // Add animatable attributes , attr: function(a, v, n) { if (typeof a == 'object') @@ -108,9 +118,25 @@ SVG.extend(SVG.FX, { return this } // Add animatable transformations -, transform: function(t, v) { - for (var key in t) - this.trans[key] = { from: this.target.trans[key], to: t[key] } +, transform: function(o, v) { + if (arguments.length == 1) { + /* parse matrix string */ + o = this.target._parseMatrix(o) + + /* dlete matrixstring from object */ + delete o.matrix + + /* store matrix values */ + for (v in o) + this.trans[v] = { from: this.target.trans[v], to: o[v] } + + } else { + /* apply transformations as object if key value arguments are given*/ + var transform = {} + transform[o] = v + + this.transform(transform) + } return this } @@ -125,17 +151,42 @@ SVG.extend(SVG.FX, { return this } - // Add animatable move -, move: function(x, y) { - var box = this.target.bbox() + // Animatable x-axis +, x: function(x) { + var b = this.bbox() + this._x = { from: b.x, to: x } - this._move = { - x: { from: box.x, to: x } - , y: { from: box.y, to: y } - } + return this + } + // Animatable y-axis +, y: function(y) { + var b = this.bbox() + this._y = { from: b.y, to: y } + + return this + } + // Animatable center x-axis +, cx: function(x) { + var b = this.bbox() + this._cx = { from: b.cx, to: x } return this } + // Animatable center y-axis +, cy: function(y) { + var b = this.bbox() + this._cy = { from: b.cy, to: y } + + return this + } + // Add animatable move +, move: function(x, y) { + return this.x(x).y(y) + } + // Add animatable center +, center: function(x, y) { + return this.cx(x).cy(y) + } // Add animatable size , size: function(width, height) { if (this.target instanceof SVG.Text) { @@ -154,17 +205,6 @@ SVG.extend(SVG.FX, { return this } - // Add animatable center -, center: function(x, y) { - var box = this.target.bbox() - - this._move = { - x: { from: box.cx, to: x - box.width / 2 } - , y: { from: box.cy, to: y - box.height / 2 } - } - - return this - } // Add callback for each keyframe , during: function(during) { this._during = during diff --git a/src/group.js b/src/group.js index fe09c56..a9f046f 100644 --- a/src/group.js +++ b/src/group.js @@ -6,12 +6,13 @@ SVG.G = function() { SVG.G.prototype = new SVG.Container SVG.extend(SVG.G, { - // Move using translate - move: function(x, y) { - return this.transform({ - x: x - , y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis +, y: function(y) { + return this.transform('y', y) } // Get defs , defs: function() { diff --git a/src/line.js b/src/line.js index 0712f1e..7407983 100644 --- a/src/line.js +++ b/src/line.js @@ -3,45 +3,43 @@ SVG.Line = function() { } // Inherit from SVG.Shape -SVG.Line.prototype = new SVG.Shape() +SVG.Line.prototype = new SVG.Shape // Add required methods SVG.extend(SVG.Line, { - // Move line - move: function(x, y) { - var bbox = this.bbox() + // Move over x-axis + x: function(x) { + var b = this.bbox() return this.attr({ - x1: this.attr('x1') - bbox.x + x - , y1: this.attr('y1') - bbox.y + y - , x2: this.attr('x2') - bbox.x + x - , y2: this.attr('y2') - bbox.y + y + x1: this.attrs.x1 - b.x + x + , x2: this.attrs.x2 - b.x + x }) } - // Move element by its center -, center: function(x, y) { - var bbox = this.bbox() + // Move over y-axis +, y: function(y) { + var b = this.bbox() - return this.move(x - bbox.width / 2, y - bbox.height / 2) + return this.attr({ + y1: this.attrs.y1 - b.y + y + , y2: this.attrs.y2 - b.y + y + }) + } + // Move by center over x-axis +, cx: function(x) { + return this.x(x - this.bbox().width / 2) + } + // Move by center over y-axis +, cy: function(y) { + return this.y(y - this.bbox().height / 2) } // Set line size by width and height , size: function(width, height) { - var bbox = this.bbox() + var b = this.bbox() return this - .attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', bbox.x + width) - .attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', bbox.y + height) - } -}) - -// Extend all container modules -SVG.extend(SVG.Container, { - line: function(x1, y1, x2, y2) { - return this.put(new SVG.Line().attr({ - x1: x1 - , y1: y1 - , x2: x2 - , y2: y2 - })) + .attr(this.attrs.x1 < this.attrs.x2 ? 'x2' : 'x1', b.x + width) + .attr(this.attrs.y1 < this.attrs.y2 ? 'y2' : 'y1', b.y + height) } + }) \ No newline at end of file diff --git a/src/path.js b/src/path.js index 2d3558f..4f53892 100644 --- a/src/path.js +++ b/src/path.js @@ -6,14 +6,14 @@ SVG.Path = function() { SVG.Path.prototype = new SVG.Shape() SVG.extend(SVG.Path, { - // Move using transform - move: function(x, y) { - this.transform({ - x: x, - y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis +, y: function(y) { + return this.transform('y', y) } - // Set path data , plot: function(data) { return this.attr('d', data || 'M0,0') diff --git a/src/regex.js b/src/regex.js index adf82b4..3639358 100644 --- a/src/regex.js +++ b/src/regex.js @@ -1,33 +1,33 @@ // Storage for regular expressions SVG.regex = { /* parse unit value */ - unit: /^([\d\.]+)([a-z%]{0,2})$/ + unit: /^([\d\.]+)([a-z%]{0,2})$/ /* parse hex value */ -, hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i +, hex: /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i /* parse rgb value */ -, rgb: /rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/ +, rgb: /rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/ /* parse hsb value */ -, hsb: /hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/ +, hsb: /hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/ /* test hex value */ -, isHex: /^#[a-f0-9]{3,6}$/i +, isHex: /^#[a-f0-9]{3,6}$/i /* test rgb value */ -, isRgb: /^rgb\(/ +, isRgb: /^rgb\(/ /* test hsb value */ -, isHsb: /^hsb\(/ +, isHsb: /^hsb\(/ /* test css declaration */ -, isCss: /[^:]+:[^;]+;?/ +, isCss: /[^:]+:[^;]+;?/ /* test css property */ -, isStyle: /^font|text|leading|cursor/ +, isStyle: /^font|text|leading|cursor/ /* test for blank string */ -, isBlank: /^(\s+)?$/ - +, isBlank: /^(\s+)?$/ + } \ No newline at end of file diff --git a/src/sugar.js b/src/sugar.js index 1f7339a..2edb429 100644 --- a/src/sugar.js +++ b/src/sugar.js @@ -54,6 +54,10 @@ SVG.extend(SVG.Element, SVG.FX, { scaleY: y == null ? x : y }) } + // Matrix +, matrix: function(m) { + return this.transform({ matrix: m }) + } // Opacity , opacity: function(value) { return this.attr('opacity', value) diff --git a/src/wrap.js b/src/wrap.js index 9fa10a2..1caaaad 100644 --- a/src/wrap.js +++ b/src/wrap.js @@ -11,12 +11,13 @@ SVG.Wrap = function(element) { SVG.Wrap.prototype = new SVG.Shape() SVG.extend(SVG.Wrap, { - // Move wrapper around - move: function(x, y) { - return this.transform({ - x: x - , y: y - }) + // Move over x-axis + x: function(x) { + return this.transform('x', x) + } + // Move over y-axis +, y: function(y) { + return this.transform('y', y) } // Set the actual size in pixels , size: function(width, height) {