W3C home > Mailing lists > Public > www-svg@w3.org > September 2007

Re: Best way to get the the bbox of an element with respect to its transformations?

From: Jake B <otakuj462@gmail.com>
Date: Tue, 11 Sep 2007 13:26:55 -0400
Message-ID: <8e648abd0709111026v78c35a61v7fa034546deef4ba@mail.gmail.com>
To: www-svg@w3.org
Hi, I hate to reply to my own question, but I did some more research, and I
found out that my use case (finding bounding boxes of groups in terms of
their screen coordinates) was actually something that had been requested,
and built into the 1.2 specification as SVGLocatable.getScreenBBox(). Also,
I have a sense of how you would script getScreenBBox if you wanted to stay
in SVG 1.1 world. Basically, to translate the user coordinate system to
screen coordinates, I think I'd have to parse the value of the transform
attribute, then apply each individual transform to the coordinates of the
group's user-space bbox. As I'm building my application in Javascript +
Mozilla native SVG rendering, I believe that I will need to write such a
My question is, though, as a getScreenBBox function was such a common
request, it seems likely that a script would have already been implemented
and might be available somewhere under a public license. This would save me
the trouble of trying to role my own. If anyone is aware of such a script, I
would greatly appreciate it if you would let me know.
Much thanks.


On 9/10/07, Jake B <otakuj462@gmail.com> wrote:
> Hi, I tried sending this message earlier without being subscribed to the
> mailing list, and I don't think it went through. My apologies if you're
> receiving this twice...
> Hello, I was wondering, is there was a simple way to calculate the
> bounding box of an SVG element with respect to its transformations? The
> getBBox method does not seem to take transformations into account.
> I'm using the transform attribute because it seems to be the easiest and
> most elegant way to translate a group of elements. However, I still need to
> get the bounding box of the group in terms of the viewport coordinate space.
> If there is not an easy way to get the bounding box of an element with
> respect to its transform, it seems like there are only two alternatives:
> 1)
> to make a newer, smarter getBBox method that does take transforms into account, or
> 2) to not use translate, instead recursively changing the x,y values
> of every member of a group.
> However, neither of these seems like a very pretty solution, so I am
> somewhat stuck...
> I would greatly appreciate any guidance anyone can provide. Thanks.
> Jake
Received on Tuesday, 11 September 2007 17:27:00 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:11 UTC