Update ellipse.class.js

Mirrored from circle the way it updates width and height following rx and ry of ellipse.
This commit is contained in:
Andrea Bogazzi 2014-09-25 14:29:27 +02:00 committed by asturur
parent e524c13521
commit d0de45e11a
2 changed files with 48 additions and 3 deletions

View file

@ -53,9 +53,46 @@
this.set('rx', options.rx || 0);
this.set('ry', options.ry || 0);
},
this.set('width', this.get('rx') * 2);
this.set('height', this.get('ry') * 2);
/**
* @private
* @param {String} key
* @param {Any} value
* @return {fabric.Ellipse} thisArg
*/
_set: function(key, value) {
this.callSuper('_set', key, value);
switch (key) {
case 'rx':
this.rx = value;
this.set('width', value * 2);
break;
case 'ry':
this.ry = value;
this.set('height', value * 2);
break;
}
return this;
},
/**
* Returns horizontal radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRx: function() {
return this.get('rx') * this.get('scaleX');
},
/**
* Returns Vertical radius of an object (according to how an object is scaled)
* @return {Number}
*/
getRY: function() {
return this.get('ry') * this.get('scaleY');
},
/**

View file

@ -60,10 +60,18 @@
left: 100,
top: 200,
rx: 15,
ry: 25
ry: 25,
width: 30,
height: 50
});
deepEqual(ellipse.toObject(), augmentedProperties);
ellipse.set('rx', 30);
deepEqual(ellipse.width, ellipse.rx * 2);
ellipse.set('scaleX', 2);
deepEqual(ellipse.getRx(), ellipse.rx * ellipse.scaleX);
});
test('render', function() {