diff options
author | wout <wout@impinc.co.uk> | 2012-12-18 13:16:25 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-18 13:16:25 +0100 |
commit | ecc7c2b21cc484a0a57cd7df02a533c65f7bde97 (patch) | |
tree | ccf3cce51e73e7dfd454d44ce366901a1242635d /src/sugar.js | |
parent | 1d8f6a6bfda2c09a1fafe330ac2d91e9d38e2019 (diff) | |
download | svg.js-ecc7c2b21cc484a0a57cd7df02a533c65f7bde97.tar.gz svg.js-ecc7c2b21cc484a0a57cd7df02a533c65f7bde97.zip |
Added transform()
Diffstat (limited to 'src/sugar.js')
-rw-r--r-- | src/sugar.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/sugar.js b/src/sugar.js new file mode 100644 index 0000000..9b5b482 --- /dev/null +++ b/src/sugar.js @@ -0,0 +1,49 @@ + +// Add shape-specific functions +SVG.extend(SVG.Shape, { + + // set fill color and opacity + fill: function(f) { + if (f.color != null) + this.attr('fill', f.color); + + if (f.opacity != null) + this.attr('fill-opacity', f.opacity); + + return this; + }, + + // set stroke color and opacity + stroke: function(s) { + if (s.color) + this.attr('stroke', s.color); + + var a = ('width opacity linecap linejoin miterlimit dasharray dashoffset').split(' '); + + for (var i = a.length - 1; i >= 0; i--) + if (s[a[i]] != null) + this.attr('stroke-' + a[i], s[a[i]]); + + //-D if (this.attrs['fill-opacity'] == null) + //-D this.fill({ opacity: 0 }); + + return this; + } + +}); + +// Add element-specific functions +SVG.extend(SVG.Element, { + + // rotation + rotate: function(o) { + var b = this.bbox(); + if (o.x == null) o.x = b.cx; + if (o.y == null) o.y = b.cy; + + this.transform('rotate(' + (o.deg || 0) + ' ' + o.x + ' ' + o.y + ')', o.absolute); + + return this; + } + +}); |