(function() { // the 0.0001 offset fixes a bug in Chrome 27 var PIx2 = (Math.PI * 2) - 0.0001, ELLIPSE = 'Ellipse'; /** * Ellipse constructor * @constructor * @augments Kinetic.Shape * @param {Object} config * @param {Object} config.radius defines x and y radius * @@ShapeParams * @@NodeParams * @example * var ellipse = new Kinetic.Ellipse({
* radius : {
* x : 50,
* y : 50
* },
* fill: 'red'
* }); */ Kinetic.Ellipse = function(config) { this.___init(config); }; Kinetic.Ellipse.prototype = { ___init: function(config) { // call super constructor Kinetic.Shape.call(this, config); this.className = ELLIPSE; this.sceneFunc(this._sceneFunc); }, _sceneFunc: function(context) { var r = this.getRadius(), rx = r.x, ry = r.y; context.beginPath(); context.save(); if(rx !== ry) { context.scale(1, ry / rx); } context.arc(0, 0, rx, 0, PIx2, false); context.restore(); context.closePath(); context.fillStrokeShape(this); }, // implements Shape.prototype.getWidth() getWidth: function() { return this.getRadius().x * 2; }, // implements Shape.prototype.getHeight() getHeight: function() { return this.getRadius().y * 2; }, // implements Shape.prototype.setWidth() setWidth: function(width) { Kinetic.Node.prototype.setWidth.call(this, width); this.setRadius({ x: width / 2 }); }, // implements Shape.prototype.setHeight() setHeight: function(height) { Kinetic.Node.prototype.setHeight.call(this, height); this.setRadius({ y: height / 2 }); } }; Kinetic.Util.extend(Kinetic.Ellipse, Kinetic.Shape); // add getters setters Kinetic.Factory.addComponentsGetterSetter(Kinetic.Ellipse, 'radius', ['x', 'y']); /** * get/set radius * @name radius * @method * @memberof Kinetic.Ellipse.prototype * @param {Object} radius * @param {Number} radius.x * @param {Number} radius.y * @returns {Object} * @example * // get radius
* var radius = ellipse.radius();

* * // set radius
* ellipse.radius({
* x: 200,
* y: 100
* }); */ Kinetic.Factory.addGetterSetter(Kinetic.Ellipse, 'radiusX', 0); /** * get/set radius x * @name radiusX * @method * @memberof Kinetic.Ellipse.prototype * @param {Number} x * @returns {Number} * @example * // get radius x
* var radiusX = ellipse.radiusX();

* * // set radius x
* ellipse.radiusX(200); */ Kinetic.Factory.addGetterSetter(Kinetic.Ellipse, 'radiusY', 0); /** * get/set radius y * @name radiusY * @method * @memberof Kinetic.Ellipse.prototype * @param {Number} y * @returns {Number} * @example * // get radius y
* var radiusY = ellipse.radiusY();

* * // set radius y
* ellipse.radiusY(200); */ Kinetic.Collection.mapMethods(Kinetic.Ellipse); })();