diff options
author | wout <wout@impinc.co.uk> | 2012-12-16 16:15:47 +0100 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2012-12-16 16:15:47 +0100 |
commit | c6ac1246c271c66733366086f467e381c3fd65a8 (patch) | |
tree | 09ff273e5ffea615ba9555e38a441e5248e37190 /src/shape.js | |
parent | 1fc78fe531ded4bc8a1ed5e176774600b897fcb1 (diff) | |
download | svg.js-c6ac1246c271c66733366086f467e381c3fd65a8.tar.gz svg.js-c6ac1246c271c66733366086f467e381c3fd65a8.zip |
Implemented core library
Diffstat (limited to 'src/shape.js')
-rw-r--r-- | src/shape.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/shape.js b/src/shape.js index e69de29..8295f1c 100644 --- a/src/shape.js +++ b/src/shape.js @@ -0,0 +1,51 @@ + +SVG.Shape = function Shape(element) { + this.drag = new SVG.Draggable(this); + this.constructor.call(this, element); +}; + +// inherit from SVG.Element +SVG.Shape.prototype = new SVG.Element(); + +// set fill color and opacity +SVG.Shape.prototype.fill = function(fill) { + this._formatColor(fill); + + if (fill.color != null) + this.setAttribute('fill', fill.color); + + if (fill.opacity != null) + this.setAttribute('fill-opacity', fill.opacity); + + return this; +}; + +// set stroke color and opacity +SVG.Shape.prototype.stroke = function(stroke) { + this._formatColor(stroke); + + if (stroke.color != null) + this.setAttribute('stroke', stroke.color); + + if (stroke.width != null) + this.setAttribute('stroke-width', stroke.width); + + if (stroke.opacity != null) + this.setAttribute('stroke-opacity', stroke.opacity); + + if (this.attributes['fill-opacity'] == null) + this.fill({ opacity: 0 }); + + return this; +}; + +// ensure correct color string +SVG.Shape.prototype._formatColor = function(obj) { + if (typeof obj.color === 'number') { + obj.color = '' + obj.color.toString(16); + while (obj.color.length < 6) + obj.color = '0' + obj.color; + + return obj.color = '#' + obj.color; + } +};
\ No newline at end of file |