diff options
author | wout <wout@impinc.co.uk> | 2013-06-23 14:59:46 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2013-06-23 14:59:46 +0100 |
commit | a72b8a7afb609b9a76c494d9123d78e5c40962bf (patch) | |
tree | fdaacf9d56a3cc9e935ab1a5dcb4ad0458f929e4 /src/gradient.js | |
parent | 5e52bd4f9f309b20bc848d5d45e5e620b17c1ad7 (diff) | |
download | svg.js-a72b8a7afb609b9a76c494d9123d78e5c40962bf.tar.gz svg.js-a72b8a7afb609b9a76c494d9123d78e5c40962bf.zip |
Added SVG.Number, reworked gradient system
Diffstat (limited to 'src/gradient.js')
-rw-r--r-- | src/gradient.js | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/gradient.js b/src/gradient.js index f98a0b0..71da7d1 100644 --- a/src/gradient.js +++ b/src/gradient.js @@ -13,19 +13,19 @@ SVG.extend(SVG.Gradient, { // From position from: function(x, y) { return this.type == 'radial' ? - this.attr({ fx: x + '%', fy: y + '%' }) : - this.attr({ x1: x + '%', y1: y + '%' }) + this.attr({ fx: new SVG.Number(x), fy: new SVG.Number(y) }) : + this.attr({ x1: new SVG.Number(x), y1: new SVG.Number(y) }) } // To position , to: function(x, y) { return this.type == 'radial' ? - this.attr({ cx: x + '%', cy: y + '%' }) : - this.attr({ x2: x + '%', y2: y + '%' }) + this.attr({ cx: new SVG.Number(x), cy: new SVG.Number(y) }) : + this.attr({ x2: new SVG.Number(x), y2: new SVG.Number(y) }) } // Radius for radial gradient -, radius: function(radius) { +, radius: function(r) { return this.type == 'radial' ? - this.attr({ r: radius + '%' }) : + this.attr({ r: new SVG.Number(r) }) : this } // Add a color stop @@ -35,8 +35,7 @@ SVG.extend(SVG.Gradient, { // Update gradient , update: function(block) { /* remove all stops */ - while (this.node.hasChildNodes()) - this.node.removeChild(this.node.lastChild) + this.clear() /* invoke passed block */ block(this) @@ -47,6 +46,10 @@ SVG.extend(SVG.Gradient, { , fill: function() { return 'url(#' + this.attr('id') + ')' } + // Get a stop at the given index +, get: function(i) { + return this.children()[i] + } }) @@ -82,22 +85,18 @@ SVG.Stop = function(stop) { } // Inherit from SVG.Element -SVG.Stop.prototype = new SVG.Element() +SVG.Stop.prototype = new SVG.Element // SVG.extend(SVG.Stop, { // add color stops update: function(o) { - var index - , attr = ['opacity', 'color'] - - /* build style attribute */ - for (index = attr.length - 1; index >= 0; index--) - if (o[attr[index]] != null) - this.style('stop-' + attr[index], o[attr[index]]) - /* set attributes */ - return this.attr('offset', (o.offset != null ? o.offset : this.attr('offset')) + '%') + if (o.opacity != null) this.attr('stop-opacity', o.opacity) + if (o.color != null) this.attr('stop-color', o.color) + if (o.offset != null) this.attr('offset', new SVG.Number(o.offset)) + + return this } }) |