Reputation: 5334
I need to calculate area of a circle after scaling, following are the codes I am using to calculate it -
function calculateArea(obj){
switch (obj.type){
case 'circle':
alert((Math.PI*obj.radius*obj.radius).toFixed(2));
break;
case 'rect':
return obj.width*obj.height;
break;
}
}
This is working fine if I just create a circle and click on 'calculate area' button. But if I resize circle and then calculate area, it still showing the old area that is at the time of it's creation.
I found object:scaling event and getting width and height after scaling as -
canvas.on("object:scaling", function(e){
var obj = e.target
console.log(obj.width*obj.scaleX);
console.log(obj.height* e.target.scaleY);
});
but don't know how to use these values to calculate updated area, any suggestion please?
Upvotes: 0
Views: 895
Reputation: 15831
Just use
getScaledWidth() → {Number}
Returns width of an object bounding box counting transformations before 2.0 it was named getWidth();
Using this method will return always the scaled width or height (with getScaledHeight()
) in pixel.
Upvotes: 2