diff options
author | wout <wout@impinc.co.uk> | 2013-03-24 19:19:06 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-03-24 19:19:06 +0100 |
commit | 67d367e0d74b3287956130da0077e42c6483dd2f (patch) | |
tree | bb2d23315e39c89b79cb8c52e7a5db54636e08ad /dist | |
parent | ff09596144c3fd6770d1dc64178a10c2432396ca (diff) | |
download | svg.js-67d367e0d74b3287956130da0077e42c6483dd2f.tar.gz svg.js-67d367e0d74b3287956130da0077e42c6483dd2f.zip |
Bumped to v0.11
- removed SVG.Wrap on SVG.Polyline, SVG.Polygon and SVG.Path
- added delay on SVG.FX module
- made x(), y(), cx() and cy() as getters
- added SGB.get() method, to get elements by a DOM id
- fixed bug in remove() method on container elements
- added jasmine test suite to repo
Diffstat (limited to 'dist')
-rw-r--r-- | dist/svg.js | 858 | ||||
-rw-r--r-- | dist/svg.min.js | 4 |
2 files changed, 452 insertions, 410 deletions
diff --git a/dist/svg.js b/dist/svg.js index da992fe..89aa45d 100644 --- a/dist/svg.js +++ b/dist/svg.js @@ -1,4 +1,4 @@ -/* svg.js v0.10-1-g4bd21ec - 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 */ +/* svg.js v0.11 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ ;(function() { this.SVG = function(element) { @@ -21,7 +21,7 @@ // Get next named element id SVG.eid = function(name) { - return 'Svgjs' + name.charAt(0).toUpperCase() + name.slice(1) + 'Element' + (SVG.did++) + return 'Svgjs' + name.charAt(0).toUpperCase() + name.slice(1) + (SVG.did++) } // Method for element creation @@ -35,7 +35,7 @@ return element } - // Method for extending objects + // Method for extending objects SVG.extend = function() { var modules, methods, key, i @@ -51,6 +51,12 @@ modules[i].prototype[key] = methods[key] } + // Method for getting an eleemnt by id + SVG.get = function(id) { + var node = document.getElementById(id) + if (node) return node.instance + } + // svg support test SVG.supported = (function() { return !! document.createElementNS && @@ -60,8 +66,13 @@ if (!SVG.supported) return false SVG.regex = { + /* test a given value */ + test: function(value, test) { + return this[test].test(value) + } + /* 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 @@ -90,6 +101,9 @@ /* test for blank string */ , isBlank: /^(\s+)?$/ + /* test for numeric string */ + , isNumber: /^-?[\d\.]+$/ + } SVG.default = { @@ -97,28 +111,28 @@ 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 - } + , attrs: { + /* 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 + /* gradient */ + , offset: 0 } // Default transformation values @@ -304,12 +318,12 @@ // Test if given value is a rgb object SVG.Color.isRgb = function(color) { - return typeof color.r == 'number' + return color && typeof color.r == 'number' } // Test if given value is a hsb object SVG.Color.isHsb = function(color) { - return typeof color.h == 'number' + return color && typeof color.h == 'number' } SVG.ViewBox = function(element) { @@ -363,19 +377,19 @@ this.x = box.x + element.trans.x this.y = box.y + element.trans.y - /* add the center */ - this.cx = this.x + box.width / 2 - this.cy = this.x + box.height / 2 - /* plain width and height */ - this.width = box.width - this.height = box.height + this.width = box.width * element.trans.scaleX + this.height = box.height * element.trans.scaleY + + /* add the center */ + this.cx = this.x + this.width / 2 + this.cy = this.y + this.height / 2 } SVG.Element = function(node) { - /* initialize attribute store with defaults */ - this.attrs = SVG.default.attrs() + /* make stroke value accessible dynamically */ + this._stroke = SVG.default.attrs.stroke /* initialize style store */ this.styles = {} @@ -386,28 +400,29 @@ /* keep reference to the element node */ if (this.node = node) { this.type = node.nodeName - this.attrs.id = node.getAttribute('id') + this.node.instance = this } - } // SVG.extend(SVG.Element, { // Move over x-axis x: function(x) { + if (x) x /= this.trans.scaleX return this.attr('x', x) } // Move over y-axis , y: function(y) { + if (y) y /= this.trans.scaleY return this.attr('y', y) } // Move by center over x-axis , cx: function(x) { - return this.x(x - this.bbox().width / 2) + return x == null ? this.bbox().cx : this.x(x - this.bbox().width / 2) } // Move by center over y-axis , cy: function(y) { - return this.y(y - this.bbox().height / 2) + return y == null ? this.bbox().cy : this.y(y - this.bbox().height / 2) } // Move element to given x and y values , move: function(x, y) { @@ -426,40 +441,30 @@ } // Clone element , clone: function() { - var clone - - /* if this is a wrapped shape */ - if (this instanceof SVG.Wrap) { - /* build new wrapped shape */ - clone = this.parent[this.child.node.nodeName]() - clone.attrs = this.attrs - - /* copy child attributes and transformations */ - clone.child.trans = this.child.trans - clone.child.attr(this.child.attrs).transform({}) - - /* re-plot shape */ - if (clone.plot) - clone.plot(this.child.attrs[this.child instanceof SVG.Path ? 'd' : 'points']) - - } else { - var name = this.node.nodeName - - /* invoke shape method with shape-specific arguments */ - clone = name == 'rect' ? - this.parent[name](this.attrs.width, this.attrs.height) : - name == 'ellipse' ? - this.parent[name](this.attrs.rx * 2, this.attrs.ry * 2) : - name == 'image' ? - this.parent[name](this.src) : - name == 'text' ? - this.parent[name](this.content) : - name == 'g' ? - this.parent.group() : - this.parent[name]() - - clone.attr(this.attrs) - } + var clone , attr + , type = this.type + + /* invoke shape method with shape-specific arguments */ + clone = type == 'rect' || type == 'ellipse' ? + this.parent[type](0,0) : + type == 'line' ? + this.parent[type](0,0,0,0) : + type == 'image' ? + this.parent[type](this.src) : + type == 'text' ? + this.parent[type](this.content) : + type == 'path' ? + this.parent[type](this.attr('d')) : + type == 'polyline' || type == 'polygon' ? + this.parent[type](this.attr('points')) : + type == 'g' ? + this.parent.group() : + this.parent[type]() + + /* apply attributes attributes */ + attr = this.attr() + delete attr.id + clone.attr(attr) /* copy transformations */ clone.trans = this.trans @@ -470,28 +475,36 @@ // Remove element , remove: function() { if (this.parent) - this.parent.remove(this) + this.parent.removeElement(this) return this } // Get parent document - , doc: function() { - return this._parent(SVG.Doc) - } - // Get parent nested document - , nested: function() { - return this._parent(SVG.Nested) + , doc: function(type) { + return this._parent(type || SVG.Doc) } // Set svg element attribute , attr: function(a, v, n) { - if (arguments.length < 2) { + if (a == null) { + /* get an object of attributes */ + a = {} + v = this.node.attributes + for (n = v.length - 1; n >= 0; n--) + a[v[n].nodeName] = v[n].nodeValue + + return a + + } else if (typeof a == 'object') { /* apply every attribute individually if an object is passed */ - if (typeof a == 'object') - for (v in a) - this.attr(v, a[v]) + for (v in a) this.attr(v, a[v]) + } else if (v === null) { + /* remove value */ + this.node.removeAttribute(a) + + } else if (v == null) { /* act as a getter for style attributes */ - else if (this._isStyle(a)) + if (this._isStyle(a)) { return a == 'text' ? this.content : a == 'leading' ? @@ -499,41 +512,38 @@ this.style(a) /* act as a getter if the first and only argument is not an object */ - else - return this.attrs[a] || this.node.getAttribute(a) + } else { + v = this.node.getAttribute(a) + return v == null ? + SVG.default.attrs[a] : + SVG.regex.test(v, 'isNumber') ? + parseFloat(v) : v + } - } else if (v === null) { - /* remove value */ - this.node.removeAttribute(a) - } else if (a == 'style') { /* redirect to the style method */ return this.style(v) } else { - /* store value */ - this.attrs[a] = v - /* treat x differently on text elements */ - if (a == 'x' && this._isText()) { - for (var i = this.lines.length - 1; i >= 0; i--) - this.lines[i].attr(a, v) + if (a == 'x' && this instanceof SVG.Text) + for (n = this.lines.length - 1; n >= 0; n--) + this.lines[n].attr(a, v) - /* set the actual attribute */ - } else { - /* BUG FIX: some browsers will render a stroke if a color is given even though stroke width is 0 */ - if (a == 'stroke-width') - this.attr('stroke', parseFloat(v) > 0 ? this.attrs.stroke : null) + /* BUG FIX: some browsers will render a stroke if a color is given even though stroke width is 0 */ + if (a == 'stroke-width') + this.attr('stroke', parseFloat(v) > 0 ? this._stroke : null) + else if (a == 'stroke') + this._stroke = v + + /* ensure hex color */ + if (SVG.Color.test(v) || SVG.Color.isRgb(v) || SVG.Color.isHsb(v)) + v = new SVG.Color(v).toHex() - /* ensure hex color */ - if (SVG.Color.test(v) || SVG.Color.isRgb(v) || SVG.Color.isHsb(v)) - v = new SVG.Color(v).toHex() - - /* set give attribute on node */ - n != null ? - this.node.setAttributeNS(n, a, v) : - this.node.setAttribute(a, v) - } + /* set give attribute on node */ + n != null ? + this.node.setAttributeNS(n, a, v) : + this.node.setAttribute(a, v) /* if the passed argument belongs to the style as well, add it there */ if (this._isStyle(a)) { @@ -614,10 +624,15 @@ /* add translation */ if (o.x != 0 || o.y != 0) - transform.push('translate(' + o.x + ',' + o.y + ')') + transform.push('translate(' + o.x / o.scaleX + ',' + o.y / o.scaleY + ')') + + /* add offset translation */ + if (this._offset) + transform.push('translate(' + (-this._offset.x) + ',' + (-this._offset.y) + ')') /* add only te required transformations */ - this.node.setAttribute('transform', transform.join(' ')) + if (transform.length > 0) + this.node.setAttribute('transform', transform.join(' ')) return this } @@ -648,7 +663,7 @@ return this.styles[s] } - } else if (v === null) { + } else if (v === null || SVG.regex.test(v, 'isBlank')) { /* remove value */ delete this.styles[s] @@ -717,12 +732,8 @@ return element } // Private: tester method for style detection - , _isStyle: function(attr) { - return typeof attr == 'string' ? SVG.regex.isStyle.test(attr) : false - } - // Private: element type tester - , _isText: function() { - return this instanceof SVG.Text + , _isStyle: function(a) { + return typeof a == 'string' ? SVG.regex.test(a, 'isStyle') : false } // Private: parse a matrix string , _parseMatrix: function(o) { @@ -746,7 +757,6 @@ }) - SVG.Container = function(element) { this.constructor.call(this, element) } @@ -756,55 +766,55 @@ // SVG.extend(SVG.Container, { + // Returns all child elements + children: function() { + return this._children || (this._children = []) + } // Add given element at a position - add: function(element, index) { + , add: function(element, i) { if (!this.has(element)) { /* define insertion index if none given */ - index = index == null ? this.children().length : index + i = i == null ? this.children().length : i /* remove references from previous parent */ if (element.parent) { - var i = element.parent.children().indexOf(element) - element.parent.children().splice(i, 1) + var index = element.parent.children().indexOf(element) + element.parent.children().splice(index, 1) } /* add element references */ - this.children().splice(index, 0, element) - this.node.insertBefore(element.node, this.node.childNodes[index] || null) + this.children().splice(i, 0, element) + this.node.insertBefore(element.node, this.node.childNodes[i] || null) element.parent = this } return this } - // Basically does the same as `add()` but returns the added element - , put: function(element, index) { - this.add(element, index) + // Basically does the same as `add()` but returns the added element instead + , put: function(element, i) { + this.add(element, i) return element } // Checks if the given element is a child , has: function(element) { return this.children().indexOf(element) >= 0 } - // Returns all child elements - , children: function() { - return this._children || (this._children = []) - } // Iterates over all children and invokes a given block , each: function(block) { var index, children = this.children() - + for (index = 0, length = children.length; index < length; index++) if (children[index] instanceof SVG.Shape) block.apply(children[index], [index, children]) - + return this } // Remove a child element at a position - , remove: function(element) { - var index = this.children().indexOf(element) + , removeElement: function(element) { + var i = this.children().indexOf(element) - this.children().splice(index, 1) + this.children().splice(i, 1) this.node.removeChild(element.node) element.parent = null @@ -812,15 +822,15 @@ } // Returns defs element , defs: function() { - return this._defs || (this._defs = this.put(new SVG.Defs(), 0)) + return this._defs || (this._defs = this.put(new SVG.Defs, 0)) } // Re-level defs to first positon in element stack , level: function() { - return this.remove(this.defs()).put(this.defs(), 0) + return this.removeElement(this.defs()).put(this.defs(), 0) } // Create a group element , group: function() { - return this.put(new SVG.G()) + return this.put(new SVG.G) } // Create a rect element , rect: function(width, height) { @@ -840,15 +850,15 @@ } // Create a wrapped polyline element , polyline: function(points) { - return this.put(new SVG.Wrap(new SVG.Polyline())).plot(points) + return this.put(new SVG.Polyline).plot(points) } // Create a wrapped polygon element , polygon: function(points) { - return this.put(new SVG.Wrap(new SVG.Polygon())).plot(points) + return this.put(new SVG.Polygon).plot(points) } // Create a wrapped path element , path: function(data) { - return this.put(new SVG.Wrap(new SVG.Path())).plot(data) + return this.put(new SVG.Path).plot(data) } // Create image element, load image and set its size , image: function(source, width, height) { @@ -861,7 +871,7 @@ } // Create nested svg document , nested: function() { - return this.put(new SVG.Nested()) + return this.put(new SVG.Nested) } // Create gradient element in defs , gradient: function(type, block) { @@ -873,7 +883,7 @@ } // Create masking element , mask: function() { - return this.defs().put(new SVG.Mask()) + return this.defs().put(new SVG.Mask) } // Get first child, skipping the defs node , first: function() { @@ -884,20 +894,22 @@ return this.children()[this.children().length - 1] } // Get the viewBox and calculate the zoom value - , viewbox: function() { - /* act as a getter if there are no arguments */ + , viewbox: function(v) { if (arguments.length == 0) + /* act as a getter if there are no arguments */ return new SVG.ViewBox(this) /* otherwise act as a setter */ - return this.attr('viewBox', Array.prototype.slice.call(arguments).join(' ')) + v = arguments.length == 1 ? + [v.x, v.y, v.width, v.height] : + Array.prototype.slice.call(arguments) + + return this.attr('viewBox', v.join(' ')) } // Remove all elements in this container , clear: function() { - this._children = [] - - while (this.node.hasChildNodes()) - this.node.removeChild(this.node.lastChild) + for (var i = this.children().length - 1; i >= 0; i--) + this.removeElement(this.children()[i]) return this } @@ -912,99 +924,122 @@ // SVG.extend(SVG.FX, { // Add animation parameters and start animation - animate: function(duration, ease) { - /* ensure default duration and easing */ - duration = duration == null ? 1000 : duration - ease = ease || '<>' - - var akeys, tkeys, skeys - , element = this.target - , fx = this - , start = new Date().getTime() - , finish = start + duration - - /* start animation */ - this.interval = setInterval(function(){ - // This code was borrowed from the emile.js micro framework by Thomas Fuchs, aka MadRobby. - var i, key - , time = new Date().getTime() - , pos = time > finish ? 1 : (time - start) / duration - - /* collect attribute keys */ - if (akeys == null) { - akeys = [] - for (key in fx.attrs) - akeys.push(key) - } - - /* collect transformation keys */ - if (tkeys == null) { - tkeys = [] - for (key in fx.trans) - tkeys.push(key) - } - - /* collect style keys */ - if (skeys == null) { - skeys = [] - for (key in fx.styles) - skeys.push(key) - } - - /* apply easing */ - pos = ease == '<>' ? - (-Math.cos(pos * Math.PI) / 2) + 0.5 : - ease == '>' ? - Math.sin(pos * Math.PI / 2) : - ease == '<' ? - -Math.cos(pos * Math.PI / 2) + 1 : - ease == '-' ? - pos : - typeof ease == 'function' ? - ease(pos) : - 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) - element.size(fx._at(fx._size.width, pos), fx._at(fx._size.height, pos)) - - /* animate attributes */ - for (i = akeys.length - 1; i >= 0; i--) - element.attr(akeys[i], fx._at(fx.attrs[akeys[i]], pos)) - - /* animate transformations */ - for (i = tkeys.length - 1; i >= 0; i--) - element.transform(tkeys[i], fx._at(fx.trans[tkeys[i]], pos)) - - /* animate styles */ - for (i = skeys.length - 1; i >= 0; i--) - element.style(skeys[i], fx._at(fx.styles[skeys[i]], pos)) + animate: function(d, ease, delay) { + var fx = this + + /* dissect object if one is passed */ + if (typeof d == 'object') { + delay = d.delay + ease = d.ease + d = d.duration + } + + /* delay animation */ + this.timeout = setTimeout(function() { - /* callback for each keyframe */ - if (fx._during) - fx._during.call(element, pos, function(from, to) { - return fx._at({ from: from, to: to }, pos) - }) + /* ensure default duration and easing */ + d = d == null ? 1000 : d + ease = ease || '<>' - /* finish off animation */ - if (time > finish) { - clearInterval(fx.interval) - fx._after ? fx._after.apply(element, [fx]) : fx.stop() - } + var akeys, tkeys, skeys + , interval = 1000 / 60 + , element = fx.target + , start = new Date().getTime() + , finish = start + d + + /* start animation */ + fx.interval = setInterval(function(){ + // This code was borrowed from the emile.js micro framework by Thomas Fuchs, aka MadRobby. + var i, key + , time = new Date().getTime() + , pos = time > finish ? 1 : (time - start) / d + + /* collect attribute keys */ + if (akeys == null) { + akeys = [] + for (key in fx.attrs) + akeys.push(key) + } + + /* collect transformation keys */ + if (tkeys == null) { + tkeys = [] + for (key in fx.trans) + tkeys.push(key) + } + + /* collect style keys */ + if (skeys == null) { + skeys = [] + for (key in fx.styles) + skeys.push(key) + } + + /* apply easing */ + pos = ease == '<>' ? + (-Math.cos(pos * Math.PI) / 2) + 0.5 : + ease == '>' ? + Math.sin(pos * Math.PI / 2) : + ease == '<' ? + -Math.cos(pos * Math.PI / 2) + 1 : + ease == '-' ? + pos : + typeof ease == 'function' ? + ease(pos) : + 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) + element.size(fx._at(fx._size.width, pos), fx._at(fx._size.height, pos)) + + /* run all viewbox properties */ + if (fx._viewbox) + element.viewbox( + fx._at(fx._viewbox.x, pos) + , fx._at(fx._viewbox.y, pos) + , fx._at(fx._viewbox.width, pos) + , fx._at(fx._viewbox.height, pos) + ) + + /* animate attributes */ + for (i = akeys.length - 1; i >= 0; i--) + element.attr(akeys[i], fx._at(fx.attrs[akeys[i]], pos)) + + /* animate transformations */ + for (i = tkeys.length - 1; i >= 0; i--) + element.transform(tkeys[i], fx._at(fx.trans[tkeys[i]], pos)) + + /* animate styles */ + for (i = skeys.length - 1; i >= 0; i--) + element.style(skeys[i], fx._at(fx.styles[skeys[i]], pos)) + + /* callback for each keyframe */ + if (fx._during) + fx._during.call(element, pos, function(from, to) { + return fx._at({ from: from, to: to }, pos) + }) + + /* finish off animation */ + if (time > finish) { + clearInterval(fx.interval) + fx._after ? fx._after.apply(element, [fx]) : fx.stop() + } + + }, d > interval ? interval : d) - }, duration > 10 ? 10 : duration) + }, delay || 0) return this } @@ -1059,29 +1094,25 @@ } // Animatable x-axis , x: function(x) { - var b = this.bbox() - this._x = { from: b.x, to: x } + this._x = { from: this.target.x(), to: x } return this } // Animatable y-axis , y: function(y) { - var b = this.bbox() - this._y = { from: b.y, to: y } + this._y = { from: this.target.y(), to: y } return this } // Animatable center x-axis , cx: function(x) { - var b = this.bbox() - this._cx = { from: b.cx, to: x } + this._cx = { from: this.target.cx(), to: x } return this } // Animatable center y-axis , cy: function(y) { - var b = this.bbox() - this._cy = { from: b.cy, to: y } + this._cy = { from: this.target.cy(), to: y } return this } @@ -1111,6 +1142,21 @@ return this } + // Add animatable viewbox + , viewbox: function(x, y, width, height) { + if (this.target instanceof SVG.Container) { + var box = this.target.viewbox() + + this._viewbox = { + x: { from: box.x, to: x } + , y: { from: box.y, to: y } + , width: { from: box.width, to: width } + , height: { from: box.height, to: height } + } + } + + return this + } // Add callback for each keyframe , during: function(during) { this._during = during @@ -1126,6 +1172,7 @@ // Stop running animation , stop: function() { /* stop current animation */ + clearTimeout(this.timeout) clearInterval(this.interval) /* reset storage for properties that need animation */ @@ -1139,10 +1186,11 @@ delete this._size delete this._after delete this._during + delete this._viewbox return this } - // Private: at position according to from and to + // Private: calculate position according to from and to , _at: function(o, pos) { /* number recalculation */ return typeof o.from == 'number' ? @@ -1165,7 +1213,7 @@ /* convert FROM unit */ match = SVG.regex.unit.exec(o.from.toString()) - from = parseFloat(match[1]) + from = parseFloat(match ? match[1] : 0) /* convert TO unit */ match = SVG.regex.unit.exec(o.to) @@ -1197,12 +1245,13 @@ // SVG.extend(SVG.Element, { // Get fx module or create a new one, then animate with given duration and ease - animate: function(duration, ease) { - return (this.fx || (this.fx = new SVG.FX(this))).stop().animate(duration, ease) + animate: function(d, ease, delay) { + return (this.fx || (this.fx = new SVG.FX(this))).stop().animate(d, ease, delay) }, // Stop current animation; this is an alias to the fx instance stop: function() { - this.fx.stop() + if (this.fx) + this.fx.stop() return this } @@ -1284,11 +1333,11 @@ SVG.extend(SVG.G, { // Move over x-axis x: function(x) { - return this.transform('x', x) + return x == null ? this.trans.x : this.transform('x', x) } // Move over y-axis , y: function(y) { - return this.transform('y', y) + return y == null ? this.trans.y : this.transform('y', y) } // Get defs , defs: function() { @@ -1316,7 +1365,7 @@ } // Send given element one step forward , forward: function() { - return this.parent.remove(this).put(this, this.position() + 1) + return this.parent.removeElement(this).put(this, this.position() + 1) } // Send given element one step backward , backward: function() { @@ -1325,20 +1374,20 @@ var i = this.position() if (i > 1) - this.parent.remove(this).add(this, i - 1) + this.parent.removeElement(this).add(this, i - 1) return this } // Send given element all the way to the front , front: function() { - return this.parent.remove(this).put(this) + return this.parent.removeElement(this).put(this) } // Send given element all the way to the back , back: function() { this.parent.level() if (this.position() > 1) - this.parent.remove(this).add(this, 0) + this.parent.removeElement(this).add(this, 0) return this } @@ -1360,7 +1409,6 @@ SVG.Mask.prototype = new SVG.Container SVG.extend(SVG.Element, { - // Distribute mask to svg element maskWith: function(element) { /* use given mask or create a new one */ @@ -1371,6 +1419,35 @@ }) + SVG.Clip = function Clip() { + this.constructor.call(this, SVG.create('clipPath')) + } + + // Inherit from SVG.Container + SVG.Clip.prototype = new SVG.Container + + SVG.extend(SVG.Element, { + + // Distribute clipPath to svg element + clipWith: function(element) { + /* use given clip or create a new one */ + this.clip = element instanceof SVG.Clip ? element : this.parent.clip().add(element) + + return this.attr('clip-path', 'url(#' + this.clip.attr('id') + ')') + } + + }) + + // Add container method + SVG.extend(SVG.Container, { + // Create clipping element + clip: function() { + return this.defs().put(new SVG.Clip) + } + + }) + + SVG.Pattern = function(type) { this.constructor.call(this, SVG.create('pattern')) } @@ -1462,8 +1539,7 @@ // SVG.extend(SVG.Defs, { - - /* define gradient */ + // define gradient gradient: function(type, block) { var element = this.put(new SVG.Gradient(type)) @@ -1488,8 +1564,7 @@ // SVG.extend(SVG.Stop, { - - /* add color stops */ + // add color stops update: function(o) { var index , attr = ['opacity', 'color'] @@ -1500,7 +1575,7 @@ this.style('stop-' + attr[index], o[attr[index]]) /* set attributes */ - return this.attr('offset', (o.offset != null ? o.offset : this.attrs.offset || 0) + '%') + return this.attr('offset', (o.offset != null ? o.offset : this.attr('offset')) + '%') } }) @@ -1574,89 +1649,6 @@ // Inherit from SVG.Element SVG.Shape.prototype = new SVG.Element - SVG.Wrap = function(element) { - this.constructor.call(this, SVG.create('g')) - - /* insert and store child */ - this.node.insertBefore(element.node, null) - this.child = element - this.type = element.node.nodeName - } - - // inherit from SVG.Shape - SVG.Wrap.prototype = new SVG.Shape() - - SVG.extend(SVG.Wrap, { - // 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) { - var scale = width / this._b.width - - this.child.transform({ - scaleX: scale - , scaleY: height != null ? height / this._b.height : scale - }) - - return this - } - // Move by center - , center: function(x, y) { - return this.move( - x + (this._b.width * this.child.trans.scaleX) / -2 - , y + (this._b.height * this.child.trans.scaleY) / -2 - ) - } - // Create distributed attr - , attr: function(a, v, n) { - /* call individual attributes if an object is given */ - if (typeof a == 'object') { - for (v in a) this.attr(v, a[v]) - - /* act as a getter if only one argument is given */ - } else if (arguments.length < 2) { - return a == 'transform' ? this.attrs[a] : this.child.attrs[a] - - /* apply locally for certain attributes */ - } else if (a == 'transform') { - this.attrs[a] = v - - n != null ? - this.node.setAttributeNS(n, a, v) : - this.node.setAttribute(a, v) - - /* apply attributes to child */ - } else { - this.child.attr(a, v, n) - } - - return this - } - // Distribute plot method to child - , plot: function(data) { - /* plot new shape */ - this.child.plot(data) - - /* get and store new bbox */ - this._b = this.child.bbox() - - /* reposition element withing wrapper */ - this.child.transform({ - x: -this._b.x - , y: -this._b.y - }) - - return this - } - - }) - SVG.Rect = function() { this.constructor.call(this, SVG.create('rect')) } @@ -1675,19 +1667,19 @@ SVG.extend(SVG.Ellipse, { // Move over x-axis x: function(x) { - return this.cx(x + this.attrs.rx) + return x == null ? this.cx() - this.attr('rx') : this.cx(x + this.attr('rx')) } // Move over y-axis , y: function(y) { - return this.cy(y + this.attrs.ry) + return y == null ? this.cy() - this.attr('ry') : this.cy(y + this.attr('ry')) } // Move by center over x-axis , cx: function(x) { - return this.attr('cx', x) + return x == null ? this.attr('cx') : this.attr('cx', x / this.trans.scaleX) } // Move by center over y-axis , cy: function(y) { - return this.attr('cy', y) + return y == null ? this.attr('cy') : this.attr('cy', y / this.trans.scaleY) } // Custom size function , size: function(width, height) { @@ -1716,48 +1708,42 @@ x: function(x) { var b = this.bbox() - return this.attr({ - x1: this.attrs.x1 - b.x + x - , x2: this.attrs.x2 - b.x + x + return x == null ? b.x : this.attr({ + x1: this.attr('x1') - b.x + x + , x2: this.attr('x2') - b.x + x }) } // Move over y-axis , y: function(y) { var b = this.bbox() - return this.attr({ - y1: this.attrs.y1 - b.y + y - , y2: this.attrs.y2 - b.y + y + return y == null ? b.y : this.attr({ + y1: this.attr('y1') - b.y + y + , y2: this.attr('y2') - b.y + y }) } // Move by center over x-axis , cx: function(x) { - return this.x(x - this.bbox().width / 2) + var half = this.bbox().width / 2 + return x == null ? this.x() + half : this.x(x - half) } // Move by center over y-axis , cy: function(y) { - return this.y(y - this.bbox().height / 2) + var half = this.bbox().height / 2 + return y == null ? this.y() + half : this.y(y - half) } // Set line size by width and height , size: function(width, height) { var b = this.bbox() return this - .attr(this.attrs.x1 < this.attrs.x2 ? 'x2' : 'x1', b.x + width) - .attr(this.attrs.y1 < this.attrs.y2 ? 'y2' : 'y1', b.y + height) + .attr(this.attr('x1') < this.attr('x2') ? 'x2' : 'x1', b.x + width) + .attr(this.attr('y1') < this.attr('y2') ? 'y2' : 'y1', b.y + height) } }) - SVG.Poly = { - // Set polygon data with default zero point if no data is passed - plot: function(points) { - this.attr('points', points || '0,0') - - return this - } - } - + SVG.Polyline = function() { this.constructor.call(this, SVG.create('polyline')) } @@ -1765,9 +1751,6 @@ // Inherit from SVG.Shape SVG.Polyline.prototype = new SVG.Shape - // Add polygon-specific functions - SVG.extend(SVG.Polyline, SVG.Poly) - SVG.Polygon = function() { this.constructor.call(this, SVG.create('polygon')) } @@ -1776,27 +1759,70 @@ SVG.Polygon.prototype = new SVG.Shape // Add polygon-specific functions - SVG.extend(SVG.Polygon, SVG.Poly) + SVG.extend(SVG.Polyline, SVG.Polygon, { + // Private: Native plot + _plot: function(p) { + if (Array.isArray(p)) { + var i, l, points = [] + + for (i = 0, l = p.length; i < l; i++) + points.push(p[i].join(',')) + + p = points.length == 0 ? points.join(' ') : '0,0' + } + + return this.attr('points', p || '0,0') + } + + }) SVG.Path = function() { this.constructor.call(this, SVG.create('path')) } // Inherit from SVG.Shape - SVG.Path.prototype = new SVG.Shape() + SVG.Path.prototype = new SVG.Shape SVG.extend(SVG.Path, { + // Private: Native plot + _plot: function(data) { + return this.attr('d', data || 'M0,0') + } + + }) + + SVG.extend(SVG.Polyline, SVG.Polygon, SVG.Path, { // Move over x-axis x: function(x) { - return this.transform('x', x) + return x == null ? this.bbox().x : this.transform('x', x) } // Move over y-axis , y: function(y) { - return this.transform('y', y) + return y == null ? this.bbox().y : this.transform('y', y) + } + // Set the actual size in pixels + , size: function(width, height) { + var scale = width / this._offset.width + + return this.transform({ + scaleX: scale + , scaleY: height != null ? height / this._offset.height : scale + }) } // Set path data , plot: function(data) { - return this.attr('d', data || 'M0,0') + var x = this.trans.scaleX + , y = this.trans.scaleY + + /* native plot */ + this._plot(data) + + /* get and store the actual offset of the element */ + this._offset = this.transform({ scaleX: 1, scaleY: 1 }).bbox() + this._offset.x -= this.trans.x + this._offset.y -= this.trans.y + + return this.transform({ scaleX: x, scaleY: y }) } }) @@ -1806,14 +1832,13 @@ } // Inherit from SVG.Element - SVG.Image.prototype = new SVG.Shape() + SVG.Image.prototype = new SVG.Shape SVG.extend(SVG.Image, { - /* (re)load image */ + // (re)load image load: function(url) { - this.src = url - return (url ? this.attr('xlink:href', url, SVG.xlink) : this) + return (url ? this.attr('xlink:href', (this.src = url), SVG.xlink) : this) } }) @@ -1826,7 +1851,7 @@ /* define default style */ this.styles = { 'font-size': 16 - , 'font-family': 'Helvetica' + , 'font-family': 'Helvetica, Arial, sans-serif' , 'text-anchor': 'start' } @@ -1837,8 +1862,37 @@ SVG.Text.prototype = new SVG.Shape SVG.extend(SVG.Text, { + // Move over x-axis + x: function(x, a) { + /* act as getter */ + if (x == null) return a ? this.attr('x') : this.bbox().x + + /* set x taking anchor in mind */ + if (!a) { + a = this.style('text-anchor') + x = a == 'start' ? x : a == 'end' ? x + this.bbox().width : x + this.bbox().width / 2 + } + + return this.attr('x', x) + } + // Move center over x-axis + , cx: function(x, a) { + return x == null ? this.bbox().cx : this.x(x - this.bbox().width / 2) + } + // Move center over y-axis + , cy: function(y, a) { + return y == null ? this.bbox().cy : this.y(a ? y : y - this.bbox().height / 2) + } + // Move element to given x and y values + , move: function(x, y, a) { + return this.x(x, a).y(y) + } + // Move element by its center + , center: function(x, y, a) { + return this.cx(x, a).cy(y, a) + } // Set the text content - text: function(text) { + , text: function(text) { /* act as getter */ if (text == null) return this.content @@ -1856,8 +1910,7 @@ for (i = 0, il = lines.length; i < il; i++) this.tspan(lines[i]) - /* set style */ - return this.attr('style', this.style()) + return this.attr('textLength', 1).attr('textLength', null) } // Create a tspan , tspan: function(text) { @@ -1869,17 +1922,6 @@ return tspan.attr('style', this.style()) } - // Move element by its center - , center: function(x, y) { - var anchor = this.style('text-anchor') - , box = this.bbox() - , x = anchor == 'start' ? - x - box.width / 2 : - anchor == 'end' ? - x + box.width / 2 : x - - return this.move(x, y - box.height / 2) - } // Set font size , size: function(size) { return this.attr('font-size', size) @@ -1903,8 +1945,8 @@ /* define position of all lines */ for (i = 0, il = this.lines.length; i < il; i++) this.lines[i].attr({ - dy: size * this._leading - (i == 0 ? size * 0.3 : 0) - , x: (this.attrs.x || 0) + dy: size * this._leading - (i == 0 ? size * 0.276666666 : 0) + , x: (this.attr('x') || 0) , style: this.style() }) @@ -1985,11 +2027,11 @@ SVG.extend(SVG.Element, SVG.FX, { // Rotation - rotate: function(deg, cx, cy) { + rotate: function(deg, x, y) { return this.transform({ rotation: deg || 0 - , cx: cx - , cy: cy + , cx: x + , cy: y }) } // Skew diff --git a/dist/svg.min.js b/dist/svg.min.js index 7fd6401..7302e4b 100644 --- a/dist/svg.min.js +++ b/dist/svg.min.js @@ -1,2 +1,2 @@ -/* svg.js v0.10-1-g4bd21ec - 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=this.x+t.width/2,this.cy=this.x+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);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;n<e.length;n++)t=e[n].split(":"),t.length==2&&this.style(t[0].replace(/\s+/g,""),t[1].replace(/^\s+/,"").replace(/\s+$/,""))}else t===null?delete this.styles[e]:this.styles[e]=t;e="";for(t in this.styles)e+=t+":"+this.styles[t]+";";return this.node.setAttribute("style",e),this},data:function(e,t,n){if(arguments.length<2)try{return JSON.parse(this.attr("data-"+e))}catch(r){return this.attr("data-"+e)}else this.attr("data-"+e,t===null?null:n===!0?t:JSON.stringify(t));return this},bbox:function(){return new SVG.BBox(this)},inside:function(e,t){var n=this.bbox();return e>n.x&&t>n.y&&e<n.x+n.width&&t<n.y+n.height},show:function(){return this.style("display","")},hide:function(){return this.style("display","none")},visible:function(){return this.style("display")!="none"},_parent:function(e){var t=this;while(t!=null&&!(t instanceof e))t=t.parent;return t},_isStyle:function(e){return typeof e=="string"?SVG.regex.isStyle.test(e):!1},_isText:function(){return this instanceof SVG.Text},_parseMatrix:function(e){if(e.matrix){var t=e.matrix.replace(/\s/g,"").split(",");t.length==6&&(e.a=parseFloat(t[0]),e.b=parseFloat(t[1]),e.c=parseFloat(t[2]),e.d=parseFloat(t[3]),e.e=parseFloat(t[4]),e.f=parseFloat(t[5]))}return e}}),SVG.Container=function(e){this.constructor.call(this,e)},SVG.Container.prototype=new SVG.Element,SVG.extend(SVG.Container,{add:function(e,t){if(!this.has(e)){t=t==null?this.children().length:t;if(e.parent){var n=e.parent.children().indexOf(e);e.parent.children().splice(n,1)}this.children().splice(t,0,e),this.node.insertBefore(e.node,this.node.childNodes[t]||null),e.parent=this}return this},put:function(e,t){return this.add(e,t),e},has:function(e){return this.children().indexOf(e)>=0},children:function(){return this._children||(this._children=[])},each:function(e){var t,n=this.children();for(t=0,length=n.length;t<length;t++)n[t]instanceof SVG.Shape&&e.apply(n[t],[t,n]);return this},remove:function(e){var t=this.children().indexOf(e);return this.children().splice(t,1),this.node.removeChild(e.node),e.parent=null,this},defs:function(){return this._defs||(this._defs=this.put(new SVG.Defs,0))},level:function(){return this.remove(this.defs()).put(this.defs(),0)},group:function(){return this.put(new SVG.G)},rect:function(e,t){return this.put((new SVG.Rect).size(e,t))},circle:function(e){return this.ellipse(e,e)},ellipse:function(e,t){return this.put((new SVG.Ellipse).size(e,t).move(0,0))},line:function(e,t,n,r){return this.put((new SVG.Line).attr({x1:e,y1:t,x2:n,y2:r}))},polyline:function(e){return this.put(new SVG.Wrap(new SVG.Polyline)).plot(e)},polygon:function(e){return this.put(new SVG.Wrap(new SVG.Polygon)).plot(e)},path:function(e){return this.put(new SVG.Wrap(new SVG.Path)).plot(e)},image:function(e,t,n){return t=t!=null?t:100,this.put((new SVG.Image).load(e).size(t,n!=null?n:t))},text:function(e){return this.put((new SVG.Text).text(e))},nested:function(){return this.put(new SVG.Nested)},gradient:function(e,t){return this.defs().gradient(e,t)},pattern:function(e,t,n){return this.defs().pattern(e,t,n)},mask:function(){return this.defs().put(new SVG.Mask)},first:function(){return this.children()[0]instanceof SVG.Defs?this.children()[1]:this.children()[0]},last:function(){return this.children()[this.children().length-1]},viewbox:function(){return arguments.length==0?new SVG.ViewBox(this):this.attr("viewBox",Array.prototype.slice.call(arguments).join(" "))},clear:function(){this._children=[];while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return this}}),SVG.FX=function(e){this.target=e},SVG.extend(SVG.FX,{animate:function(e,t){e=e==null?1e3:e,t=t||"<>";var n,r,i,s=this.target,o=this,u=(new Date).getTime(),a=u+e;return this.interval=setInterval(function(){var f,l,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={},delete this._x,delete this._y,delete this._cx,delete this._cy,delete this._size,delete this._after,delete this._during,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<this.attrs.x2?"x2":"x1",n.x+e).attr(this.attrs.y1<this.attrs.y2?"y2":"y1",n.y+t)}}),SVG.Poly={plot:function(e){return this.attr("points",e||"0,0"),this}},SVG.Polyline=function(){this.constructor.call(this,SVG.create("polyline"))},SVG.Polyline.prototype=new SVG.Shape,SVG.extend(SVG.Polyline,SVG.Poly),SVG.Polygon=function(){this.constructor.call(this,SVG.create("polygon"))},SVG.Polygon.prototype=new SVG.Shape,SVG.extend(SVG.Polygon,SVG.Poly),SVG.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{x:function(e){return this.transform("x",e)},y:function(e){return this.transform("y",e)},plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return this.src=e,e?this.attr("xlink:href",e,SVG.xlink):this}});var e="size family weight stretch variant style".split(" ");SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.styles={"font-size":16,"font-family":"Helvetica","text-anchor":"start"},this._leading=1.2},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{text:function(e){if(e==null)return this.content;this.clear(),this.content=SVG.regex.isBlank.test(e)?"text":e;var t,n,r=e.split("\n");for(t=0,n=r.length;t<n;t++)this.tspan(r[t]);return this.attr("style",this.style())},tspan:function(e){var t=(new SVG.TSpan).text(e);return this.node.appendChild(t.node),this.lines.push(t),t.attr("style",this.style())},center:function(e,t){var n=this.style("text-anchor"),r=this.bbox(),e=n=="start"?e-r.width/2:n=="end"?e+r.width/2:e;return this.move(e,t-r.height/2)},size:function(e){return this.attr("font-size",e)},leading:function(e){return e==null?this._leading:(this._leading=e,this.rebuild())},rebuild:function(){var e,t,n=this.styles["font-size"];for(e=0,t=this.lines.length;e<t;e++)this.lines[e].attr({dy:n*this._leading-(e==0?n*.3:0),x:this.attrs.x||0,style:this.style()});return this},clear:function(){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return this.lines=[],this}}),SVG.TSpan=function(){this.constructor.call(this,SVG.create("tspan"))},SVG.TSpan.prototype=new SVG.Shape,SVG.extend(SVG.TSpan,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.Nested=function(){this.constructor.call(this,SVG.create("svg")),this.style("overflow","visible")},SVG.Nested.prototype=new SVG.Container,SVG._stroke=["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],SVG._fill=["color","opacity","rule"];var t=function(e,t){return t=="color"?e:e+"-"+t};["fill","stroke"].forEach(function(e){var n={};n[e]=function(n){var r;if(typeof n=="string"||SVG.Color.isRgb(n)||SVG.Color.isHsb(n))this.attr(e,n);else for(index=SVG["_"+e].length-1;index>=0;index--)n[SVG["_"+e][index]]!=null&&this.attr(t(e,SVG["_"+e][index]),n[SVG["_"+e][index]]);return this},SVG.extend(SVG.Shape,SVG.FX,n)}),SVG.extend(SVG.Element,SVG.FX,{rotate:function(e,t,n){return this.transform({rotation:e||0,cx:t,cy:n})},skew:function(e,t){return this.transform({skewX:e||0,skewY:t||0})},scale:function(e,t){return this.transform({scaleX:e,scaleY:t==null?e:t})},matrix:function(e){return this.transform({matrix:e})},opacity:function(e){return this.attr("opacity",e)}}),SVG.Text&&SVG.extend(SVG.Text,SVG.FX,{font:function(t){for(var n in t)n=="anchor"?this.attr("text-anchor",t[n]):e.indexOf(n)>-1?this.attr("font-"+n,t[n]):this.attr(n,t[n]);return this}})}).call(this);
\ No newline at end of file +/* svg.js v0.11 - svg regex default color viewbox bbox element container fx event group arrange defs mask clip pattern gradient doc shape rect ellipse line poly path plotable image text nested sugar - svgjs.com/license */ +(function(){this.SVG=function(e){if(SVG.supported)return new SVG.Doc(e)},this.svg=function(e){return console.warn("WARNING: svg() is deprecated, please use SVG() instead."),SVG(e)},SVG.ns="http://www.w3.org/2000/svg",SVG.xlink="http://www.w3.org/1999/xlink",SVG.did=1e3,SVG.eid=function(e){return"Svgjs"+e.charAt(0).toUpperCase()+e.slice(1)+SVG.did++},SVG.create=function(e){var t=document.createElementNS(this.ns,e);return t.setAttribute("id",this.eid(e)),t},SVG.extend=function(){var e,t,n,r;e=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.get=function(e){var t=document.getElementById(e);if(t)return t.instance},SVG.supported=function(){return!!document.createElementNS&&!!document.createElementNS(SVG.ns,"svg").createSVGRect}();if(!SVG.supported)return!1;SVG.regex={test:function(e,t){return this[t].test(e)},unit:/^([\d\.]+)([a-z%]{0,2})$/,hex:/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,rgb:/rgb\((\d+),(\d+),(\d+),([\d\.]+)\)/,hsb:/hsb\((\d+),(\d+),(\d+),([\d\.]+)\)/,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isHsb:/^hsb\(/,isCss:/[^:]+:[^;]+;?/,isStyle:/^font|text|leading|cursor/,isBlank:/^(\s+)?$/,isNumber:/^-?[\d\.]+$/},SVG.default={matrix:"1,0,0,1,0,0",attrs:{"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,fill:"#000",stroke:"#000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0},trans:function(){return{x:0,y:0,scaleX:1,scaleY:1,rotation:0,skewX:0,skewY:0,matrix:this.matrix,a:1,b:0,c:0,d:1,e:0,f:0}}},SVG.Color=function(e){var t;this.r=0,this.g=0,this.b=0,typeof e=="string"?SVG.regex.isRgb.test(e)?(t=SVG.regex.rgb.exec(e.replace(/\s/g,"")),this.r=parseInt(m[1]),this.g=parseInt(m[2]),this.b=parseInt(m[3])):SVG.regex.isHex.test(e)?(t=SVG.regex.hex.exec(this._fullHex(e)),this.r=parseInt(t[1],16),this.g=parseInt(t[2],16),this.b=parseInt(t[3],16)):SVG.regex.isHsb.test(e)&&(t=SVG.regex.hsb.exec(e.replace(/\s/g,"")),e=this._hsbToRgb(t[1],t[2],t[3])):typeof e=="object"&&(SVG.Color.isHsb(e)&&(e=this._hsbToRgb(e.h,e.s,e.b)),this.r=e.r,this.g=e.g,this.b=e.b)},SVG.extend(SVG.Color,{toString:function(){return this.toHex()},toHex:function(){return"#"+this._compToHex(this.r)+this._compToHex(this.g)+this._compToHex(this.b)},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},_hsbToRgb:function(e,t,n){var i,s;e=parseInt(e)%360,e<0&&(e+=360),t=parseInt(t),t=t>100?100:t,n=parseInt(n),n=(n<0?0:n>100?100:n)*255/100,i=n*t/100,s=i*(e*256/60%256)/256;switch(Math.floor(e/60)){case 0:r=n,g=n-i+s,b=n-i;break;case 1:r=n-s,g=n,b=n-i;break;case 2:r=n-i,g=n,b=n-i+s;break;case 3:r=n-i,g=n-s,b=n;break;case 4:r=n-i+s,g=n-i,b=n;break;case 5:r=n,g=n-i,b=n-s}return{r:Math.floor(r+.5),g:Math.floor(g+.5),b:Math.floor(b+.5)}},_fullHex:function(e){return e.length==4?["#",e.substring(1,2),e.substring(1,2),e.substring(2,3),e.substring(2,3),e.substring(3,4),e.substring(3,4)].join(""):e},_compToHex:function(e){var t=e.toString(16);return t.length==1?"0"+t:t}}),SVG.Color.test=function(e){return e+="",SVG.regex.isHex.test(e)||SVG.regex.isRgb.test(e)||SVG.regex.isHsb.test(e)},SVG.Color.isRgb=function(e){return e&&typeof e.r=="number"},SVG.Color.isHsb=function(e){return e&&typeof e.h=="number"},SVG.ViewBox=function(e){var t,n,r,i,s=e.bbox(),o=(e.attr("viewBox")||"").match(/[\d\.]+/g);this.x=s.x,this.y=s.y,this.width=e.node.offsetWidth||e.attr("width"),this.height=e.node.offsetHeight||e.attr("height"),o&&(t=parseFloat(o[0]),n=parseFloat(o[1]),r=parseFloat(o[2])-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.width=t.width*e.trans.scaleX,this.height=t.height*e.trans.scaleY,this.cx=this.x+this.width/2,this.cy=this.y+this.height/2},SVG.Element=function(e){this._stroke=SVG.default.attrs.stroke,this.styles={},this.trans=SVG.default.trans();if(this.node=e)this.type=e.nodeName,this.node.instance=this},SVG.extend(SVG.Element,{x:function(e){return e&&(e/=this.trans.scaleX),this.attr("x",e)},y:function(e){return e&&(e/=this.trans.scaleY),this.attr("y",e)},cx:function(e){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e){return e==null?this.bbox().cy:this.y(e-this.bbox().height/2)},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){return this.attr({width:e,height:t})},clone:function(){var e,t,n=this.type;return e=n=="rect"||n=="ellipse"?this.parent[n](0,0):n=="line"?this.parent[n](0,0,0,0):n=="image"?this.parent[n](this.src):n=="text"?this.parent[n](this.content):n=="path"?this.parent[n](this.attr("d")):n=="polyline"||n=="polygon"?this.parent[n](this.attr("points")):n=="g"?this.parent.group():this.parent[n](),t=this.attr(),delete t.id,e.attr(t),e.trans=this.trans,e.transform({})},remove:function(){return this.parent&&this.parent.removeElement(this),this},doc:function(e){return this._parent(e||SVG.Doc)},attr:function(e,t,n){if(e==null){e={},t=this.node.attributes;for(n=t.length-1;n>=0;n--)e[t[n].nodeName]=t[n].nodeValue;return e}if(typeof e=="object")for(t in e)this.attr(t,e[t]);else if(t===null)this.node.removeAttribute(e);else{if(t==null)return this._isStyle(e)?e=="text"?this.content:e=="leading"?this.leading():this.style(e):(t=this.node.getAttribute(e),t==null?SVG.default.attrs[e]:SVG.regex.test(t,"isNumber")?parseFloat(t):t);if(e=="style")return this.style(t);if(e=="x"&&this instanceof SVG.Text)for(n=this.lines.length-1;n>=0;n--)this.lines[n].attr(e,t);e=="stroke-width"?this.attr("stroke",parseFloat(t)>0?this._stroke:null):e=="stroke"&&(this._stroke=t);if(SVG.Color.test(t)||SVG.Color.isRgb(t)||SVG.Color.isHsb(t))t=(new SVG.Color(t)).toHex();n!=null?this.node.setAttributeNS(n,e,t):this.node.setAttribute(e,t),this._isStyle(e)&&(e=="text"?this.text(t):e=="leading"?this.leading(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.scaleX+","+e.y/e.scaleY+")"),this._offset&&n.push("translate("+ -this._offset.x+","+ -this._offset.y+")"),n.length>0&&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;n<e.length;n++)t=e[n].split(":"),t.length==2&&this.style(t[0].replace(/\s+/g,""),t[1].replace(/^\s+/,"").replace(/\s+$/,""))}else t===null||SVG.regex.test(t,"isBlank")?delete this.styles[e]:this.styles[e]=t;e="";for(t in this.styles)e+=t+":"+this.styles[t]+";";return this.node.setAttribute("style",e),this},data:function(e,t,n){if(arguments.length<2)try{return JSON.parse(this.attr("data-"+e))}catch(r){return this.attr("data-"+e)}else this.attr("data-"+e,t===null?null:n===!0?t:JSON.stringify(t));return this},bbox:function(){return new SVG.BBox(this)},inside:function(e,t){var n=this.bbox();return e>n.x&&t>n.y&&e<n.x+n.width&&t<n.y+n.height},show:function(){return this.style("display","")},hide:function(){return this.style("display","none")},visible:function(){return this.style("display")!="none"},_parent:function(e){var t=this;while(t!=null&&!(t instanceof e))t=t.parent;return t},_isStyle:function(e){return typeof e=="string"?SVG.regex.test(e,"isStyle"):!1},_parseMatrix:function(e){if(e.matrix){var t=e.matrix.replace(/\s/g,"").split(",");t.length==6&&(e.a=parseFloat(t[0]),e.b=parseFloat(t[1]),e.c=parseFloat(t[2]),e.d=parseFloat(t[3]),e.e=parseFloat(t[4]),e.f=parseFloat(t[5]))}return e}}),SVG.Container=function(e){this.constructor.call(this,e)},SVG.Container.prototype=new SVG.Element,SVG.extend(SVG.Container,{children:function(){return this._children||(this._children=[])},add:function(e,t){if(!this.has(e)){t=t==null?this.children().length:t;if(e.parent){var n=e.parent.children().indexOf(e);e.parent.children().splice(n,1)}this.children().splice(t,0,e),this.node.insertBefore(e.node,this.node.childNodes[t]||null),e.parent=this}return this},put:function(e,t){return this.add(e,t),e},has:function(e){return this.children().indexOf(e)>=0},each:function(e){var t,n=this.children();for(t=0,length=n.length;t<length;t++)n[t]instanceof SVG.Shape&&e.apply(n[t],[t,n]);return this},removeElement:function(e){var t=this.children().indexOf(e);return this.children().splice(t,1),this.node.removeChild(e.node),e.parent=null,this},defs:function(){return this._defs||(this._defs=this.put(new SVG.Defs,0))},level:function(){return this.removeElement(this.defs()).put(this.defs(),0)},group:function(){return this.put(new SVG.G)},rect:function(e,t){return this.put((new SVG.Rect).size(e,t))},circle:function(e){return this.ellipse(e,e)},ellipse:function(e,t){return this.put((new SVG.Ellipse).size(e,t).move(0,0))},line:function(e,t,n,r){return this.put((new SVG.Line).attr({x1:e,y1:t,x2:n,y2:r}))},polyline:function(e){return this.put(new SVG.Polyline).plot(e)},polygon:function(e){return this.put(new SVG.Polygon).plot(e)},path:function(e){return this.put(new SVG.Path).plot(e)},image:function(e,t,n){return t=t!=null?t:100,this.put((new SVG.Image).load(e).size(t,n!=null?n:t))},text:function(e){return this.put((new SVG.Text).text(e))},nested:function(){return this.put(new SVG.Nested)},gradient:function(e,t){return this.defs().gradient(e,t)},pattern:function(e,t,n){return this.defs().pattern(e,t,n)},mask:function(){return this.defs().put(new SVG.Mask)},first:function(){return this.children()[0]instanceof SVG.Defs?this.children()[1]:this.children()[0]},last:function(){return this.children()[this.children().length-1]},viewbox:function(e){return arguments.length==0?new SVG.ViewBox(this):(e=arguments.length==1?[e.x,e.y,e.width,e.height]:Array.prototype.slice.call(arguments),this.attr("viewBox",e.join(" ")))},clear:function(){for(var e=this.children().length-1;e>=0;e--)this.removeElement(this.children()[e]);return this}}),SVG.FX=function(e){this.target=e},SVG.extend(SVG.FX,{animate:function(e,t,n){var r=this;return typeof e=="object"&&(n=e.delay,t=e.ease,e=e.duration),this.timeout=setTimeout(function(){e=e==null?1e3:e,t=t||"<>";var n,i,s,o=1e3/60,u=r.target,a=(new Date).getTime(),f=a+e;r.interval=setInterval(function(){var o,l,c=(new Date).getTime(),h=c>f?1:(c-a)/e;if(n==null){n=[];for(l in r.attrs)n.push(l)}if(i==null){i=[];for(l in r.trans)i.push(l)}if(s==null){s=[];for(l in r.styles)s.push(l)}h=t=="<>"?-Math.cos(h*Math.PI)/2+.5:t==">"?Math.sin(h*Math.PI/2):t=="<"?-Math.cos(h*Math.PI/2)+1:t=="-"?h:typeof t=="function"?t(h):h,r._x?u.x(r._at(r._x,h)):r._cx&&u.cx(r._at(r._cx,h)),r._y?u.y(r._at(r._y,h)):r._cy&&u.cy(r._at(r._cy,h)),r._size&&u.size(r._at(r._size.width,h),r._at(r._size.height,h)),r._viewbox&&u.viewbox(r._at(r._viewbox.x,h),r._at(r._viewbox.y,h),r._at(r._viewbox.width,h),r._at(r._viewbox.height,h));for(o=n.length-1;o>=0;o--)u.attr(n[o],r._at(r.attrs[n[o]],h));for(o=i.length-1;o>=0;o--)u.transform(i[o],r._at(r.trans[i[o]],h));for(o=s.length-1;o>=0;o--)u.style(s[o],r._at(r.styles[s[o]],h));r._during&&r._during.call(u,h,function(e,t){return r._at({from:e,to:t},h)}),c>f&&(clearInterval(r.interval),r._after?r._after.apply(u,[r]):r.stop())},e>o?o:e)},n||0),this},bbox:function(){return this.target.bbox()},attr:function(e,t,n){if(typeof e=="object")for(var r in e)this.attr(r,e[r]);else this.attrs[e]={from:this.target.attr(e),to:t};return this},transform:function(e,t){if(arguments.length==1){e=this.target._parseMatrix(e),delete e.matrix;for(t in e)this.trans[t]={from:this.target.trans[t],to:e[t]}}else{var n={};n[e]=t,this.transform(n)}return this},style:function(e,t){if(typeof e=="object")for(var n in e)this.style(n,e[n]);else this.styles[e]={from:this.target.style(e),to:t};return this},x:function(e){return this._x={from:this.target.x(),to:e},this},y:function(e){return this._y={from:this.target.y(),to:e},this},cx:function(e){return this._cx={from:this.target.cx(),to:e},this},cy:function(e){return this._cy={from:this.target.cy(),to:e},this},move:function(e,t){return this.x(e).y(t)},center:function(e,t){return this.cx(e).cy(t)},size:function(e,t){if(this.target instanceof SVG.Text)this.attr("font-size",e);else{var n=this.target.bbox();this._size={width:{from:n.width,to:e},height:{from:n.height,to:t}}}return this},viewbox:function(e,t,n,r){if(this.target instanceof SVG.Container){var i=this.target.viewbox();this._viewbox={x:{from:i.x,to:e},y:{from:i.y,to:t},width:{from:i.width,to:n},height:{from:i.height,to:r}}}return this},during:function(e){return this._during=e,this},after:function(e){return this._after=e,this},stop:function(){return clearTimeout(this.timeout),clearInterval(this.interval),this.attrs={},this.trans={},this.styles={},delete this._x,delete this._y,delete this._cx,delete this._cy,delete this._size,delete this._after,delete this._during,delete this._viewbox,this},_at:function(e,t){return typeof e.from=="number"?e.from+(e.to-e.from)*t:SVG.regex.unit.test(e.to)?this._unit(e,t):e.to&&(e.to.r||SVG.Color.test(e.to))?this._color(e,t):t<1?e.from:e.to},_unit:function(e,t){var n,r;return n=SVG.regex.unit.exec(e.from.toString()),r=parseFloat(n?n[1]:0),n=SVG.regex.unit.exec(e.to),r+(parseFloat(n[1])-r)*t+n[2]},_color:function(e,t){var n,r;return t=t<0?0:t>1?1:t,n=new SVG.Color(e.from),r=new SVG.Color(e.to),(new SVG.Color({r:~~(n.r+(r.r-n.r)*t),g:~~(n.g+(r.g-n.g)*t),b:~~(n.b+(r.b-n.b)*t)})).toHex()}}),SVG.extend(SVG.Element,{animate:function(e,t,n){return(this.fx||(this.fx=new SVG.FX(this))).stop().animate(e,t,n)},stop:function(){return this.fx&&this.fx.stop(),this}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchend","touchmove","touchcancel"].forEach(function(e){SVG.Element.prototype[e]=function(t){var n=this;return this.node["on"+e]=typeof t=="function"?function(){return t.apply(n,arguments)}:null,this}}),SVG.on=function(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent("on"+t,n)},SVG.off=function(e,t,n){e.removeEventListener?e.removeEventListener(t,n,!1):e.detachEvent("on"+t,n)},SVG.extend(SVG.Element,{on:function(e,t){return SVG.on(this.node,e,t),this},off:function(e,t){return SVG.off(this.node,e,t),this}}),SVG.G=function(){this.constructor.call(this,SVG.create("g"))},SVG.G.prototype=new SVG.Container,SVG.extend(SVG.G,{x:function(e){return e==null?this.trans.x:this.transform("x",e)},y:function(e){return e==null?this.trans.y:this.transform("y",e)},defs:function(){return this.doc().defs()}}),SVG.extend(SVG.Element,{siblings:function(){return this.parent.children()},position:function(){return this.siblings().indexOf(this)},next:function(){return this.siblings()[this.position()+1]},previous:function(){return this.siblings()[this.position()-1]},forward:function(){return this.parent.removeElement(this).put(this,this.position()+1)},backward:function(){this.parent.level();var e=this.position();return e>1&&this.parent.removeElement(this).add(this,e-1),this},front:function(){return this.parent.removeElement(this).put(this)},back:function(){return this.parent.level(),this.position()>1&&this.parent.removeElement(this).add(this,0),this}}),SVG.Defs=function(){this.constructor.call(this,SVG.create("defs"))},SVG.Defs.prototype=new SVG.Container,SVG.Mask=function(){this.constructor.call(this,SVG.create("mask"))},SVG.Mask.prototype=new SVG.Container,SVG.extend(SVG.Element,{maskWith:function(e){return this.mask=e instanceof SVG.Mask?e:this.parent.mask().add(e),this.attr("mask","url(#"+this.mask.attr("id")+")")}}),SVG.Clip=function(){this.constructor.call(this,SVG.create("clipPath"))},SVG.Clip.prototype=new SVG.Container,SVG.extend(SVG.Element,{clipWith:function(e){return this.clip=e instanceof SVG.Clip?e:this.parent.clip().add(e),this.attr("clip-path","url(#"+this.clip.attr("id")+")")}}),SVG.extend(SVG.Container,{clip:function(){return this.defs().put(new SVG.Clip)}}),SVG.Pattern=function(e){this.constructor.call(this,SVG.create("pattern"))},SVG.Pattern.prototype=new SVG.Container,SVG.extend(SVG.Pattern,{fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{pattern:function(e,t,n){var r=this.put(new SVG.Pattern);return n(r),r.attr({x:0,y:0,width:e,height:t,patternUnits:"userSpaceOnUse"})}}),SVG.Gradient=function(e){this.constructor.call(this,SVG.create(e+"Gradient")),this.type=e},SVG.Gradient.prototype=new SVG.Container,SVG.extend(SVG.Gradient,{from:function(e,t){return this.type=="radial"?this.attr({fx:e+"%",fy:t+"%"}):this.attr({x1:e+"%",y1:t+"%"})},to:function(e,t){return this.type=="radial"?this.attr({cx:e+"%",cy:t+"%"}):this.attr({x2:e+"%",y2:t+"%"})},radius:function(e){return this.type=="radial"?this.attr({r:e+"%"}):this},at:function(e){return this.put(new SVG.Stop(e))},update:function(e){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return e(this),this},fill:function(){return"url(#"+this.attr("id")+")"}}),SVG.extend(SVG.Defs,{gradient:function(e,t){var n=this.put(new SVG.Gradient(e));return t(n),n}}),SVG.Stop=function(e){this.constructor.call(this,SVG.create("stop")),this.update(e)},SVG.Stop.prototype=new SVG.Element,SVG.extend(SVG.Stop,{update:function(e){var t,n=["opacity","color"];for(t=n.length-1;t>=0;t--)e[n[t]]!=null&&this.style("stop-"+n[t],e[n[t]]);return this.attr("offset",(e.offset!=null?e.offset:this.attr("offset"))+"%")}}),SVG.Doc=function(e){this.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.Rect=function(){this.constructor.call(this,SVG.create("rect"))},SVG.Rect.prototype=new SVG.Shape,SVG.Ellipse=function(){this.constructor.call(this,SVG.create("ellipse"))},SVG.Ellipse.prototype=new SVG.Shape,SVG.extend(SVG.Ellipse,{x:function(e){return e==null?this.cx()-this.attr("rx"):this.cx(e+this.attr("rx"))},y:function(e){return e==null?this.cy()-this.attr("ry"):this.cy(e+this.attr("ry"))},cx:function(e){return e==null?this.attr("cx"):this.attr("cx",e/this.trans.scaleX)},cy:function(e){return e==null?this.attr("cy"):this.attr("cy",e/this.trans.scaleY)},size:function(e,t){return this.attr({rx:e/2,ry:t/2})}}),SVG.Line=function(){this.constructor.call(this,SVG.create("line"))},SVG.Line.prototype=new SVG.Shape,SVG.extend(SVG.Line,{x:function(e){var t=this.bbox();return e==null?t.x:this.attr({x1:this.attr("x1")-t.x+e,x2:this.attr("x2")-t.x+e})},y:function(e){var t=this.bbox();return e==null?t.y:this.attr({y1:this.attr("y1")-t.y+e,y2:this.attr("y2")-t.y+e})},cx:function(e){var t=this.bbox().width/2;return e==null?this.x()+t:this.x(e-t)},cy:function(e){var t=this.bbox().height/2;return e==null?this.y()+t:this.y(e-t)},size:function(e,t){var n=this.bbox();return this.attr(this.attr("x1")<this.attr("x2")?"x2":"x1",n.x+e).attr(this.attr("y1")<this.attr("y2")?"y2":"y1",n.y+t)}}),SVG.Polyline=function(){this.constructor.call(this,SVG.create("polyline"))},SVG.Polyline.prototype=new SVG.Shape,SVG.Polygon=function(){this.constructor.call(this,SVG.create("polygon"))},SVG.Polygon.prototype=new SVG.Shape,SVG.extend(SVG.Polyline,SVG.Polygon,{_plot:function(e){if(Array.isArray(e)){var t,n,r=[];for(t=0,n=e.length;t<n;t++)r.push(e[t].join(","));e=r.length==0?r.join(" "):"0,0"}return this.attr("points",e||"0,0")}}),SVG.Path=function(){this.constructor.call(this,SVG.create("path"))},SVG.Path.prototype=new SVG.Shape,SVG.extend(SVG.Path,{_plot:function(e){return this.attr("d",e||"M0,0")}}),SVG.extend(SVG.Polyline,SVG.Polygon,SVG.Path,{x:function(e){return e==null?this.bbox().x:this.transform("x",e)},y:function(e){return e==null?this.bbox().y:this.transform("y",e)},size:function(e,t){var n=e/this._offset.width;return this.transform({scaleX:n,scaleY:t!=null?t/this._offset.height:n})},plot:function(e){var t=this.trans.scaleX,n=this.trans.scaleY;return this._plot(e),this._offset=this.transform({scaleX:1,scaleY:1}).bbox(),this._offset.x-=this.trans.x,this._offset.y-=this.trans.y,this.transform({scaleX:t,scaleY:n})}}),SVG.Image=function(){this.constructor.call(this,SVG.create("image"))},SVG.Image.prototype=new SVG.Shape,SVG.extend(SVG.Image,{load:function(e){return e?this.attr("xlink:href",this.src=e,SVG.xlink):this}});var e="size family weight stretch variant style".split(" ");SVG.Text=function(){this.constructor.call(this,SVG.create("text")),this.styles={"font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"},this._leading=1.2},SVG.Text.prototype=new SVG.Shape,SVG.extend(SVG.Text,{x:function(e,t){return e==null?t?this.attr("x"):this.bbox().x:(t||(t=this.style("text-anchor"),e=t=="start"?e:t=="end"?e+this.bbox().width:e+this.bbox().width/2),this.attr("x",e))},cx:function(e,t){return e==null?this.bbox().cx:this.x(e-this.bbox().width/2)},cy:function(e,t){return e==null?this.bbox().cy:this.y(t?e:e-this.bbox().height/2)},move:function(e,t,n){return this.x(e,n).y(t)},center:function(e,t,n){return this.cx(e,n).cy(t,n)},text:function(e){if(e==null)return this.content;this.clear(),this.content=SVG.regex.isBlank.test(e)?"text":e;var t,n,r=e.split("\n");for(t=0,n=r.length;t<n;t++)this.tspan(r[t]);return this.attr("textLength",1).attr("textLength",null)},tspan:function(e){var t=(new SVG.TSpan).text(e);return this.node.appendChild(t.node),this.lines.push(t),t.attr("style",this.style())},size:function(e){return this.attr("font-size",e)},leading:function(e){return e==null?this._leading:(this._leading=e,this.rebuild())},rebuild:function(){var e,t,n=this.styles["font-size"];for(e=0,t=this.lines.length;e<t;e++)this.lines[e].attr({dy:n*this._leading-(e==0?n*.276666666:0),x:this.attr("x")||0,style:this.style()});return this},clear:function(){while(this.node.hasChildNodes())this.node.removeChild(this.node.lastChild);return this.lines=[],this}}),SVG.TSpan=function(){this.constructor.call(this,SVG.create("tspan"))},SVG.TSpan.prototype=new SVG.Shape,SVG.extend(SVG.TSpan,{text:function(e){return this.node.appendChild(document.createTextNode(e)),this}}),SVG.Nested=function(){this.constructor.call(this,SVG.create("svg")),this.style("overflow","visible")},SVG.Nested.prototype=new SVG.Container,SVG._stroke=["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],SVG._fill=["color","opacity","rule"];var t=function(e,t){return t=="color"?e:e+"-"+t};["fill","stroke"].forEach(function(e){var n={};n[e]=function(n){var r;if(typeof n=="string"||SVG.Color.isRgb(n)||SVG.Color.isHsb(n))this.attr(e,n);else for(index=SVG["_"+e].length-1;index>=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 |