diff options
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 |