Get BBox of a GROUP of Raphael objects?
Asked Answered
S

1

8

What's the best way to get the bounding box of several Raphael objects as a whole?

Can I put them all in a set and call mySet.getBBox()?

Or do I need to loop through them all, get bbox for each one and calculate the overall height and width?

(Also, I can't use SVG directly - I need VML support.)

Sn answered 2/2, 2011 at 16:59 Comment(0)
S
11

Uh. It's really easy. (Thanks @Dylan):

var paper = Raphael ('test', 100, 100);

var circles = paper.set();

var c1 = paper.circle(70,30,10);
var c2 = paper.circle(50,10,10);
var c3 = paper.circle(10,80,10);

circles.push(c1, c2, c3);

alert(c3.getBBox().width); // --> 20

alert(circles.getBBox().width); // --> 80
Sn answered 8/2, 2011 at 23:49 Comment(2)
Isn't that because you didn't push the c-objects in the circles-set ?Descant
@Descant - wow, my answer was painfully wrong. Thanks for the tip - now updated in the answer.Sn

© 2022 - 2024 — McMap. All rights reserved.