diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/array.js | 6 | ||||
-rwxr-xr-x | src/bbox.js | 14 | ||||
-rwxr-xr-x | src/color.js | 28 | ||||
-rwxr-xr-x | src/element.js | 101 | ||||
-rwxr-xr-x | src/ellipse.js | 2 | ||||
-rwxr-xr-x | src/fx.js | 130 | ||||
-rw-r--r-- | src/helpers.js | 124 | ||||
-rwxr-xr-x | src/image.js | 3 | ||||
-rwxr-xr-x | src/line.js | 2 | ||||
-rwxr-xr-x | src/nested.js | 2 | ||||
-rwxr-xr-x | src/number.js | 52 | ||||
-rwxr-xr-x | src/path.js | 2 | ||||
-rwxr-xr-x | src/patharray.js | 39 | ||||
-rwxr-xr-x | src/poly.js | 2 | ||||
-rwxr-xr-x | src/rbox.js | 10 | ||||
-rwxr-xr-x | src/regex.js | 7 | ||||
-rwxr-xr-x | src/relative.js | 4 | ||||
-rwxr-xr-x | src/sugar.js | 2 | ||||
-rwxr-xr-x | src/text.js | 20 |
19 files changed, 277 insertions, 273 deletions
diff --git a/src/array.js b/src/array.js index b239c78..bc79ceb 100755 --- a/src/array.js +++ b/src/array.js @@ -70,6 +70,12 @@ SVG.extend(SVG.Array, { , split: function(string) { return string.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g,'').split(' ') } + // Reverse array +, reverse: function() { + this.value.reverse() + + return this + } }) diff --git a/src/bbox.js b/src/bbox.js index 603b6c9..c68bec5 100755 --- a/src/bbox.js +++ b/src/bbox.js @@ -1,4 +1,4 @@ - + SVG.BBox = function(element) { var box @@ -31,10 +31,9 @@ SVG.BBox = function(element) { 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 + + /* add center, right and bottom */ + boxProperties(this) } @@ -50,9 +49,8 @@ SVG.extend(SVG.BBox, { b.width = Math.max(this.x + this.width, box.x + box.width) - b.x b.height = Math.max(this.y + this.height, box.y + box.height) - b.y - /* add the center */ - b.cx = b.x + b.width / 2 - b.cy = b.y + b.height / 2 + /* add center, right and bottom */ + boxProperties(b) return b } diff --git a/src/color.js b/src/color.js index e73d7e0..956693c 100755 --- a/src/color.js +++ b/src/color.js @@ -8,7 +8,7 @@ SVG.Color = function(color) { this.b = 0 /* parse color */ - if (typeof color == 'string') { + if (typeof color === 'string') { if (SVG.regex.isRgb.test(color)) { /* get rgb values */ match = SVG.regex.rgb.exec(color.replace(/\s/g,'')) @@ -20,7 +20,7 @@ SVG.Color = function(color) { } else if (SVG.regex.isHex.test(color)) { /* get hex values */ - match = SVG.regex.hex.exec(this._fullHex(color)) + match = SVG.regex.hex.exec(fullHex(color)) /* parse numeric values */ this.r = parseInt(match[1], 16) @@ -29,7 +29,7 @@ SVG.Color = function(color) { } - } else if (typeof color == 'object') { + } else if (typeof color === 'object') { this.r = color.r this.g = color.g this.b = color.b @@ -46,9 +46,9 @@ SVG.extend(SVG.Color, { // Build hex value , toHex: function() { return '#' - + this._compToHex(this.r) - + this._compToHex(this.g) - + this._compToHex(this.b) + + compToHex(this.r) + + compToHex(this.g) + + compToHex(this.b) } // Build rgb value , toRgb: function() { @@ -81,23 +81,11 @@ SVG.extend(SVG.Color, { , b: ~~(this.b + (this.destination.b - this.b) * pos) }) } - // Private: ensure to six-based hex -, _fullHex: function(hex) { - return hex.length == 4 ? - [ '#', - hex.substring(1, 2), hex.substring(1, 2) - , hex.substring(2, 3), hex.substring(2, 3) - , hex.substring(3, 4), hex.substring(3, 4) - ].join('') : hex - } - // Private: component to hex value -, _compToHex: function(comp) { - var hex = comp.toString(16) - return hex.length == 1 ? '0' + hex : hex - } }) +// Testers + // Test if given value is a color string SVG.Color.test = function(color) { color += '' diff --git a/src/element.js b/src/element.js index 116e8d1..1e86104 100755 --- a/src/element.js +++ b/src/element.js @@ -4,14 +4,11 @@ SVG.Element = SVG.invent({ create: function(node) { /* make stroke value accessible dynamically */ this._stroke = SVG.defaults.attrs.stroke - - /* initialize style store */ - this.styles = {} - + /* initialize transformation store with defaults */ this.trans = SVG.defaults.trans() - /* keep reference to the element node */ + /* create circular reference */ if (this.node = node) { this.type = node.nodeName this.node.instance = this @@ -22,7 +19,7 @@ SVG.Element = SVG.invent({ , extend: { // Move over x-axis x: function(x) { - if (x) { + if (x != null) { x = new SVG.Number(x) x.value /= this.trans.scaleX } @@ -30,7 +27,7 @@ SVG.Element = SVG.invent({ } // Move over y-axis , y: function(y) { - if (y) { + if (y != null) { y = new SVG.Number(y) y.value /= this.trans.scaleY } @@ -62,7 +59,7 @@ SVG.Element = SVG.invent({ } // Set element size to given width and height , size: function(width, height) { - var p = this._proportionalSize(width, height) + var p = proportionalSize(this.bbox(), width, height) return this.attr({ width: new SVG.Number(p.width) @@ -134,7 +131,7 @@ SVG.Element = SVG.invent({ a = {} v = this.node.attributes for (n = v.length - 1; n >= 0; n--) - a[v[n].nodeName] = SVG.regex.test(v[n].nodeValue, 'isNumber') ? parseFloat(v[n].nodeValue) : v[n].nodeValue + a[v[n].nodeName] = SVG.regex.isNumber.test(v[n].nodeValue) ? parseFloat(v[n].nodeValue) : v[n].nodeValue return a @@ -151,7 +148,7 @@ SVG.Element = SVG.invent({ v = this.node.getAttribute(a) return v == null ? SVG.defaults.attrs[a] : - SVG.regex.test(v, 'isNumber') ? + SVG.regex.isNumber.test(v) ? parseFloat(v) : v } else if (a == 'style') { @@ -176,14 +173,14 @@ SVG.Element = SVG.invent({ }) } - /* ensure full hex color */ - if (SVG.Color.isColor(v)) - v = new SVG.Color(v) - - /* ensure correct numeric values */ - else if (typeof v === 'number') + /* ensure correct numeric values (also accepts NaN and Infinity) */ + if (typeof v === 'number') v = new SVG.Number(v) + /* ensure full hex color */ + else if (SVG.Color.isColor(v)) + v = new SVG.Color(v) + /* parse array values */ else if (Array.isArray(v)) v = new SVG.Array(v) @@ -194,8 +191,8 @@ SVG.Element = SVG.invent({ if (this.leading) this.leading(v) } else { - /* set give attribute on node */ - n != null ? + /* set given attribute on node */ + typeof n === 'string' ? this.node.setAttributeNS(n, a, v.toString()) : this.node.setAttribute(a, v.toString()) } @@ -230,7 +227,7 @@ SVG.Element = SVG.invent({ var transform = [] /* parse matrix */ - o = this._parseMatrix(o) + o = parseMatrix(o) /* merge values */ for (v in o) @@ -284,7 +281,7 @@ SVG.Element = SVG.invent({ , style: function(s, v) { if (arguments.length == 0) { /* get full style */ - return this.attr('style') || '' + return this.node.style.cssText || '' } else if (arguments.length < 2) { /* apply every style individually if an object is passed */ @@ -296,37 +293,19 @@ SVG.Element = SVG.invent({ s = s.split(';') /* apply every definition individually */ - for (var i = 0; i < s.length; i++) { - v = s[i].split(':') - - if (v.length == 2) - this.style(v[0].replace(/\s+/g, ''), v[1].replace(/^\s+/,'').replace(/\s+$/,'')) + for (v = 0; v < s.length; v++) { + v = s[v].split(':') + this.style(v[0].replace(/\s+/g, ''), v[1]) } } else { /* act as a getter if the first and only argument is not an object */ - return this.styles[s] + return this.node.style[camelCase(s)] } - } else if (v === null || SVG.regex.test(v, 'isBlank')) { - /* remove value */ - delete this.styles[s] - } else { - /* store value */ - this.styles[s] = v + this.node.style[camelCase(s)] = v === null || SVG.regex.isBlank.test(v) ? null : v } - /* rebuild style string */ - s = '' - for (v in this.styles) - s += v + ':' + this.styles[v] + ';' - - /* apply style */ - if (s == '') - this.node.removeAttribute('style') - else - this.node.setAttribute('style', s) - return this } // Get bounding box @@ -371,41 +350,5 @@ SVG.Element = SVG.invent({ return element } - // 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 - } - // Private: calculate proportional width and height values when necessary - , _proportionalSize: function(width, height) { - if (width == null || height == null) { - var box = this.bbox() - - if (height == null) - height = box.height / box.width * width - else if (width == null) - width = box.width / box.height * height - } - - return { - width: width - , height: height - } - } } - })
\ No newline at end of file diff --git a/src/ellipse.js b/src/ellipse.js index d84f988..0d23e6e 100755 --- a/src/ellipse.js +++ b/src/ellipse.js @@ -33,7 +33,7 @@ SVG.Ellipse = SVG.invent({ } // Custom size function , size: function(width, height) { - var p = this._proportionalSize(width, height) + var p = proportionalSize(this.bbox(), width, height) return this.attr({ rx: new SVG.Number(p.width).divide(2) @@ -100,30 +100,34 @@ SVG.FX = SVG.invent({ } else { /* run all x-position properties */ if (fx._x) - element.x(at(fx._x, pos)) + element.x(fx._x.at(pos)) else if (fx._cx) - element.cx(at(fx._cx, pos)) + element.cx(fx._cx.at(pos)) /* run all y-position properties */ if (fx._y) - element.y(at(fx._y, pos)) + element.y(fx._y.at(pos)) else if (fx._cy) - element.cy(at(fx._cy, pos)) + element.cy(fx._cy.at(pos)) /* run all size properties */ if (fx._size) - element.size(at(fx._size.width, pos), at(fx._size.height, pos)) + element.size(fx._size.width.at(pos), fx._size.height.at(pos)) } /* run all viewbox properties */ if (fx._viewbox) element.viewbox( - at(fx._viewbox.x, pos) - , at(fx._viewbox.y, pos) - , at(fx._viewbox.width, pos) - , at(fx._viewbox.height, pos) + fx._viewbox.x.at(pos) + , fx._viewbox.y.at(pos) + , fx._viewbox.width.at(pos) + , fx._viewbox.height.at(pos) ) + /* run leading property */ + if (fx._leading) + element.leading(fx._leading.at(pos)) + /* animate attributes */ for (i = akeys.length - 1; i >= 0; i--) element.attr(akeys[i], at(fx.attrs[akeys[i]], pos)) @@ -158,7 +162,7 @@ SVG.FX = SVG.invent({ } /* render function */ - fx.render = function(){ + fx.render = function() { if (fx.situation.play === true) { // This code was borrowed from the emile.js micro framework by Thomas Fuchs, aka MadRobby. @@ -224,7 +228,7 @@ SVG.FX = SVG.invent({ , transform: function(o, v) { if (arguments.length == 1) { /* parse matrix string */ - o = this.target._parseMatrix(o) + o = parseMatrix(o) /* dlete matrixstring from object */ delete o.matrix @@ -256,25 +260,25 @@ SVG.FX = SVG.invent({ } // Animatable x-axis , x: function(x) { - this._x = { from: this.target.x(), to: x } + this._x = new SVG.Number(this.target.x()).morph(x) return this } // Animatable y-axis , y: function(y) { - this._y = { from: this.target.y(), to: y } + this._y = new SVG.Number(this.target.y()).morph(y) return this } // Animatable center x-axis , cx: function(x) { - this._cx = { from: this.target.cx(), to: x } + this._cx = new SVG.Number(this.target.cx()).morph(x) return this } // Animatable center y-axis , cy: function(y) { - this._cy = { from: this.target.cy(), to: y } + this._cy = new SVG.Number(this.target.cy()).morph(y) return this } @@ -297,8 +301,8 @@ SVG.FX = SVG.invent({ var box = this.target.bbox() this._size = { - width: { from: box.width, to: width } - , height: { from: box.height, to: height } + width: new SVG.Number(box.width).morph(width) + , height: new SVG.Number(box.height).morph(height) } } @@ -310,16 +314,23 @@ SVG.FX = SVG.invent({ return this } + // Add leading method + , leading: function(value) { + if (this.target._leading) + this._leading = new SVG.Number(this.target._leading).morph(value) + + 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 } + x: new SVG.Number(box.x).morph(x) + , y: new SVG.Number(box.y).morph(y) + , width: new SVG.Number(box.width).morph(width) + , height: new SVG.Number(box.height).morph(height) } } @@ -354,28 +365,35 @@ SVG.FX = SVG.invent({ return this } // Stop running animation - , stop: function() { - /* stop current animation */ - clearTimeout(this.timeout) - clearInterval(this.interval) - - /* reset storage for properties that need animation */ - this.attrs = {} - this.trans = {} - this.styles = {} - this.situation = {} - - delete this._x - delete this._y - delete this._cx - delete this._cy - delete this._size - delete this._plot - delete this._loop - delete this._after - delete this._during - delete this._viewbox + , stop: function(fulfill) { + /* fulfill animation */ + if (fulfill === true) { + this.animate(0) + } else { + /* stop current animation */ + clearTimeout(this.timeout) + + /* reset storage for properties that need animation */ + this.attrs = {} + this.trans = {} + this.styles = {} + this.situation = {} + + /* delete destinations */ + delete this._x + delete this._y + delete this._cx + delete this._cy + delete this._size + delete this._plot + delete this._loop + delete this._after + delete this._during + delete this._leading + delete this._viewbox + } + return this } // Pause running animation @@ -412,9 +430,9 @@ SVG.FX = SVG.invent({ 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() { + , stop: function(fulfill) { if (this.fx) - this.fx.stop() + this.fx.stop(fulfill) return this } @@ -434,26 +452,4 @@ SVG.FX = SVG.invent({ } } -}) - -// Calculate position according to from and to -function at(o, pos) { - /* number recalculation (don't bother converting to SVG.Number for performance reasons) */ - return typeof o.from == 'number' ? - o.from + (o.to - o.from) * pos : - - /* instance recalculation */ - o instanceof SVG.Color || o instanceof SVG.Number ? o.at(pos) : - - /* for all other values wait until pos has reached 1 to return the final value */ - pos < 1 ? o.from : o.to -} - -// Shim layer with setTimeout fallback by Paul Irish -window.requestAnimFrame = (function(){ - return window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.msRequestAnimationFrame || - function (c) { window.setTimeout(c, 1000 / 60) } -})()
\ No newline at end of file +})
\ No newline at end of file diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000..5a1dd6d --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,124 @@ +// Convert dash-separated-string to camelCase +function camelCase(s) { + return s.toLowerCase().replace(/-(.)/g, function(m, g) { + return g.toUpperCase() + }) +} + +// Ensure to six-based hex +function fullHex(hex) { + return hex.length == 4 ? + [ '#', + hex.substring(1, 2), hex.substring(1, 2) + , hex.substring(2, 3), hex.substring(2, 3) + , hex.substring(3, 4), hex.substring(3, 4) + ].join('') : hex +} + +// Component to hex value +function compToHex(comp) { + var hex = comp.toString(16) + return hex.length == 1 ? '0' + hex : hex +} + +// Calculate proportional width and height values when necessary +function proportionalSize(box, width, height) { + if (width == null || height == null) { + if (height == null) + height = box.height / box.width * width + else if (width == null) + width = box.width / box.height * height + } + + return { + width: width + , height: height + } +} + +// Calculate position according to from and to +function at(o, pos) { + /* number recalculation (don't bother converting to SVG.Number for performance reasons) */ + return typeof o.from == 'number' ? + o.from + (o.to - o.from) * pos : + + /* instance recalculation */ + o instanceof SVG.Color || o instanceof SVG.Number ? o.at(pos) : + + /* for all other values wait until pos has reached 1 to return the final value */ + pos < 1 ? o.from : o.to +} + +// PathArray Helpers +function arrayToString(a) { + for (var i = 0, il = a.length, s = ''; i < il; i++) { + s += a[i][0] + + if (a[i][1] != null) { + s += a[i][1] + + if (a[i][2] != null) { + s += ' ' + s += a[i][2] + + if (a[i][3] != null) { + s += ' ' + s += a[i][3] + s += ' ' + s += a[i][4] + + if (a[i][5] != null) { + s += ' ' + s += a[i][5] + s += ' ' + s += a[i][6] + + if (a[i][7] != null) { + s += ' ' + s += a[i][7] + } + } + } + } + } + } + + return s + ' ' +} + +// Add more bounding box properties +function boxProperties(b) { + b.x2 = b.x + b.width + b.y2 = b.y + b.height + b.cx = b.x + b.width / 2 + b.cy = b.y + b.height / 2 +} + +// Parse a matrix string +function parseMatrix(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 +} + +// Shim layer with setTimeout fallback by Paul Irish +window.requestAnimFrame = (function(){ + return window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.msRequestAnimationFrame || + function (c) { window.setTimeout(c, 1000 / 60) } +})()
\ No newline at end of file diff --git a/src/image.js b/src/image.js index 60d57b1..d70cfb4 100755 --- a/src/image.js +++ b/src/image.js @@ -27,7 +27,7 @@ SVG.Image = SVG.invent({ p.size(self.width(), self.height()) /* callback */ - if (typeof self._loaded == 'function') + if (typeof self._loaded === 'function') self._loaded.call(self, { width: img.width , height: img.height @@ -52,4 +52,5 @@ SVG.Image = SVG.invent({ return this.put(new SVG.Image).load(source).size(width || 0, height || width || 0) } } + })
\ No newline at end of file diff --git a/src/line.js b/src/line.js index bdbbcde..c11a734 100755 --- a/src/line.js +++ b/src/line.js @@ -49,7 +49,7 @@ SVG.Line = SVG.invent({ } // Set line size by width and height , size: function(width, height) { - var p = this._proportionalSize(width, height) + var p = proportionalSize(this.bbox(), width, height) return this.width(p.width).height(p.height) } diff --git a/src/nested.js b/src/nested.js index cd3a0e0..f856e52 100755 --- a/src/nested.js +++ b/src/nested.js @@ -12,7 +12,7 @@ SVG.Nested = SVG.invent({ // Add parent method , construct: { // Create nested svg document - nested: function() { + nested: function() { return this.put(new SVG.Nested) } } diff --git a/src/number.js b/src/number.js index 697d1dc..92ff796 100755 --- a/src/number.js +++ b/src/number.js @@ -6,36 +6,34 @@ SVG.Number = function(value) { this.unit = '' /* parse value */ - switch(typeof value) { - case 'number': - /* ensure a valid numeric value */ - this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value - break - case 'string': - var match = value.match(SVG.regex.unit) + if (typeof value === 'number') { + /* ensure a valid numeric value */ + this.value = isNaN(value) ? 0 : !isFinite(value) ? (value < 0 ? -3.4e+38 : +3.4e+38) : value - if (match) { - /* make value numeric */ - this.value = parseFloat(match[1]) + } else if (typeof value === 'string') { + var match = value.match(SVG.regex.unit) + + if (match) { + /* make value numeric */ + this.value = parseFloat(match[1]) - /* normalize percent value */ - if (match[2] == '%') - this.value /= 100 - else if (match[2] == 's') - this.value *= 1000 + /* normalize percent value */ + if (match[2] == '%') + this.value /= 100 + else if (match[2] == 's') + this.value *= 1000 - /* store unit */ - this.unit = match[2] - } - - break - default: - if (value instanceof SVG.Number) { - this.value = value.value - this.unit = value.unit - } - break + /* store unit */ + this.unit = match[2] + } + + } else { + if (value instanceof SVG.Number) { + this.value = value.value + this.unit = value.unit + } } + } SVG.extend(SVG.Number, { @@ -93,7 +91,7 @@ SVG.extend(SVG.Number, { /* make sure a destination is defined */ if (!this.destination) return this - /* generate morphed number */ + /* generate new morphed number */ return new SVG.Number(this.destination) .minus(this) .times(pos) diff --git a/src/path.js b/src/path.js index ad231dc..773b3d8 100755 --- a/src/path.js +++ b/src/path.js @@ -25,7 +25,7 @@ SVG.Path = SVG.invent({ } // Set element size to given width and height , size: function(width, height) { - var p = this._proportionalSize(width, height) + var p = proportionalSize(this.bbox(), width, height) return this.attr('d', this.array.size(p.width, p.height)) } diff --git a/src/patharray.js b/src/patharray.js index 2ccb7d5..1a2fdd5 100755 --- a/src/patharray.js +++ b/src/patharray.js @@ -201,41 +201,4 @@ SVG.extend(SVG.PathArray, { return SVG.parser.path.getBBox() } -}) - -// PathArray Helpers -function arrayToString(a) { - for (var i = 0, il = a.length, s = ''; i < il; i++) { - s += a[i][0] - - if (a[i][1] != null) { - s += a[i][1] - - if (a[i][2] != null) { - s += ' ' - s += a[i][2] - - if (a[i][3] != null) { - s += ' ' - s += a[i][3] - s += ' ' - s += a[i][4] - - if (a[i][5] != null) { - s += ' ' - s += a[i][5] - s += ' ' - s += a[i][6] - - if (a[i][7] != null) { - s += ' ' - s += a[i][7] - } - } - } - } - } - } - - return s + ' ' -}
\ No newline at end of file +})
\ No newline at end of file diff --git a/src/poly.js b/src/poly.js index 5a0f9b2..1586c77 100755 --- a/src/poly.js +++ b/src/poly.js @@ -64,7 +64,7 @@ SVG.extend(SVG.Polyline, SVG.Polygon, { } // Set element size to given width and height , size: function(width, height) { - var p = this._proportionalSize(width, height) + var p = proportionalSize(this.bbox(), width, height) return this.attr('points', this.array.size(p.width, p.height)) } diff --git a/src/rbox.js b/src/rbox.js index 95cc1e2..30779a4 100755 --- a/src/rbox.js +++ b/src/rbox.js @@ -46,9 +46,8 @@ SVG.RBox = function(element) { this.width = box.width /= zoom this.height = box.height /= zoom - /* add the center */ - this.cx = this.x + this.width / 2 - this.cy = this.y + this.height / 2 + /* add center, right and bottom */ + boxProperties(this) } @@ -64,9 +63,8 @@ SVG.extend(SVG.RBox, { b.width = Math.max(this.x + this.width, box.x + box.width) - b.x b.height = Math.max(this.y + this.height, box.y + box.height) - b.y - /* add the center */ - b.cx = b.x + b.width / 2 - b.cy = b.y + b.height / 2 + /* add center, right and bottom */ + boxProperties(b) return b } diff --git a/src/regex.js b/src/regex.js index c75b46f..c78d9f3 100755 --- a/src/regex.js +++ b/src/regex.js @@ -1,12 +1,7 @@ // Storage for regular expressions 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 diff --git a/src/relative.js b/src/relative.js index 7759bb9..6bb11b7 100755 --- a/src/relative.js +++ b/src/relative.js @@ -2,11 +2,11 @@ SVG.extend(SVG.Element, SVG.FX, { // Relative move over x axis dx: function(x) { - return this.x(this.x() + x) + return this.x((this.target || this).x() + x) } // Relative move over y axis , dy: function(y) { - return this.y(this.y() + y) + return this.y((this.target || this).y() + y) } // Relative move over x and y axes , dmove: function(x, y) { diff --git a/src/sugar.js b/src/sugar.js index 1a96c23..4a8fff8 100755 --- a/src/sugar.js +++ b/src/sugar.js @@ -89,7 +89,7 @@ SVG.extend(SVG.Path, { }) -SVG.extend(SVG.Text, SVG.FX, { +SVG.extend(SVG.Parent, SVG.Text, SVG.FX, { // Set font font: function(o) { for (var k in o) diff --git a/src/text.js b/src/text.js index 9d95b55..170b9de 100755 --- a/src/text.js +++ b/src/text.js @@ -4,9 +4,9 @@ SVG.Text = SVG.invent({ create: function() { this.constructor.call(this, SVG.create('text')) - this._leading = new SVG.Number(1.3) /* store leading value for rebuilding */ - this._rebuild = true /* enable automatic updating of dy values */ - this._build = false /* disable build mode for adding multiple lines */ + this._leading = new SVG.Number(1.3) /* store leading value for rebuilding */ + this._rebuild = true /* enable automatic updating of dy values */ + this._build = false /* disable build mode for adding multiple lines */ /* set default font */ this.attr('font-family', SVG.defaults.attrs['font-family']) @@ -31,11 +31,13 @@ SVG.Text = SVG.invent({ } // Move over y-axis , y: function(y) { + var o = this.attr('y') - this.bbox().y + /* act as getter */ if (y == null) - return this.attr('y') + return this.attr('y') - o - return this.attr('y', y + this.attr('y') - this.bbox().y) + return this.attr('y', y + o) } // Move center over x-axis , cx: function(x) { @@ -45,14 +47,6 @@ SVG.Text = SVG.invent({ , cy: function(y) { 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) { - return this.x(x).y(y) - } - // Move element by its center - , center: function(x, y) { - return this.cx(x).cy(y) - } // Set the text content , text: function(text) { /* act as getter */ |