In Raphel.js, how to get BBox width & height of a group of Raphael objects ?
For example, I have rendered several elements on my Rapheal paper as below:
var paper = Raphael(10, 50, 320, 200);
var st = paper.set();
var c = paper.rect(40, 40, 50, 50, 10);
var e = paper.ellipse(50, 50, 40, 20);
var i = pap开发者_如何学编程er.image("apple.png", 10, 10, 80, 80);
var t = paper.text(50, 50, "Raphaël\nkicks\nbutt!");
...
st.push(c, e, i, t ...);
I tried to use the following way to get BBox width and height of a group of elements:
var myBBox = st.getBBox();
var width = myBBox.width;
var height = myBBox.height;
console.log(width+','+height);
Sometimes it is working, but sometimes I got value Infinity for height. I guess it is a bug of Rapheal. So, If I want to get the current BBox size of my canvas (a group of elements), what is the correct way to do it?
You can do it manually. For each element of group:
Get
left
orx
coordinate. Get the minimal value.var MinLeft
Get
right
coordinate. It can be calculated likeleft
+width
orx2
. Get the maximum value.var MaxRight
Get
top
ory
coordinate. Get the minimal value.var MinTop
Get
bottom
coordinate. It can be calculated liketop
+height
ory2
. Get the maximum value.var MaxBottom
Result: your group's
left
=MinLeft
; your group'stop
=MinTop
; your group'sheight
=MaxBottom-MinTop
; your group'swidth
=MaxRight-MinLeft
精彩评论